Skip to content

Commit

Permalink
Merge pull request #66 from MTgeophysics/updates
Browse files Browse the repository at this point in the history
Fix bug in MTData, added impedance units, updated simpeg 2d recipe.
  • Loading branch information
kujaku11 authored Oct 24, 2024
2 parents 392a56b + 050b731 commit 8784a36
Show file tree
Hide file tree
Showing 24 changed files with 1,569 additions and 349 deletions.
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

0 comments on commit 8784a36

Please sign in to comment.