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

View File

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

View File

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

View File

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