Skip to content

Commit

Permalink
Better logging for when no event or pick information is found
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiodsf committed Oct 23, 2024
1 parent 311bfa1 commit a449e0b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
9 changes: 9 additions & 0 deletions sourcespec2/input/event_and_picks.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ def _read_event_and_picks_from_stream(stream):
ssp_event = read_event_from_SAC(trace)
except RuntimeError as err:
_read_event_and_picks_from_stream.event_warnings.append(err)
except ValueError:
# ValueError is raised when trace is not in SAC format
continue
try:
picks += read_picks_from_SAC(trace)
except RuntimeError as err:
_read_event_and_picks_from_stream.picks_warnings.append(err)
except ValueError:
# ValueError is raised when trace is not in SAC format
continue
return ssp_event, picks
_read_event_and_picks_from_stream.event_warnings = [] # noqa
_read_event_and_picks_from_stream.picks_warnings = [] # noqa
Expand Down Expand Up @@ -191,14 +197,17 @@ def _log_event_and_pick_info(ssp_event, picks, event_source, picks_source):
:param picks_source: Picks source
"""
if ssp_event is None:
logger.warning('No event information found')
# only log warnings if no event information was found
for warning in _read_event_and_picks_from_stream.event_warnings:
logger.warning(warning)
else:
logger.info(f'Event information read from: {event_source}')
for line in str(ssp_event).splitlines():
logger.info(line)
logger.info('---------------------------------------------------')
if not picks:
logger.warning('No pick information found')
# only log warnings if no pick information was found
for warning in _read_event_and_picks_from_stream.picks_warnings:
logger.warning(warning)
Expand Down
14 changes: 8 additions & 6 deletions sourcespec2/input/event_parsers/sac_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ def read_event_from_SAC(trace):
:return: Event information
:rtype: :class:`ssp_event.SSPEvent`
:raises: ValueError if trace is not a SAC trace
:raises: RuntimeError if hypocenter information is not found in header
"""
try:
sac_hdr = trace.stats.sac
except AttributeError as e:
raise RuntimeError(
f'{trace.id}: not a SAC trace: cannot get hypocenter from header'
) from e
raise ValueError(f'{trace.id}: not a SAC trace') from e
try:
evla = sac_hdr['evla']
evlo = sac_hdr['evlo']
Expand Down Expand Up @@ -85,13 +86,14 @@ def read_picks_from_SAC(trace):
:return: List of picks
:rtype: list of :class:`ssp_pick.SSPPick`
:raises: ValueError if trace is not a SAC trace
:raises: RuntimeError if pick information is not found in header
"""
try:
sac_hdr = trace.stats.sac
except AttributeError as e:
raise RuntimeError(
f'{trace.id}: not a SAC trace: cannot get picks from header'
) from e
raise ValueError(f'{trace.id}: not a SAC trace') from e
trace_picks = []
pick_fields = (
'a', 't0', 't1', 't2', 't3', 't4', 't5', 't6', 't7', 't8', 't9')
Expand Down

0 comments on commit a449e0b

Please sign in to comment.