some fixes calling autopylot (figures=None), added log for autoTuner

This commit is contained in:
Marcel Paffrath 2017-05-15 17:21:22 +02:00
parent a2ab98c202
commit cae5c961b0
7 changed files with 252 additions and 93 deletions

View File

@ -1181,6 +1181,7 @@ class MainWindow(QMainWindow):
if not self.tap: if not self.tap:
self.tap = TuneAutopicker(self) self.tap = TuneAutopicker(self)
self.update_autopicker()
self.tap.update.connect(self.update_autopicker) self.tap.update.connect(self.update_autopicker)
else: else:
self.tap.fill_eventbox() self.tap.fill_eventbox()
@ -1761,10 +1762,18 @@ class Project(object):
return return
for item in eventlist: for item in eventlist:
event = Event(item) event = Event(item)
if not event in self.eventlist: if not event.path in self.getPaths():
self.eventlist.append(event) self.eventlist.append(event)
else:
print('Skipping event with path {}. Already part of project.'.format(event.path))
self.setDirty() self.setDirty()
def getPaths(self):
paths = []
for event in self.eventlist:
paths.append(event.path)
return paths
def setDirty(self): def setDirty(self):
self.dirty = True self.dirty = True

View File

@ -29,7 +29,7 @@ from pylot.core.util.version import get_git_version as _getVersionString
__version__ = _getVersionString() __version__ = _getVersionString()
def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, savepath=None, iplot=0): def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, savepath=None, station='all', iplot=0):
""" """
Determine phase onsets automatically utilizing the automatic picking Determine phase onsets automatically utilizing the automatic picking
algorithms by Kueperkoch et al. 2010/2012. algorithms by Kueperkoch et al. 2010/2012.
@ -55,15 +55,20 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, save
***********************************'''.format(version=_getVersionString()) ***********************************'''.format(version=_getVersionString())
print(splash) print(splash)
locflag = 1
if input_dict: if input_dict:
if input_dict.has_key('parameter'): if input_dict.has_key('parameter'):
parameter = input_dict['parameter'] parameter = input_dict['parameter']
if input_dict.has_key('fig_dict'): if input_dict.has_key('fig_dict'):
fig_dict = input_dict['fig_dict'] fig_dict = input_dict['fig_dict']
if input_dict.has_key('station'):
station = input_dict['station']
if input_dict.has_key('fnames'): if input_dict.has_key('fnames'):
fnames = input_dict['fnames'] fnames = input_dict['fnames']
if input_dict.has_key('iplot'): if input_dict.has_key('iplot'):
iplot = input_dict['iplot'] iplot = input_dict['iplot']
if input_dict.has_key('locflag'):
locflag = input_dict['locflag']
if not parameter: if not parameter:
if inputfile: if inputfile:
@ -103,8 +108,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, save
datastructure.setExpandFields(exf) datastructure.setExpandFields(exf)
# check if default location routine NLLoc is available # check if default location routine NLLoc is available
if parameter['nllocbin']: if parameter['nllocbin'] and locflag:
locflag = 1
# get NLLoc-root path # get NLLoc-root path
nllocroot = parameter.get('nllocroot') nllocroot = parameter.get('nllocroot')
# get path to NLLoc executable # get path to NLLoc executable
@ -168,12 +172,17 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, save
now.minute) now.minute)
parameter.setParam(eventID=evID) parameter.setParam(eventID=evID)
wfdat = data.getWFData() # all available streams wfdat = data.getWFData() # all available streams
if not station == 'all':
wfdat = wfdat.select(station=station)
if not wfdat:
print('Could not find station {}. STOP!'.format(station))
return
wfdat = remove_underscores(wfdat) wfdat = remove_underscores(wfdat)
metadata = read_metadata(parameter.get('invdir')) metadata = read_metadata(parameter.get('invdir'))
corr_dat = restitute_data(wfdat.copy(), *metadata) corr_dat = restitute_data(wfdat.copy(), *metadata)
print('Working on event %s' % event) print('Working on event %s. Stations: %s' % (event, station))
print(data) print(wfdat)
########################################################## ##########################################################
# !automated picking starts here! # !automated picking starts here!
picks = autopickevent(wfdat, parameter, iplot=iplot, fig_dict=fig_dict) picks = autopickevent(wfdat, parameter, iplot=iplot, fig_dict=fig_dict)
@ -243,7 +252,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, save
print("autoPyLoT: Number of maximum iterations reached, stop iterative picking!") print("autoPyLoT: Number of maximum iterations reached, stop iterative picking!")
break break
print("autoPyLoT: Starting with iteration No. %d ..." % nlloccounter) print("autoPyLoT: Starting with iteration No. %d ..." % nlloccounter)
picks, _ = iteratepicker(wfdat, nllocfile, picks, badpicks, parameter) picks = iteratepicker(wfdat, nllocfile, picks, badpicks, parameter, fig_dict=fig_dict)
# write phases to NLLoc-phase file # write phases to NLLoc-phase file
nll.export(picks, phasefile, parameter) nll.export(picks, phasefile, parameter)
# remove actual NLLoc-location file to keep only the last # remove actual NLLoc-location file to keep only the last

View File

@ -1 +1 @@
4d9c-dirty a2ab-dirty

View File

@ -186,11 +186,15 @@ class AutoPickParameter(object):
if not is_type == expect_type and not is_type == tuple: if not is_type == expect_type and not is_type == tuple:
message = 'Type check failed for param: {}, is type: {}, expected type:{}' message = 'Type check failed for param: {}, is type: {}, expected type:{}'
message = message.format(param, is_type, expect_type) message = message.format(param, is_type, expect_type)
raise TypeError(message) print(Warning(message))
def setParam(self, param, value): def setParamKV(self, param, value):
self.__setitem__(param, value) self.__setitem__(param, value)
def setParam(self, **kwargs):
for key in kwargs:
self.__setitem__(key, kwargs[key])
@staticmethod @staticmethod
def _printParameterError(errmsg): def _printParameterError(errmsg):
print('ParameterError:\n non-existent parameter %s' % errmsg) print('ParameterError:\n non-existent parameter %s' % errmsg)

View File

@ -233,6 +233,10 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
# get prelimenary onset time from AIC-HOS-CF using subclass AICPicker # get prelimenary onset time from AIC-HOS-CF using subclass AICPicker
# of class AutoPicking # of class AutoPicking
key = 'aicFig' key = 'aicFig'
if fig_dict:
fig = fig_dict[key]
else:
fig = None
aicpick = AICPicker(aiccf, tsnrz, pickwinP, iplot, None, tsmoothP, fig=fig_dict[key]) aicpick = AICPicker(aiccf, tsnrz, pickwinP, iplot, None, tsmoothP, fig=fig_dict[key])
############################################################## ##############################################################
if aicpick.getpick() is not None: if aicpick.getpick() is not None:
@ -248,10 +252,14 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
'{1}'.format(minsiglength, minsiglength / 2) '{1}'.format(minsiglength, minsiglength / 2)
if verbose: print(msg) if verbose: print(msg)
key = 'slength' key = 'slength'
if fig_dict:
fig = fig_dict[key]
else:
fig = None
Pflag = checksignallength(zne, aicpick.getpick(), tsnrz, Pflag = checksignallength(zne, aicpick.getpick(), tsnrz,
minsiglength / 2, minsiglength / 2,
nfacsl, minpercent, iplot, nfacsl, minpercent, iplot,
fig_dict[key]) fig)
else: else:
# filter and taper horizontal traces # filter and taper horizontal traces
trH1_filt = edat.copy() trH1_filt = edat.copy()
@ -266,11 +274,14 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
trH2_filt.taper(max_percentage=0.05, type='hann') trH2_filt.taper(max_percentage=0.05, type='hann')
zne += trH1_filt zne += trH1_filt
zne += trH2_filt zne += trH2_filt
key = 'slength' if fig_dict:
fig = fig_dict['slength']
else:
fig = None
Pflag = checksignallength(zne, aicpick.getpick(), tsnrz, Pflag = checksignallength(zne, aicpick.getpick(), tsnrz,
minsiglength, minsiglength,
nfacsl, minpercent, iplot, nfacsl, minpercent, iplot,
fig_dict[key]) fig)
if Pflag == 1: if Pflag == 1:
# check for spuriously picked S onset # check for spuriously picked S onset
@ -281,9 +292,12 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
if verbose: print(msg) if verbose: print(msg)
else: else:
if iplot>1: if iplot>1:
key = 'checkZ4s' if fig_dict:
fig = fig_dict['checkZ4s']
else:
fig = None
Pflag = checkZ4S(zne, aicpick.getpick(), zfac, Pflag = checkZ4S(zne, aicpick.getpick(), zfac,
tsnrz[3], iplot, fig_dict[key]) tsnrz[3], iplot, fig)
if Pflag == 0: if Pflag == 0:
Pmarker = 'SinsteadP' Pmarker = 'SinsteadP'
Pweight = 9 Pweight = 9
@ -330,18 +344,24 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
'correctly: maybe the algorithm name ({algoP}) is ' \ 'correctly: maybe the algorithm name ({algoP}) is ' \
'corrupted'.format( 'corrupted'.format(
algoP=algoP) algoP=algoP)
key = 'refPpick' if fig_dict:
fig = fig_dict['refPpick']
else:
fig = None
refPpick = PragPicker(cf2, tsnrz, pickwinP, iplot, ausP, tsmoothP, refPpick = PragPicker(cf2, tsnrz, pickwinP, iplot, ausP, tsmoothP,
aicpick.getpick(), fig_dict[key]) aicpick.getpick(), fig)
mpickP = refPpick.getpick() mpickP = refPpick.getpick()
############################################################# #############################################################
if mpickP is not None: if mpickP is not None:
# quality assessment # quality assessment
# get earliest/latest possible pick and symmetrized uncertainty # get earliest/latest possible pick and symmetrized uncertainty
if iplot: if iplot:
key = 'el_Ppick' if fig_dict:
fig = fig_dict['el_Ppick']
else:
fig = None
epickP, lpickP, Perror = earllatepicker(z_copy, nfacP, tsnrz, epickP, lpickP, Perror = earllatepicker(z_copy, nfacP, tsnrz,
mpickP, iplot, fig=fig_dict[key]) mpickP, iplot, fig=fig)
else: else:
epickP, lpickP, Perror = earllatepicker(z_copy, nfacP, tsnrz, epickP, lpickP, Perror = earllatepicker(z_copy, nfacP, tsnrz,
mpickP, iplot) mpickP, iplot)
@ -366,8 +386,11 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
# certain quality required # certain quality required
if Pweight <= minfmweight and SNRP >= minFMSNR: if Pweight <= minfmweight and SNRP >= minFMSNR:
if iplot: if iplot:
key = 'fm_picker' if fig_dict:
FM = fmpicker(zdat, z_copy, fmpickwin, mpickP, iplot, fig_dict[key]) fig = fig_dict['fm_picker']
else:
fig = None
FM = fmpicker(zdat, z_copy, fmpickwin, mpickP, iplot, fig)
else: else:
FM = fmpicker(zdat, z_copy, fmpickwin, mpickP, iplot) FM = fmpicker(zdat, z_copy, fmpickwin, mpickP, iplot)
else: else:
@ -468,9 +491,12 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
############################################################## ##############################################################
# get prelimenary onset time from AIC-HOS-CF using subclass AICPicker # get prelimenary onset time from AIC-HOS-CF using subclass AICPicker
# of class AutoPicking # of class AutoPicking
key = 'aicARHfig' if fig_dict:
fig = fig_dict['aicARHfig']
else:
fig = None
aicarhpick = AICPicker(haiccf, tsnrh, pickwinS, iplot, None, aicarhpick = AICPicker(haiccf, tsnrh, pickwinS, iplot, None,
aictsmoothS, fig = fig_dict[key]) aictsmoothS, fig=fig)
############################################################### ###############################################################
# go on with processing if AIC onset passes quality control # go on with processing if AIC onset passes quality control
if (aicarhpick.getSlope() >= minAICSslope and if (aicarhpick.getSlope() >= minAICSslope and
@ -524,9 +550,12 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
addnoise) # instance of ARHcf addnoise) # instance of ARHcf
# get refined onset time from CF2 using class Picker # get refined onset time from CF2 using class Picker
key = 'refSpick' if fig_dict:
fig = fig_dict['refSpick']
else:
fig = None
refSpick = PragPicker(arhcf2, tsnrh, pickwinS, iplot, ausS, refSpick = PragPicker(arhcf2, tsnrh, pickwinS, iplot, ausS,
tsmoothS, aicarhpick.getpick(), fig_dict[key]) tsmoothS, aicarhpick.getpick(), fig)
mpickS = refSpick.getpick() mpickS = refSpick.getpick()
############################################################# #############################################################
if mpickS is not None: if mpickS is not None:
@ -534,11 +563,14 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
# get earliest/latest possible pick and symmetrized uncertainty # get earliest/latest possible pick and symmetrized uncertainty
h_copy[0].data = trH1_filt.data h_copy[0].data = trH1_filt.data
if iplot: if iplot:
key = 'el_S1pick' if fig_dict:
fig = fig_dict['el_S1pick']
else:
fig = None
epickS1, lpickS1, Serror1 = earllatepicker(h_copy, nfacS, epickS1, lpickS1, Serror1 = earllatepicker(h_copy, nfacS,
tsnrh, tsnrh,
mpickS, iplot, mpickS, iplot,
fig_dict[key]) fig=fig)
else: else:
epickS1, lpickS1, Serror1 = earllatepicker(h_copy, nfacS, epickS1, lpickS1, Serror1 = earllatepicker(h_copy, nfacS,
tsnrh, tsnrh,
@ -546,11 +578,14 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
h_copy[0].data = trH2_filt.data h_copy[0].data = trH2_filt.data
if iplot: if iplot:
key = 'el_S2pick' if fig_dict:
fig = fig_dict['el_S2pick']
else:
fig = None
epickS2, lpickS2, Serror2 = earllatepicker(h_copy, nfacS, epickS2, lpickS2, Serror2 = earllatepicker(h_copy, nfacS,
tsnrh, tsnrh,
mpickS, iplot, mpickS, iplot,
fig_dict[key]) fig=fig)
else: else:
epickS2, lpickS2, Serror2 = earllatepicker(h_copy, nfacS, epickS2, lpickS2, Serror2 = earllatepicker(h_copy, nfacS,
tsnrh, tsnrh,
@ -841,7 +876,7 @@ def autopickstation(wfstream, pickparam, verbose=False, iplot=0, fig_dict=None):
return picks return picks
def iteratepicker(wf, NLLocfile, picks, badpicks, pickparameter): def iteratepicker(wf, NLLocfile, picks, badpicks, pickparameter, fig_dict=None):
''' '''
Repicking of bad onsets. Uses theoretical onset times from NLLoc-location file. Repicking of bad onsets. Uses theoretical onset times from NLLoc-location file.
@ -916,7 +951,7 @@ def iteratepicker(wf, NLLocfile, picks, badpicks, pickparameter):
print("zfac: %f => %f" % (zfac_old, pickparameter.get('zfac'))) print("zfac: %f => %f" % (zfac_old, pickparameter.get('zfac')))
# repick station # repick station
newpicks, fig = autopickstation(wf2pick, pickparameter) newpicks = autopickstation(wf2pick, pickparameter, fig_dict=fig_dict)
# replace old dictionary with new one # replace old dictionary with new one
picks[badpicks[i][0]] = newpicks picks[badpicks[i][0]] = newpicks
@ -931,4 +966,4 @@ def iteratepicker(wf, NLLocfile, picks, badpicks, pickparameter):
pickparameter.setParam(noisefactor=noisefactor_old) pickparameter.setParam(noisefactor=noisefactor_old)
pickparameter.setParam(zfac=zfac_old) pickparameter.setParam(zfac=zfac_old)
return picks, fig return picks

View File

@ -39,39 +39,57 @@ class AutoPickThread(QThread):
class Thread(QThread): class Thread(QThread):
def __init__(self, parent, func, arg=None, progressText=None): message = Signal(str)
def __init__(self, parent, func, arg=None, progressText=None, pb_widget=None, redirect_stdout=False):
QThread.__init__(self, parent) QThread.__init__(self, parent)
self.func = func self.func = func
self.arg = arg self.arg = arg
self.progressText = progressText self.progressText = progressText
self.pbdlg = None self.pb_widget = pb_widget
self.redirect_stdout = redirect_stdout
self.finished.connect(self.hideProgressbar) self.finished.connect(self.hideProgressbar)
self.showProgressbar() self.showProgressbar()
def run(self): def run(self):
if self.arg: if self.redirect_stdout:
self.data = self.func(self.arg) sys.stdout = self
else: try:
self.data = self.func() if self.arg:
self.data = self.func(self.arg)
else:
self.data = self.func()
self._executed = True
except Exception as e:
self._executed = False
self._executedError = e
print(e)
sys.stdout = sys.__stdout__
def __del__(self): def __del__(self):
self.wait() self.wait()
def showProgressbar(self): def showProgressbar(self):
if self.progressText: if self.progressText:
self.pbdlg = QDialog(self.parent()) if not self.pb_widget:
self.pbdlg.setModal(True) self.pb_widget = QDialog(self.parent())
self.pb_widget.setWindowFlags(Qt.SplashScreen)
self.pb_widget.setModal(True)
vl = QVBoxLayout() vl = QVBoxLayout()
pb = QProgressBar() pb = QProgressBar()
pb.setRange(0, 0) pb.setRange(0, 0)
vl.addWidget(pb) vl.addWidget(pb)
vl.addWidget(QLabel(self.progressText)) vl.addWidget(QLabel(self.progressText))
self.pbdlg.setLayout(vl) self.pb_widget.setLayout(vl)
self.pbdlg.setWindowFlags(Qt.SplashScreen) self.pb_widget.show()
self.pbdlg.show()
def hideProgressbar(self): def hideProgressbar(self):
if self.pbdlg: if self.pb_widget:
self.pbdlg.hide() self.pb_widget.hide()
def write(self, text):
self.message.emit(text)
def flush(self):
pass

View File

@ -1289,11 +1289,14 @@ class TuneAutopicker(QWidget):
self.init_eventlist() self.init_eventlist()
self.init_stationlist() self.init_stationlist()
self.init_figure_tabs() self.init_figure_tabs()
self.add_parameter() self.init_pbwidget()
self.add_parameters()
self.add_buttons() self.add_buttons()
self.add_log()
self.set_stretch() self.set_stretch()
self.resize(1280, 720) self.resize(1280, 720)
self.setWindowModality(QtCore.Qt.WindowModality.ApplicationModal) self.figure_tabs.setCurrentIndex(0)
#self.setWindowModality(QtCore.Qt.WindowModality.ApplicationModal)
#self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) #self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
def init_main_layouts(self): def init_main_layouts(self):
@ -1309,12 +1312,15 @@ class TuneAutopicker(QWidget):
def init_eventlist(self): def init_eventlist(self):
self.eventBox = self.parent.createEventBox() self.eventBox = self.parent.createEventBox()
self.fill_eventbox() self.fill_eventbox()
self.eventBox.setCurrentIndex(1)
self.trace_layout.addWidget(self.eventBox) self.trace_layout.addWidget(self.eventBox)
self.eventBox.activated.connect(self.fill_stationbox) self.eventBox.activated.connect(self.fill_stationbox)
self.eventBox.activated.connect(self.update_eventID)
def init_stationlist(self): def init_stationlist(self):
self.stationBox = QtGui.QComboBox() self.stationBox = QtGui.QComboBox()
self.trace_layout.addWidget(self.stationBox) self.trace_layout.addWidget(self.stationBox)
self.fill_stationbox()
def fill_stationbox(self): def fill_stationbox(self):
fnames = self.parent.getWFFnames_from_eventbox(eventbox=self.eventBox) fnames = self.parent.getWFFnames_from_eventbox(eventbox=self.eventBox)
@ -1325,19 +1331,23 @@ class TuneAutopicker(QWidget):
station = trace.stats.station station = trace.stats.station
if not station in stations: if not station in stations:
stations.append(str(station)) stations.append(str(station))
stations.sort()
for station in stations: for station in stations:
self.stationBox.addItem(str(station)) self.stationBox.addItem(str(station))
def init_figure_tabs(self): def init_figure_tabs(self):
self.main_tabs = QtGui.QTabWidget() self.figure_tabs = QtGui.QTabWidget()
self.p_tabs = QtGui.QTabWidget() self.fill_figure_tabs()
self.s_tabs = QtGui.QTabWidget()
self.tune_layout.insertWidget(0, self.main_tabs)
self.init_tab_names()
def add_parameter(self): def init_pbwidget(self):
self.pb_widget = QtGui.QWidget()
def add_parameters(self):
self.parameters = AutoPickParaBox(self.ap) self.parameters = AutoPickParaBox(self.ap)
self.parameters.set_tune_mode(True)
self.update_eventID()
self.parameter_layout.addWidget(self.parameters) self.parameter_layout.addWidget(self.parameters)
self.parameter_layout.addWidget(self.pb_widget)
self.tune_layout.insertLayout(1, self.parameter_layout) self.tune_layout.insertLayout(1, self.parameter_layout)
def add_buttons(self): def add_buttons(self):
@ -1346,29 +1356,83 @@ class TuneAutopicker(QWidget):
self.trace_layout.addWidget(self.pick_button) self.trace_layout.addWidget(self.pick_button)
self.trace_layout.setStretch(0, 1) self.trace_layout.setStretch(0, 1)
def add_log(self):
self.listWidget = QtGui.QListWidget()
self.figure_tabs.insertTab(3, self.listWidget, 'log')
def fill_figure_tabs(self):
self.p_tabs = QtGui.QTabWidget()
self.s_tabs = QtGui.QTabWidget()
self.tune_layout.insertWidget(0, self.figure_tabs)
self.init_tab_names()
def fill_eventbox(self): def fill_eventbox(self):
self.parent.fill_eventbox(self.eventBox, 'ref') self.parent.fill_eventbox(self.eventBox, 'ref')
def get_current_event(self):
return self.eventBox.currentText().split('/')[-1]
def update_eventID(self):
self.parameters.boxes['eventID'].setText(self.get_current_event())
def add_log_item(self, text):
self.listWidget.addItem(text)
self.listWidget.scrollToBottom()
def call_picker(self): def call_picker(self):
self.ap = self.update_params() self.ap = self.params_from_gui()
station = str(self.stationBox.currentText())
if not station:
self._warn('No station selected')
return
args = {'parameter': self.ap, args = {'parameter': self.ap,
'station': station,
'fnames': 'None', 'fnames': 'None',
'iplot': 2, 'iplot': 2,
'fig_dict': self.fig_dict} 'fig_dict': self.fig_dict,
self.ap_thread = Thread(self, autoPyLoT, arg=args, progressText='Picking trace...') 'locflag': 0}
for key in self.fig_dict.keys():
self.fig_dict[key].clear()
self.ap_thread = Thread(self, autoPyLoT, arg=args,
progressText='Picking trace...', pb_widget=self.pb_widget,
redirect_stdout=True)
self.enable(False)
self.ap_thread.message.connect(self.add_log_item)
self.ap_thread.finished.connect(self.finish_picker) self.ap_thread.finished.connect(self.finish_picker)
self.figure_tabs.setCurrentIndex(3)
self.ap_thread.start() self.ap_thread.start()
#picks = autoPyLoT(self.ap, fnames='None', iplot=2, fig_dict=self.fig_dict) #picks = autoPyLoT(self.ap, fnames='None', iplot=2, fig_dict=self.fig_dict)
def finish_picker(self): def finish_picker(self):
self.enable(True)
if not self.ap_thread._executed:
self._warn('Could not execute picker:\n{}'.format(
self.ap_thread._executedError))
return
self.picks = self.ap_thread.data self.picks = self.ap_thread.data
self.main_tabs.setParent(None) if not self.picks:
self.init_figure_tabs() self._warn('No picks found. See terminal output.')
return
#renew tabs
self.overview.setParent(None)
self.p_tabs.setParent(None)
self.s_tabs.setParent(None)
self.fill_figure_tabs()
self.set_stretch() self.set_stretch()
self.update.emit('Update') self.update.emit('Update')
self.figure_tabs.setCurrentIndex(0)
def update_params(self): def enable(self, bool):
ap = self.parameters.update_params() self.pick_button.setEnabled(bool)
self.parameters.setEnabled(bool)
self.eventBox.setEnabled(bool)
self.stationBox.setEnabled(bool)
self.overview.setEnabled(bool)
self.p_tabs.setEnabled(bool)
self.s_tabs.setEnabled(bool)
def params_from_gui(self):
ap = self.parameters.params_from_gui()
if self.parent: if self.parent:
self.parent._inputs = ap self.parent._inputs = ap
return ap return ap
@ -1382,10 +1446,11 @@ class TuneAutopicker(QWidget):
self.stb_names = ['aicARHfig', 'refSpick', 'el_S1pick', 'el_S2pick'] self.stb_names = ['aicARHfig', 'refSpick', 'el_S1pick', 'el_S2pick']
def fill_tabs(self, canvas_dict): def fill_tabs(self, canvas_dict):
id = self.main_tabs.addTab(self.gen_tab_widget('Overview', canvas_dict['mainFig']), 'Overview') self.overview = self.gen_tab_widget('Overview', canvas_dict['mainFig'])
self.main_tabs.setTabEnabled(id, bool(self.fig_dict['mainFig'].axes)) id = self.figure_tabs.insertTab(0, self.overview, 'Overview')
self.main_tabs.addTab(self.p_tabs, 'P') #self.figure_tabs.setTabEnabled(id, bool(self.fig_dict['mainFig'].axes))
self.main_tabs.addTab(self.s_tabs, 'S') self.figure_tabs.insertTab(1, self.p_tabs, 'P')
self.figure_tabs.insertTab(2, self.s_tabs, 'S')
self.fill_p_tabs(canvas_dict) self.fill_p_tabs(canvas_dict)
self.fill_s_tabs(canvas_dict) self.fill_s_tabs(canvas_dict)
try: try:
@ -1419,6 +1484,11 @@ class TuneAutopicker(QWidget):
widget.setLayout(v_layout) widget.setLayout(v_layout)
return widget return widget
def _warn(self, message):
self.qmb = QtGui.QMessageBox(QtGui.QMessageBox.Icon.Warning,
'Warning', message)
self.qmb.show()
class PropertiesDlg(QDialog): class PropertiesDlg(QDialog):
def __init__(self, parent=None, infile=None): def __init__(self, parent=None, infile=None):
@ -1701,6 +1771,7 @@ class AutoPickParaBox(QtGui.QWidget):
self.setLayout(self.layout) self.setLayout(self.layout)
self.add_main_parameters_tab() self.add_main_parameters_tab()
self.add_special_pick_parameters_tab() self.add_special_pick_parameters_tab()
self.params_to_gui()
self._toggle_advanced_settings() self._toggle_advanced_settings()
def _init_sublayouts(self): def _init_sublayouts(self):
@ -1729,7 +1800,15 @@ class AutoPickParaBox(QtGui.QWidget):
for b in box: for b in box:
b.setEnabled(enable) b.setEnabled(enable)
def init_boxes(self, parameter_names, defaults=False): def set_tune_mode(self, bool):
keys = ['rootpath', 'datapath', 'database',
'eventID', 'invdir', 'nllocbin',
'nllocroot', 'phasefile',
'ctrfile', 'ttpatter', 'outpatter']
for key in keys:
self.boxes[key].setEnabled(not(bool))
def init_boxes(self, parameter_names):
grid = QtGui.QGridLayout() grid = QtGui.QGridLayout()
for index1, name in enumerate(parameter_names): for index1, name in enumerate(parameter_names):
@ -1739,22 +1818,15 @@ class AutoPickParaBox(QtGui.QWidget):
tooltip = default_item['tooltip'] tooltip = default_item['tooltip']
tooltip += ' | type: {}'.format(default_item['type']) tooltip += ' | type: {}'.format(default_item['type'])
if not type(default_item['type']) == tuple: if not type(default_item['type']) == tuple:
if defaults:
value = default_item['value']
else:
value = self.ap[name]
typ = default_item['type'] typ = default_item['type']
box = self.create_box(value, typ, tooltip) box = self.create_box(typ, tooltip)
self.boxes[name] = box self.boxes[name] = box
elif type(default_item['type']) == tuple: elif type(default_item['type']) == tuple:
boxes = [] boxes = []
if defaults: values = self.ap[name]
values = default_item['value']
else:
values = self.ap[name]
for index2, val in enumerate(values): for index2, val in enumerate(values):
typ = default_item['type'][index2] typ = default_item['type'][index2]
boxes.append(self.create_box(val, typ, tooltip)) boxes.append(self.create_box(typ, tooltip))
box = self.create_multi_box(boxes) box = self.create_multi_box(boxes)
self.boxes[name] = boxes self.boxes[name] = boxes
label.setToolTip(tooltip) label.setToolTip(tooltip)
@ -1762,25 +1834,15 @@ class AutoPickParaBox(QtGui.QWidget):
grid.addWidget(box, index1, 2) grid.addWidget(box, index1, 2)
return grid return grid
def create_box(self, value, typ, tooltip): def create_box(self, typ, tooltip):
if typ == str: if typ == str:
box = QtGui.QLineEdit() box = QtGui.QLineEdit()
box.setText(value)
elif typ == float: elif typ == float:
box = QtGui.QDoubleSpinBox() box = QtGui.QDoubleSpinBox()
box.setMaximum(100*value)
box.setValue(value)
elif typ == int: elif typ == int:
box = QtGui.QSpinBox() box = QtGui.QSpinBox()
box.setMaximum(100*value)
box.setValue(value)
elif typ == bool: elif typ == bool:
if value == 'True':
value = True
if value == 'False':
value = False
box = QtGui.QCheckBox() box = QtGui.QCheckBox()
box.setChecked(value)
else: else:
raise TypeError('Unrecognized type {}'.format(typ)) raise TypeError('Unrecognized type {}'.format(typ))
return box return box
@ -1847,14 +1909,37 @@ class AutoPickParaBox(QtGui.QWidget):
if seperator: if seperator:
layout.addWidget(self.gen_h_seperator()) layout.addWidget(self.gen_h_seperator())
def update_params(self): def params_from_gui(self):
for param in self.ap.get_all_para_names(): for param in self.ap.get_all_para_names():
box = self.boxes[param] box = self.boxes[param]
value = self.getValue(box) value = self.getValue(box)
self.ap.checkValue(param, value) self.ap.checkValue(param, value)
self.ap.setParam(param, value) self.ap.setParamKV(param, value)
return self.ap return self.ap
def params_to_gui(self):
for param in self.ap.get_all_para_names():
box = self.boxes[param]
value = self.ap[param]
#self.ap.checkValue(param, value)
self.setValue(box, value)
def setValue(self, box, value):
if type(box) == QtGui.QLineEdit:
box.setText(value)
elif type(box) == QtGui.QSpinBox or type(box) == QtGui.QDoubleSpinBox:
box.setMaximum(100*value)
box.setValue(value)
elif type(box) == QtGui.QCheckBox:
if value == 'True':
value = True
if value == 'False':
value = False
box.setChecked(value)
elif type(box) == list:
for index, b in enumerate(box):
self.setValue(b, value[index])
def getValue(self, box): def getValue(self, box):
if type(box) == QtGui.QLineEdit: if type(box) == QtGui.QLineEdit:
value = str(box.text()) value = str(box.text())
@ -1869,7 +1954,6 @@ class AutoPickParaBox(QtGui.QWidget):
value = tuple(value) value = tuple(value)
return value return value
class ParametersTab(PropTab): class ParametersTab(PropTab):
def __init__(self, parent=None, infile=None): def __init__(self, parent=None, infile=None):
super(ParametersTab, self).__init__(parent) super(ParametersTab, self).__init__(parent)