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

Updates #40

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
cc73324
updated smalle bug in data, added
kujaku11 Jun 12, 2024
288e257
updates to fix reading in of wsinv3d initial model
alkirkby Jun 26, 2024
cc81363
try to fix deprecation errors so tests pass
alkirkby Jun 26, 2024
3bee0af
Update mt_data.py
kujaku11 Jun 29, 2024
25efd3c
add apply_bounding_box to mtdata
kujaku11 Jun 29, 2024
6ac5e77
Update mt_data.py
kujaku11 Jun 29, 2024
f66b461
Merge branch 'main' into updates
kujaku11 Jun 29, 2024
15daa50
Merge branch 'fix_issue_34' into updates
kujaku11 Jun 29, 2024
796e5f3
changing arrow direction to point towards a conductor
kujaku11 Jul 1, 2024
c0d1ec5
Update plot_mt_responses.py
kujaku11 Jul 1, 2024
0460696
Merge pull request #41 from MTgeophysics/fix_issue38
kujaku11 Jul 1, 2024
88386a5
Update base.py
kujaku11 Jul 9, 2024
576a8ae
updates to reading wsinv3d files
alkirkby Jul 16, 2024
165f8d2
updates to fix reading in of wsinv3d initial model
alkirkby Jun 26, 2024
d43483a
updates to reading wsinv3d files
alkirkby Jul 16, 2024
5dd2412
fixes to reading wsinv3d data
alkirkby Jul 17, 2024
ff00dbe
Merge branch 'ak2' of https://github.com/MTgeophysics/mtpy-v2 into ak2
alkirkby Jul 17, 2024
84955c0
Update residual.py
kujaku11 Jul 25, 2024
055102d
add capability to read tipper
alkirkby Jul 26, 2024
cb74367
updates to fix reading in of wsinv3d initial model
alkirkby Jun 26, 2024
089f4df
updates to reading wsinv3d files
alkirkby Jul 16, 2024
f18d7ee
add capability to read tipper
alkirkby Jul 26, 2024
09531af
Merge branch 'ak2' of https://github.com/MTgeophysics/mtpy-v2 into ak2
alkirkby Jul 26, 2024
2e3acdf
Update plot_mt_response.py
kujaku11 Jul 26, 2024
655eeb5
updating how resistivity limits are estimated
kujaku11 Jul 26, 2024
4843486
Update test_mt_location.py
kujaku11 Jul 26, 2024
d7d032a
Merge branch 'updates' into ak2
kujaku11 Jul 26, 2024
0dc2dfb
Merge pull request #43 from MTgeophysics/ak2
kujaku11 Jul 26, 2024
9a0f25c
Update plot_phase_tensor_maps.py
kujaku11 Jul 26, 2024
7f4253b
adding ltipper egend to pt maps
kujaku11 Jul 26, 2024
6e269dd
Update plot_phase_tensor_pseudosection.py
kujaku11 Jul 26, 2024
56e1731
remove print statement
alkirkby Aug 2, 2024
6ff4d65
Update structured_mesh_3d.py
kujaku11 Aug 6, 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
50 changes: 49 additions & 1 deletion mtpy/core/mt_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,38 @@
except KeyError:
raise KeyError(f"Could not find {station_key} in MTData.")

def apply_bounding_box(self, lon_min, lon_max, lat_min, lat_max):
"""
Apply a bounding box


:param lon_min: DESCRIPTION
:type lon_min: TYPE
:param lon_max: DESCRIPTION
:type lon_max: TYPE
:param lat_min: DESCRIPTION
:type lat_min: TYPE
:param lat_max: DESCRIPTION
:type lat_max: TYPE
:return: DESCRIPTION
:rtype: TYPE

"""

bb_df = self.station_locations.loc[

Check warning on line 442 in mtpy/core/mt_data.py

View check run for this annotation

Codecov / codecov/patch

mtpy/core/mt_data.py#L442

Added line #L442 was not covered by tests
(self.station_locations.longitude >= lon_min)
& (self.station_locations.longitude <= lon_max)
& (self.station_locations.latitude >= lat_min)
& (self.station_locations.latitude <= lat_max)
]

station_keys = [

Check warning on line 449 in mtpy/core/mt_data.py

View check run for this annotation

Codecov / codecov/patch

mtpy/core/mt_data.py#L449

Added line #L449 was not covered by tests
f"{survey}.{station}"
for survey, station in zip(bb_df.survey, bb_df.station)
]

return self.get_subset(station_keys)

Check warning on line 454 in mtpy/core/mt_data.py

View check run for this annotation

Codecov / codecov/patch

mtpy/core/mt_data.py#L454

Added line #L454 was not covered by tests

def get_subset(self, station_list):
"""
get a subset of the data from a list of stations, could be station_id
Expand Down Expand Up @@ -1199,6 +1231,22 @@

return PlotPhaseTensorMaps(mt_data=self, **kwargs)

def plot_tipper_map(self, **kwargs):
"""
Plot Phase tensor maps for transfer functions in the working_dataframe

.. seealso:: :class:`mtpy.imaging.PlotPhaseTensorMaps`

:param **kwargs: DESCRIPTION
:type **kwargs: TYPE
:return: DESCRIPTION
:rtype: TYPE

"""
kwargs["plot_pt"] = False
kwargs["plot_tipper"] = "yri"
return PlotPhaseTensorMaps(mt_data=self, **kwargs)

Check warning on line 1248 in mtpy/core/mt_data.py

View check run for this annotation

Codecov / codecov/patch

mtpy/core/mt_data.py#L1246-L1248

Added lines #L1246 - L1248 were not covered by tests

def plot_phase_tensor_pseudosection(self, mt_data=None, **kwargs):
"""
Plot a pseudo section of phase tensor ellipses and induction vectors
Expand Down Expand Up @@ -1306,7 +1354,7 @@

return PlotResidualPTMaps(survey_data_01, survey_data_02, **kwargs)

def to_shp(
def to_shp_pt_tipper(
self,
save_dir,
output_crs=None,
Expand Down
9 changes: 6 additions & 3 deletions mtpy/imaging/mtplot_tools/arrows.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@author: jpeacock
"""


# ==============================================================================
# Arrows properties for induction vectors
# ==============================================================================
Expand Down Expand Up @@ -36,8 +37,8 @@ class MTArrows:
scaling by 'size'

* 'direction : [ 0 | 1 ]
- 0 for arrows to point toward a conductor
- 1 for arrow to point away from conductor
- 0 for arrows to point away a conductor
- 1 for arrow to point toward from conductor

"""

Expand All @@ -51,7 +52,9 @@ def __init__(self, **kwargs):
self.arrow_threshold = 2
self.arrow_color_imag = "c"
self.arrow_color_real = "k"
self.arrow_direction = 0
# the data is inherently pointing away from conductor, need to flip
# to be in parkinson convention
self.arrow_direction = 1

# Set class property values from kwargs and pop them
for v in vars(self):
Expand Down
24 changes: 11 additions & 13 deletions mtpy/imaging/mtplot_tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,32 +336,30 @@
np.array(
[
[
tf.z_interp_dict["zxx"]["real"](1 / self.plot_period)[
0
]
tf.z_interp_dict["zxx"]["real"](1 / self.plot_period)[0]
+ 1j
* tf.z_interp_dict["zxx"]["imag"](
1.0 / self.plot_period
)[0],
tf.z_interp_dict["zxy"]["real"](
1.0 / self.plot_period
)[0]
tf.z_interp_dict["zxy"]["real"](1.0 / self.plot_period)[
0
]
+ 1j
* tf.z_interp_dict["zxy"]["imag"](
1.0 / self.plot_period
)[0],
],
[
tf.z_interp_dict["zyx"]["real"](
1.0 / self.plot_period
)[0]
tf.z_interp_dict["zyx"]["real"](1.0 / self.plot_period)[
0
]
+ 1j
* tf.z_interp_dict["zyx"]["imag"](
1.0 / self.plot_period
)[0],
tf.z_interp_dict["zyy"]["real"](
1.0 / self.plot_period
)[0]
tf.z_interp_dict["zyy"]["real"](1.0 / self.plot_period)[
0
]
+ 1j
* tf.z_interp_dict["zyy"]["imag"](
1.0 / self.plot_period
Expand Down Expand Up @@ -568,7 +566,7 @@

"""

return add_raster(ax, raster_fn, add_colorbar=True, **kwargs)
return add_raster(ax, raster_fn, add_colorbar=add_colorbar, **kwargs)

Check warning on line 569 in mtpy/imaging/mtplot_tools/base.py

View check run for this annotation

Codecov / codecov/patch

mtpy/imaging/mtplot_tools/base.py#L569

Added line #L569 was not covered by tests


class PlotBaseProfile(PlotBase):
Expand Down
126 changes: 52 additions & 74 deletions mtpy/imaging/mtplot_tools/plot_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,40 @@
10 ** (np.ceil(np.log10(period.max()))),
)

def _estimate_resistivity_min(self, res_array):
"""
estimate resistivity minimum
"""

nz = np.nonzero(res_array)
return np.nanmin(res_array[nz])

def _estimate_resistivity_max(self, res_array):
"""
estimate resistivity maximum
"""

nz = np.nonzero(res_array)
return np.nanmax(res_array[nz])

def _compute_power_ten_min(self, value):
return 10 ** (np.floor(np.log10(value)))

def _compute_power_ten_max(self, value):
return 10 ** (np.ceil(np.log10(value)))

def _estimate_resistivity_limits_min(self, res_list):

return self._compute_power_ten_min(
min([self._estimate_resistivity_min(rr) for rr in res_list])
)

def _estimate_resistivity_limits_max(self, res_list):

return self._compute_power_ten_max(
max([self._estimate_resistivity_max(rr) for rr in res_list])
)

def set_resistivity_limits(self, resistivity, mode="od", scale="log"):
"""
set resistivity limits
Expand All @@ -176,82 +210,26 @@
"""

if mode in ["od"]:
try:
nz_xy = np.nonzero(resistivity[:, 0, 1])
nz_yx = np.nonzero(resistivity[:, 1, 0])
limits = [
10
** (
np.floor(
np.log10(
min(
[
np.nanmin(resistivity[nz_xy, 0, 1]),
np.nanmin(resistivity[nz_yx, 1, 0]),
]
)
)
)
),
10
** (
np.ceil(
np.log10(
max(
[
np.nanmax(resistivity[nz_xy, 0, 1]),
np.nanmax(resistivity[nz_yx, 1, 0]),
]
)
)
)
),
]
except (ValueError, TypeError):
limits = [0.1, 10000]
res_list = [resistivity[:, 0, 1], resistivity[:, 1, 0]]

elif mode == "d":
try:
nz_xx = np.nonzero(resistivity[:, 0, 1])
nz_yy = np.nonzero(resistivity[:, 1, 0])
limits = [
10
** (
np.floor(
np.log10(
min(
[
np.nanmin(resistivity[nz_xx, 0, 0]),
np.nanmin(resistivity[nz_yy, 1, 1]),
]
)
)
)
),
10
** (
np.ceil(
np.log10(
max(
[
np.nanmax(resistivity[nz_xx, 0, 0]),
np.nanmax(resistivity[nz_yy, 1, 1]),
]
)
)
)
),
]
except (ValueError, TypeError):
limits = [0.1, 10000]
res_list = [resistivity[:, 0, 0], resistivity[:, 1, 1]]

Check warning on line 216 in mtpy/imaging/mtplot_tools/plot_settings.py

View check run for this annotation

Codecov / codecov/patch

mtpy/imaging/mtplot_tools/plot_settings.py#L216

Added line #L216 was not covered by tests
elif mode in ["det", "det_only"]:
try:
nz = np.nonzero(resistivity)
limits = [
10 ** (np.floor(np.log10(np.nanmin(resistivity[nz])))),
10 ** (np.ceil(np.log10(np.nanmax(resistivity[nz])))),
]
except (ValueError, TypeError):
limits = [0.1, 10000]
res_list = [resistivity]
elif mode in ["all"]:
res_list = [

Check warning on line 220 in mtpy/imaging/mtplot_tools/plot_settings.py

View check run for this annotation

Codecov / codecov/patch

mtpy/imaging/mtplot_tools/plot_settings.py#L218-L220

Added lines #L218 - L220 were not covered by tests
resistivity[:, 0, 0],
resistivity[:, 0, 1],
resistivity[:, 1, 0],
resistivity[:, 1, 1],
]
try:
limits = [
self._estimate_resistivity_limits_min(res_list),
self._estimate_resistivity_limits_max(res_list),
]
except (ValueError, TypeError):
limits = [0.1, 10000]

Check warning on line 232 in mtpy/imaging/mtplot_tools/plot_settings.py

View check run for this annotation

Codecov / codecov/patch

mtpy/imaging/mtplot_tools/plot_settings.py#L231-L232

Added lines #L231 - L232 were not covered by tests
if scale == "log":
if limits[0] == 0:
limits[0] = 0.1
Expand Down
17 changes: 13 additions & 4 deletions mtpy/imaging/mtplot_tools/plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ def plot_tipper_lateral(
font_size=6,
legend=True,
zero_reference=False,
arrow_direction=1,
):
"""

Expand All @@ -357,11 +358,19 @@ def plot_tipper_lateral(
return None, None, None

if plot_tipper.find("y") == 0 or plot_tipper:
txr = t_obj.mag_real * np.cos(np.deg2rad(-t_obj.angle_real))
tyr = t_obj.mag_real * np.sin(np.deg2rad(-t_obj.angle_real))
txr = t_obj.mag_real * np.cos(
np.deg2rad(-t_obj.angle_real) + arrow_direction * np.pi
)
tyr = t_obj.mag_real * np.sin(
np.deg2rad(-t_obj.angle_real) + arrow_direction * np.pi
)

txi = t_obj.mag_imag * np.cos(np.deg2rad(-t_obj.angle_imag))
tyi = t_obj.mag_imag * np.sin(np.deg2rad(-t_obj.angle_imag))
txi = t_obj.mag_imag * np.cos(
np.deg2rad(-t_obj.angle_imag) + arrow_direction * np.pi
)
tyi = t_obj.mag_imag * np.sin(
np.deg2rad(-t_obj.angle_imag) + arrow_direction * np.pi
)

nt = len(txr)
period = 1.0 / t_obj.frequency
Expand Down
18 changes: 13 additions & 5 deletions mtpy/imaging/plot_mt_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@
2,
subplot_spec=gs_master[0],
height_ratios=[2, 1.5],
hspace=0.05,
wspace=0.15,
hspace=self.subplot_hspace,
wspace=self.subplot_wspace,
)

# --> make figure for xy,yx components
Expand Down Expand Up @@ -482,6 +482,7 @@
self.arrow_real_properties,
self.arrow_imag_properties,
self.font_size,
arrow_direction=self.arrow_direction,
)
if self.plot_tipper.find("y") >= 0:
self.axt.set_xlabel("Period (s)", fontdict=self.font_dict)
Expand Down Expand Up @@ -579,9 +580,14 @@

if self.plot_z:
if self.res_limits is None:
self.res_limits = self.set_resistivity_limits(
self.Z.resistivity
)
if self.plot_num == 1:
self.res_limits = self.set_resistivity_limits(
self.Z.resistivity
)
elif self.plot_num == 2 or self.plot_num == 3:
self.res_limits = self.set_resistivity_limits(

Check warning on line 588 in mtpy/imaging/plot_mt_response.py

View check run for this annotation

Codecov / codecov/patch

mtpy/imaging/plot_mt_response.py#L587-L588

Added lines #L587 - L588 were not covered by tests
self.Z.resistivity, mode="all"
)

eb_list, labels = self._plot_resistivity(
self.axr, self.period, self.Z, mode="od"
Expand All @@ -594,9 +600,11 @@
if self.plot_num == 2:
self._plot_resistivity(self.axr2, self.period, self.Z, mode="d")
self._plot_phase(self.axp2, self.period, self.Z, mode="d")

# ===Plot the Determinant if desired================================
if self.plot_num == 3:
self._plot_determinant()

self._plot_tipper()
self._plot_pt()

Expand Down
Loading
Loading