Skip to content

Commit

Permalink
rename d_mc to dmc and include proper testing
Browse files Browse the repository at this point in the history
  • Loading branch information
aronsho committed Jun 7, 2024
1 parent 57cd97b commit 18e45d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions seismostats/analysis/estimate_beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def differences(magnitudes: np.ndarray) -> np.ndarray:
def estimate_b_positive(
magnitudes: np.ndarray,
delta_m: float = 0,
d_mc: float | None = None,
dmc: float | None = None,
b_parameter: str = "b_value",
return_std: bool = False,
return_n: bool = False,
Expand All @@ -272,7 +272,7 @@ def estimate_b_positive(
To achieve the effect
of reduced STAI, the magnitudes must be ordered in time.
delta_m: discretization of magnitudes. default is no discretization.
d_mc: cutoff value for the differences (diffferences below this
dmc: cutoff value for the differences (diffferences below this
value are not considered). If None, the cutoff is set to delta_m
b_parameter:either 'b-value', then the corresponding value of the
Gutenberg-Richter law is returned, otherwise 'beta' from the
Expand All @@ -290,17 +290,17 @@ def estimate_b_positive(
n: number of events used for the estimation
"""

if d_mc is None:
d_mc = delta_m
if dmc is None:
dmc = delta_m

mag_diffs = np.diff(magnitudes)
# only take the values where the next earthquake is d_mc larger than the
# previous one. delta_m is added to avoid numerical errors
mag_diffs = abs(mag_diffs[mag_diffs > d_mc - delta_m / 2])
mag_diffs = abs(mag_diffs[mag_diffs > dmc - delta_m / 2])

out = estimate_b_tinti(
mag_diffs,
mc=d_mc,
mc=dmc,
delta_m=delta_m,
b_parameter=b_parameter,
return_std=return_std,
Expand Down
9 changes: 5 additions & 4 deletions seismostats/analysis/tests/test_estimate_beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ def test_differences(magnitudes: np.ndarray, mag_diffs: np.ndarray):


@pytest.mark.parametrize(
"n,b,mc,delta_m,b_parameter,precision",
"n,b,mc,delta_m,b_parameter,dmc,precision",
[
(1000000, 1.2 * np.log(10), 3, 0, "beta", 0.005),
(1000000, np.log(10), 3, 0.1, "beta", 0.01),
(1000000, 1.2, 3, 0, "b_value", None, 0.005),
(1000000, np.log(10), 3, 0.1, "beta", 1, 0.01),
],
)
def test_estimate_b_positive(
Expand All @@ -162,13 +162,14 @@ def test_estimate_b_positive(
mc: float,
delta_m: float,
b_parameter: str,
dmc: float,
precision: float,
):
mags = simulate_magnitudes_binned(
n, b, mc, delta_m, b_parameter=b_parameter
)
b_estimate = estimate_b_positive(
mags, delta_m=delta_m, b_parameter=b_parameter
mags, delta_m=delta_m, dmc=dmc, b_parameter=b_parameter
)
assert abs(b - b_estimate) / b <= precision

Expand Down

0 comments on commit 18e45d4

Please sign in to comment.