From 19e60e5f0c2b51eeb0d985af0d1d212679b4f09f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludger=20K=C3=BCperkoch?= Date: Tue, 17 Nov 2015 17:03:59 +0100 Subject: [PATCH 1/7] Replaced writephases with new function picskExport from module nll. --- autoPyLoT.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/autoPyLoT.py b/autoPyLoT.py index e3f696f5..d0c94689 100755 --- a/autoPyLoT.py +++ b/autoPyLoT.py @@ -1,7 +1,6 @@ #!/usr/bin/python # -*- coding: utf-8 -*- - import os import argparse import glob @@ -12,7 +11,7 @@ from pylot.core.read.data import Data from pylot.core.read.inputs import AutoPickParameter from pylot.core.util.structure import DATASTRUCTURE from pylot.core.pick.autopick import autopickevent -from pylot.core.pick.utils import writephases +from pylot.core.loc.nll import * from pylot.core.util.version import get_git_version as _getVersionString __version__ = _getVersionString() @@ -110,7 +109,7 @@ def autoPyLoT(inputfile): # locating if locflag == 1: # write phases to NLLoc-phase file - writephases(picks, 'NLLoc', phasefile) + picksExport(picks, 'NLLoc', phasefile) # For locating the event the NLLoc-control file has to be modified! # create comment line for NLLoc-control file @@ -165,7 +164,7 @@ def autoPyLoT(inputfile): # locating if locflag == 1: # write phases to NLLoc-phase file - writephases(picks, 'NLLoc', phasefile) + picksExport(picks, 'NLLoc', phasefile) # For locating the event the NLLoc-control file has to be modified! # create comment line for NLLoc-control file NLLoc-output file From 1d6d786dbbdb8c89988ceefaaf04d18a4fa3c65e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludger=20K=C3=BCperkoch?= Date: Tue, 17 Nov 2015 17:05:36 +0100 Subject: [PATCH 2/7] Modyfied picksExport: additional parameter locrt to choose location routine, i.e. phase-file format. --- pylot/core/loc/nll.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pylot/core/loc/nll.py b/pylot/core/loc/nll.py index 3ecd1211..f45cbfe4 100644 --- a/pylot/core/loc/nll.py +++ b/pylot/core/loc/nll.py @@ -10,16 +10,18 @@ from pylot.core.util.version import get_git_version as _getVersionString __version__ = _getVersionString() -def picksExport(picks, phasefile): +def picksExport(picks, locrt, phasefile): ''' Take dictionary and exports picking data to a NLLOC-obs without creating an ObsPy event object. :param picks: picking data dictionary :type picks: dict + :param locrt: choose location routine + :type locrt: str :param phasefile: complete path to the exporting obs file :type phasefile: str ''' # write phases to NLLoc-phase file - writephases(picks, 'NLLoc', phasefile) + writephases(picks, locrt, phasefile) def modfiyInputFile(fn, root, outpath, phasefn, tttn): ''' From c51ba1bd566f03eaed89e8dd9dcc61a5428bdbf2 Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Wed, 18 Nov 2015 09:30:32 +0100 Subject: [PATCH 3/7] [bugfix] trying to figure out cause of segmentation fault --- QtPyLoT.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index 02b0dd1d..f5d1c352 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -36,7 +36,7 @@ from PySide.QtGui import QMainWindow, QInputDialog, QIcon, QFileDialog, \ QDialog, QErrorMessage, QApplication, QPixmap, QMessageBox, QSplashScreen, \ QActionGroup, QListWidget, QDockWidget import numpy as np -from obspy import UTCDateTime, readEvents +from obspy import UTCDateTime from pylot.core.read.data import Data from pylot.core.read.inputs import FilterOptions, AutoPickParameter @@ -59,7 +59,6 @@ locateTool = dict(nll=locateNll) class MainWindow(QMainWindow): __version__ = _getVersionString() - __slots__ = ['loc'] closing = Signal() def __init__(self, parent=None): @@ -651,10 +650,10 @@ class MainWindow(QMainWindow): self.drawPicks(station) else: self.updateStatus('picks discarded ({0})'.format(station)) - if not self.locflag() and self.check4Loc(): - self.locflag(True) - elif self.locflag() and not self.check4Loc(): - self.locflag(False) + if not self.getLocflag() and self.check4Loc(): + self.setLocflag(True) + elif self.getLocflag() and not self.check4Loc(): + self.setLocflag(False) def autoPick(self): list = QListWidget() @@ -783,12 +782,10 @@ class MainWindow(QMainWindow): num += len(phases) return num - @property - def locflag(self): + def getLocflag(self): return self.loc - @locflag.setter - def locflag(self, value): + def setLocflag(self, value): self.loc = value def updateStatus(self, message, duration=5000): From 8a843428838dd56460056ee5dfd88c88ec206a85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludger=20K=C3=BCperkoch?= Date: Wed, 18 Nov 2015 10:27:42 +0100 Subject: [PATCH 4/7] Implementation of module /loc/nll finished, running for single and multiple event processing. --- autoPyLoT.py | 52 ++++++++++++++-------------------------------------- 1 file changed, 14 insertions(+), 38 deletions(-) diff --git a/autoPyLoT.py b/autoPyLoT.py index d0c94689..85d65a48 100755 --- a/autoPyLoT.py +++ b/autoPyLoT.py @@ -78,12 +78,11 @@ def autoPyLoT(inputfile): phasef = parameter.getParam('phasefile') phasefile = '%s/obs/%s' % (nllocroot, phasef) # get name of NLLoc-control file - locf = parameter.getParam('locfile') - locfile = '%s/run/%s' % (nllocroot, locf) - # patter of NLLoc ttimes from location grid + ctrf = parameter.getParam('ctrfile') + ctrfile = '%s/run/%s' % (nllocroot, ctrf) + # pattern of NLLoc ttimes from location grid ttpat = parameter.getParam('ttpatter') - ttpatter = '%s/time/%s' % (nllocroot, ttpat) - # patter of NLLoc-output file + # pattern of NLLoc-output file nllocoutpatter = parameter.getParam('outpatter') else: locflag = 0 @@ -112,27 +111,15 @@ def autoPyLoT(inputfile): picksExport(picks, 'NLLoc', phasefile) # For locating the event the NLLoc-control file has to be modified! - # create comment line for NLLoc-control file - # NLLoc-output file evID = event[string.rfind(event, "/") + 1 : len(events) - 1] - nllocout = '%s/loc/%s_%s' % (nllocroot, evID, nllocoutpatter) - locfiles = 'LOCFILES %s NLLOC_OBS %s %s 0' % (phasefile, ttpatter, nllocout) - print ("Modifying NLLoc-control file %s ..." % locfile) - # modification of NLLoc-control file - filedata = None - nllfile = open(locfile, 'r') - filedata = nllfile.read() - if filedata.find(locfiles) < 0: - # replace old command - filedata = filedata.replace('LOCFILES', locfiles) - nllfile = open(locfile, 'w') - nllfile.write(filedata) - nllfile.close() + nllocout = '%s_%s' % (evID, nllocoutpatter) + # create comment line for NLLoc-control file + modifyInputFile(ctrf, nllocroot, nllocout, phasef, ttpat) # locate the event - subprocess.call([nlloccall, locfile]) + locate(nlloccall, ctrfile) - # !iterative picking if traces remained unpicked or with bad picks! + # !iterative picking if traces remained unpicked or occupied with bad picks! # get theoretical onset times for picks with weights >= 4 # in order to reprocess them using smaller time windows ########################################################## @@ -167,25 +154,14 @@ def autoPyLoT(inputfile): picksExport(picks, 'NLLoc', phasefile) # For locating the event the NLLoc-control file has to be modified! - # create comment line for NLLoc-control file NLLoc-output file - nllocout = '%s/loc/%s_%s' % (nllocroot, parameter.getParam('eventID'), nllocoutpatter) - locfiles = 'LOCFILES %s NLLOC_OBS %s %s 0' % (phasefile, ttpatter, nllocout) - print ("Modifying NLLoc-control file %s ..." % locfile) - # modification of NLLoc-control file - filedata = None - nllfile = open(locfile, 'r') - filedata = nllfile.read() - if filedata.find(locfiles) < 0: - # replace old command - filedata = filedata.replace('LOCFILES', locfiles) - nllfile = open(locfile, 'w') - nllfile.write(filedata) - nllfile.close() + nllocout = '%s_%s' % (parameter.getParam('eventID'), nllocoutpatter) + # create comment line for NLLoc-control file + modifyInputFile(ctrf, nllocroot, nllocout, phasef, ttpat) # locate the event - subprocess.call([nlloccall, locfile]) + locate(nlloccall, ctrfile) - # !iterative picking if traces remained unpicked or with bad picks! + # !iterative picking if traces remained unpicked or occupied with bad picks! # get theoretical onset times for picks with weights >= 4 # in order to reprocess them using smaller time windows ########################################################## From 85925576139bd26c38f6d6c43ff6a341dc42d62e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludger=20K=C3=BCperkoch?= Date: Wed, 18 Nov 2015 10:28:46 +0100 Subject: [PATCH 5/7] Minor changes --- pylot/core/loc/nll.py | 46 +++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/pylot/core/loc/nll.py b/pylot/core/loc/nll.py index f45cbfe4..00ef8b02 100644 --- a/pylot/core/loc/nll.py +++ b/pylot/core/loc/nll.py @@ -12,54 +12,70 @@ __version__ = _getVersionString() def picksExport(picks, locrt, phasefile): ''' - Take dictionary and exports picking data to a NLLOC-obs without creating an ObsPy event object. + Take dictionary and exports picking data to a NLLOC-obs + without creating an ObsPy event object. + :param picks: picking data dictionary :type picks: dict + :param locrt: choose location routine :type locrt: str + :param phasefile: complete path to the exporting obs file :type phasefile: str ''' # write phases to NLLoc-phase file writephases(picks, locrt, phasefile) -def modfiyInputFile(fn, root, outpath, phasefn, tttn): +def modifyInputFile(ctrfn, root, nllocoutn, phasefn, tttn): ''' + :param ctrfn: name of NLLoc-control file + :type: str - :param fn: - :param root: - :param outpath: - :param phasefile: - :param tttable: - :return: + :param root: root path to NLLoc working directory + :type: str + + :param nllocoutn: name of NLLoc-location output file + :type: str + + :param phasefn: name of NLLoc-input phase file + :type: str + + :param tttn: pattern of precalculated NLLoc traveltime tables + :type: str ''' - # For locating the event we have to modify the NLLoc-control file! + # For locating the event the NLLoc-control file has to be modified! # create comment line for NLLoc-control file NLLoc-output file - print ("Modifying NLLoc-control file %s ..." % fn) - nllocout = os.path.join(root,'loc', outpath) + ctrfile = os.path.join(root, 'run', ctrfn) + nllocout = os.path.join(root,'loc', nllocoutn) phasefile = os.path.join(root, 'obs', phasefn) tttable = os.path.join(root, 'time', tttn) locfiles = 'LOCFILES %s NLLOC_OBS %s %s 0\n' % (phasefile, tttable, nllocout) # modification of NLLoc-control file - curlocfiles = getPatternLine(fn, 'LOCFILES') - nllfile = open(fn, 'r') + print ("Modifying NLLoc-control file %s ..." % ctrfile) + curlocfiles = getPatternLine(ctrfile, 'LOCFILES') + nllfile = open(ctrfile, 'r') filedata = nllfile.read() if filedata.find(locfiles) < 0: # replace old command filedata = filedata.replace(curlocfiles, locfiles) - nllfile = open(fn, 'w') + nllfile = open(ctrfile, 'w') nllfile.write(filedata) nllfile.close() def locate(call, fnin): ''' - Takes paths to NLLoc executable and input parameter file and starts the location calculation. + Takes paths to NLLoc executable and input parameter file + and starts the location calculation. + :param call: full path to NLLoc executable :type call: str + :param fnin: full path to input parameter file :type fnin: str ''' + # locate the event subprocess.call([call, fnin]) From e1c2629f97513fa0b139a4822118c6800a44a313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludger=20K=C3=BCperkoch?= Date: Wed, 18 Nov 2015 11:11:10 +0100 Subject: [PATCH 6/7] Modified writephases for NLLoc: writes dummy onset times (start of seismic trace) into phase file in order to derive theoretical onset times later needed for iterative picking. --- pylot/core/pick/utils.py | 92 +++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 40 deletions(-) diff --git a/pylot/core/pick/utils.py b/pylot/core/pick/utils.py index 9887c78d..f4eb2282 100644 --- a/pylot/core/pick/utils.py +++ b/pylot/core/pick/utils.py @@ -961,46 +961,58 @@ def writephases(arrivals, fformat, filename): # write header fid.write('# EQEVENT: Label: EQ001 Loc: X 0.00 Y 0.00 Z 10.00 OT 0.00 \n') for key in arrivals: - if arrivals[key]['P']['weight'] < 4: - fm = arrivals[key]['P']['fm'] - if fm == None: - fm = '?' - onset = arrivals[key]['P']['mpp'] - year = onset.year - month = onset.month - day = onset.day - hh = onset.hour - mm = onset.minute - ss = onset.second - ms = onset.microsecond - ss_ms = ss + ms / 1000000.0 - fid.write('%s ? ? ? P %s %d%02d%02d %02d%02d %7.4f GAU 0 0 0 0 1 \n' % (key, - fm, - year, - month, - day, - hh, - mm, - ss_ms)) - if arrivals[key]['S']['weight'] < 4: - fm = '?' - onset = arrivals[key]['S']['mpp'] - year = onset.year - month = onset.month - day = onset.day - hh = onset.hour - mm = onset.minute - ss = onset.second - ms = onset.microsecond - ss_ms = ss + ms / 1000000.0 - fid.write('%s ? ? ? S %s %d%02d%02d %02d%02d %7.4f GAU 0 0 0 0 1 \n' % (key, - fm, - year, - month, - day, - hh, - mm, - ss_ms)) + # P onsets + if arrivals[key]['P']: + fm = arrivals[key]['P']['fm'] + if fm == None: + fm = '?' + onset = arrivals[key]['P']['mpp'] + year = onset.year + month = onset.month + day = onset.day + hh = onset.hour + mm = onset.minute + ss = onset.second + ms = onset.microsecond + ss_ms = ss + ms / 1000000.0 + if arrivals[key]['P']['weight'] < 4: + pweight = 1 # use pick + else: + pweight = 0 # do not use pick + fid.write('%s ? ? ? P %s %d%02d%02d %02d%02d %7.4f GAU 0 0 0 0 %d \n' % (key, + fm, + year, + month, + day, + hh, + mm, + ss_ms, + pweight)) + # S onsets + if arrivals[key]['S']: + fm = '?' + onset = arrivals[key]['S']['mpp'] + year = onset.year + month = onset.month + day = onset.day + hh = onset.hour + mm = onset.minute + ss = onset.second + ms = onset.microsecond + ss_ms = ss + ms / 1000000.0 + if arrivals[key]['S']['weight'] < 4: + sweight = 1 # use pick + else: + sweight = 0 # do not use pick + fid.write('%s ? ? ? S %s %d%02d%02d %02d%02d %7.4f GAU 0 0 0 0 %d \n' % (key, + fm, + year, + month, + day, + hh, + mm, + ss_ms, + sweight)) fid.close() From 96fcc2470b98fb46b77972bf6558fbfb2f729c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludger=20K=C3=BCperkoch?= Date: Wed, 18 Nov 2015 11:12:53 +0100 Subject: [PATCH 7/7] Modified pick dictionary: writes dummy onset times (start of seismic trace) into dictionary in order to derive theoretical onset times later needed for iterative picking. --- pylot/core/pick/autopick.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pylot/core/pick/autopick.py b/pylot/core/pick/autopick.py index 0e1c3030..988c8e5c 100755 --- a/pylot/core/pick/autopick.py +++ b/pylot/core/pick/autopick.py @@ -764,11 +764,23 @@ def autopickstation(wfstream, pickparam): lpickP = zdat[0].stats.starttime + lpickP epickP = zdat[0].stats.starttime + epickP mpickP = zdat[0].stats.starttime + mpickP + else: + # dummy values (start of seismic trace) in order to derive + # theoretical onset times for iteratve picking + lpickP = zdat[0].stats.starttime + epickP = zdat[0].stats.starttime + mpickP = zdat[0].stats.starttime if mpickS is not None and epickS is not None and mpickS is not None: lpickS = edat[0].stats.starttime + lpickS epickS = edat[0].stats.starttime + epickS mpickS = edat[0].stats.starttime + mpickS + else: + # dummy values (start of seismic trace) in order to derive + # theoretical onset times for iteratve picking + lpickS = edat[0].stats.starttime + epickS = edat[0].stats.starttime + mpickS = edat[0].stats.starttime # create dictionary # for P phase