Skip to content

Commit a70d92d

Browse files
committed
Update mt_data.py
1 parent cc05449 commit a70d92d

File tree

1 file changed

+15
-39
lines changed

1 file changed

+15
-39
lines changed

mtpy/core/mt_data.py

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ class MTData(OrderedDict, MTStations):
6161

6262
def __init__(self, mt_list=None, **kwargs):
6363

64-
self._coordinate_reference_frame_options = (
65-
COORDINATE_REFERENCE_FRAME_OPTIONS
66-
)
64+
self._coordinate_reference_frame_options = COORDINATE_REFERENCE_FRAME_OPTIONS
6765

6866
self.z_model_error = ModelErrors(
6967
error_value=5,
@@ -150,9 +148,7 @@ def __eq__(self, other):
150148
value_other = getattr(other, attr)
151149

152150
if value_og != value_other:
153-
self.logger.info(
154-
f"Attribute {attr}: {value_og} != {value_other}"
155-
)
151+
self.logger.info(f"Attribute {attr}: {value_og} != {value_other}")
156152
return False
157153
fail = False
158154
if len(self) == len(other):
@@ -279,9 +275,7 @@ def impedance_units(self, value):
279275
if not isinstance(value, str):
280276
raise TypeError("Units input must be a string.")
281277
if value.lower() not in self._impedance_unit_factors.keys():
282-
raise ValueError(
283-
f"{value} is not an acceptable unit for impedance."
284-
)
278+
raise ValueError(f"{value} is not an acceptable unit for impedance.")
285279

286280
self._impedance_units = value
287281

@@ -325,9 +319,7 @@ def get_survey(self, survey_id):
325319
:rtype: :class:`mtpy.MTData`
326320
"""
327321

328-
survey_list = [
329-
mt_obj for key, mt_obj in self.items() if survey_id in key
330-
]
322+
survey_list = [mt_obj for key, mt_obj in self.items() if survey_id in key]
331323
md = self.clone_empty()
332324
md.add_station(survey_list)
333325
return md
@@ -477,9 +469,7 @@ def get_station(self, station_id=None, survey_id=None, station_key=None):
477469
if station_key is not None:
478470
station_key = station_key
479471
else:
480-
station_key = self._get_station_key(
481-
station_id, validate_name(survey_id)
482-
)
472+
station_key = self._get_station_key(station_id, validate_name(survey_id))
483473

484474
try:
485475
return self[station_key]
@@ -634,9 +624,7 @@ def to_geo_df(self, model_locations=False, data_type="station_locations"):
634624
elif data_type in ["both", "shapefiles"]:
635625
df = self.to_mt_dataframe().for_shapefiles
636626
else:
637-
raise ValueError(
638-
f"Option for 'data_type' {data_type} is unsupported."
639-
)
627+
raise ValueError(f"Option for 'data_type' {data_type} is unsupported.")
640628
if model_locations:
641629
gdf = gpd.GeoDataFrame(
642630
df,
@@ -853,8 +841,7 @@ def get_nearby_stations(self, station_key, radius, radius_units="m"):
853841
"Cannot estimate distances in meters without a UTM CRS. Set 'utm_crs' first."
854842
)
855843
sdf["radius"] = np.sqrt(
856-
(local_station.east - sdf.east) ** 2
857-
+ (local_station.north - sdf.north)
844+
(local_station.east - sdf.east) ** 2 + (local_station.north - sdf.north)
858845
)
859846
elif radius_units in ["deg", "degrees"]:
860847
sdf["radius"] = np.sqrt(
@@ -864,9 +851,7 @@ def get_nearby_stations(self, station_key, radius, radius_units="m"):
864851

865852
return [
866853
f"{row.survey}.{row.station}"
867-
for row in sdf.loc[
868-
(sdf.radius <= radius) & (sdf.radius > 0)
869-
].itertuples()
854+
for row in sdf.loc[(sdf.radius <= radius) & (sdf.radius > 0)].itertuples()
870855
]
871856

872857
def estimate_spatial_static_shift(
@@ -910,8 +895,7 @@ def estimate_spatial_static_shift(
910895

911896
interp_periods = local_site.period[
912897
np.where(
913-
(local_site.period >= period_min)
914-
& (local_site.period <= period_max)
898+
(local_site.period >= period_min) & (local_site.period <= period_max)
915899
)
916900
]
917901

@@ -956,9 +940,7 @@ def estimate_starting_rho(self):
956940
fig = plt.figure()
957941

958942
ax = fig.add_subplot(1, 1, 1)
959-
(l1,) = ax.loglog(
960-
mean_rho.index, mean_rho.res_det, lw=2, color=(0.75, 0.25, 0)
961-
)
943+
(l1,) = ax.loglog(mean_rho.index, mean_rho.res_det, lw=2, color=(0.75, 0.25, 0))
962944
(l2,) = ax.loglog(
963945
median_rho.index, median_rho.res_det, lw=2, color=(0, 0.25, 0.75)
964946
)
@@ -979,9 +961,7 @@ def estimate_starting_rho(self):
979961
)
980962

981963
ax.set_xlabel("Period (s)", fontdict={"size": 12, "weight": "bold"})
982-
ax.set_ylabel(
983-
"Resistivity (Ohm-m)", fontdict={"size": 12, "weight": "bold"}
984-
)
964+
ax.set_ylabel("Resistivity (Ohm-m)", fontdict={"size": 12, "weight": "bold"})
985965

986966
ax.legend(
987967
[l1, l2],
@@ -1206,7 +1186,7 @@ def to_simpeg_2d(self, **kwargs):
12061186
- `invert_tm` -> bool
12071187
"""
12081188

1209-
return Simpeg2DData(self.to_dataframe(), **kwargs)
1189+
return Simpeg2DData(self.to_dataframe(impedance_units="ohm"), **kwargs)
12101190

12111191
def to_simpeg_3d(self, **kwargs):
12121192
"""Create a data object that Simpeg can work with.
@@ -1228,7 +1208,7 @@ def to_simpeg_3d(self, **kwargs):
12281208
- invert_types = ["real", "imaginary"]
12291209
"""
12301210

1231-
return Simpeg3DData(self.to_dataframe(), **kwargs)
1211+
return Simpeg3DData(self.to_dataframe(impedance_units="ohm"), **kwargs)
12321212

12331213
def plot_mt_response(
12341214
self, station_key=None, station_id=None, survey_id=None, **kwargs
@@ -1262,9 +1242,7 @@ def plot_mt_response(
12621242
mt_data = MTData()
12631243
if isinstance(survey_id, (list, tuple)):
12641244
if len(survey_id) != len(station_key):
1265-
raise ValueError(
1266-
"Number of survey must match number of stations"
1267-
)
1245+
raise ValueError("Number of survey must match number of stations")
12681246
elif isinstance(survey_id, (str, type(None))):
12691247
survey_id = [survey_id] * len(station_id)
12701248
for survey, station in zip(survey_id, station_id):
@@ -1514,9 +1492,7 @@ def to_shp_pt_tipper(
15141492
:rtype: dictionary
15151493
"""
15161494

1517-
sc = ShapefileCreator(
1518-
self.to_mt_dataframe(), output_crs, save_dir=save_dir
1519-
)
1495+
sc = ShapefileCreator(self.to_mt_dataframe(), output_crs, save_dir=save_dir)
15201496
sc.utm = utm
15211497
if ellipse_size is None and pt:
15221498
sc.ellipse_size = sc.estimate_ellipse_size()

0 commit comments

Comments
 (0)