Merge branch 'develop' of ariadne.geophysik.ruhr-uni-bochum.de:/data/git/pylot into develop

This commit is contained in:
Marcel Paffrath 2015-11-18 17:22:51 +01:00
commit 82089a6490
5 changed files with 123 additions and 109 deletions

View File

@ -36,7 +36,7 @@ from PySide.QtGui import QMainWindow, QInputDialog, QIcon, QFileDialog, \
QDialog, QErrorMessage, QApplication, QPixmap, QMessageBox, QSplashScreen, \ QDialog, QErrorMessage, QApplication, QPixmap, QMessageBox, QSplashScreen, \
QActionGroup, QListWidget, QDockWidget QActionGroup, QListWidget, QDockWidget
import numpy as np import numpy as np
from obspy import UTCDateTime, readEvents from obspy import UTCDateTime
from pylot.core.read.data import Data from pylot.core.read.data import Data
from pylot.core.read.inputs import FilterOptions, AutoPickParameter from pylot.core.read.inputs import FilterOptions, AutoPickParameter
@ -59,7 +59,6 @@ locateTool = dict(nll=locateNll)
class MainWindow(QMainWindow): class MainWindow(QMainWindow):
__version__ = _getVersionString() __version__ = _getVersionString()
__slots__ = ['loc']
closing = Signal() closing = Signal()
def __init__(self, parent=None): def __init__(self, parent=None):
@ -651,10 +650,10 @@ class MainWindow(QMainWindow):
self.drawPicks(station) self.drawPicks(station)
else: else:
self.updateStatus('picks discarded ({0})'.format(station)) self.updateStatus('picks discarded ({0})'.format(station))
if not self.locflag() and self.check4Loc(): if not self.getLocflag() and self.check4Loc():
self.locflag(True) self.setLocflag(True)
elif self.locflag() and not self.check4Loc(): elif self.getLocflag() and not self.check4Loc():
self.locflag(False) self.setLocflag(False)
def autoPick(self): def autoPick(self):
list = QListWidget() list = QListWidget()
@ -783,12 +782,10 @@ class MainWindow(QMainWindow):
num += len(phases) num += len(phases)
return num return num
@property def getLocflag(self):
def locflag(self):
return self.loc return self.loc
@locflag.setter def setLocflag(self, value):
def locflag(self, value):
self.loc = value self.loc = value
def updateStatus(self, message, duration=5000): def updateStatus(self, message, duration=5000):

View File

@ -1,7 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os import os
import argparse import argparse
import glob import glob
@ -12,7 +11,7 @@ from pylot.core.read.data import Data
from pylot.core.read.inputs import AutoPickParameter from pylot.core.read.inputs import AutoPickParameter
from pylot.core.util.structure import DATASTRUCTURE from pylot.core.util.structure import DATASTRUCTURE
from pylot.core.pick.autopick import autopickevent 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 from pylot.core.util.version import get_git_version as _getVersionString
__version__ = _getVersionString() __version__ = _getVersionString()
@ -79,12 +78,11 @@ def autoPyLoT(inputfile):
phasef = parameter.getParam('phasefile') phasef = parameter.getParam('phasefile')
phasefile = '%s/obs/%s' % (nllocroot, phasef) phasefile = '%s/obs/%s' % (nllocroot, phasef)
# get name of NLLoc-control file # get name of NLLoc-control file
locf = parameter.getParam('locfile') ctrf = parameter.getParam('ctrfile')
locfile = '%s/run/%s' % (nllocroot, locf) ctrfile = '%s/run/%s' % (nllocroot, ctrf)
# patter of NLLoc ttimes from location grid # pattern of NLLoc ttimes from location grid
ttpat = parameter.getParam('ttpatter') ttpat = parameter.getParam('ttpatter')
ttpatter = '%s/time/%s' % (nllocroot, ttpat) # pattern of NLLoc-output file
# patter of NLLoc-output file
nllocoutpatter = parameter.getParam('outpatter') nllocoutpatter = parameter.getParam('outpatter')
else: else:
locflag = 0 locflag = 0
@ -110,30 +108,18 @@ def autoPyLoT(inputfile):
# locating # locating
if locflag == 1: if locflag == 1:
# write phases to NLLoc-phase file # 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! # 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] evID = event[string.rfind(event, "/") + 1 : len(events) - 1]
nllocout = '%s/loc/%s_%s' % (nllocroot, evID, nllocoutpatter) nllocout = '%s_%s' % (evID, nllocoutpatter)
locfiles = 'LOCFILES %s NLLOC_OBS %s %s 0' % (phasefile, ttpatter, nllocout) # create comment line for NLLoc-control file
print ("Modifying NLLoc-control file %s ..." % locfile) modifyInputFile(ctrf, nllocroot, nllocout, phasef, ttpat)
# 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()
# locate the event # 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 # get theoretical onset times for picks with weights >= 4
# in order to reprocess them using smaller time windows # in order to reprocess them using smaller time windows
########################################################## ##########################################################
@ -165,28 +151,17 @@ def autoPyLoT(inputfile):
# locating # locating
if locflag == 1: if locflag == 1:
# write phases to NLLoc-phase file # 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! # For locating the event the NLLoc-control file has to be modified!
# create comment line for NLLoc-control file NLLoc-output file nllocout = '%s_%s' % (parameter.getParam('eventID'), nllocoutpatter)
nllocout = '%s/loc/%s_%s' % (nllocroot, parameter.getParam('eventID'), nllocoutpatter) # create comment line for NLLoc-control file
locfiles = 'LOCFILES %s NLLOC_OBS %s %s 0' % (phasefile, ttpatter, nllocout) modifyInputFile(ctrf, nllocroot, nllocout, phasef, ttpat)
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()
# locate the event # 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 # get theoretical onset times for picks with weights >= 4
# in order to reprocess them using smaller time windows # in order to reprocess them using smaller time windows
########################################################## ##########################################################

View File

@ -10,54 +10,72 @@ from pylot.core.util.version import get_git_version as _getVersionString
__version__ = _getVersionString() __version__ = _getVersionString()
def picksExport(picks, phasefile): def picksExport(picks, locrt, phasefile):
''' '''
Take <picks> dictionary and exports picking data to a NLLOC-obs <phasefile> without creating an ObsPy event object. Take <picks> dictionary and exports picking data to a NLLOC-obs
<phasefile> without creating an ObsPy event object.
:param picks: picking data dictionary :param picks: picking data dictionary
:type picks: dict :type picks: dict
:param locrt: choose location routine
:type locrt: str
:param phasefile: complete path to the exporting obs file :param phasefile: complete path to the exporting obs file
:type phasefile: str :type phasefile: str
''' '''
# write phases to NLLoc-phase file # write phases to NLLoc-phase file
writephases(picks, 'NLLoc', phasefile) 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: root path to NLLoc working directory
:param root: :type: str
:param outpath:
:param phasefile: :param nllocoutn: name of NLLoc-location output file
:param tttable: :type: str
:return:
: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 # create comment line for NLLoc-control file NLLoc-output file
print ("Modifying NLLoc-control file %s ..." % fn) ctrfile = os.path.join(root, 'run', ctrfn)
nllocout = os.path.join(root,'loc', outpath) nllocout = os.path.join(root,'loc', nllocoutn)
phasefile = os.path.join(root, 'obs', phasefn) phasefile = os.path.join(root, 'obs', phasefn)
tttable = os.path.join(root, 'time', tttn) tttable = os.path.join(root, 'time', tttn)
locfiles = 'LOCFILES %s NLLOC_OBS %s %s 0\n' % (phasefile, tttable, nllocout) locfiles = 'LOCFILES %s NLLOC_OBS %s %s 0\n' % (phasefile, tttable, nllocout)
# modification of NLLoc-control file # modification of NLLoc-control file
curlocfiles = getPatternLine(fn, 'LOCFILES') print ("Modifying NLLoc-control file %s ..." % ctrfile)
nllfile = open(fn, 'r') curlocfiles = getPatternLine(ctrfile, 'LOCFILES')
nllfile = open(ctrfile, 'r')
filedata = nllfile.read() filedata = nllfile.read()
if filedata.find(locfiles) < 0: if filedata.find(locfiles) < 0:
# replace old command # replace old command
filedata = filedata.replace(curlocfiles, locfiles) filedata = filedata.replace(curlocfiles, locfiles)
nllfile = open(fn, 'w') nllfile = open(ctrfile, 'w')
nllfile.write(filedata) nllfile.write(filedata)
nllfile.close() nllfile.close()
def locate(call, fnin): def locate(call, fnin):
''' '''
Takes paths to NLLoc executable <call> and input parameter file <fnin> and starts the location calculation. Takes paths to NLLoc executable <call> and input parameter file <fnin>
and starts the location calculation.
:param call: full path to NLLoc executable :param call: full path to NLLoc executable
:type call: str :type call: str
:param fnin: full path to input parameter file :param fnin: full path to input parameter file
:type fnin: str :type fnin: str
''' '''
# locate the event # locate the event
subprocess.call([call, fnin]) subprocess.call([call, fnin])

View File

@ -764,11 +764,23 @@ def autopickstation(wfstream, pickparam):
lpickP = zdat[0].stats.starttime + lpickP lpickP = zdat[0].stats.starttime + lpickP
epickP = zdat[0].stats.starttime + epickP epickP = zdat[0].stats.starttime + epickP
mpickP = zdat[0].stats.starttime + mpickP 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: if mpickS is not None and epickS is not None and mpickS is not None:
lpickS = edat[0].stats.starttime + lpickS lpickS = edat[0].stats.starttime + lpickS
epickS = edat[0].stats.starttime + epickS epickS = edat[0].stats.starttime + epickS
mpickS = edat[0].stats.starttime + mpickS 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 # create dictionary
# for P phase # for P phase

View File

@ -961,46 +961,58 @@ def writephases(arrivals, fformat, filename):
# write header # write header
fid.write('# EQEVENT: Label: EQ001 Loc: X 0.00 Y 0.00 Z 10.00 OT 0.00 \n') fid.write('# EQEVENT: Label: EQ001 Loc: X 0.00 Y 0.00 Z 10.00 OT 0.00 \n')
for key in arrivals: for key in arrivals:
if arrivals[key]['P']['weight'] < 4: # P onsets
fm = arrivals[key]['P']['fm'] if arrivals[key]['P']:
if fm == None: fm = arrivals[key]['P']['fm']
fm = '?' if fm == None:
onset = arrivals[key]['P']['mpp'] fm = '?'
year = onset.year onset = arrivals[key]['P']['mpp']
month = onset.month year = onset.year
day = onset.day month = onset.month
hh = onset.hour day = onset.day
mm = onset.minute hh = onset.hour
ss = onset.second mm = onset.minute
ms = onset.microsecond ss = onset.second
ss_ms = ss + ms / 1000000.0 ms = onset.microsecond
fid.write('%s ? ? ? P %s %d%02d%02d %02d%02d %7.4f GAU 0 0 0 0 1 \n' % (key, ss_ms = ss + ms / 1000000.0
fm, if arrivals[key]['P']['weight'] < 4:
year, pweight = 1 # use pick
month, else:
day, pweight = 0 # do not use pick
hh, fid.write('%s ? ? ? P %s %d%02d%02d %02d%02d %7.4f GAU 0 0 0 0 %d \n' % (key,
mm, fm,
ss_ms)) year,
if arrivals[key]['S']['weight'] < 4: month,
fm = '?' day,
onset = arrivals[key]['S']['mpp'] hh,
year = onset.year mm,
month = onset.month ss_ms,
day = onset.day pweight))
hh = onset.hour # S onsets
mm = onset.minute if arrivals[key]['S']:
ss = onset.second fm = '?'
ms = onset.microsecond onset = arrivals[key]['S']['mpp']
ss_ms = ss + ms / 1000000.0 year = onset.year
fid.write('%s ? ? ? S %s %d%02d%02d %02d%02d %7.4f GAU 0 0 0 0 1 \n' % (key, month = onset.month
fm, day = onset.day
year, hh = onset.hour
month, mm = onset.minute
day, ss = onset.second
hh, ms = onset.microsecond
mm, ss_ms = ss + ms / 1000000.0
ss_ms)) 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() fid.close()