[new] added new function to read metadata from disk

this new function prevents multiple reading of large dataless seed volume to enhance overall performance
This commit is contained in:
Sebastian Wehling-Benatelli 2016-09-20 09:55:54 +02:00
parent c73435dec3
commit 4a6b653a72

View File

@ -155,22 +155,16 @@ def evt_head_check(root_dir, out_dir = None):
print(nfiles) print(nfiles)
def restitute_data(data, path_to_inventory, unit='VEL', force=False): def read_metadata(path_to_inventory):
""" """
takes a data stream and a path_to_inventory and returns the corrected take path_to_inventory and return either the corresponding list of files
waveform data stream found or the Parser object for a network dataless seed volume to prevent
:param data: seismic data stream read overhead for large dataless seed volumes
:param path_to_inventory: path to inventory folder or file :param path_to_inventory:
:param unit: unit to correct for (default: 'VEL') :return: tuple containing a either list of files or `obspy.io.xseed.Parser`
:param force: force restitution for already corrected traces (default: object and the inventory type found
True) :rtype: tuple
:return: corrected data stream
""" """
restflag = list()
data = remove_underscores(data)
dlfile = list() dlfile = list()
invfile = list() invfile = list()
respfile = list() respfile = list()
@ -185,12 +179,35 @@ def restitute_data(data, path_to_inventory, unit='VEL', force=False):
invtype = key_for_set_value(inv) invtype = key_for_set_value(inv)
if invtype is None: if invtype is None:
print("Neither dataless-SEED file,inventory-xml file nor RESP-file " raise IOError("Neither dataless-SEED file, inventory-xml file nor "
"found!") "RESP-file found!")
return data, False elif invtype == 'dless': # prevent multiple read of large dlsv
elif invtype == 'dless': # prevent multiple read of large dlsv
if len(inv[invtype]) == 1: if len(inv[invtype]) == 1:
fname = Parser(inv[invtype][0]) robj = Parser(inv[invtype][0])
else:
robj = inv[invtype]
else:
robj = inv[invtype]
return invtype, robj
def restitute_data(data, invtype, inobj, unit='VEL', force=False):
"""
takes a data stream and a path_to_inventory and returns the corrected
waveform data stream
:param data: seismic data stream
:param invtype: type of found metadata
:param inobj: either list of metadata files or `obspy.io.xseed.Parser`
object
:param unit: unit to correct for (default: 'VEL')
:param force: force restitution for already corrected traces (default:
False)
:return: corrected data stream
"""
restflag = list()
data = remove_underscores(data)
# loop over traces # loop over traces
for tr in data: for tr in data:
@ -208,7 +225,7 @@ def restitute_data(data, path_to_inventory, unit='VEL', force=False):
stime = tr.stats.starttime stime = tr.stats.starttime
prefilt = get_prefilt(tr) prefilt = get_prefilt(tr)
if invtype == 'resp': if invtype == 'resp':
fresp = find_in_list(inv[invtype], seed_id) fresp = find_in_list(inobj, seed_id)
if not fresp: if not fresp:
raise IOError('no response file found ' raise IOError('no response file found '
'for trace {0}'.format(seed_id)) 'for trace {0}'.format(seed_id))
@ -218,14 +235,16 @@ def restitute_data(data, path_to_inventory, unit='VEL', force=False):
units=unit) units=unit)
kwargs = dict(paz_remove=None, pre_filt=prefilt, seedresp=seedresp) kwargs = dict(paz_remove=None, pre_filt=prefilt, seedresp=seedresp)
elif invtype == 'dless': elif invtype == 'dless':
if len(inv[invtype]) > 1: if type(inobj) is list:
fname = Parser(find_in_list(inv[invtype], seed_id)) fname = Parser(find_in_list(inobj, seed_id))
else:
fname = inobj
seedresp = dict(filename=fname, seedresp = dict(filename=fname,
date=stime, date=stime,
units=unit) units=unit)
kwargs = dict(pre_filt=prefilt, seedresp=seedresp) kwargs = dict(pre_filt=prefilt, seedresp=seedresp)
elif invtype == 'xml': elif invtype == 'xml':
invlist = inv[invtype] invlist = inobj
if len(invlist) > 1: if len(invlist) > 1:
finv = find_in_list(invlist, seed_id) finv = find_in_list(invlist, seed_id)
else: else: