Skip to content

Commit 0b2bd01

Browse files
committed
adding logic for matplotlib versions
1 parent be8faf1 commit 0b2bd01

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

mtpy/imaging/mtplot_tools/plot_settings.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import matplotlib.colors as colors
1414
import matplotlib.colorbar as mcb
15+
from matplotlib import __version__ as matplotlib_version
1516

1617
from . import MTEllipse, MTArrows
1718

@@ -350,7 +351,13 @@ def det_error_bar_properties(self):
350351

351352
@property
352353
def font_dict(self):
353-
return {"fontsize": self.font_size + 2, "fontweight": self.font_weight}
354+
if int(matplotlib_version[2]) < 9:
355+
return {"size": self.font_size + 2, "weight": self.font_weight}
356+
else:
357+
return {
358+
"fontsize": self.font_size + 2,
359+
"fontweight": self.font_weight,
360+
}
354361

355362
def make_pt_cb(self, ax):
356363
cmap = mtcl.cmapdict[self.ellipse_cmap]

mtpy/modeling/simpeg/recipes/inversion_1d.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def __init__(self, mt_dataframe=None, **kwargs):
5353
self.rho_initial = 100
5454
self.rho_reference = 100
5555
self.output_dict = None
56+
self.max_iterations = 40
5657

5758
for key, value in kwargs.items():
5859
setattr(self, key, value)
@@ -192,12 +193,35 @@ def cull_from_difference(self, sub_df, max_diff_res=1.0, max_diff_phase=10):
192193
np.where(np.log10(abs(np.diff(sub_df.res))) > max_diff_res)[0] + 1
193194
] = 0
194195

195-
self._sub_df = sub_df.loc[(sub_df != 0).all(axis=1)]
196+
return sub_df.loc[(sub_df != 0).all(axis=1)]
196197

197-
def cull_from_interpolated(
198-
self,
199-
):
200-
pass
198+
def cull_from_interpolated(self, sub_df, tolerance=0.1, s_factor=2):
199+
"""
200+
create a cubic spline as a smooth version of the data and then
201+
find points a certain distance away to remove.
202+
203+
:param : DESCRIPTION
204+
:type : TYPE
205+
:return: DESCRIPTION
206+
:rtype: TYPE
207+
208+
"""
209+
210+
from scipy import interpolate
211+
212+
spline_res = interpolate.splrep(
213+
sub_df.period,
214+
sub_df.resistivity,
215+
s=s_factor * len(sub_df.period),
216+
)
217+
218+
bad_res = np.where(
219+
abs(
220+
interpolate.splev(sub_df.period, spline_res)
221+
- sub_df.resistivity
222+
)
223+
> tolerance
224+
)
201225

202226
def cull_from_model(self, iteration):
203227
"""
@@ -244,7 +268,7 @@ def run_fixed_layer_inversion(
244268

245269
# Cull the data
246270
if cull_from_difference:
247-
self.cull_from_difference(self._sub_df)
271+
self._sub_df = self.cull_from_difference(self._sub_df)
248272

249273
source_list = []
250274
for freq in self.frequencies:
@@ -316,7 +340,7 @@ def run_fixed_layer_inversion(
316340
reg.norms = [p_s, p_z]
317341
# Reach target misfit for L2 solution, then use IRLS until model stops changing.
318342
IRLS = directives.Update_IRLS(
319-
max_irls_iterations=40, minGNiter=1, f_min_change=1e-5
343+
max_irls_iterations=maxIter, minGNiter=1, f_min_change=1e-5
320344
)
321345

322346
# The directives are defined as a list.

0 commit comments

Comments
 (0)