[bugfixes] autopylot

This commit is contained in:
Marcel Paffrath 2018-06-26 17:07:38 +02:00
parent 77b4458ab5
commit 19f943627a
4 changed files with 76 additions and 46 deletions

View File

@ -194,16 +194,16 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
events = [events for events in glob.glob(os.path.join(datapath, '*')) if os.path.isdir(events)]
elif fnames == 'None' and parameter['eventID'] is not '*' and not type(parameter['eventID']) == list:
# single event processing
events = glob.glob(os.path.join(datapath, parameter['eventID'], wfpath_extension))
events = glob.glob(os.path.join(datapath, parameter['eventID']))
elif fnames == 'None' and type(parameter['eventID']) == list:
# multiple event processing
events = []
for eventID in parameter['eventID']:
events.append(os.path.join(datapath, eventID, wfpath_extension))
events.append(os.path.join(datapath, eventID))
else:
# autoPyLoT was initialized from GUI
events = []
events.append(os.path.join(eventid, wfpath_extension))
events.append(eventid)
evID = os.path.split(eventid)[-1]
locflag = 2
else:
@ -214,8 +214,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
for eventID in eventid:
events.append(os.path.join(datapath,
parameter['database'],
eventID,
wfpath_extension))
eventID))
if not events:
print('autoPyLoT: No events given. Return!')
@ -229,10 +228,9 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
allpicks = {}
glocflag = locflag
for eventpath in events:
if not wfpath_extension:
evID = os.path.split(eventpath)[-1]
else:
evID = os.path.split(os.path.split(eventpath)[0])[-1]
if wfpath_extension:
event_datapath = os.path.join(eventpath, wfpath_extension)
fext = '.xml'
filename = os.path.join(eventpath, 'PyLoT_' + evID + fext)
try:
@ -245,7 +243,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
pylot_event = Event(eventpath) # event should be path to event directory
data.setEvtData(pylot_event)
if fnames == 'None':
data.setWFData(glob.glob(os.path.join(datapath, eventpath, '*')))
data.setWFData(glob.glob(os.path.join(datapath, event_datapath, '*')))
# the following is necessary because within
# multiple event processing no event ID is provided
# in autopylot.in

View File

@ -43,7 +43,7 @@ class Data(object):
elif isinstance(evtdata, dict):
evt = readPILOTEvent(**evtdata)
evtdata = evt
elif isinstance(evtdata, str):
elif type(evtdata) in [str, unicode]:
try:
cat = read_events(evtdata)
if len(cat) is not 1:

View File

@ -222,41 +222,72 @@ def read_metadata(path_to_inventory):
# return metadata_objects
# def read_metadata_file(path_to_inventory_filename):
# # functions used to read metadata for different file endings (or file types)
# read_functions = {'dless': _read_dless,
# 'dseed': _read_dless,
# 'xml': _read_inventory_file,
# 'resp': _read_inventory_file}
# file_ending = path_to_inventory_filename.split('.')[-1]
# if file_ending in read_functions.keys():
# robj, exc = read_functions[file_ending](path_to_inventory_filename)
# if exc is not None:
# raise exc
# return file_ending, robj
# # in case file endings did not match the above keys, try and error
# for file_type in ['dless', 'xml']:
# robj, exc = read_functions[file_type](path_to_inventory_filename)
# if exc is None:
# return file_type, robj
#
#
# def _read_dless(path_to_inventory):
# exc = None
# try:
# parser = Parser(path_to_inventory)
# except Exception as exc:
# parser = None
# return parser, exc
#
#
# def _read_inventory_file(path_to_inventory):
# exc = None
# try:
# inv = read_inventory(path_to_inventory)
# except Exception as exc:
# inv = None
# return inv, exc
def read_metadata_iterator(path_to_inventory, station_seed_id):
'''
# search for metadata for a specific station iteratively
'''
station, network, location, channel = station_seed_id.split('.')
fnames = glob.glob(os.path.join(path_to_inventory, '*' + station_seed_id + '*'))
if not fnames:
# search for station name in filename
fnames = glob.glob(os.path.join(path_to_inventory, '*' + station + '*'))
if not fnames:
# search for network name in filename
fnames = glob.glob(os.path.join(path_to_inventory, '*' + network + '*'))
if not fnames:
print('Could not find filenames matching station name, network name or seed id')
return
for fname in fnames:
invtype, robj = read_metadata_file(os.path.join(path_to_inventory, fname))
try:
robj.get_coordinates(station_seed_id)
return invtype, robj
except Exception as e:
continue
print('Could not find metadata for station_seed_id {} in path {}'.format(station_seed_id, path_to_inventory))
def read_metadata_file(path_to_inventory_filename):
'''
function reading metadata files (either dataless seed, xml or resp)
:param path_to_inventory_filename:
:return: file type/ending, inventory object (Parser or Inventory)
'''
# functions used to read metadata for different file endings (or file types)
read_functions = {'dless': _read_dless,
'dseed': _read_dless,
'xml': _read_inventory_file,
'resp': _read_inventory_file}
file_ending = path_to_inventory_filename.split('.')[-1]
if file_ending in read_functions.keys():
robj, exc = read_functions[file_ending](path_to_inventory_filename)
if exc is not None:
raise exc
return file_ending, robj
# in case file endings did not match the above keys, try and error
for file_type in ['dless', 'xml']:
robj, exc = read_functions[file_type](path_to_inventory_filename)
if exc is None:
return file_type, robj
def _read_dless(path_to_inventory):
exc = None
try:
parser = Parser(path_to_inventory)
except Exception as exc:
parser = None
return parser, exc
def _read_inventory_file(path_to_inventory):
exc = None
try:
inv = read_inventory(path_to_inventory)
except Exception as exc:
inv = None
return inv, exc
def restitute_trace(input_tuple):

View File

@ -3476,6 +3476,7 @@ class TuneAutopicker(QWidget):
def clear_all(self):
if hasattr(self, 'pdlg_widget'):
if self.pdlg_widget:
self.pdlg_widget.setParent(None)
del(self.pdlg_widget)
if hasattr(self, 'overview'):
self.overview.setParent(None)