From bec86049049393e8a0b638a14bda73859e4af69e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludger=20K=C3=BCperkoch?= Date: Mon, 26 Jun 2017 14:47:36 +0200 Subject: [PATCH] autoPyLoT appends manual picks to xml-file, and manualPyLoT appends automatic picks to xml-file. --- autoPyLoT.py | 2 +- pylot/core/io/data.py | 35 +++++++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/autoPyLoT.py b/autoPyLoT.py index 84d24dea..a5ca4035 100755 --- a/autoPyLoT.py +++ b/autoPyLoT.py @@ -353,7 +353,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even if evt is not None: data.applyEVTData(evt, 'event') fnqml = '%s/PyLoT_%s' % (event, evID) - data.exportEvent(fnqml) + data.exportEvent(fnqml, fnext='.xml', fcheck='manual') # HYPO71 hypo71file = '%s/PyLoT_%s_HYPO71_phases' % (event, evID) hypo71.export(picks, hypo71file, parameter) diff --git a/pylot/core/io/data.py b/pylot/core/io/data.py index eb424094..4b1f5018 100644 --- a/pylot/core/io/data.py +++ b/pylot/core/io/data.py @@ -145,12 +145,13 @@ class Data(object): # handle forbidden filenames especially on windows systems return fnConstructor(str(ID)) - def exportEvent(self, fnout, fnext='.xml'): + def exportEvent(self, fnout, fnext='.xml', fcheck='auto'): """ :param fnout: :param fnext: + :param fcheck: :raise KeyError: """ from pylot.core.util.defaults import OUTPUTFORMATS @@ -161,13 +162,35 @@ class Data(object): errmsg = '{0}; selected file extension {1} not ' \ 'supported'.format(e, fnext) raise FormatError(errmsg) + + # check for already existing xml-file + if fnext == '.xml': + if os.path.isfile(fnout + fnext): + print("xml-file already exists! Check content ...") + cat_old = read_events(fnout + fnext) + checkflag = 0 + for j in range(len(cat_old.events[0].picks)): + if cat_old.events[0].picks[j].method_id.id.split('/')[1] == fcheck: + print("Found %s pick(s), append to new catalog." % fcheck) + checkflag = 1 + break + if checkflag == 1: + self.get_evt_data().write(fnout + fnext, format=evtformat) + cat_new = read_events(fnout + fnext) + cat_new.append(cat_old.events[0]) + cat_new.write(fnout + fnext, format=evtformat) + else: + self.get_evt_data().write(fnout + fnext, format=evtformat) + else: + self.get_evt_data().write(fnout + fnext, format=evtformat) # try exporting event via ObsPy - try: - self.get_evt_data().write(fnout + fnext, format=evtformat) - except KeyError as e: - raise KeyError('''{0} export format - not implemented: {1}'''.format(evtformat, e)) + else: + try: + self.get_evt_data().write(fnout + fnext, format=evtformat) + except KeyError as e: + raise KeyError('''{0} export format + not implemented: {1}'''.format(evtformat, e)) def getComp(self): """