[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.util.widgets import FilterOptionsDialog, NewEventDlg, \
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.structure import DATASTRUCTURE
from pylot.core.util.thread import Thread, Worker
@ -1025,6 +1025,11 @@ class MainWindow(QMainWindow):
:param: select_events, can be 'all', 'ref'
:type: str
'''
# if pick widget is open, refresh tooltips as well
if hasattr(self, 'apw'):
self.apw.refresh_tooltips()
if not eventBox:
eventBox = self.eventBox
index = eventBox.currentIndex()
@ -1837,9 +1842,7 @@ class MainWindow(QMainWindow):
'el_S1pick',
'el_S2pick',
'refSpick',
'aicARHfig',
'jackknife',
'wadati'
'aicARHfig'
]
for key in self.fig_keys:
fig = Figure()
@ -1850,6 +1853,25 @@ class MainWindow(QMainWindow):
for key in self.fig_keys:
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):
'''
Initiates TuneAutopicker widget use to interactively
@ -1886,38 +1908,79 @@ class MainWindow(QMainWindow):
QMessageBox.warning(self, "PyLoT Warning",
"No autoPyLoT output declared!")
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.setDirty(True)
self.logDockWidget = QDockWidget("AutoPickLog", self)
self.logDockWidget.setObjectName("LogDockWidget")
self.logDockWidget.setAllowedAreas(
Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
self.logDockWidget.setWidget(self.listWidget)
self.addDockWidget(Qt.LeftDockWidgetArea, self.logDockWidget)
self.apw = AutoPickWidget(self, self.pickoptions)
self.apw.insert_log_widget(self.listWidget)
self.apw.refresh_tooltips()
# self.logDockWidget = QDockWidget("AutoPickLog", self)
# 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.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,
'station': 'all',
'fnames': 'None',
'eventid': self.get_current_event_path(),
'eventid': eventPaths,
'iplot': 0,
'fig_dict': self.fig_dict,
'fig_dict': None,
'fig_dict_wadatijack': self.fig_dict_wadatijack,
'locflag': 0}
# init pick thread
self.mp_thread = QtCore.QThreadPool()
self.mp_worker = Worker(autoPyLoT, args, redirect_stdout=True)
self.mp_thread.start(self.mp_worker)
self.addListItem(str(self._inputs))
self.mp_worker.signals.message.connect(self.addListItem)
self.mp_worker.signals.result.connect(self.finalizeAutoPick)
self.mp_thread.start(self.mp_worker)
def autoPickProject(self):
if not self.apd_local:
self.apd_local = AutoPickDlg(self, sge=False)
@ -1929,14 +1992,59 @@ class MainWindow(QMainWindow):
self.apd_sge.show()
def finalizeAutoPick(self, result):
self.apw.enable(True)
if result:
event = self.get_current_event()
event.addAutopicks(result)
self.init_canvas_dict_wadatijack()
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.draw()
self.init_canvas_dict()
jkw = JackknifeWidget(self, self.canvas_dict['jackknife'])
jkw.show()
def get_event_from_id(self, eventID):
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'):
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)
eventid = real_None(eventid)
fig_dict = None
fig_dict_wadatijack = None
locflag = 1
if input_dict and isinstance(input_dict, dict):
if 'parameter' in input_dict:
parameter = input_dict['parameter']
if 'fig_dict' in input_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:
station = input_dict['station']
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]
locflag = 2
else:
# started in tune mode
# started in tune or interactive mode
datapath = os.path.join(parameter['rootpath'],
parameter['datapath'])
events = []
for eventID in eventid:
events.append(os.path.join(datapath,
parameter['database'],
eventid))
eventID))
if not events:
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, '/')
events[index] = eventpath
allpicks = {}
glocflag = locflag
for eventpath in events:
evID = os.path.split(eventpath)[-1]
@ -257,13 +264,8 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
print(wfdat)
##########################################################
# !automated picking starts here!
if input_dict:
if 'fig_dict' in input_dict:
fig_dict = input_dict['fig_dict']
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,
fig_dict_wadatijack=fig_dict_wadatijack[evID],
ncores=ncores, metadata=metadata, origin=data.get_evt_data().origins)
##########################################################
# locating
@ -451,13 +453,16 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
if locflag == 0:
print("autoPyLoT was running in non-location mode!")
# save picks for current event ID to dictionary with ALL picks
allpicks[evID] = picks
endsp = '''####################################\n
************************************\n
*********autoPyLoT terminates*******\n
The Python picking and Location Tool\n
************************************'''.format(version=_getVersionString())
print(endsp)
return picks
return allpicks
if __name__ == "__main__":

View File

@ -24,7 +24,7 @@ from pylot.core.util.utils import getPatternLine, gen_Pool,\
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 = []
all_onsets = {}
input_tuples = []
@ -80,10 +80,10 @@ def autopickevent(data, param, iplot=0, fig_dict=None, ncores=0, metadata=None,
# quality control
# 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
# 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):

View File

@ -2016,18 +2016,20 @@ class JackknifeWidget(QWidget):
'''
def __init__(self, parent, canvas):
QtGui.QWidget.__init__(self, parent, 1)
QtGui.QWidget.__init__(self, parent)#, 1)
self.main_layout = QtGui.QVBoxLayout()
self.setLayout(self.main_layout)
self.main_layout.addWidget(canvas)
class AutoPickWidget(QWidget):
start = Signal()
'''
'''
def __init__(self, parent):
def __init__(self, parent, pickoptions):
QtGui.QWidget.__init__(self, parent, 1)
self.pickoptions = pickoptions
self.setupUi()
self.connect_buttons()
# set initial size
@ -2054,42 +2056,69 @@ class AutoPickWidget(QWidget):
self.start_button.clicked.connect(self.start_picker)
def init_checkboxes(self):
self.cb_layout = QtGui.QHBoxLayout()
self.rb_layout = QtGui.QHBoxLayout()
cb_keys = ['current event',
'reference set',
'test set',
'all']
self.cb_dict = {}
self.rb_dict = {}
self.start_button = QtGui.QPushButton('Start')
for index, key in enumerate(cb_keys):
cb = QCheckBox(key)
self.cb_dict[key] = cb
self.cb_layout.insertWidget(index, cb)
self.cb_layout.setStretch(index, 0)
for index, (key, func) in enumerate(self.pickoptions):
rb = QtGui.QRadioButton(key)
if index == 0:
rb.setChecked(True)
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.cb_layout.setStretch(len(cb_keys)+1, 1)
self.rb_layout.addWidget(QtGui.QWidget())
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):
self.tab_plots = QtGui.QTabWidget()
self.gb_plots = QtGui.QGroupBox('Plots')
self.gb_plots.setMinimumSize(100, 100)
self.main_splitter.insertWidget(1, self.gb_plots)
self.plot_layout = QtGui.QVBoxLayout()
self.plot_layout.addWidget(self.tab_plots)
self.gb_plots.setLayout(self.plot_layout)
def init_log_layout(self):
self.gb_log = QtGui.QGroupBox('Log')
self.gb_log.setMinimumSize(100, 100)
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):
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):
@ -2422,7 +2451,7 @@ class TuneAutopicker(QWidget):
args = {'parameter': self.parameter,
'station': station,
'fnames': 'None',
'eventid': self.get_current_event_fp(),
'eventid': [self.get_current_event_fp()],
'iplot': 2,
'fig_dict': self.fig_dict,
'locflag': 0,
@ -2448,7 +2477,7 @@ class TuneAutopicker(QWidget):
info = self.ap_thread._executedErrorInfo
self._warn(msg, info)
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:
self._warn('No picks found. See terminal output.')
return