|
22 | 22 |
|
23 | 23 | valid_plot_types = [
|
24 | 24 | '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'] |
26 | 26 |
|
27 | 27 |
|
28 | 28 | class Annot():
|
@@ -263,6 +263,8 @@ def __init__(self, args):
|
263 | 263 | query_condition = ''
|
264 | 264 | self.evids = query_event_params_into_numpy(
|
265 | 265 | self.cur, 'evid', str, query_condition)
|
| 266 | + self.depth = query_event_params_into_numpy( |
| 267 | + self.cur, 'depth', np.float64, query_condition) |
266 | 268 | self.vp = query_event_params_into_numpy(
|
267 | 269 | self.cur, 'vp', np.float64, query_condition)
|
268 | 270 | self.vs = query_event_params_into_numpy(
|
@@ -358,6 +360,7 @@ def _open_db(self, sqlite_file):
|
358 | 360 | def skip_events(self, idx):
|
359 | 361 | """Skip events with index idx."""
|
360 | 362 | self.evids = np.delete(self.evids, idx)
|
| 363 | + self.depth = np.delete(self.depth, idx) |
361 | 364 | self.vp = np.delete(self.vp, idx)
|
362 | 365 | self.vs = np.delete(self.vs, idx)
|
363 | 366 | self.rho = np.delete(self.rho, idx)
|
@@ -673,6 +676,20 @@ def _scatter_ssd_mw(self, fig, ax):
|
673 | 676 | annot = Annot(self.mw, self.ssd, self.evids, yformat)
|
674 | 677 | fig.canvas.mpl_connect('pick_event', annot)
|
675 | 678 |
|
| 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 | + |
676 | 693 | def _fit_fc_mw(self, vel, k_parameter, ax, slope=False):
|
677 | 694 | """Plot a linear regression of fc vs mw."""
|
678 | 695 | mag_min, mag_max = ax.get_xlim()
|
@@ -815,6 +832,37 @@ def plot_ssd_mw(self, hist=False, fit=False, nbins=None):
|
815 | 832 | ax_Mo.set_ylabel('ssd (MPa)')
|
816 | 833 | plt.show()
|
817 | 834 |
|
| 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 | + |
818 | 866 | def plot_hist(self, param_name, nbins=None, wave_type='S'):
|
819 | 867 | """Plot a histogram of the given parameter."""
|
820 | 868 | parameters = {
|
@@ -906,6 +954,8 @@ def run():
|
906 | 954 | params.plot_Er_mw(args.hist, args.fit, args.nbins)
|
907 | 955 | elif args.plot_type == 'ssd_mw':
|
908 | 956 | 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) |
909 | 959 | elif args.plot_type in valid_plot_types:
|
910 | 960 | params.plot_hist(args.plot_type, args.nbins, args.wave_type)
|
911 | 961 |
|
|
0 commit comments