[new] first working version of jackknife plots for multiple events (WIP)

This commit is contained in:
Marcel Paffrath 2017-08-22 16:43:09 +02:00
parent d818e6aef9
commit c6c13f85bc
4 changed files with 199 additions and 57 deletions

View File

@ -79,7 +79,7 @@ from pylot.core.util.event import Event
from pylot.core.io.location import create_creation_info, create_event from pylot.core.io.location import create_creation_info, create_event
from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \ from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \
WaveformWidget, WaveformWidgetPG, PropertiesDlg, HelpForm, createAction, PickDlg, \ WaveformWidget, WaveformWidgetPG, PropertiesDlg, HelpForm, createAction, PickDlg, \
getDataType, ComparisonWidget, TuneAutopicker, PylotParaBox, AutoPickDlg, JackknifeWidget getDataType, ComparisonWidget, TuneAutopicker, PylotParaBox, AutoPickDlg, JackknifeWidget, AutoPickWidget
from pylot.core.util.map_projection import map_projection from pylot.core.util.map_projection import map_projection
from pylot.core.util.structure import DATASTRUCTURE from pylot.core.util.structure import DATASTRUCTURE
from pylot.core.util.thread import Thread, Worker from pylot.core.util.thread import Thread, Worker
@ -1025,6 +1025,11 @@ class MainWindow(QMainWindow):
:param: select_events, can be 'all', 'ref' :param: select_events, can be 'all', 'ref'
:type: str :type: str
''' '''
# if pick widget is open, refresh tooltips as well
if hasattr(self, 'apw'):
self.apw.refresh_tooltips()
if not eventBox: if not eventBox:
eventBox = self.eventBox eventBox = self.eventBox
index = eventBox.currentIndex() index = eventBox.currentIndex()
@ -1837,9 +1842,7 @@ class MainWindow(QMainWindow):
'el_S1pick', 'el_S1pick',
'el_S2pick', 'el_S2pick',
'refSpick', 'refSpick',
'aicARHfig', 'aicARHfig'
'jackknife',
'wadati'
] ]
for key in self.fig_keys: for key in self.fig_keys:
fig = Figure() fig = Figure()
@ -1850,6 +1853,25 @@ class MainWindow(QMainWindow):
for key in self.fig_keys: for key in self.fig_keys:
self.canvas_dict[key] = FigureCanvas(self.fig_dict[key]) self.canvas_dict[key] = FigureCanvas(self.fig_dict[key])
def init_fig_dict_wadatijack(self, eventIDs):
self.fig_dict_wadatijack = {}
self.fig_keys_wadatijack = [
'jackknife',
'wadati'
]
for eventID in eventIDs:
self.fig_dict_wadatijack[eventID] = {}
for key in self.fig_keys_wadatijack:
fig = Figure()
self.fig_dict_wadatijack[eventID][key] = fig
def init_canvas_dict_wadatijack(self):
self.canvas_dict_wadatijack = {}
for eventID in self.fig_dict_wadatijack.keys():
self.canvas_dict_wadatijack[eventID] = {}
for key in self.fig_keys_wadatijack:
self.canvas_dict_wadatijack[eventID][key] = FigureCanvas(self.fig_dict_wadatijack[eventID][key])
def tune_autopicker(self): def tune_autopicker(self):
''' '''
Initiates TuneAutopicker widget use to interactively Initiates TuneAutopicker widget use to interactively
@ -1886,38 +1908,79 @@ class MainWindow(QMainWindow):
QMessageBox.warning(self, "PyLoT Warning", QMessageBox.warning(self, "PyLoT Warning",
"No autoPyLoT output declared!") "No autoPyLoT output declared!")
return return
event = self.get_current_event()
self.saveData(event, event.path, outformats=['.xml']) self.pickoptions =[('current event', self.get_current_event),
('reference set events', self.get_ref_events),
('test set events', self.get_test_events),
('all (picked) events', self.get_manu_picked_events),
('all events', self.get_all_events)]
self.listWidget = QListWidget() self.listWidget = QListWidget()
self.setDirty(True) self.setDirty(True)
self.logDockWidget = QDockWidget("AutoPickLog", self) self.apw = AutoPickWidget(self, self.pickoptions)
self.logDockWidget.setObjectName("LogDockWidget") self.apw.insert_log_widget(self.listWidget)
self.logDockWidget.setAllowedAreas( self.apw.refresh_tooltips()
Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
self.logDockWidget.setWidget(self.listWidget) # self.logDockWidget = QDockWidget("AutoPickLog", self)
self.addDockWidget(Qt.LeftDockWidgetArea, self.logDockWidget) # self.logDockWidget.setObjectName("LogDockWidget")
# self.logDockWidget.setAllowedAreas(
# Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
# self.logDockWidget.setWidget(self.listWidget)
# self.addDockWidget(Qt.LeftDockWidgetArea, self.logDockWidget)
# self.addListItem('Loading default values from PyLoT-input file %s' # self.addListItem('Loading default values from PyLoT-input file %s'
# % self.infile) # % self.infile)
self.init_fig_dict() self.apw.start.connect(self.start_autopick)
self.apw.show()
def start_autopick(self):
for key, func in self.pickoptions:
if self.apw.rb_dict[key].isChecked():
# if radio button is checked break for loop and use func
break
events = func()
if not type(events) == list:
events = [events]
eventPaths = self.get_event_paths(events)
eventIDs = self.get_event_ids(events)
self.init_fig_dict_wadatijack(eventIDs)
if not eventPaths:
self.addListItem("No events found for '{}'".format(key))
return
else:
self.addListItem("Picking the following events ({}):".format(key))
for eventID in eventPaths:
self.addListItem(str(eventID))
self.apw.enable(False)
# export current picks etc.
self.exportAllEvents(['.xml'])
# define arguments for picker
args = {'parameter': self._inputs, args = {'parameter': self._inputs,
'station': 'all', 'station': 'all',
'fnames': 'None', 'fnames': 'None',
'eventid': self.get_current_event_path(), 'eventid': eventPaths,
'iplot': 0, 'iplot': 0,
'fig_dict': self.fig_dict, 'fig_dict': None,
'fig_dict_wadatijack': self.fig_dict_wadatijack,
'locflag': 0} 'locflag': 0}
# init pick thread
self.mp_thread = QtCore.QThreadPool() self.mp_thread = QtCore.QThreadPool()
self.mp_worker = Worker(autoPyLoT, args, redirect_stdout=True) self.mp_worker = Worker(autoPyLoT, args, redirect_stdout=True)
self.mp_thread.start(self.mp_worker)
self.addListItem(str(self._inputs)) self.addListItem(str(self._inputs))
self.mp_worker.signals.message.connect(self.addListItem) self.mp_worker.signals.message.connect(self.addListItem)
self.mp_worker.signals.result.connect(self.finalizeAutoPick) self.mp_worker.signals.result.connect(self.finalizeAutoPick)
self.mp_thread.start(self.mp_worker)
def autoPickProject(self): def autoPickProject(self):
if not self.apd_local: if not self.apd_local:
self.apd_local = AutoPickDlg(self, sge=False) self.apd_local = AutoPickDlg(self, sge=False)
@ -1929,14 +1992,59 @@ class MainWindow(QMainWindow):
self.apd_sge.show() self.apd_sge.show()
def finalizeAutoPick(self, result): def finalizeAutoPick(self, result):
self.apw.enable(True)
if result: if result:
event = self.get_current_event() self.init_canvas_dict_wadatijack()
event.addAutopicks(result) for eventID in result.keys():
event = self.get_event_from_id(eventID)
if not event:
continue
event.addAutopicks(result[eventID])
jkw = JackknifeWidget(self, self.canvas_dict_wadatijack[eventID]['jackknife'])
self.apw.insert_plot_widget(jkw, 'Jackknife', eventID)
self.drawPicks(picktype='auto') self.drawPicks(picktype='auto')
self.draw() self.draw()
self.init_canvas_dict()
jkw = JackknifeWidget(self, self.canvas_dict['jackknife']) def get_event_from_id(self, eventID):
jkw.show() for event in self.project.eventlist:
if event.pylot_id == eventID:
return event
def get_event_paths(self, eventlist):
eventPaths = []
for event in eventlist:
eventPaths.append(event.path)
return eventPaths
def get_event_ids(self, eventlist):
eventIDs = []
for event in eventlist:
eventIDs.append(event.pylot_id)
return eventIDs
def get_all_events(self):
return self.project.eventlist
def get_ref_events(self):
events = []
for event in self.project.eventlist:
if event.isRefEvent():
events.append(event)
return events
def get_test_events(self):
events = []
for event in self.project.eventlist:
if event.isTestEvent():
events.append(event)
return events
def get_manu_picked_events(self):
events = []
for event in self.project.eventlist:
if len(event.pylot_picks) > 0:
events.append(event)
return events
def addPicks(self, station, picks, type='manual'): def addPicks(self, station, picks, type='manual'):
stat_picks = self.getPicksOnStation(station, type) stat_picks = self.getPicksOnStation(station, type)

View File

@ -77,12 +77,17 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
inputfile = real_None(inputfile) inputfile = real_None(inputfile)
eventid = real_None(eventid) eventid = real_None(eventid)
fig_dict = None
fig_dict_wadatijack = None
locflag = 1 locflag = 1
if input_dict and isinstance(input_dict, dict): if input_dict and isinstance(input_dict, dict):
if 'parameter' in input_dict: if 'parameter' in input_dict:
parameter = input_dict['parameter'] parameter = input_dict['parameter']
if 'fig_dict' in input_dict: if 'fig_dict' in input_dict:
fig_dict = input_dict['fig_dict'] fig_dict = input_dict['fig_dict']
if 'fig_dict_wadatijack' in input_dict:
fig_dict_wadatijack = input_dict['fig_dict_wadatijack']
if 'station' in input_dict: if 'station' in input_dict:
station = input_dict['station'] station = input_dict['station']
if 'fnames' in input_dict: if 'fnames' in input_dict:
@ -178,13 +183,14 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
evID = os.path.split(eventid)[-1] evID = os.path.split(eventid)[-1]
locflag = 2 locflag = 2
else: else:
# started in tune mode # started in tune or interactive mode
datapath = os.path.join(parameter['rootpath'], datapath = os.path.join(parameter['rootpath'],
parameter['datapath']) parameter['datapath'])
events = [] events = []
events.append(os.path.join(datapath, for eventID in eventid:
parameter['database'], events.append(os.path.join(datapath,
eventid)) parameter['database'],
eventID))
if not events: if not events:
print('autoPyLoT: No events given. Return!') print('autoPyLoT: No events given. Return!')
@ -195,6 +201,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
eventpath = eventpath.replace(SEPARATOR, '/') eventpath = eventpath.replace(SEPARATOR, '/')
events[index] = eventpath events[index] = eventpath
allpicks = {}
glocflag = locflag glocflag = locflag
for eventpath in events: for eventpath in events:
evID = os.path.split(eventpath)[-1] evID = os.path.split(eventpath)[-1]
@ -257,14 +264,9 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
print(wfdat) print(wfdat)
########################################################## ##########################################################
# !automated picking starts here! # !automated picking starts here!
if input_dict: picks = autopickevent(wfdat, parameter, iplot=iplot, fig_dict=fig_dict,
if 'fig_dict' in input_dict: fig_dict_wadatijack=fig_dict_wadatijack[evID],
fig_dict = input_dict['fig_dict'] ncores=ncores, metadata=metadata, origin=data.get_evt_data().origins)
picks = autopickevent(wfdat, parameter, iplot=iplot, fig_dict=fig_dict,
ncores=ncores, metadata=metadata, origin=data.get_evt_data().origins)
else:
picks = autopickevent(wfdat, parameter, iplot=iplot,
ncores=ncores, metadata=metadata, origin=data.get_evt_data().origins)
########################################################## ##########################################################
# locating # locating
if locflag > 0: if locflag > 0:
@ -451,13 +453,16 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
if locflag == 0: if locflag == 0:
print("autoPyLoT was running in non-location mode!") print("autoPyLoT was running in non-location mode!")
# save picks for current event ID to dictionary with ALL picks
allpicks[evID] = picks
endsp = '''####################################\n endsp = '''####################################\n
************************************\n ************************************\n
*********autoPyLoT terminates*******\n *********autoPyLoT terminates*******\n
The Python picking and Location Tool\n The Python picking and Location Tool\n
************************************'''.format(version=_getVersionString()) ************************************'''.format(version=_getVersionString())
print(endsp) print(endsp)
return picks return allpicks
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -24,7 +24,7 @@ from pylot.core.util.utils import getPatternLine, gen_Pool,\
from obspy.taup import TauPyModel from obspy.taup import TauPyModel
def autopickevent(data, param, iplot=0, fig_dict=None, ncores=0, metadata=None, origin=None): def autopickevent(data, param, iplot=0, fig_dict=None, fig_dict_wadatijack=None, ncores=0, metadata=None, origin=None):
stations = [] stations = []
all_onsets = {} all_onsets = {}
input_tuples = [] input_tuples = []
@ -80,10 +80,10 @@ def autopickevent(data, param, iplot=0, fig_dict=None, ncores=0, metadata=None,
# quality control # quality control
# median check and jackknife on P-onset times # median check and jackknife on P-onset times
jk_checked_onsets = checkPonsets(all_onsets, mdttolerance, 1, fig_dict) jk_checked_onsets = checkPonsets(all_onsets, mdttolerance, 1, fig_dict_wadatijack)
return jk_checked_onsets return jk_checked_onsets
# check S-P times (Wadati) # check S-P times (Wadati)
return wadaticheck(jk_checked_onsets, wdttolerance, iplot, fig_dict) return wadaticheck(jk_checked_onsets, wdttolerance, iplot, fig_dict_wadatijack)
def call_autopickstation(input_tuple): def call_autopickstation(input_tuple):

View File

@ -2016,18 +2016,20 @@ class JackknifeWidget(QWidget):
''' '''
def __init__(self, parent, canvas): def __init__(self, parent, canvas):
QtGui.QWidget.__init__(self, parent, 1) QtGui.QWidget.__init__(self, parent)#, 1)
self.main_layout = QtGui.QVBoxLayout() self.main_layout = QtGui.QVBoxLayout()
self.setLayout(self.main_layout) self.setLayout(self.main_layout)
self.main_layout.addWidget(canvas) self.main_layout.addWidget(canvas)
class AutoPickWidget(QWidget): class AutoPickWidget(QWidget):
start = Signal()
''' '''
''' '''
def __init__(self, parent): def __init__(self, parent, pickoptions):
QtGui.QWidget.__init__(self, parent, 1) QtGui.QWidget.__init__(self, parent, 1)
self.pickoptions = pickoptions
self.setupUi() self.setupUi()
self.connect_buttons() self.connect_buttons()
# set initial size # set initial size
@ -2054,42 +2056,69 @@ class AutoPickWidget(QWidget):
self.start_button.clicked.connect(self.start_picker) self.start_button.clicked.connect(self.start_picker)
def init_checkboxes(self): def init_checkboxes(self):
self.cb_layout = QtGui.QHBoxLayout() self.rb_layout = QtGui.QHBoxLayout()
cb_keys = ['current event', self.rb_dict = {}
'reference set',
'test set',
'all']
self.cb_dict = {}
self.start_button = QtGui.QPushButton('Start') self.start_button = QtGui.QPushButton('Start')
for index, key in enumerate(cb_keys): for index, (key, func) in enumerate(self.pickoptions):
cb = QCheckBox(key) rb = QtGui.QRadioButton(key)
self.cb_dict[key] = cb if index == 0:
self.cb_layout.insertWidget(index, cb) rb.setChecked(True)
self.cb_layout.setStretch(index, 0) self.rb_dict[key] = rb
self.rb_layout.insertWidget(index, rb)
self.rb_layout.setStretch(index, 0)
self.cb_layout.addWidget(self.start_button) self.rb_layout.addWidget(self.start_button)
self.cb_layout.addWidget(QtGui.QWidget()) self.rb_layout.addWidget(QtGui.QWidget())
self.cb_layout.setStretch(len(cb_keys)+1, 1) self.rb_layout.setStretch(len(self.pickoptions)+1, 1)
self.main_layout.insertLayout(0, self.cb_layout) self.main_layout.insertLayout(0, self.rb_layout)
def init_plot_layout(self): def init_plot_layout(self):
self.tab_plots = QtGui.QTabWidget()
self.gb_plots = QtGui.QGroupBox('Plots') self.gb_plots = QtGui.QGroupBox('Plots')
self.gb_plots.setMinimumSize(100, 100) self.gb_plots.setMinimumSize(100, 100)
self.main_splitter.insertWidget(1, self.gb_plots) self.main_splitter.insertWidget(1, self.gb_plots)
self.plot_layout = QtGui.QVBoxLayout() self.plot_layout = QtGui.QVBoxLayout()
self.plot_layout.addWidget(self.tab_plots)
self.gb_plots.setLayout(self.plot_layout)
def init_log_layout(self): def init_log_layout(self):
self.gb_log = QtGui.QGroupBox('Log') self.gb_log = QtGui.QGroupBox('Log')
self.gb_log.setMinimumSize(100, 100) self.gb_log.setMinimumSize(100, 100)
self.main_splitter.insertWidget(0, self.gb_log) self.main_splitter.insertWidget(0, self.gb_log)
def insert_log_widget(self, widget):
vl = QtGui.QVBoxLayout()
vl.addWidget(widget)
self.gb_log.setLayout(vl)
def insert_plot_widget(self, widget, key, eventID):
self.tab_plots.addTab(widget, str(key+eventID))
def refresh_tooltips(self):
for key, func in self.pickoptions:
eventlist = func()
if not type(eventlist) == list:
eventlist = [eventlist]
tooltip=''
for index, event in enumerate(eventlist):
tooltip += '{}'.format(event.pylot_id)
if not index + 1 == len(eventlist):
tooltip += '\n'
self.rb_dict[key].setToolTip(tooltip)
def start_picker(self): def start_picker(self):
pass self.tab_plots.clear()
self.start.emit()
def enable(self, bool):
for rb in self.rb_dict.values():
rb.setEnabled(bool)
self.start_button.setEnabled(bool)
class TuneAutopicker(QWidget): class TuneAutopicker(QWidget):
@ -2422,7 +2451,7 @@ class TuneAutopicker(QWidget):
args = {'parameter': self.parameter, args = {'parameter': self.parameter,
'station': station, 'station': station,
'fnames': 'None', 'fnames': 'None',
'eventid': self.get_current_event_fp(), 'eventid': [self.get_current_event_fp()],
'iplot': 2, 'iplot': 2,
'fig_dict': self.fig_dict, 'fig_dict': self.fig_dict,
'locflag': 0, 'locflag': 0,
@ -2448,7 +2477,7 @@ class TuneAutopicker(QWidget):
info = self.ap_thread._executedErrorInfo info = self.ap_thread._executedErrorInfo
self._warn(msg, info) self._warn(msg, info)
return return
self.pylot_picks = self.ap_thread.data self.pylot_picks = self.ap_thread.data[self.get_current_event_name()]
if not self.pylot_picks: if not self.pylot_picks:
self._warn('No picks found. See terminal output.') self._warn('No picks found. See terminal output.')
return return