18
18
Z ,
19
19
Tipper ,
20
20
COORDINATE_REFERENCE_FRAME_OPTIONS ,
21
+ MT_TO_OHM_FACTOR ,
22
+ IMPEDANCE_UNITS ,
21
23
)
22
24
from mtpy .core .mt_location import MTLocation
23
25
from mtpy .core .mt_dataframe import MTDataFrame
@@ -78,7 +80,7 @@ class MT(TF, MTLocation):
78
80
79
81
"""
80
82
81
- def __init__ (self , fn = None , ** kwargs ):
83
+ def __init__ (self , fn = None , impedance_units = "mt" , ** kwargs ):
82
84
tf_kwargs = {}
83
85
for key in [
84
86
"period" ,
@@ -117,6 +119,9 @@ def __init__(self, fn=None, **kwargs):
117
119
self .station_metadata .transfer_function .sign_convention
118
120
)
119
121
122
+ self ._impedance_unit_factors = IMPEDANCE_UNITS
123
+ self .impedance_units = impedance_units
124
+
120
125
for key , value in kwargs .items ():
121
126
setattr (self , key , value )
122
127
@@ -215,6 +220,23 @@ def coordinate_reference_frame(self, value):
215
220
216
221
self .station_metadata .transfer_function .sign_convention = value
217
222
223
+ @property
224
+ def impedance_units (self ):
225
+ """impedance units"""
226
+ return self ._impedance_units
227
+
228
+ @impedance_units .setter
229
+ def impedance_units (self , value ):
230
+ """impedance units setter options are [ mt | ohm ]"""
231
+ if not isinstance (value , str ):
232
+ raise TypeError ("Units input must be a string." )
233
+ if value .lower () not in self ._impedance_unit_factors .keys ():
234
+ raise ValueError (
235
+ f"{ value } is not an acceptable unit for impedance."
236
+ )
237
+
238
+ self ._impedance_units = value
239
+
218
240
@property
219
241
def rotation_angle (self ):
220
242
"""Rotation angle in degrees from north. In the coordinate reference frame"""
@@ -291,6 +313,7 @@ def Z(self):
291
313
z_error = self .impedance_error .to_numpy (),
292
314
frequency = self .frequency ,
293
315
z_model_error = self .impedance_model_error .to_numpy (),
316
+ units = self .impedance_units ,
294
317
)
295
318
return Z ()
296
319
@@ -301,6 +324,9 @@ def Z(self, z_object):
301
324
recalculate phase tensor and invariants, which shouldn't change except
302
325
for strike angle.
303
326
"""
327
+ # if a z object is given the underlying data is in mt units, even
328
+ # if the units are set to ohm.
329
+ z_object .units = "mt"
304
330
if not isinstance (z_object .frequency , type (None )):
305
331
if self .frequency .size != z_object .frequency .size :
306
332
self .frequency = z_object .frequency
@@ -638,7 +664,7 @@ def plot_depth_of_penetration(self, **kwargs):
638
664
639
665
return PlotPenetrationDepth1D (self , ** kwargs )
640
666
641
- def to_dataframe (self , utm_crs = None , cols = None ):
667
+ def to_dataframe (self , utm_crs = None , cols = None , impedance_units = "mt" ):
642
668
"""Create a dataframe from the transfer function for use with plotting
643
669
and modeling.
644
670
:param cols:
@@ -648,6 +674,8 @@ def to_dataframe(self, utm_crs=None, cols=None):
648
674
:param eter utm_crs: The utm zone to project station to, could be a
649
675
name, pyproj.CRS, EPSG number, or anything that pyproj.CRS can intake.
650
676
:type eter utm_crs: string, int, :class:`pyproj.CRS`
677
+ :param impedance_units: ["mt" [mV/km/nT] | "ohm" [Ohms] ]
678
+ :type impedance_units: str
651
679
"""
652
680
if utm_crs is not None :
653
681
self .utm_crs = utm_crs
@@ -671,19 +699,22 @@ def to_dataframe(self, utm_crs=None, cols=None):
671
699
672
700
mt_df .dataframe .loc [:, "period" ] = self .period
673
701
if self .has_impedance ():
674
- mt_df .from_z_object (self .Z )
702
+ z_object = self .Z
703
+ z_object .units = impedance_units
704
+ mt_df .from_z_object (z_object )
705
+ mt_df .from_z_object (z_object )
675
706
if self .has_tipper ():
676
707
mt_df .from_t_object (self .Tipper )
677
708
678
709
return mt_df
679
710
680
- def from_dataframe (self , mt_df ):
711
+ def from_dataframe (self , mt_df , impedance_units = "mt" ):
681
712
"""Fill transfer function attributes from a dataframe for a single station.
682
713
:param mt_df:
683
714
:param df: DESCRIPTION.
684
715
:type df: TYPE
685
- :return: DESCRIPTION.
686
- :rtype: TYPE
716
+ :param impedance_units: ["mt" [mV/km/nT] | "ohm" [Ohms] ]
717
+ :type impedance_units: str
687
718
"""
688
719
689
720
if not isinstance (mt_df , MTDataFrame ):
@@ -717,11 +748,9 @@ def from_dataframe(self, mt_df):
717
748
718
749
self .tf_id = self .station
719
750
720
- # self._transfer_function = self._initialize_transfer_function(
721
- # mt_df.period
722
- # )
723
-
724
- self .Z = mt_df .to_z_object ()
751
+ z_obj = mt_df .to_z_object ()
752
+ z_obj .units = impedance_units
753
+ self .Z = z_obj
725
754
self .Tipper = mt_df .to_t_object ()
726
755
727
756
def compute_model_z_errors (
0 commit comments