From a449e0b5ce9fb3888d4b65de05aa75a137c1c3b4 Mon Sep 17 00:00:00 2001 From: Claudio Satriano Date: Wed, 23 Oct 2024 12:02:43 +0200 Subject: [PATCH] Better logging for when no event or pick information is found --- sourcespec2/input/event_and_picks.py | 9 +++++++++ sourcespec2/input/event_parsers/sac_event.py | 14 ++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/sourcespec2/input/event_and_picks.py b/sourcespec2/input/event_and_picks.py index 10af8858..9c70fb32 100644 --- a/sourcespec2/input/event_and_picks.py +++ b/sourcespec2/input/event_and_picks.py @@ -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 @@ -191,6 +197,7 @@ 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) @@ -198,7 +205,9 @@ def _log_event_and_pick_info(ssp_event, picks, event_source, picks_source): 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) diff --git a/sourcespec2/input/event_parsers/sac_event.py b/sourcespec2/input/event_parsers/sac_event.py index 0b889331..2416e7b8 100644 --- a/sourcespec2/input/event_parsers/sac_event.py +++ b/sourcespec2/input/event_parsers/sac_event.py @@ -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'] @@ -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')