Skip to content

Commit 02a7c49

Browse files
committed
Miscellaneous Changes
* Improved data-coverage function in FederatedASDFDataSet * Improved handling of location codes in cross-correlation routines
1 parent 8308aec commit 02a7c49

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

seismic/ASDFdatabase/FederatedASDFDataSet.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,15 @@ def get_global_time_range(self, network, station=None, location=None, channel=No
138138

139139
# end func
140140

141-
def get_nslc_list(self):
141+
def get_nslc_coverage(self):
142142
"""
143-
Get a list of all net, sta, loc, cha combinations featured in the database
143+
Get a structured numpy array with named columns
144+
'net', 'sta', 'loc', 'cha', 'min_st', 'max_et'
145+
representing contents of the database
144146
@return:
145147
"""
146148

147-
results = self.fds.get_nslc_list()
149+
results = self.fds.get_nslc_coverage()
148150
return results
149151
# end if
150152

seismic/ASDFdatabase/_FederatedASDFDataSetImpl.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,17 @@ def get_global_time_range(self, network, station=None, location=None, channel=No
490490
return min, max
491491
# end func
492492

493-
def get_nslc_list(self):
494-
query = "select net, sta, loc, cha from nslc"
493+
def get_nslc_coverage(self):
494+
query = "select net, sta, loc, cha, st, et from nslc"
495495
rows = self.conn.execute(query).fetchall()
496496

497-
return rows
497+
fields = {'names': ['net', 'sta', 'loc', 'cha', 'min_st', 'max_et'],
498+
'formats': ['U10', 'U10', 'U10', 'U10', 'f8', 'f8']}
499+
result = np.zeros(len(rows), dtype=fields)
500+
501+
for i, row in enumerate(rows): result[i] = row
502+
503+
return result
498504
# end if
499505

500506
def get_stations(self, starttime, endtime, network=None, station=None, location=None, channel=None):

seismic/ASDFdatabase/viewer/FederatedASDFViewer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,9 @@ def addWidget(emitter):
482482
# populate net, sta, loc, cha dict
483483
self.nslc_dict = defaultdict(lambda: defaultdict(lambda: defaultdict(list)))
484484

485-
nslc_list = self.fds.get_nslc_list()
486-
for row in nslc_list:
487-
net, sta, loc, cha = row
485+
nslc_coverage = self.fds.get_nslc_coverage()
486+
for row in nslc_coverage:
487+
net, sta, loc, cha, _, _ = row
488488
self.nslc_dict[net][sta][loc].append(cha)
489489
# end for
490490

seismic/xcorqc/correlator.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ def cull_pairs(pairs, keep_list_fn):
193193

194194
startTime = UTCDateTime(start_time)
195195
endTime = UTCDateTime(end_time)
196-
stationsCache = defaultdict(list)
197196
for pair in proc_stations[rank]:
198197
netsta1, netsta2 = pair
199198

@@ -212,7 +211,9 @@ def get_loccha(cha1, cha2):
212211
cha1 and cha2 -- e.g. ['.SHZ', '00.BHZ'], ['01.HHZ']
213212
"""
214213
result = [[], []]
215-
for chidx, (netsta, cha, ds) in enumerate(zip((netsta1, netsta2), (cha1, cha2), (ds1, ds2))):
214+
for chidx, (netsta, cha, ds) in enumerate(zip((netsta1, netsta2),
215+
(cha1, cha2),
216+
(ds1, ds2))):
216217
if('*' in cha1):
217218
cha = cha.replace('*', '.*') # hack to capture simple regex comparisons
218219
# end if
@@ -225,12 +226,14 @@ def get_loccha(cha1, cha2):
225226

226227
net, sta = netsta.split('.')
227228

228-
if((start_time, end_time, net, sta) in stationsCache):
229-
stations = stationsCache[(start_time, end_time, net, sta)]
230-
else:
231-
stations = ds.fds.get_stations(start_time, end_time, net, sta)
232-
stationsCache[(start_time, end_time, net, sta)] = stations
233-
# end if
229+
# find a list of entries where network and station names match and
230+
# start- and end-times overlap with data coverage. Note that this is
231+
# an approximate estimate and an actual cross-correlation may not be
232+
# computed due to gaps in data
233+
stations = ds.nslc_coverage[(ds.nslc_coverage['net'] == net) & \
234+
(ds.nslc_coverage['sta'] == sta) & \
235+
(ds.nslc_coverage['max_et'] >= startTime.timestamp) & \
236+
(ds.nslc_coverage['min_st'] <= endTime.timestamp)]
234237

235238
loc_pref = location_preferences_dict[netsta]
236239
ulocs = set()

seismic/xcorqc/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def __init__(self, asdf_file_name, netsta_list='*'):
2020
self._earth_radius = 6371 # km
2121

2222
self.fds = FederatedASDFDataSet(asdf_file_name)
23+
self.nslc_coverage = self.fds.get_nslc_coverage()
24+
2325
# Gather station metadata
2426
netsta_list_subset = set(netsta_list.split(' ')) if netsta_list != '*' else netsta_list
2527
self.netsta_list = []

0 commit comments

Comments
 (0)