Skip to content

Commit

Permalink
Filtering out unwanted channels in asdf2salvus.py
Browse files Browse the repository at this point in the history
  • Loading branch information
geojunky committed Mar 10, 2023
1 parent 68b8ab7 commit b86f2fa
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions seismic/ASDFdatabase/asdf2salvus.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def extract_data_for_event(fds:FederatedASDFDataSet,
@return:
"""

def filter_channels(rows, include_sband=False):
def filter_channels_locations(rows, preferred_location_codes:list = ['00', '', '10'],
include_sband=False):
"""
@param rows: output of FederatedASDFDataset.get_stations
@param include_sband:
Expand All @@ -133,7 +134,6 @@ def is_preferred_component(cha: str):
# end for

return False

# end func

itype_dict = defaultdict(lambda: defaultdict( \
Expand All @@ -149,6 +149,44 @@ def is_preferred_component(cha: str):
itype_dict[net][sta][loc][comp].append([cha, irow])
# end for

#################################################
# Remove multiple location codes
#################################################
for nk, nv in itype_dict.items():
for sk, sv in itype_dict[nk].items():
if(len(itype_dict[nk][sk]) > 1): # multiple location codes found
# first remove location codes not in preferred_location_codes
for lk in list(itype_dict[nk][sk].keys()):
if(lk not in preferred_location_codes):
itype_dict[nk][sk].pop(lk)
# end if
# end for

if(len(itype_dict[nk][sk]) > 1): # still multiple location codes found
for lk in list(itype_dict[nk][sk].keys()):
# remove all location codes other than the first entry in
# preferred_location_codes
if(lk in preferred_location_codes[1:]):
itype_dict[nk][sk].pop(lk)
# end if
# end for
# end if
# end if
# end for
# end for

# sanity checks
for nk, nv in itype_dict.items():
for sk, sv in itype_dict[nk].items():
assert len(itype_dict[nk][sk]) == 1, 'Failed to remove multiple location codes ' \
'found for station {}.{}:{}'.format(nk, sk,
itype_dict[nk][sk].keys())
# end for
# end for

#################################################
# Remove unwanted bands
#################################################
bands = ['H', 'B', 'S'] if include_sband else ['H', 'B']
orows = []
for nk, nv in itype_dict.items():
Expand Down Expand Up @@ -218,15 +256,15 @@ def remove_comments(iinv: Inventory) -> Inventory:

st, et = otime - seconds_before, otime + seconds_after
rows = fds.get_stations(st, et)
rows = filter_channels(rows) # filter out unwanted channels and band-codes
rows = filter_channels_locations(rows) # filter out unwanted channels and band-codes

receivers_dict = defaultdict(dict)
pbar = tqdm(total=len(rows), desc=ename)
for row in rows:
net, sta, loc, cha, lon, lat, elev = row

if (not domain.contains(lon, lat)): continue
if (DEBUG and net not in nets): continue
#if (DEBUG and net not in nets): continue

stream = get_validated_waveform(fds, net, sta, loc,
cha, st, et)
Expand Down

0 comments on commit b86f2fa

Please sign in to comment.