diff --git a/QtPyLoT.py b/QtPyLoT.py index 0abc2d0d..3d1207fd 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -1311,11 +1311,13 @@ class MainWindow(QMainWindow): % self.infile) autopick_parameter = self._inputs self.addListItem(str(autopick_parameter)) - + ep = self.get_current_event_path().split('/') + eventid = ep[len(ep) - 1] self.thread = AutoPickThread(parent=self, func=autoPyLoT, infile = self.infile, fnames=self.fnames, + eventid=eventid, savepath=self.autosave) self.thread.message.connect(self.addListItem) diff --git a/autoPyLoT.py b/autoPyLoT.py index f688902b..2bf916b8 100755 --- a/autoPyLoT.py +++ b/autoPyLoT.py @@ -8,7 +8,6 @@ import glob import os import datetime from obspy import read_events - import pylot.core.loc.hyposat as hyposat import pylot.core.loc.hypo71 as hypo71 import pylot.core.loc.velest as velest @@ -29,7 +28,7 @@ from pylot.core.util.version import get_git_version as _getVersionString __version__ = _getVersionString() -def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, savepath=None, station='all', iplot=0): +def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, eventid=None, savepath=None, station='all', iplot=0): """ Determine phase onsets automatically utilizing the automatic picking algorithms by Kueperkoch et al. 2010/2012. @@ -141,7 +140,9 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, save events = glob.glob(os.path.join(datapath, parameter.get('eventID'))) else: # autoPyLoT was initialized from GUI - events = fnames + events = [os.path.join(datapath, eventid)] + evID = eventid + locflag = 2 for event in events: if fnames == 'None': @@ -162,14 +163,14 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, save parameter.setParam(eventID=eventID) else: data.setWFData(fnames) - event = savepath - now = datetime.datetime.now() - evID = '%d%02d%02d%02d%02d' % (now.year, - now.month, - now.day, - now.hour, - now.minute) - parameter.setParam(eventID=evID) + event = events[0] + #now = datetime.datetime.now() + #evID = '%d%02d%02d%02d%02d' % (now.year, + # now.month, + # now.day, + # now.hour, + # now.minute) + parameter.setParam(eventID=eventid) wfdat = data.getWFData() # all available streams if not station == 'all': wfdat = wfdat.select(station=station) @@ -178,6 +179,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, save return wfdat = remove_underscores(wfdat) metadata = read_metadata(parameter.get('invdir')) + print("Restitute data ...") corr_dat = restitute_data(wfdat.copy(), *metadata) print('Working on event %s. Stations: %s' % (event, station)) @@ -192,7 +194,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, save picks = autopickevent(wfdat, parameter, iplot=iplot) ########################################################## # locating - if locflag == 1: + if locflag > 0: # write phases to NLLoc-phase file nll.export(picks, phasefile, parameter) @@ -282,23 +284,24 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, save print("autoPyLoT: No more bad onsets found, stop iterative picking!") nlloccounter = maxnumit evt = read_events(nllocfile)[0] - # calculating seismic moment Mo and moment magnitude Mw - moment_mag = MomentMagnitude(corr_dat, evt, parameter.get('vp'), - parameter.get('Qp'), - parameter.get('rho'), True, \ - iplot) - # update pick with moment property values (w0, fc, Mo) - for station, props in moment_mag.moment_props.items(): - picks[station]['P'].update(props) - evt = moment_mag.updated_event() - local_mag = RichterMagnitude(corr_dat, evt, - parameter.get('sstop'), True, \ - iplot) - for station, amplitude in local_mag.amplitudes.items(): - picks[station]['S']['Ao'] = amplitude.generic_amplitude - evt = local_mag.updated_event() - net_mw = moment_mag.net_magnitude() - print("Network moment magnitude: %4.1f" % net_mw.mag) + if locflag < 2: + # calculating seismic moment Mo and moment magnitude Mw + moment_mag = MomentMagnitude(corr_dat, evt, parameter.get('vp'), + parameter.get('Qp'), + parameter.get('rho'), True, \ + iplot) + # update pick with moment property values (w0, fc, Mo) + for station, props in moment_mag.moment_props.items(): + picks[station]['P'].update(props) + evt = moment_mag.updated_event() + local_mag = RichterMagnitude(corr_dat, evt, + parameter.get('sstop'), True, \ + iplot) + for station, amplitude in local_mag.amplitudes.items(): + picks[station]['S']['Ao'] = amplitude.generic_amplitude + evt = local_mag.updated_event() + net_mw = moment_mag.net_magnitude() + print("Network moment magnitude: %4.1f" % net_mw.mag) else: print("autoPyLoT: No NLLoc-location file available! Stop iteration!") locflag = 9 @@ -361,6 +364,9 @@ if __name__ == "__main__": parser.add_argument('-f', '-F', '--fnames', type=str, action='store', help='''optional, list of data file names''') + parser.add_argument('-e', '-E', '--eventid', type=str, + action='store', + help='''optional, event ID''') # parser.add_argument('-p', '-P', '--plot', action='store', # help='show interactive plots') parser.add_argument('-s', '-S', '--spath', type=str, @@ -373,4 +379,5 @@ if __name__ == "__main__": cla = parser.parse_args() picks, mainFig = autoPyLoT(inputfile=str(cla.inputfile), - fnames=str(cla.fnames), savepath=str(cla.spath)) + fnames=str(cla.fnames), eventid=str(cla.eventid), + savepath=str(cla.spath)) diff --git a/pylot/core/util/thread.py b/pylot/core/util/thread.py index 859740a8..609cf9df 100644 --- a/pylot/core/util/thread.py +++ b/pylot/core/util/thread.py @@ -8,18 +8,19 @@ class AutoPickThread(QThread): message = Signal(str) finished = Signal() - def __init__(self, parent, func, infile, fnames, savepath): + def __init__(self, parent, func, infile, fnames, eventid, savepath): super(AutoPickThread, self).__init__() self.setParent(parent) self.func = func self.infile = infile self.fnames = fnames + self.eventid = eventid self.savepath = savepath def run(self): sys.stdout = self - picks = self.func(self.infile, self.fnames, self.savepath) + picks = self.func(None, None, self.infile, self.fnames, self.eventid, self.savepath) print("Autopicking finished!\n")