From 9f48b23d887843b61625612925d89fa0363ff225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludger=20K=C3=BCperkoch?= Date: Wed, 16 Aug 2017 16:24:35 +0200 Subject: [PATCH] Use writephases for exporting to VELEST-input file, as VELEST can handle only 4-string station IDs which is already implemented in source code. --- QtPyLoT.py | 2 +- autoPyLoT.py | 2 +- pylot/core/io/data.py | 6 +++--- pylot/core/io/phases.py | 8 ++++++-- pylot/core/loc/velest.py | 8 ++++---- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index a1ea2a47..e1154a8f 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -1149,7 +1149,7 @@ class MainWindow(QMainWindow): upperErrors=[uppererrorP[3], uppererrorS[3]]) saved_as += str(outformat) + ' ' except TypeError: - print('WARNING: Format: {} not yet implemented'.format(outformat)) #MP MP TODO: .obs export (event.copy) + print('WARNING: Format: {} not yet implemented'.format(outformat)) msg = 'Event {} saved as {} in format(s) {}'.format(event.pylot_id, fbasename, saved_as.strip()) self.update_status(msg) diff --git a/autoPyLoT.py b/autoPyLoT.py index 62a47525..d5cd340c 100755 --- a/autoPyLoT.py +++ b/autoPyLoT.py @@ -425,7 +425,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even hyposat.export(picks, hyposatfile, parameter) # VELEST velestfile = '%s/PyLoT_%s_VELEST_phases.cnv' % (eventpath, evID) - velest.export(picks, velestfile, parameter, evt) + velest.export(picks, velestfile, evt, parameter) # hypoDD hypoddfile = '%s/PyLoT_%s_hypoDD_phases.pha' % (eventpath, evID) hypodd.export(picks, hypoddfile, parameter, evt) diff --git a/pylot/core/io/data.py b/pylot/core/io/data.py index 0e44ca5c..112a52ab 100644 --- a/pylot/core/io/data.py +++ b/pylot/core/io/data.py @@ -13,6 +13,7 @@ from pylot.core.io.phases import readPILOTEvent, picks_from_picksdict, \ from pylot.core.util.errors import FormatError, OverwriteError from pylot.core.util.event import Event from pylot.core.util.utils import fnConstructor, full_range +import pylot.core.loc.velest as velest class Data(object): @@ -223,8 +224,7 @@ class Data(object): self.checkEvent(event, fcheck) self.setEvtData(event) self.get_evt_data().write(fnout + fnext, format=evtformat) - - # try exporting event via ObsPy + # try exporting event else: evtdata_org = self.get_evt_data() picks = evtdata_org.picks @@ -296,7 +296,7 @@ class Data(object): not implemented: {1}'''.format(evtformat, e)) if fnext == '.cnv': try: - evtdata_org.write(fnout + fnext, format=evtformat) + velest.export(picks_copy, fnout + fnext, eventinfo=self.get_evt_data()) except KeyError as e: raise KeyError('''{0} export format not implemented: {1}'''.format(evtformat, e)) diff --git a/pylot/core/io/phases.py b/pylot/core/io/phases.py index 959b1059..ac0dff38 100644 --- a/pylot/core/io/phases.py +++ b/pylot/core/io/phases.py @@ -403,7 +403,7 @@ def reassess_pilot_event(root_dir, db_dir, event_id, out_dir=None, fn_param=None # evt.write(fnout_prefix + 'cnv', format='VELEST') -def writephases(arrivals, fformat, filename, parameter, eventinfo=None): +def writephases(arrivals, fformat, filename, parameter=None, eventinfo=None): """ Function of methods to write phases to the following standard file formats used for locating earthquakes: @@ -622,7 +622,11 @@ def writephases(arrivals, fformat, filename, parameter, eventinfo=None): fid = open("%s" % filename, 'w') # get informations needed in cnv-file # check, whether latitude is N or S and longitude is E or W - eventsource = eventinfo.origins[0] + try: + eventsource = eventinfo.origins[0] + except: + print("No source origin calculated yet, thus no cnv-file creation possible!") + return if eventsource['latitude'] < 0: cns = 'S' else: diff --git a/pylot/core/loc/velest.py b/pylot/core/loc/velest.py index 325b8d59..1ec9fd6a 100644 --- a/pylot/core/loc/velest.py +++ b/pylot/core/loc/velest.py @@ -7,7 +7,7 @@ from pylot.core.util.version import get_git_version as _getVersionString __version__ = _getVersionString() -def export(picks, fnout, parameter, eventinfo): +def export(picks, fnout, eventinfo, parameter=None): ''' Take dictionary and exports picking data to a VELEST-cnv without creating an ObsPy event object. @@ -18,11 +18,11 @@ def export(picks, fnout, parameter, eventinfo): :param fnout: complete path to the exporting obs file :type fnout: str - :param: parameter, all input information - :type: object - :param: eventinfo, source time needed for VELEST-cnv format :type: list object + + :param: parameter, all input information + :type: object ''' # write phases to VELEST-phase file writephases(picks, 'VELEST', fnout, parameter, eventinfo)