Skip to content

Commit

Permalink
Instrument Response
Browse files Browse the repository at this point in the history
* Added support for reading instrument responses in both stationXML and
  .resp formats
  • Loading branch information
geojunky committed Feb 7, 2024
1 parent 8fe4278 commit 3f2c286
Showing 1 changed file with 51 additions and 25 deletions.
76 changes: 51 additions & 25 deletions seismic/ASDFdatabase/waveform_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,20 +556,44 @@ def add_image(ax, img):
# end func
# end class

def get_response(resp_file):
resp_name = 'resp'
# read resp file
resp_inv = None
try:
resp_inv = read_inventory(resp_file, format='RESP')
except Exception as e:
print('Failed to read RESP file {} with error: {}'.format(resp_file, e))
# end try

rf = ResponseFactory()
rf.CreateFromInventory(resp_name, resp_inv)
def get_response(input_file, network=None, station=None, location=None, channel=None):
result = None
if('xml' in input_file.lower()):
inv = None
try:
inv = read_inventory(input_file)
except Exception as e:
print('Failed to read inventory file {} with error: {}'.format(input_file, e))
# end try

if(inv is not None):
inv = inv.select(network=network, station=station, location=location,
channel=channel)
if(inv is not None):
seedid = inv.get_contents()['channels'][0]
resp_obj = inv.get_response(seedid,
inv.networks[0].stations[0].channels[0].start_date)
result = resp_obj
# end if
else:
resp_name = 'resp'
# read resp file
resp_inv = None
try:
resp_inv = read_inventory(input_file, format='RESP')
except Exception as e:
print('Failed to read RESP file {} with error: {}'.format(input_file, e))
# end try

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

result = rf.getResponse(resp_name)
# end if
# end if

return rf.getResponse(resp_name)
return result
# end func

CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
Expand Down Expand Up @@ -625,7 +649,8 @@ def process_mseed(mseed_folder, mseed_pattern, instrument_response,
MSEDD_FOLDER: Path to folder containing mseed files\n
MSEED_PATTERN: File pattern to be used to capture files pertaining to specific channels.
Note that pattern must be specified within quotes. \n
INSTRUMENT_RESPONSE: Path to instrument response in .resp format\n
INSTRUMENT_RESPONSE: Path to inventory containing instrument response in
StationXML or .resp format\n
SAMPLING_RATE: Sampling rate used to record the mssed files
OUTPUT_FOLDER: Path to output folder\n
"""
Expand All @@ -637,11 +662,6 @@ def process_mseed(mseed_folder, mseed_pattern, instrument_response,
raise RuntimeError('Invalid start- or end-dates')
# end try

print('Loading response..')
resp = get_response(instrument_response)
if(resp is not None): print('Found response: {}'.format(resp))
else: raise(RuntimeError('No instrument response found. Aborting..'))

# instantiate MseedIndex
print('Inspecting mseed files in {}..'.format(mseed_folder))
mseed_index = MseedIndex(mseed_folder, mseed_pattern)
Expand All @@ -659,6 +679,11 @@ def process_mseed(mseed_folder, mseed_pattern, instrument_response,
# end if
net, sta, loc, cha = meta

print('Loading response..')
resp = get_response(instrument_response, net, sta, loc, cha)
if(resp is not None): print('Found response: {}'.format(resp))
else: raise(RuntimeError('No instrument response found. Aborting..'))

# instantiate progress tracker
manager = Manager()
prog_tracker = ProgressTracker(manager)
Expand Down Expand Up @@ -709,7 +734,8 @@ def process_asdf(asdf_source, network, station, location, channel, instrument_re
NETWORK: network code
STATION: station code
CHANNEL: channel code
INSTRUMENT_RESPONSE: Path to instrument response in .resp format\n
INSTRUMENT_RESPONSE: Path to inventory containing instrument response in
StationXML or .resp format\n
SAMPLING_RATE: Sampling rate used to record the mssed files
OUTPUT_FOLDER: Path to output folder\n
"""
Expand All @@ -724,11 +750,6 @@ def process_asdf(asdf_source, network, station, location, channel, instrument_re
raise RuntimeError('Invalid start- or end-dates')
# end try

print('Loading response..')
resp = get_response(instrument_response)
if(resp is not None): print('Found response: {}'.format(resp))
else: raise(RuntimeError('No instrument response found. Aborting..'))

# instantiate FederatedASDFDataSet
fds = FederatedASDFDataSet(asdf_source)

Expand All @@ -744,6 +765,11 @@ def process_asdf(asdf_source, network, station, location, channel, instrument_re
# end if
net, sta, loc, cha = meta[:4]

print('Loading response..')
resp = get_response(instrument_response, net, sta, loc, cha)
if(resp is not None): print('Found response: {}'.format(resp))
else: raise(RuntimeError('No instrument response found. Aborting..'))

# instantiate progress tracker
manager = Manager()
prog_tracker = ProgressTracker(manager)
Expand Down

0 comments on commit 3f2c286

Please sign in to comment.