Skip to content

Commit 8683eb1

Browse files
committed
style: added verbose coding of in_place catalog filtering
fix: bypassed a pycsep error where sometimes CartesianGrid2D are not imported with a proper dh
1 parent 4684a58 commit 8683eb1

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

floatcsep/experiment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def catalog(self) -> CSEPCatalog:
350350
)
351351

352352
if self.region:
353-
catalog.filter_spatial(region=self.region)
353+
catalog.filter_spatial(region=self.region, in_place=True)
354354
catalog.region = None
355355
catalog.write_json(self._catpath)
356356

@@ -408,7 +408,7 @@ def get_test_cat(self, tstring: str = None) -> CSEPCatalog:
408408
f'magnitude >= {self.mag_min}',
409409
f'magnitude < {self.mag_max}'], in_place=False)
410410
if self.region:
411-
sub_cat.filter_spatial(region=self.region)
411+
sub_cat.filter_spatial(region=self.region, in_place=True)
412412

413413
return sub_cat
414414

@@ -437,7 +437,7 @@ def set_test_cat(self, tstring: str) -> None:
437437
f'magnitude >= {self.mag_min}',
438438
f'magnitude < {self.mag_max}'], in_place=False)
439439
if self.region:
440-
sub_cat.filter_spatial(region=self.region)
440+
sub_cat.filter_spatial(region=self.region, in_place=True)
441441
sub_cat.write_json(filename=testcat_name)
442442
else:
443443
log.debug(f'Using stored test sub-catalog from {testcat_name}')

floatcsep/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,13 @@ def read_region_cfg(region_config, **kwargs):
220220
except ValueError:
221221
data = numpy.array([re.split(r'\s+|,', i.strip()) for i in
222222
parsed_region[1:]], dtype=float)
223-
region = CartesianGrid2D.from_origins(data, name=region_data,
224-
magnitudes=magnitudes)
223+
dh1 = scipy.stats.mode(np.diff(np.unique(data[:, 0]))).mode
224+
dh2 = scipy.stats.mode(np.diff(np.unique(data[:, 1]))).mode
225+
dh = np.min([dh1, dh2])
226+
region = CartesianGrid2D.from_origins(data,
227+
name=region_data,
228+
magnitudes=magnitudes,
229+
dh=dh)
225230
region_config.update({'path': region_data})
226231
else:
227232
region_data['magnitudes'] = magnitudes

0 commit comments

Comments
 (0)