Skip to content

Commit

Permalink
review: include .nonzero instead of where, and adjust binning warning
Browse files Browse the repository at this point in the history
  • Loading branch information
aronsho committed Feb 18, 2025
1 parent 9f28123 commit 733f568
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
5 changes: 3 additions & 2 deletions seismostats/analysis/avalue/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _filter_magnitudes(self) -> np.ndarray:
'''
Filter out magnitudes below the completeness magnitude.
'''
self.idx = np.where(self.magnitudes >= self.mc - self.delta_m / 2)[0]
self.idx = (self.magnitudes >= self.mc - self.delta_m / 2).nonzero()[0]
self.magnitudes = self.magnitudes[self.idx]

if len(self.magnitudes) == 0:
Expand All @@ -92,7 +92,8 @@ def _sanity_checks(self):
'''
# test magnitude binnning
if len(self.magnitudes) > 0:
if not binning_test(self.magnitudes, self.delta_m,
tolerance = 1e-8
if not binning_test(self.magnitudes, max(self.delta_m, tolerance),
check_larger_binning=False):
raise ValueError('Magnitudes are not binned correctly.')

Expand Down
6 changes: 2 additions & 4 deletions seismostats/analysis/avalue/tests/test_avalue.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from datetime import datetime, timedelta
import warnings

import numpy as np
import pytest
Expand Down Expand Up @@ -42,9 +41,8 @@ def test_estimate_a_classic():
assert a_estimate == 1.0

# reference magnitude is given and b-value given
with warnings.catch_warnings(record=True):
a_estimate = estimator.calculate(mags, mc=1, delta_m=0.0,
m_ref=0, b_value=1)
a_estimate = estimator.calculate(mags, mc=1, delta_m=0.0,
m_ref=0, b_value=1)
assert a_estimate == 2.0

# reference magnitude but no b-value
Expand Down
5 changes: 3 additions & 2 deletions seismostats/analysis/bvalue/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _filter_magnitudes(self):
'''
Filter out magnitudes below the completeness magnitude.
'''
self.idx = np.where(self.magnitudes >= self.mc - self.delta_m / 2)[0]
self.idx = (self.magnitudes >= self.mc - self.delta_m / 2).nonzero()[0]
self.magnitudes = self.magnitudes[self.idx]

if self.weights is not None:
Expand All @@ -81,7 +81,8 @@ def _sanity_checks(self):
'''
# test magnitude binnning
if len(self.magnitudes) > 0:
if not binning_test(self.magnitudes, self.delta_m,
tolerance = 1e-8
if not binning_test(self.magnitudes, max(self.delta_m, tolerance),
check_larger_binning=False):
raise ValueError('Magnitudes are not binned correctly.')

Expand Down

0 comments on commit 733f568

Please sign in to comment.