Skip to content

Commit

Permalink
Miscellaneous Changes
Browse files Browse the repository at this point in the history
* Extended response-factory to be able to retrieve responses from a
database
* Minor cleanups in associated files
  • Loading branch information
geojunky committed Jan 29, 2025
1 parent 83061a2 commit 623390b
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 113 deletions.
5 changes: 2 additions & 3 deletions seismic/ASDFdatabase/analytics/station_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def get_period_details(self, sampling_rate: float):

class ResponseAmplitudesCache():
class ResponseAmplitudes():
def __init__(self, sampling_rate:float, response:Response):
def __init__(self, sampling_rate: float, response: Response):
self.response = response
self.sampling_rate = sampling_rate

Expand Down Expand Up @@ -208,8 +208,7 @@ def analyse_data(self,
network: str,
station: str,
location: str,
channel: str,
sampling_rate: int):
channel: str):

# collate timespans to be allocated to each parallel process
st, et = self.get_time_range_func(network,
Expand Down
2 changes: 1 addition & 1 deletion seismic/ASDFdatabase/analytics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_response(input_file, network=None, station=None, location=None, channel=

if(resp_inv is not None):
rf = ResponseFactory()
rf.CreateFromInventory(resp_name, resp_inv)
rf.createFromInventory(resp_name, resp_inv)

result = rf.getResponse(resp_name)
# end if
Expand Down
7 changes: 1 addition & 6 deletions seismic/ASDFdatabase/analytics/wa.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ def get_time_range_func(net, sta, loc, cha):
# account for the possibility of each combination of net, sta, loc, cha to have
# recordings under different sampling rates
meta_dict = select_channel(mseed_index, sd, ed)
sr_dict = mseed_index.get_channel_sampling_rates()

# instantiate progress tracker
manager = Manager()
Expand All @@ -199,11 +198,7 @@ def get_time_range_func(net, sta, loc, cha):
""".format(cha))
for meta in meta_list:
net, sta, loc, cha = meta

nslc = '.'.join(meta)
sampling_rate = sr_dict[nslc]

sa.analyse_data(net, sta, loc, cha, sampling_rate)
sa.analyse_data(net, sta, loc, cha)
# end for

ofn = os.path.join(output_folder, '{}.pdf'.format(cha))
Expand Down
10 changes: 3 additions & 7 deletions seismic/ASDFdatabase/analytics/wa_asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,18 @@
type=str)
@click.argument('station', required=True,
type=str)
@click.argument('location', required=True,
type=str)
@click.argument('channel', required=True,
type=str)
@click.argument('instrument-response', required=True,
@click.argument('response-database', required=True,
type=click.Path(exists=True))
@click.argument('sampling-rate', required=True,
type=int)
@click.argument('output-folder', required=True,
type=click.Path(exists=True))
@click.option('--start-date', type=str, default=None, show_default=True,
help="Start date in UTC format for processing data")
@click.option('--end-date', type=str, default=None, show_default=True,
help="End date in UTC format for processing data")
def process_asdf(asdf_source, network, station, location, channel, instrument_response,
sampling_rate, output_folder, start_date, end_date):
def process_asdf(asdf_source, network, station, channel, response_database,
output_folder, start_date, end_date):
"""
ASDF_SOURCE: Path to text file containing paths to ASDF files\n
NETWORK: network code
Expand Down
23 changes: 2 additions & 21 deletions seismic/ASDFdatabase/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ def __init__(self, mseed_folder, pattern):
self.tree = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(list))))
self.stream_cache = MseedIndex.StreamCache()
self.mseed_files = np.array(sorted(glob(os.path.join(self.mseed_folder, pattern))))
self.sr_dict = defaultdict(list) # sampling rates for each nslc combination
self.coverage_dict = defaultdict(float) # dict keyed by nslc, with coverage as values

fc = len(self.mseed_files)
Expand All @@ -211,10 +210,10 @@ def __init__(self, mseed_folder, pattern):
# end try

for tr in st:
nc, sc, lc, cc, st, et, sr = \
nc, sc, lc, cc, st, et = \
tr.stats.network, tr.stats.station, tr.stats.location, \
tr.stats.channel, tr.stats.starttime.timestamp, \
tr.stats.endtime.timestamp, tr.stats.sampling_rate
tr.stats.endtime.timestamp

# skip bogus traces
if(nc == sc == lc == cc == ''): continue
Expand All @@ -223,25 +222,11 @@ def __init__(self, mseed_folder, pattern):
nslc = '.'.join((nc, sc, lc, cc))
# store coverage for unique channels and sampling rates
cov = float(et - st) # coverage in seconds
self.sr_dict[nslc].append(sr)
self.coverage_dict[nslc] += cov
# end for
# if (i > 0): break
# end for

# take median of sampling rates found
for k, v in self.sr_dict.items():
vals = np.array(self.sr_dict[k])

unique_sr = set(vals)
chosen_sr = np.median(vals)
if(len(unique_sr) > 1):
print('Multiple sampling rates ({}) found under {}. '
'Selecting median sampling rate ({}).'.format(unique_sr, k, chosen_sr))
# end if
self.sr_dict[k] = chosen_sr
# end for

print('\nCreating metadata index for a total of {} traces found..'.format(len(self.meta_list)))

for row in tqdm(self.meta_list):
Expand All @@ -254,10 +239,6 @@ def __init__(self, mseed_folder, pattern):
# end for
# end func

def get_channel_sampling_rates(self) -> defaultdict:
return self.sr_dict
# end func

def get_channel_coverages(self) -> defaultdict:
return self.coverage_dict
# end func
Expand Down
2 changes: 1 addition & 1 deletion seismic/inventory/fdsnxml_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def toSc3ml(src_path, dst_path, response_fdsnxml=None):
response = None
if response_fdsnxml is not None:
rf = ResponseFactory()
rf.CreateFromStationXML('resp', response_fdsnxml)
rf.createFromStationXML('resp', response_fdsnxml)
response = rf.getResponse('resp')

if os.path.isfile(src_path):
Expand Down
Loading

0 comments on commit 623390b

Please sign in to comment.