From 18e45d4f3fa63f05ce987e1e3e1304c1d706365e Mon Sep 17 00:00:00 2001 From: Aron Mirwald Date: Fri, 7 Jun 2024 10:51:06 +0200 Subject: [PATCH] rename d_mc to dmc and include proper testing --- seismostats/analysis/estimate_beta.py | 12 ++++++------ seismostats/analysis/tests/test_estimate_beta.py | 9 +++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/seismostats/analysis/estimate_beta.py b/seismostats/analysis/estimate_beta.py index be7f6cb..b0f3b80 100644 --- a/seismostats/analysis/estimate_beta.py +++ b/seismostats/analysis/estimate_beta.py @@ -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, @@ -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 @@ -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, diff --git a/seismostats/analysis/tests/test_estimate_beta.py b/seismostats/analysis/tests/test_estimate_beta.py index 178d090..232dea4 100644 --- a/seismostats/analysis/tests/test_estimate_beta.py +++ b/seismostats/analysis/tests/test_estimate_beta.py @@ -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( @@ -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