Skip to content

Commit 8784a36

Browse files
authored
Merge pull request #66 from MTgeophysics/updates
Fix bug in MTData, added impedance units, updated simpeg 2d recipe.
2 parents 392a56b + 050b731 commit 8784a36

File tree

24 files changed

+1569
-349
lines changed

24 files changed

+1569
-349
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 2.0.11
2+
current_version = 2.0.12
33
files = setup.py mtpy/__init__.py README.md docs/source/conf.py
44
commit = True
55
tag = True

HISTORY.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,14 @@ History
5858
* Occam2d fixes by @alkirkby in https://github.com/MTgeophysics/mtpy-v2/pull/56
5959
* Updates by @kujaku11 in https://github.com/MTgeophysics/mtpy-v2/pull/61
6060

61-
**Full Changelog**: https://github.com/MTgeophysics/mtpy-v2/compare/v2.0.10...v2.0.11
61+
**Full Changelog**: https://github.com/MTgeophysics/mtpy-v2/compare/v2.0.10...v2.0.11
62+
63+
2.0.12 (2024-10-22)
64+
----------------------------
65+
66+
* Fix rotations again by @kujaku11 in https://github.com/MTgeophysics/mtpy-v2/pull/57
67+
* Pin numpy versions <2.0 by @kkappler in https://github.com/MTgeophysics/mtpy-v2/pull/62
68+
* Occam2d fixes by @alkirkby in https://github.com/MTgeophysics/mtpy-v2/pull/56
69+
* Updates by @kujaku11 in https://github.com/MTgeophysics/mtpy-v2/pull/61
70+
71+
**Full Changelog**: https://github.com/MTgeophysics/mtpy-v2/compare/v2.0.10...v2.0.12

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[![Documentation Status](https://readthedocs.org/projects/mtpy-v2/badge/?version=latest)](https://mtpy-v2.readthedocs.io/en/latest/?badge=latest)
88
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/MTgeophysics/mtpy-v2/main)
99

10-
## Version 2.0.11
10+
## Version 2.0.12
1111

1212
# Description
1313

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
#
6868

6969
# The short X.Y version.
70-
version = "2.0.11"
70+
version = "2.0.12"
7171
# The full version, including alpha/beta/rc tags.
72-
release = "2.0.11"
72+
release = "2.0.12"
7373

7474
# The language for content autogenerated by Sphinx. Refer to documentation
7575
# for a list of supported languages.

mtpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from mtpy.imaging.mtcolors import MT_CMAP_DICT, register_cmaps
1919

2020

21-
__version__ = "2.0.11"
21+
__version__ = "2.0.12"
2222
__all__ = ["MT", "MTData", "MTCollection"]
2323

2424
# =============================================================================

mtpy/core/mt.py

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414

1515
from mt_metadata.transfer_functions.core import TF
1616

17-
from mtpy.core import Z, Tipper, COORDINATE_REFERENCE_FRAME_OPTIONS
17+
from mtpy.core.transfer_function import IMPEDANCE_UNITS
18+
from mtpy.core import (
19+
Z,
20+
Tipper,
21+
COORDINATE_REFERENCE_FRAME_OPTIONS,
22+
)
1823
from mtpy.core.mt_location import MTLocation
1924
from mtpy.core.mt_dataframe import MTDataFrame
2025
from mtpy.utils.estimate_tf_quality_factor import EMTFStats
@@ -74,7 +79,7 @@ class MT(TF, MTLocation):
7479
7580
"""
7681

77-
def __init__(self, fn=None, **kwargs):
82+
def __init__(self, fn=None, impedance_units="mt", **kwargs):
7883
tf_kwargs = {}
7984
for key in [
8085
"period",
@@ -113,6 +118,9 @@ def __init__(self, fn=None, **kwargs):
113118
self.station_metadata.transfer_function.sign_convention
114119
)
115120

121+
self._impedance_unit_factors = IMPEDANCE_UNITS
122+
self.impedance_units = impedance_units
123+
116124
for key, value in kwargs.items():
117125
setattr(self, key, value)
118126

@@ -132,6 +140,7 @@ def clone_empty(self):
132140
new_mt_obj.model_elevation = self.model_elevation
133141
new_mt_obj._rotation_angle = self._rotation_angle
134142
new_mt_obj.profile_offset = self.profile_offset
143+
new_mt_obj.impedance_units = self.impedance_units
135144

136145
return new_mt_obj
137146

@@ -211,6 +220,23 @@ def coordinate_reference_frame(self, value):
211220

212221
self.station_metadata.transfer_function.sign_convention = value
213222

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+
214240
@property
215241
def rotation_angle(self):
216242
"""Rotation angle in degrees from north. In the coordinate reference frame"""
@@ -279,15 +305,17 @@ def rotate(self, theta_r, inplace=True):
279305

280306
@property
281307
def Z(self):
282-
r"""Mtpy.core.z.Z object to hold impedance tenso."""
308+
r"""Mtpy.core.z.Z object to hold impedance tensor."""
283309

284310
if self.has_impedance():
285-
return Z(
311+
z_object = Z(
286312
z=self.impedance.to_numpy(),
287313
z_error=self.impedance_error.to_numpy(),
288314
frequency=self.frequency,
289315
z_model_error=self.impedance_model_error.to_numpy(),
290316
)
317+
z_object.units = self.impedance_units
318+
return z_object
291319
return Z()
292320

293321
@Z.setter
@@ -296,16 +324,24 @@ def Z(self, z_object):
296324
297325
recalculate phase tensor and invariants, which shouldn't change except
298326
for strike angle.
327+
328+
Be sure to have appropriate units set
299329
"""
330+
# if a z object is given the underlying data is in mt units, even
331+
# if the units are set to ohm.
332+
self.impedance_units = z_object.units
300333
if not isinstance(z_object.frequency, type(None)):
301334
if self.frequency.size != z_object.frequency.size:
302335
self.frequency = z_object.frequency
303336

304337
elif not (self.frequency == z_object.frequency).all():
305338
self.frequency = z_object.frequency
306-
self.impedance = z_object.z
307-
self.impedance_error = z_object.z_error
308-
self.impedance_model_error = z_object.z_model_error
339+
# set underlying data to units of mt
340+
self.impedance = z_object._dataset.transfer_function.values
341+
self.impedance_error = z_object._dataset.transfer_function_error.values
342+
self.impedance_model_error = (
343+
z_object._dataset.transfer_function_model_error.values
344+
)
309345

310346
@property
311347
def Tipper(self):
@@ -634,7 +670,7 @@ def plot_depth_of_penetration(self, **kwargs):
634670

635671
return PlotPenetrationDepth1D(self, **kwargs)
636672

637-
def to_dataframe(self, utm_crs=None, cols=None):
673+
def to_dataframe(self, utm_crs=None, cols=None, impedance_units="mt"):
638674
"""Create a dataframe from the transfer function for use with plotting
639675
and modeling.
640676
:param cols:
@@ -644,6 +680,8 @@ def to_dataframe(self, utm_crs=None, cols=None):
644680
:param eter utm_crs: The utm zone to project station to, could be a
645681
name, pyproj.CRS, EPSG number, or anything that pyproj.CRS can intake.
646682
:type eter utm_crs: string, int, :class:`pyproj.CRS`
683+
:param impedance_units: ["mt" [mV/km/nT] | "ohm" [Ohms] ]
684+
:type impedance_units: str
647685
"""
648686
if utm_crs is not None:
649687
self.utm_crs = utm_crs
@@ -667,19 +705,21 @@ def to_dataframe(self, utm_crs=None, cols=None):
667705

668706
mt_df.dataframe.loc[:, "period"] = self.period
669707
if self.has_impedance():
670-
mt_df.from_z_object(self.Z)
708+
z_object = self.Z
709+
z_object.units = impedance_units
710+
mt_df.from_z_object(z_object)
671711
if self.has_tipper():
672712
mt_df.from_t_object(self.Tipper)
673713

674714
return mt_df
675715

676-
def from_dataframe(self, mt_df):
716+
def from_dataframe(self, mt_df, impedance_units="mt"):
677717
"""Fill transfer function attributes from a dataframe for a single station.
678718
:param mt_df:
679719
:param df: DESCRIPTION.
680720
:type df: TYPE
681-
:return: DESCRIPTION.
682-
:rtype: TYPE
721+
:param impedance_units: ["mt" [mV/km/nT] | "ohm" [Ohms] ]
722+
:type impedance_units: str
683723
"""
684724

685725
if not isinstance(mt_df, MTDataFrame):
@@ -713,11 +753,9 @@ def from_dataframe(self, mt_df):
713753

714754
self.tf_id = self.station
715755

716-
# self._transfer_function = self._initialize_transfer_function(
717-
# mt_df.period
718-
# )
719-
720-
self.Z = mt_df.to_z_object()
756+
z_obj = mt_df.to_z_object()
757+
z_obj.units = impedance_units
758+
self.Z = z_obj
721759
self.Tipper = mt_df.to_t_object()
722760

723761
def compute_model_z_errors(
@@ -1072,9 +1110,7 @@ def add_white_noise(self, value, inplace=True):
10721110
] = self._transfer_function.transfer_function.real * (
10731111
noise_real
10741112
) + (
1075-
1j
1076-
* self._transfer_function.transfer_function.imag
1077-
* noise_imag
1113+
1j * self._transfer_function.transfer_function.imag * noise_imag
10781114
)
10791115

10801116
self._transfer_function["transfer_function_error"] = (
@@ -1088,9 +1124,7 @@ def add_white_noise(self, value, inplace=True):
10881124
] = self._transfer_function.transfer_function.real * (
10891125
noise_real
10901126
) + (
1091-
1j
1092-
* self._transfer_function.transfer_function.imag
1093-
* noise_imag
1127+
1j * self._transfer_function.transfer_function.imag * noise_imag
10941128
)
10951129

10961130
self._transfer_function["transfer_function_error"] = (

0 commit comments

Comments
 (0)