Skip to content

Commit c1b7416

Browse files
committed
fixing bugs
1 parent 350c16b commit c1b7416

File tree

4 files changed

+99
-26
lines changed

4 files changed

+99
-26
lines changed

mtpy/core/mt.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,8 @@ def edit_curve(self, method="default", tolerance=0.05):
11421142
11431143
"""
11441144

1145+
# bring up a gui of some sort.
1146+
11451147
def to_occam1d(self, data_filename=None, mode="det"):
11461148
"""Write an Occam1DData data file.
11471149
:param data_filename: Path to write file, if None returns Occam1DData

mtpy/imaging/plot_stations.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
class PlotStations(PlotBase):
3232
"""Plot station locations in map view.
3333
34+
Can set `x_limits` and `y_limits` to zoom in on a specific area.
35+
or set `image_extent` to plot an image in the background.
36+
or set `pad` to set the padding around the stations.
37+
3438
Uses contextily to get the basemap.
3539
See https://contextily.readthedocs.io/en/latest/index.html for more
3640
information about options.
@@ -115,8 +119,32 @@ def plot(self):
115119
# make a figure instance
116120
self.fig = plt.figure(self.fig_num, self.fig_size, dpi=self.fig_dpi)
117121

122+
if self.pad is None:
123+
self.pad = self._get_pad()
124+
125+
if self.image_extent:
126+
x_limits = (self.image_extent[0], self.image_extent[2])
127+
y_limits = (self.image_extent[1], self.image_extent[3])
128+
elif self.x_limits is not None:
129+
x_limits = self.x_limits
130+
if self.y_limits is None:
131+
y_limits = self._get_ylimits(self.gdf.geometry.y)
132+
else:
133+
y_limits = self.y_limits
134+
elif self.y_limits is not None:
135+
y_limits = self.y_limits
136+
if self.x_limits is None:
137+
x_limits = self._get_xlimits(self.gdf.geometry.x)
138+
else:
139+
x_limits = self.x_limits
140+
else:
141+
x_limits = self._get_xlimits(self.gdf.geometry.x)
142+
y_limits = self._get_ylimits(self.gdf.geometry.y)
143+
118144
# add and axes
119145
self.ax = self.fig.add_subplot(1, 1, 1, aspect="equal")
146+
self.ax.set_xlim(x_limits)
147+
self.ax.set_ylim(y_limits)
120148

121149
# --> plot the background image if desired-----------------------
122150
if self.image_file is not None:
@@ -164,8 +192,6 @@ def plot(self):
164192
f"Could not add base map because {error}"
165193
)
166194

167-
if self.pad is None:
168-
self.pad = self._get_pad()
169195
# set axis properties
170196
if self.plot_cx:
171197
self.ax.set_ylabel("latitude (deg)", fontdict=self.font_dict)
@@ -174,8 +200,6 @@ def plot(self):
174200
self.ax.set_xlabel("relative east (m)", fontdict=self.font_dict)
175201
self.ax.set_ylabel("relative north (m)", fontdict=self.font_dict)
176202
self.ax.grid(alpha=0.35, color=(0.35, 0.35, 0.35), lw=0.35)
177-
self.ax.set_xlim(self._get_xlimits(self.gdf.geometry.x))
178-
self.ax.set_ylim(self._get_ylimits(self.gdf.geometry.y))
179203
self.ax.set_axisbelow(True)
180204

181205
plt.show()

mtpy/modeling/simpeg/data_2d.py

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from simpeg.electromagnetics import natural_source as nsem
1414
from simpeg import data
1515

16+
from mtpy.imaging.mtplot_tools import plot_phase, plot_resistivity
17+
1618
import matplotlib.pyplot as plt
1719

1820

@@ -305,9 +307,15 @@ def plot_response(self, **kwargs):
305307
te_data = self.te_data.dobs.reshape(
306308
(self.n_frequencies, 2, self.n_stations)
307309
)
310+
te_data_errors = self.te_data.standard_deviation.reshape(
311+
(self.n_frequencies, 2, self.n_stations)
312+
)
308313
tm_data = self.tm_data.dobs.reshape(
309314
(self.n_frequencies, 2, self.n_stations)
310315
)
316+
tm_data_errors = self.tm_data.standard_deviation.reshape(
317+
(self.n_frequencies, 2, self.n_stations)
318+
)
311319

312320
if not self.invert_impedance:
313321
ax_xy_res = fig.add_subplot(2, 2, 1)
@@ -358,26 +366,58 @@ def plot_response(self, **kwargs):
358366
2, 2, 4, sharex=ax_xy_res, sharey=ax_xy_phase
359367
)
360368
for ii in range(self.n_stations):
361-
ax_xy_res.loglog(
369+
plot_resistivity(
370+
ax_xy_res,
362371
1.0 / self.frequencies,
363-
np.abs(te_data[:, 0, ii]),
372+
te_data[:, 0, ii],
364373
color=(0.5, 0.5, ii / self.n_stations),
374+
label=self.dataframe.station.unique()[ii],
375+
error=te_data_errors[:, 0, ii],
365376
)
366-
ax_xy_phase.loglog(
377+
plot_phase(
378+
ax_xy_phase,
367379
1.0 / self.frequencies,
368-
np.abs(te_data[:, 1, ii]),
380+
te_data[:, 1, ii],
369381
color=(0.25, 0.25, ii / self.n_stations),
382+
label=self.dataframe.station.unique()[ii],
383+
error=te_data_errors[:, 1, ii],
370384
)
371-
ax_yx_res.loglog(
385+
plot_resistivity(
386+
ax_yx_res,
372387
1.0 / self.frequencies,
373-
np.abs(tm_data[:, 0, ii]),
388+
tm_data[:, 0, ii],
374389
color=(0.5, ii / self.n_stations, 0.75),
390+
label=self.dataframe.station.unique()[ii],
391+
error=tm_data_errors[:, 0, ii],
375392
)
376-
ax_yx_phase.loglog(
393+
plot_phase(
394+
ax_yx_phase,
377395
1.0 / self.frequencies,
378-
np.abs(tm_data[:, 1, ii]),
396+
tm_data[:, 1, ii],
379397
color=(0.25, ii / self.n_stations, 0.75),
398+
label=self.dataframe.station.unique()[ii],
399+
error=tm_data_errors[:, 1, ii],
380400
)
401+
# ax_xy_res.loglog(
402+
# 1.0 / self.frequencies,
403+
# np.abs(te_data[:, 0, ii]),
404+
# color=(0.5, 0.5, ii / self.n_stations),
405+
# )
406+
# ax_xy_phase.loglog(
407+
# 1.0 / self.frequencies,
408+
# np.abs(te_data[:, 1, ii]),
409+
# color=(0.25, 0.25, ii / self.n_stations),
410+
# )
411+
# ax_yx_res.loglog(
412+
# 1.0 / self.frequencies,
413+
# np.abs(tm_data[:, 0, ii]),
414+
# color=(0.5, ii / self.n_stations, 0.75),
415+
# )
416+
# ax_yx_phase.loglog(
417+
# 1.0 / self.frequencies,
418+
# np.abs(tm_data[:, 1, ii]),
419+
# color=(0.25, ii / self.n_stations, 0.75),
420+
# )
381421

382422
ax_xy_phase.set_xlabel("Period (s)")
383423
ax_yx_phase.set_xlabel("Period (s)")

mtpy/modeling/simpeg/make_2d_mesh.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# =============================================================================
1010

1111
import numpy as np
12+
import pandas as pd
13+
from numpy.typing import NDArray
1214

1315
from discretize import TensorMesh
1416
from discretize import TreeMesh
@@ -25,7 +27,12 @@
2527

2628

2729
class StructuredMesh:
28-
def __init__(self, station_locations, frequencies, **kwargs):
30+
def __init__(
31+
self,
32+
station_locations: pd.DataFrame,
33+
frequencies: NDArray | list[float],
34+
**kwargs
35+
) -> None:
2936
self.station_locations = station_locations
3037
self.frequencies = frequencies
3138
self.topography = None
@@ -48,29 +55,29 @@ def __init__(self, station_locations, frequencies, **kwargs):
4855
setattr(self, key, value)
4956

5057
@property
51-
def frequency_max(self):
58+
def frequency_max(self) -> float:
5259
return self.frequencies.max()
5360

5461
@property
55-
def frequency_min(self):
62+
def frequency_min(self) -> float:
5663
return self.frequencies.min()
5764

5865
@property
59-
def z1_layer_thickness(self):
66+
def z1_layer_thickness(self) -> float:
6067
return np.round(
6168
skin_depth(self.frequency_max, self.sigma_background)
6269
/ self.z_factor_max
6370
)
6471

6572
@property
66-
def z_bottom(self):
73+
def z_bottom(self) -> float:
6774
return (
6875
skin_depth(self.sigma_background, self.frequency_min)
6976
* self.z_factor_max
7077
)
7178

7279
@property
73-
def z_mesh_down(self):
80+
def z_mesh_down(self) -> NDArray[np.float64]:
7481
for nz_down in range(self.n_max):
7582
z_mesh_down = (
7683
self.z1_layer_thickness
@@ -81,7 +88,7 @@ def z_mesh_down(self):
8188
return z_mesh_down
8289

8390
@property
84-
def z_mesh_up(self):
91+
def z_mesh_up(self) -> NDArray[np.float64]:
8592
z_mesh_up = [
8693
(
8794
self.z1_layer_thickness,
@@ -91,38 +98,38 @@ def z_mesh_up(self):
9198
]
9299
return dis_utils.unpack_widths(z_mesh_up)
93100

94-
def _make_z_mesh(self):
101+
def _make_z_mesh(self) -> NDArray:
95102
"""
96103
create vertical mesh
97104
"""
98105

99106
return np.r_[self.z_mesh_down, self.z_mesh_up]
100107

101108
@property
102-
def dx(self):
109+
def dx(self) -> float:
103110
d_station = np.diff(self.station_locations[:, 0]).min()
104111
return np.round(d_station / self.x_spacing_factor)
105112

106113
@property
107-
def station_total_length(self):
114+
def station_total_length(self) -> float:
108115
return (
109116
self.station_locations[:, 0].max()
110117
- self.station_locations[:, 0].min()
111118
)
112119

113120
@property
114-
def n_station_x_cells(self):
121+
def n_station_x_cells(self) -> int:
115122
return int(self.station_total_length / self.dx)
116123

117124
@property
118-
def x_padding_cells(self):
125+
def x_padding_cells(self) -> float:
119126
return (
120127
skin_depth(self.sigma_background, self.frequency_min)
121128
* self.x_factor_max
122129
)
123130

124131
@property
125-
def n_x_padding(self):
132+
def n_x_padding(self) -> int:
126133
for npadx in range(self.n_max):
127134
x_pad = dis_utils.unpack_widths(
128135
[
@@ -137,7 +144,7 @@ def n_x_padding(self):
137144
break
138145
return npadx
139146

140-
def _make_x_mesh(self):
147+
def _make_x_mesh(self) -> list[tuple[float, int, float]]:
141148
"""
142149
make horizontal mesh
143150

0 commit comments

Comments
 (0)