Skip to content

Commit

Permalink
Cope with missing phase hints in picks
Browse files Browse the repository at this point in the history
  • Loading branch information
calum-chamberlain committed Nov 20, 2023
1 parent 4d37db3 commit 873dfd5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
24 changes: 18 additions & 6 deletions eqcorrscan/tests/catalog_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

@pytest.mark.network
class CatalogUtilsTests(unittest.TestCase):
@classmethod
@pytest.mark.flaky(reruns=2) # Rerun the test in case of network timeout
def setUpClass(cls):
client = Client(str("NCEDC"))
Expand All @@ -22,6 +23,11 @@ def setUpClass(cls):
minlatitude=35.7, maxlatitude=36.1,
minlongitude=-120.6, maxlongitude=-120.2,
includearrivals=True)
# Phase hints are not included in the picks, but are in the arrivals
for ev in cls.catalog:
for arr in ev.origins[-1].arrivals:
pick = arr.pick_id.get_referred_object()
pick.phase_hint = arr.phase

def test_filter_picks(self):
""" Test various methods of filtering picks in a catalog."""
Expand Down Expand Up @@ -55,7 +61,8 @@ def test_filter_phase_hints(self):

phase_hints = set(p.phase_hint for ev in filtered_catalog
for p in ev.picks)
self.assertEqual(phase_hints == {"P"})
print(phase_hints)
self.assertEqual(phase_hints, set("P"))

def test_filter_single_pick(self):
filtered_catalog = filter_picks(
Expand All @@ -64,12 +71,17 @@ def test_filter_single_pick(self):
for ev in filtered_catalog:
stations = {p.waveform_id.station_code for p in ev.picks}
for station in stations:
picks = [p for p in ev.picks if p.waveform_id.station_code == station]
phase_hints = {p.phase_hint for p in ev.picks}
picks = [p for p in ev.picks
if p.waveform_id.station_code == station]
phase_hints = {p.phase_hint for p in picks}
for phase_hint in phase_hints:
self.assertEqual(
1, len([p for p in picks
if p.phase_hint == phase_hint]))
matched_picks = [
p for p in picks if p.phase_hint == phase_hint]
if len(matched_picks) != 1:
print(f"Multiple picks for {station} - {phase_hint}")
for pick in matched_picks:
print(pick)
self.assertEqual(1, len(matched_picks))
return


Expand Down
3 changes: 2 additions & 1 deletion eqcorrscan/utils/catalog_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ def filter_picks(catalog, stations=None, channels=None, networks=None,
picks = [p for p in ev.picks
if p.waveform_id.station_code == station
and p.phase_hint == phase_hint]
picks.sort(key=lambda p:p.time, reverse=reverse)
picks.sort(key=lambda p: p.time, reverse=reverse)
retained_picks.append(picks[0])
ev.picks = retained_picks

Check warning on line 194 in eqcorrscan/utils/catalog_utils.py

View check run for this annotation

Codecov / codecov/patch

eqcorrscan/utils/catalog_utils.py#L193-L194

Added lines #L193 - L194 were not covered by tests

return tmp_catalog

Expand Down

0 comments on commit 873dfd5

Please sign in to comment.