Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in MTData #66

Merged
merged 37 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ea24492
needed to add in flag for rotating inplace.
kujaku11 Oct 17, 2024
f4e6269
Update plot_mt_response.py
kujaku11 Oct 17, 2024
a4a7925
update how mtdata if mt_list is given.
kujaku11 Oct 17, 2024
946fe6a
adding test for mtdata
kujaku11 Oct 18, 2024
1e83521
updated deepcopy
kujaku11 Oct 18, 2024
d5d7d52
updating mtdata
kujaku11 Oct 18, 2024
aedf12c
updating failed test
kujaku11 Oct 18, 2024
75df010
updating mtdata and tests
kujaku11 Oct 18, 2024
123bb77
Update test_mt_data.py
kujaku11 Oct 18, 2024
bbce9c3
Update test_mt_data.py
kujaku11 Oct 18, 2024
e1a8617
Update inversion_2d.py
kujaku11 Oct 18, 2024
044e0d4
removed bad variable
kujaku11 Oct 18, 2024
e1c64f1
Update z.py
kujaku11 Oct 18, 2024
8f80b15
Update z.py
kujaku11 Oct 19, 2024
4f0eec1
updating z with units
kujaku11 Oct 21, 2024
474f342
updating how z units are propagated
kujaku11 Oct 21, 2024
eca1588
updating tests
kujaku11 Oct 21, 2024
91e6153
updating how units are propagated.
kujaku11 Oct 21, 2024
c17b899
updating units propagation
kujaku11 Oct 22, 2024
46096df
Update mt_dataframe.py
kujaku11 Oct 22, 2024
2c2155b
update mt with impedance units
kujaku11 Oct 22, 2024
49bd65c
adding impedance units to mt_data
kujaku11 Oct 22, 2024
3a68d55
added impedance_units to mt_data
kujaku11 Oct 22, 2024
d5fef18
added tensor mesh to simpeg 2d
kujaku11 Oct 22, 2024
44a4af1
updating simpe2d recipe
kujaku11 Oct 22, 2024
34b3c22
Update test_simpeg_2d_inversion_recipe.py
kujaku11 Oct 22, 2024
87e07df
Update test_simpeg_2d_inversion_recipe.py
kujaku11 Oct 22, 2024
7f400f6
sorting out how to create the data
kujaku11 Oct 22, 2024
62635aa
Update data_2d.py
kujaku11 Oct 22, 2024
6040c3e
adding impedance option to simpeg_2d
kujaku11 Oct 23, 2024
e08cb87
updating tests
kujaku11 Oct 23, 2024
eeb745e
Update data_2d.py
kujaku11 Oct 23, 2024
cae0dc1
Update inversion_2d.py
kujaku11 Oct 23, 2024
87df5a3
updating plots
kujaku11 Oct 23, 2024
66d95ca
Update inversion_2d.py
kujaku11 Oct 23, 2024
643ceac
Bump version: 2.0.11 → 2.0.12
kujaku11 Oct 24, 2024
050b731
Update HISTORY.rst
kujaku11 Oct 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.0.11
current_version = 2.0.12
files = setup.py mtpy/__init__.py README.md docs/source/conf.py
commit = True
tag = True
12 changes: 11 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,14 @@ History
* Occam2d fixes by @alkirkby in https://github.com/MTgeophysics/mtpy-v2/pull/56
* Updates by @kujaku11 in https://github.com/MTgeophysics/mtpy-v2/pull/61

**Full Changelog**: https://github.com/MTgeophysics/mtpy-v2/compare/v2.0.10...v2.0.11
**Full Changelog**: https://github.com/MTgeophysics/mtpy-v2/compare/v2.0.10...v2.0.11

2.0.12 (2024-10-22)
----------------------------

* Fix rotations again by @kujaku11 in https://github.com/MTgeophysics/mtpy-v2/pull/57
* Pin numpy versions <2.0 by @kkappler in https://github.com/MTgeophysics/mtpy-v2/pull/62
* Occam2d fixes by @alkirkby in https://github.com/MTgeophysics/mtpy-v2/pull/56
* Updates by @kujaku11 in https://github.com/MTgeophysics/mtpy-v2/pull/61

**Full Changelog**: https://github.com/MTgeophysics/mtpy-v2/compare/v2.0.10...v2.0.12
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Documentation Status](https://readthedocs.org/projects/mtpy-v2/badge/?version=latest)](https://mtpy-v2.readthedocs.io/en/latest/?badge=latest)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/MTgeophysics/mtpy-v2/main)

## Version 2.0.11
## Version 2.0.12

# Description

Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
#

# The short X.Y version.
version = "2.0.11"
version = "2.0.12"
# The full version, including alpha/beta/rc tags.
release = "2.0.11"
release = "2.0.12"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion mtpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from mtpy.imaging.mtcolors import MT_CMAP_DICT, register_cmaps


__version__ = "2.0.11"
__version__ = "2.0.12"
__all__ = ["MT", "MTData", "MTCollection"]

# =============================================================================
Expand Down
80 changes: 57 additions & 23 deletions mtpy/core/mt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@

from mt_metadata.transfer_functions.core import TF

from mtpy.core import Z, Tipper, COORDINATE_REFERENCE_FRAME_OPTIONS
from mtpy.core.transfer_function import IMPEDANCE_UNITS
from mtpy.core import (
Z,
Tipper,
COORDINATE_REFERENCE_FRAME_OPTIONS,
)
from mtpy.core.mt_location import MTLocation
from mtpy.core.mt_dataframe import MTDataFrame
from mtpy.utils.estimate_tf_quality_factor import EMTFStats
Expand Down Expand Up @@ -74,7 +79,7 @@ class MT(TF, MTLocation):

"""

def __init__(self, fn=None, **kwargs):
def __init__(self, fn=None, impedance_units="mt", **kwargs):
tf_kwargs = {}
for key in [
"period",
Expand Down Expand Up @@ -113,6 +118,9 @@ def __init__(self, fn=None, **kwargs):
self.station_metadata.transfer_function.sign_convention
)

self._impedance_unit_factors = IMPEDANCE_UNITS
self.impedance_units = impedance_units

for key, value in kwargs.items():
setattr(self, key, value)

Expand All @@ -132,6 +140,7 @@ def clone_empty(self):
new_mt_obj.model_elevation = self.model_elevation
new_mt_obj._rotation_angle = self._rotation_angle
new_mt_obj.profile_offset = self.profile_offset
new_mt_obj.impedance_units = self.impedance_units

return new_mt_obj

Expand Down Expand Up @@ -211,6 +220,23 @@ def coordinate_reference_frame(self, value):

self.station_metadata.transfer_function.sign_convention = value

@property
def impedance_units(self):
"""impedance units"""
return self._impedance_units

@impedance_units.setter
def impedance_units(self, value):
"""impedance units setter options are [ mt | ohm ]"""
if not isinstance(value, str):
raise TypeError("Units input must be a string.")
if value.lower() not in self._impedance_unit_factors.keys():
raise ValueError(
f"{value} is not an acceptable unit for impedance."
)

self._impedance_units = value

@property
def rotation_angle(self):
"""Rotation angle in degrees from north. In the coordinate reference frame"""
Expand Down Expand Up @@ -279,15 +305,17 @@ def rotate(self, theta_r, inplace=True):

@property
def Z(self):
r"""Mtpy.core.z.Z object to hold impedance tenso."""
r"""Mtpy.core.z.Z object to hold impedance tensor."""

if self.has_impedance():
return Z(
z_object = Z(
z=self.impedance.to_numpy(),
z_error=self.impedance_error.to_numpy(),
frequency=self.frequency,
z_model_error=self.impedance_model_error.to_numpy(),
)
z_object.units = self.impedance_units
return z_object
return Z()

@Z.setter
Expand All @@ -296,16 +324,24 @@ def Z(self, z_object):

recalculate phase tensor and invariants, which shouldn't change except
for strike angle.

Be sure to have appropriate units set
"""
# if a z object is given the underlying data is in mt units, even
# if the units are set to ohm.
self.impedance_units = z_object.units
if not isinstance(z_object.frequency, type(None)):
if self.frequency.size != z_object.frequency.size:
self.frequency = z_object.frequency

elif not (self.frequency == z_object.frequency).all():
self.frequency = z_object.frequency
self.impedance = z_object.z
self.impedance_error = z_object.z_error
self.impedance_model_error = z_object.z_model_error
# set underlying data to units of mt
self.impedance = z_object._dataset.transfer_function.values
self.impedance_error = z_object._dataset.transfer_function_error.values
self.impedance_model_error = (
z_object._dataset.transfer_function_model_error.values
)

@property
def Tipper(self):
Expand Down Expand Up @@ -634,7 +670,7 @@ def plot_depth_of_penetration(self, **kwargs):

return PlotPenetrationDepth1D(self, **kwargs)

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

mt_df.dataframe.loc[:, "period"] = self.period
if self.has_impedance():
mt_df.from_z_object(self.Z)
z_object = self.Z
z_object.units = impedance_units
mt_df.from_z_object(z_object)
if self.has_tipper():
mt_df.from_t_object(self.Tipper)

return mt_df

def from_dataframe(self, mt_df):
def from_dataframe(self, mt_df, impedance_units="mt"):
"""Fill transfer function attributes from a dataframe for a single station.
:param mt_df:
:param df: DESCRIPTION.
:type df: TYPE
:return: DESCRIPTION.
:rtype: TYPE
:param impedance_units: ["mt" [mV/km/nT] | "ohm" [Ohms] ]
:type impedance_units: str
"""

if not isinstance(mt_df, MTDataFrame):
Expand Down Expand Up @@ -713,11 +753,9 @@ def from_dataframe(self, mt_df):

self.tf_id = self.station

# self._transfer_function = self._initialize_transfer_function(
# mt_df.period
# )

self.Z = mt_df.to_z_object()
z_obj = mt_df.to_z_object()
z_obj.units = impedance_units
self.Z = z_obj
self.Tipper = mt_df.to_t_object()

def compute_model_z_errors(
Expand Down Expand Up @@ -1072,9 +1110,7 @@ def add_white_noise(self, value, inplace=True):
] = self._transfer_function.transfer_function.real * (
noise_real
) + (
1j
* self._transfer_function.transfer_function.imag
* noise_imag
1j * self._transfer_function.transfer_function.imag * noise_imag
)

self._transfer_function["transfer_function_error"] = (
Expand All @@ -1088,9 +1124,7 @@ def add_white_noise(self, value, inplace=True):
] = self._transfer_function.transfer_function.real * (
noise_real
) + (
1j
* self._transfer_function.transfer_function.imag
* noise_imag
1j * self._transfer_function.transfer_function.imag * noise_imag
)

self._transfer_function["transfer_function_error"] = (
Expand Down
Loading
Loading