Skip to content

Commit

Permalink
Try harder to find phase names for picks in QML files
Browse files Browse the repository at this point in the history
This commit fixes the case where the phase name is not provided in the
`<pick>` tag, but rather in the corresponding `<arrival>` tag.
This is for instance the case for the QML files provided by USGS.
  • Loading branch information
claudiodsf committed Oct 14, 2024
1 parent 97fddbd commit 1dbd1ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Copyright (c) 2011-2024 Claudio Satriano <[email protected]>
- Fix I/O error when reading PAZ files
- Fix for event ids in SourceSpec event file being only numbers: they are now
correctly interpreted as strings
- Fix for ignored picks for certain kind of QuakeML files (like the ones from
USGS) where the phase name is not in the `<phase_hint>` attribute of the
`<pick>` element but in the `<phase>` attribute of the corresponding
`<arrival>` element

## v1.8 - 2024-04-07

Expand Down
20 changes: 14 additions & 6 deletions sourcespec/ssp_read_event_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def parse_qml(config):
return ssp_event, picks
try:
qml_event = _get_event_from_qml(qml_file, event_id)
ssp_event = _parse_qml_event(
ssp_event, qml_origin = _parse_qml_event(
qml_event,
parse_event_name_from_description=qml_event_description,
event_description_regex=qml_event_description_regex)
picks = _parse_picks_from_qml_event(qml_event)
picks = _parse_picks_from_qml_event(qml_event, qml_origin)
except Exception as err:
logger.error(err)
ssp_exit(1)
Expand Down Expand Up @@ -142,7 +142,7 @@ def _parse_qml_event(
ssp_event.hypocenter.depth.value = origin.depth
ssp_event.hypocenter.depth.units = 'm'
ssp_event.hypocenter.origin_time = origin.time
return ssp_event
return ssp_event, origin


def _parse_magnitude_from_qml_event(qml_event, ssp_event):
Expand Down Expand Up @@ -177,7 +177,7 @@ def _parse_focal_mechanism_from_qml_event(qml_event, ssp_event):
ssp_event.focal_mechanism.rake = nodal_plane.rake


def _parse_picks_from_qml_event(ev):
def _parse_picks_from_qml_event(ev, origin):
picks = []
for pck in ev.picks:
pick = SSPPick()
Expand All @@ -192,9 +192,17 @@ def _parse_picks_from_qml_event(ev):
pick.flag = 'E'
elif pck.onset == 'impulsive':
pick.flag = 'I'
try:
pick.phase = None
if pck.phase_hint:
pick.phase = pck.phase_hint[:1]
except Exception:
else:
# try to get the phase from the arrival object that uses this pick
pick_id = pck.resource_id.id
arrivals = [
arr for arr in origin.arrivals if arr.pick_id.id == pick_id]
if arrivals:
pick.phase = arrivals[0].phase[:1]
if pick.phase is None:
# ignore picks with no phase hint
continue
if pck.polarity == 'negative':
Expand Down

0 comments on commit 1dbd1ce

Please sign in to comment.