Skip to content

Commit 14be6eb

Browse files
committed
fixed edge case causing an issue and cleaned up some of the program flow
1 parent be8b69a commit 14be6eb

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

csep/core/catalogs.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -990,44 +990,42 @@ def read_catalog_line(line):
990990
prev_id = 0
991991
# if the first catalog doesn't start at zero
992992
if catalog_id != prev_id:
993-
prev_id = catalog_id
994993
if not empty:
995-
events.append(temp_event)
994+
events = [temp_event]
996995
else:
997996
events = []
998997
for id in range(catalog_id):
999998
yield cls(data=[], catalog_id=id, **kwargs)
999+
prev_id = catalog_id
1000+
continue
10001001
# accumulate event if catalog_id is the same as previous event
10011002
if catalog_id == prev_id:
1002-
prev_id = catalog_id
10031003
if not all([val in (None, '') for val in temp_event]):
10041004
events.append(temp_event)
1005+
prev_id = catalog_id
10051006
# create and yield class if the events are from different catalogs
10061007
elif catalog_id == prev_id + 1:
1007-
catalog = cls(data=events, catalog_id=prev_id, **kwargs)
1008-
prev_id = catalog_id
1008+
yield cls(data=events, catalog_id=prev_id, **kwargs)
10091009
# add event to new event list
10101010
if not empty:
10111011
events = [temp_event]
10121012
else:
10131013
events = []
1014-
yield catalog
1014+
prev_id = catalog_id
10151015
# this implies there are empty catalogs, because they are not listed in the ascii file
10161016
elif catalog_id > prev_id + 1:
1017-
catalog = cls(data=events, catalog_id=prev_id, **kwargs)
1018-
yield catalog
1019-
# add event to new event list
1020-
if not empty:
1021-
events = [temp_event]
1022-
else:
1023-
events = []
1017+
yield cls(data=events, catalog_id=prev_id, **kwargs)
10241018
# if prev_id = 0 and catalog_id = 2, then we skipped one catalog. thus, we skip catalog_id - prev_id - 1 catalogs
10251019
num_empty_catalogs = catalog_id - prev_id - 1
1026-
# create empty catalog classes
1020+
# first yield empty catalog classes
10271021
for id in range(num_empty_catalogs):
10281022
yield cls(data=[], catalog_id=catalog_id - num_empty_catalogs + id, **kwargs)
1029-
# finally we want to yield the buffered catalog to preserve order
10301023
prev_id = catalog_id
1024+
# add event to new event list
1025+
if not empty:
1026+
events = [temp_event]
1027+
else:
1028+
events = []
10311029
else:
10321030
raise ValueError(
10331031
"catalog_id should be monotonically increasing and events should be ordered by catalog_id")
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
,,,,,0,
21
1,1,1,1992-01-01T0:0:0.0,1,3,1
3-
,,,,,4,
4-
,,,,,6,
2+
,,,,,5,
53
1,1,1,1992-01-01T0:0:0.0,1,7,1
64
,,,,,9,

tests/test_forecast.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os, unittest
22
import numpy
33
from csep import load_catalog_forecast
4-
from csep.core.catalogs import CSEPCatalog
54

65
def get_test_catalog_root():
76
root_dir = os.path.dirname(os.path.abspath(__file__))

0 commit comments

Comments
 (0)