Skip to content

Commit 0b95738

Browse files
committed
Drop any tol=0.00001 from bin1d_vec calls or their calling function
... even in the unit tests (only used when binning magnitudes) Notes: * specifying `tol=0.00001` was not even necessary with the revised tolerance section by commit 949d342 (albeit most of the `tol=0.00001` were introduced by this commit); * Why? because magnitude bins are "cleanly" created with `np.arange()` in `csep.core.regions.magnitude_bins`; * their redundancy is confirmed by passing the corresponding unit test `test_scalar_outside` without `tol=0.00001` using the unfixed `bin1d_vec`; * yet, I left optional `tol=None` argument in `bin1d_vec` and the functions that call it -- just in case there is a real need to override tolerance.
1 parent 9c14ee8 commit 0b95738

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

csep/core/catalogs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def to_dataframe(self, with_datetime=False):
395395
def get_mag_idx(self):
396396
""" Return magnitude index from region magnitudes """
397397
try:
398-
return bin1d_vec(self.get_magnitudes(), self.region.magnitudes, tol=0.00001, right_continuous=True)
398+
return bin1d_vec(self.get_magnitudes(), self.region.magnitudes, right_continuous=True)
399399
except AttributeError:
400400
raise CSEPCatalogException("Cannot return magnitude index without self.region.magnitudes")
401401

@@ -699,7 +699,7 @@ def spatial_event_probability(self):
699699
event_flag[idx] = 1
700700
return event_flag
701701

702-
def magnitude_counts(self, mag_bins=None, tol=0.00001, retbins=False):
702+
def magnitude_counts(self, mag_bins=None, tol=None, retbins=False):
703703
""" Computes the count of events within mag_bins
704704
705705
@@ -734,7 +734,7 @@ def magnitude_counts(self, mag_bins=None, tol=0.00001, retbins=False):
734734
else:
735735
return out
736736

737-
def spatial_magnitude_counts(self, mag_bins=None, tol=0.00001):
737+
def spatial_magnitude_counts(self, mag_bins=None, tol=None):
738738
""" Return counts of events in space-magnitude region.
739739
740740
We figure out the index of the polygons and create a map that relates the spatial coordinate in the

csep/core/forecasts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def magnitude_counts(self):
213213
""" Returns counts of events in magnitude bins """
214214
return numpy.sum(self.data, axis=0)
215215

216-
def get_magnitude_index(self, mags, tol=0.00001):
216+
def get_magnitude_index(self, mags, tol=None):
217217
""" Returns the indices into the magnitude bins of selected magnitudes
218218
219219
Note: the right-most bin is treated as extending to infinity.

csep/core/regions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ def compute_vertices(origin_points, dh, tol=numpy.finfo(float).eps):
495495
"""
496496
return list(map(lambda x: compute_vertex(x, dh, tol=tol), origin_points))
497497

498-
def _bin_catalog_spatio_magnitude_counts(lons, lats, mags, n_poly, mask, idx_map, binx, biny, mag_bins, tol=0.00001):
498+
def _bin_catalog_spatio_magnitude_counts(lons, lats, mags, n_poly, mask, idx_map, binx, biny, mag_bins, tol=None):
499499
"""
500500
Returns a list of event counts as ndarray with shape (n_poly, n_cat) where each value
501501
represents the event counts within the polygon.
@@ -1182,7 +1182,7 @@ def _get_spatial_magnitude_counts(self, catalog, mag_bins=None):
11821182
out = numpy.zeros([len(self.quadkeys), len(mag_bins)])
11831183

11841184
idx_loc = self.get_index_of(lon, lat)
1185-
idx_mag = bin1d_vec(mag, mag_bins, tol=0.00001, right_continuous=True)
1185+
idx_mag = bin1d_vec(mag, mag_bins, right_continuous=True)
11861186

11871187
numpy.add.at(out, (idx_loc, idx_mag), 1)
11881188

tests/test_calc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ def test_less_and_greater_than(self):
137137
def test_scalar_outside(self):
138138
from csep.utils.calc import bin1d_vec
139139
mbins = numpy.arange(5.95, 9, 0.1) # This gives bins from 5.95 to 8.95
140-
idx = bin1d_vec(5.95, mbins, tol=0.00001, right_continuous=True)
140+
idx = bin1d_vec(5.95, mbins, right_continuous=True)
141141
self.assertEqual(idx, 0)
142142

143-
idx = bin1d_vec(6, mbins, tol=0.00001, right_continuous=True) # This would give 0: Which is fine.
143+
idx = bin1d_vec(6, mbins, right_continuous=True) # This would give 0: Which is fine.
144144
self.assertEqual(idx, 0)
145145

146-
idx = bin1d_vec(5, mbins, tol=0.00001, right_continuous=True)
146+
idx = bin1d_vec(5, mbins, right_continuous=True)
147147
self.assertEqual(idx, -1)
148148

149-
idx = bin1d_vec(4, mbins, tol=0.00001, right_continuous=True)
149+
idx = bin1d_vec(4, mbins, right_continuous=True)
150150
self.assertEqual(idx, -1)
151151

0 commit comments

Comments
 (0)