From 8411a2027e5fc5fce14014ab349e530de03c168b Mon Sep 17 00:00:00 2001 From: Rakib Hassan Date: Fri, 23 Aug 2024 00:07:34 +1000 Subject: [PATCH] Bug Fix in FederatedASDFDataSet * Fixed a stealthy bug in FederatedASDFDataSet where location codes were incorrectly handled. * Patched safe_iter_event_data to avoid loss of usable data in cases when input inventories contain incorrect recording periods --- .../ASDFdatabase/_FederatedASDFDataSetImpl.py | 22 ++++++++++++------- seismic/stream_io.py | 5 ++++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/seismic/ASDFdatabase/_FederatedASDFDataSetImpl.py b/seismic/ASDFdatabase/_FederatedASDFDataSetImpl.py index 143abc6a..d51a7cf5 100644 --- a/seismic/ASDFdatabase/_FederatedASDFDataSetImpl.py +++ b/seismic/ASDFdatabase/_FederatedASDFDataSetImpl.py @@ -491,17 +491,23 @@ def get_stations(self, starttime, endtime, network=None, station=None, location= endtime = UTCDateTime(endtime).timestamp query = 'select * from wtag where ' - if (network): query += " net='%s' "%(network) - if (station): - if(network): query += "and sta='%s' "%(station) + if (network is not None): query += " net='%s' "%(network) + if (station is not None): + if(network is not None): query += "and sta='%s' "%(station) else: query += "sta='%s' "%(station) - if (location): - if(network or station): query += "and loc='%s' "%(location) + if (location is not None): + if((network is not None) or + (station is not None)): query += "and loc='%s' "%(location) else: query += "loc='%s' "%(location) - if (channel): - if(network or station or location): query += "and cha='%s' "%(channel) + if (channel is not None): + if((network is not None) or + (station is not None) or + (location is not None)): query += "and cha='%s' "%(channel) else: query += "cha='%s' "%(channel) - if (network or station or location or channel): query += ' and ' + if ((network is not None) or + (station is not None) or + (location is not None) or + (channel is not None)): query += ' and ' query += ' et>=%f and st<=%f' \ % (starttime, endtime) query += ' group by net, sta, loc, cha' diff --git a/seismic/stream_io.py b/seismic/stream_io.py index 219604c2..e584ab17 100644 --- a/seismic/stream_io.py +++ b/seismic/stream_io.py @@ -84,7 +84,10 @@ def safe_iter_event_data(events, inventory, get_waveforms, use_rfstats=True, pha pbar.update(1) origin_time = (event.preferred_origin() or event.origins[0])['time'] try: - args = (seedid[:-1] + stations[seedid], origin_time) + # exclude datetime from call to get_coordinates to ensure incorrect + # recording periods in the inventory do not lead to loss of usable + # data + args = (seedid[:-1] + stations[seedid], None) coords = inventory.get_coordinates(*args) except Exception: # station not available at that time continue