Merge branch 'develop' of ariadne.geophysik.ruhr-uni-bochum.de:/data/git/pylot into develop
This commit is contained in:
		
						commit
						82089a6490
					
				
							
								
								
									
										17
									
								
								QtPyLoT.py
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								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): | ||||
|  | ||||
							
								
								
									
										59
									
								
								autoPyLoT.py
									
									
									
									
									
								
							
							
						
						
									
										59
									
								
								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() | ||||
| @ -79,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 | ||||
| @ -110,30 +108,18 @@ 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 | ||||
|                     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 | ||||
|                 ########################################################## | ||||
| @ -165,28 +151,17 @@ 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 | ||||
|                 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 | ||||
|             ########################################################## | ||||
|  | ||||
| @ -10,54 +10,72 @@ from pylot.core.util.version import get_git_version as _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 | ||||
|     :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): | ||||
| 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 <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 | ||||
|     :type call: str | ||||
| 
 | ||||
|     :param fnin: full path to input parameter file | ||||
|     :type fnin: str | ||||
|     ''' | ||||
| 
 | ||||
|     # locate the event | ||||
|     subprocess.call([call, fnin]) | ||||
| 
 | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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() | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user