From 85829b22ebb28421df2b7fa9e72ec2747f870528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludger=20K=C3=BCperkoch?= Date: Wed, 28 Jun 2017 12:38:21 +0200 Subject: [PATCH 1/3] Write header in ObsPy-generated NLLoc-observation file. --- pylot/core/io/data.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pylot/core/io/data.py b/pylot/core/io/data.py index 47e74053..a5449092 100644 --- a/pylot/core/io/data.py +++ b/pylot/core/io/data.py @@ -187,12 +187,23 @@ class Data(object): self.get_evt_data().write(fnout + fnext, format=evtformat) # try exporting event via ObsPy - else: + elif fnext == '.obs': 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)) + # write header afterwards + evtdata = self.get_evt_data() + evid = str(evtdata.resource_id).split('/')[1] + header = '# EQEVENT: Label: EQ%s Loc: X 0.00 Y 0.00 Z 10.00 OT 0.00 \n' % evid + nllocfile = open(fnout + fnext) + l = nllocfile.readlines() + nllocfile.close() + l.insert(0, header) + nllocfile = open(fnout + fnext, 'w') + nllocfile.write("".join(l)) + nllocfile.close() def getComp(self): """ From f52b42f009531823310b6e45ee91f0bf11479427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludger=20K=C3=BCperkoch?= Date: Wed, 28 Jun 2017 12:40:03 +0200 Subject: [PATCH 2/3] [Bugfix] Write header only, if export has been successfull. --- pylot/core/io/data.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pylot/core/io/data.py b/pylot/core/io/data.py index a5449092..586736bd 100644 --- a/pylot/core/io/data.py +++ b/pylot/core/io/data.py @@ -190,20 +190,20 @@ class Data(object): elif fnext == '.obs': try: self.get_evt_data().write(fnout + fnext, format=evtformat) + # write header afterwards + evtdata = self.get_evt_data() + evid = str(evtdata.resource_id).split('/')[1] + header = '# EQEVENT: Label: EQ%s Loc: X 0.00 Y 0.00 Z 10.00 OT 0.00 \n' % evid + nllocfile = open(fnout + fnext) + l = nllocfile.readlines() + nllocfile.close() + l.insert(0, header) + nllocfile = open(fnout + fnext, 'w') + nllocfile.write("".join(l)) + nllocfile.close() except KeyError as e: raise KeyError('''{0} export format not implemented: {1}'''.format(evtformat, e)) - # write header afterwards - evtdata = self.get_evt_data() - evid = str(evtdata.resource_id).split('/')[1] - header = '# EQEVENT: Label: EQ%s Loc: X 0.00 Y 0.00 Z 10.00 OT 0.00 \n' % evid - nllocfile = open(fnout + fnext) - l = nllocfile.readlines() - nllocfile.close() - l.insert(0, header) - nllocfile = open(fnout + fnext, 'w') - nllocfile.write("".join(l)) - nllocfile.close() def getComp(self): """ From d31fec8781eacad49366aa049df58fb5525b5edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludger=20K=C3=BCperkoch?= Date: Wed, 28 Jun 2017 14:23:24 +0200 Subject: [PATCH 3/3] Before exporting phases, check for manual picks and export them instead of automatic picks. --- pylot/core/io/data.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/pylot/core/io/data.py b/pylot/core/io/data.py index 586736bd..2526469b 100644 --- a/pylot/core/io/data.py +++ b/pylot/core/io/data.py @@ -188,11 +188,26 @@ class Data(object): # try exporting event via ObsPy elif fnext == '.obs': + # check for stations picked automatically as well as manually + # Prefer manual picks! + evtdata_copy = self.get_evt_data().copy() + evtdata_org = self.get_evt_data() + for i in range(len(evtdata_org.picks)): + if evtdata_org.picks[i].method_id == 'manual': + mstation = evtdata_org.picks[i].waveform_id.station_code + mstation_ext = mstation + '_' + for k in range(len(evtdata_copy.picks)): + if evtdata_copy.picks[k].waveform_id.station_code == mstation or \ + evtdata_copy.picks[k].waveform_id.station_code == mstation_ext and \ + evtdata_copy.picks[k].method_id == 'auto': + del evtdata_copy.picks[k] + break + + try: - self.get_evt_data().write(fnout + fnext, format=evtformat) + evtdata_copy.write(fnout + fnext, format=evtformat) # write header afterwards - evtdata = self.get_evt_data() - evid = str(evtdata.resource_id).split('/')[1] + evid = str(evtdata_org.resource_id).split('/')[1] header = '# EQEVENT: Label: EQ%s Loc: X 0.00 Y 0.00 Z 10.00 OT 0.00 \n' % evid nllocfile = open(fnout + fnext) l = nllocfile.readlines()