Skip to content

Commit d09cc8c

Browse files
committed
plot_sourcepars: new plot type: static stress drop vs. depth
1 parent ba6b215 commit d09cc8c

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Copyright (c) 2011-2024 Claudio Satriano <satriano@ipgp.fr>
1111
- Stacked spectra: color spectral curves according to the weighting function
1212
- Spectral plots: show information on the reason why a fit failed
1313
- `plot_sourcepars`: possibility of selecting the latest runid for each event
14+
- `plot_sourcepars`: new plot type: static stress drop vs. depth
1415

1516
### Config file
1617

sourcespec/plot_sourcepars.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
valid_plot_types = [
2424
'fc', 'Er', 'ssd', 'ra', 'Mo', 't_star', 'Qo', 'sigma_a',
25-
'fc_mw', 'Er_mw', 'ssd_mw']
25+
'fc_mw', 'Er_mw', 'ssd_mw', 'ssd_depth']
2626

2727

2828
class Annot():
@@ -263,6 +263,8 @@ def __init__(self, args):
263263
query_condition = ''
264264
self.evids = query_event_params_into_numpy(
265265
self.cur, 'evid', str, query_condition)
266+
self.depth = query_event_params_into_numpy(
267+
self.cur, 'depth', np.float64, query_condition)
266268
self.vp = query_event_params_into_numpy(
267269
self.cur, 'vp', np.float64, query_condition)
268270
self.vs = query_event_params_into_numpy(
@@ -358,6 +360,7 @@ def _open_db(self, sqlite_file):
358360
def skip_events(self, idx):
359361
"""Skip events with index idx."""
360362
self.evids = np.delete(self.evids, idx)
363+
self.depth = np.delete(self.depth, idx)
361364
self.vp = np.delete(self.vp, idx)
362365
self.vs = np.delete(self.vs, idx)
363366
self.rho = np.delete(self.rho, idx)
@@ -673,6 +676,20 @@ def _scatter_ssd_mw(self, fig, ax):
673676
annot = Annot(self.mw, self.ssd, self.evids, yformat)
674677
fig.canvas.mpl_connect('pick_event', annot)
675678

679+
def _scatter_ssd_depth(self, fig, ax):
680+
"""Plot the scatter plot of ssd vs depth."""
681+
alpha = 1
682+
ax.errorbar(
683+
self.depth, self.ssd,
684+
xerr=None,
685+
yerr=[self.ssd_err_minus, self.ssd_err_plus],
686+
fmt='o', mec='black', mfc='#FCBA25', ecolor='#FCBA25',
687+
alpha=alpha)
688+
ax.scatter(self.depth, self.ssd, alpha=0, picker=True, zorder=20)
689+
yformat = 'ssd {:.2e} MPa'
690+
annot = Annot(self.depth, self.ssd, self.evids, yformat)
691+
fig.canvas.mpl_connect('pick_event', annot)
692+
676693
def _fit_fc_mw(self, vel, k_parameter, ax, slope=False):
677694
"""Plot a linear regression of fc vs mw."""
678695
mag_min, mag_max = ax.get_xlim()
@@ -815,6 +832,37 @@ def plot_ssd_mw(self, hist=False, fit=False, nbins=None):
815832
ax_Mo.set_ylabel('ssd (MPa)')
816833
plt.show()
817834

835+
def plot_ssd_depth(self, hist=False, fit=False, nbins=None):
836+
"""
837+
Plot the logarithm of static stress drop vs depth.
838+
839+
Parameters
840+
----------
841+
hist : bool
842+
If True, plot a 2D histogram instead of a scatter plot.
843+
fit : bool
844+
If True, plot a linear regression of ssd vs depth.
845+
slope : bool
846+
If True, also fit the slope of the linear regression.
847+
"""
848+
fig, ax = plt.subplots()
849+
ax.set_xlabel('Depth (km)')
850+
ax.set_ylabel('ssd (MPa)')
851+
ax.set_yscale('log')
852+
ax.set_ylim(1e-3, 1e3)
853+
854+
if hist:
855+
raise NotImplementedError(
856+
'Histogram not implemented yet for ssd_depth')
857+
else:
858+
self._scatter_ssd_depth(fig, ax)
859+
if fit:
860+
raise NotImplementedError(
861+
'Fit not implemented yet for ssd_depth')
862+
863+
self._set_plot_title(ax)
864+
plt.show()
865+
818866
def plot_hist(self, param_name, nbins=None, wave_type='S'):
819867
"""Plot a histogram of the given parameter."""
820868
parameters = {
@@ -906,6 +954,8 @@ def run():
906954
params.plot_Er_mw(args.hist, args.fit, args.nbins)
907955
elif args.plot_type == 'ssd_mw':
908956
params.plot_ssd_mw(args.hist, args.fit, args.nbins)
957+
elif args.plot_type == 'ssd_depth':
958+
params.plot_ssd_depth(args.hist, args.fit, args.nbins)
909959
elif args.plot_type in valid_plot_types:
910960
params.plot_hist(args.plot_type, args.nbins, args.wave_type)
911961

0 commit comments

Comments
 (0)