Skip to content

Commit

Permalink
adjusted plotting function such that it is easier to understand what …
Browse files Browse the repository at this point in the history
…it does
  • Loading branch information
aronsho committed Dec 19, 2024
1 parent b020e71 commit f4b5019
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions seismostats/plots/statistical.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

def plot_mc_vs_b(
magnitudes: np.ndarray,
mcs: float | np.ndarray,
dmcs: float | np.ndarray | None = None,
mcs: np.ndarray,
dmc: float | None = None,
delta_m: float = 0.1,
b_method: BValueEstimator = ClassicBValueEstimator,
confidence_intvl: float = 0.95,
Expand All @@ -24,13 +24,11 @@ def plot_mc_vs_b(
Args:
magnitudes: magnitudes of the catalog
mcs: completeness magnitudes (list or numpy array)
dmc: if a positive b-value estimator is used, this is the
minimum difference that is considered. For the
ClassicBValueEstimator, leave this as the default None.
delta_m: discretization of the magnitudes
method: method used for b-value estimation, either 'classic' or
'positive' or 'positive_postcut'. positive_postcut is the
same as 'positive' but with the postcut method (differences
are taken before cutting the magnitudes below the
completeness magnitude). The mcs are then interpreted as
dmcs.
method: method used for b-value estimation
confidence_intvl: confidence interval that should be plotted
ax: axis where figure should be plotted
color: color of the data
Expand All @@ -42,26 +40,13 @@ def plot_mc_vs_b(
b_values = []
b_errors = []

# if dmc is None, the function just iterates through the mcs
if dmcs is None:
variable = mcs
var_string = 'Completeness magnitude $m_c$'
if dmc is None:
for mc in mcs:
estimator = b_method(mc=mc, delta_m=delta_m)
b_values.append(estimator(magnitudes))
b_errors.append(estimator.std)
# if dmc is given, the function iterates though the dmc and mc values
else:
if isinstance(dmcs, (float, int)):
variable = mcs
var_string = 'Completeness magnitude $m_c$'
dmcs = [dmcs] * len(mcs)
elif isinstance(mcs, (float, int)):
variable = dmcs
var_string = 'Minimum magnitude difference $dm_c$'
mcs = [mcs] * len(dmcs)

for mc, dmc in zip(mcs, dmcs):
for mc in mcs:
estimator = b_method(mc=mc, delta_m=delta_m, dmc=dmc)
b_values.append(estimator(magnitudes))
b_errors.append(estimator.std)
Expand All @@ -74,15 +59,15 @@ def plot_mc_vs_b(

# Plotting: this either
error_factor = norm.ppf((1 + confidence_intvl) / 2)
ax.plot(variable, b_values, "-o", color=color)
ax.plot(mcs, b_values, "-o", color=color)
ax.fill_between(
variable,
mcs,
b_values - error_factor * b_errors,
b_values + error_factor * b_errors,
alpha=0.2,
color=color,
)
ax.set_xlabel(var_string)
ax.set_xlabel("Completeness magnitude $m_c$")
ax.set_ylabel("b-value")
ax.grid(True)

Expand Down

0 comments on commit f4b5019

Please sign in to comment.