[update] working version to compare several events

This commit is contained in:
Marcel Paffrath 2017-08-31 14:31:33 +02:00
parent eaa7a993af
commit 79cbaf3397
3 changed files with 110 additions and 42 deletions

View File

@ -202,14 +202,6 @@ class MainWindow(QMainWindow):
s_filter['order'])}
self.loc = False
# init event selection options for compare/autopick
self.pickoptions =[('current event', self.get_current_event),
('tune events', self.get_ref_events),
('test events', self.get_test_events),
('all (picked) events', self.get_manu_picked_events),
('all events', self.get_all_events)]
def setupUi(self):
try:
self.startTime = min(
@ -1038,6 +1030,8 @@ class MainWindow(QMainWindow):
# if pick widget is open, refresh tooltips as well
if hasattr(self, 'apw'):
self.apw.refresh_tooltips()
if hasattr(self, 'cmpw'):
self.cmpw.refresh_tooltips()
if not eventBox:
eventBox = self.eventBox
@ -1253,13 +1247,36 @@ class MainWindow(QMainWindow):
eventdict[event.pylot_id] = event
if len(eventdict) < 1:
return
pickoptions = self.pickoptions.copy()
pickoptions.pop(-1)
pickoptions.pop(0)
compare_multi = CompareEventsWidget(self, pickoptions, eventdict, comparisons)
compare_multi.show()
#compare_dlg = ComparisonWidget(comparisons[self.get_current_event_name()], self)
#compare_dlg.show()
# init event selection options for autopick
self.compareoptions =[('tune events', self.get_ref_events),
('test events', self.get_test_events),
('all (picked) events', self.get_manu_picked_events)]
self.cmpw = CompareEventsWidget(self, self.compareoptions, eventdict, comparisons)
self.cmpw.start.connect(self.compareMulti)
self.cmpw.refresh_tooltips()
self.cmpw.show()
def compareMulti(self):
for key, func in self.compareoptions:
if self.cmpw.rb_dict[key].isChecked():
# if radio button is checked break for loop and use func
break
eventlist = func()
# use only events comparable
eventlist_overlap = [event for event in eventlist if self.comparable[event.pylot_id]]
compare_widget = self.buildMultiCompareWidget(eventlist_overlap)
compare_widget.show()
def buildMultiCompareWidget(self, eventlist):
global_comparison = Comparison(eventlist=eventlist)
compare_widget = ComparisonWidget(global_comparison, self)
compare_widget.setWindowTitle('Histograms for all selected events')
compare_widget.hideToolbar()
compare_widget.setHistboxChecked(True)
return compare_widget
def getPlotWidget(self):
return self.dataPlot
@ -1955,6 +1972,13 @@ class MainWindow(QMainWindow):
"No autoPyLoT output declared!")
return
# init event selection options for autopick
self.pickoptions =[('current event', self.get_current_event),
('tune events', self.get_ref_events),
('test 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.apw = AutoPickWidget(self, self.pickoptions)

View File

@ -27,16 +27,8 @@ class Comparison(object):
"""
def __init__(self, **kwargs):
names = list()
self._pdfs = dict()
for name, fn in kwargs.items():
if isinstance(fn, PDFDictionary):
self._pdfs[name] = fn
elif isinstance(fn, dict) or isinstance(fn, AttribDict):
self._pdfs[name] = PDFDictionary(fn)
else:
self._pdfs[name] = PDFDictionary.from_quakeml(fn)
names.append(name)
names = self.iter_kwargs(kwargs)
if len(names) > 2:
raise ValueError('Comparison is only defined for two '
'arguments!')
@ -48,6 +40,40 @@ class Comparison(object):
return False
return True
def iter_kwargs(self, kwargs):
names = list()
for name, fn in kwargs.items():
if name == 'eventlist':
names = self.init_by_eventlist(fn)
break
if isinstance(fn, PDFDictionary):
self._pdfs[name] = fn
elif isinstance(fn, dict) or isinstance(fn, AttribDict):
self._pdfs[name] = PDFDictionary(fn)
else:
self._pdfs[name] = PDFDictionary.from_quakeml(fn)
names.append(name)
return names
def init_by_eventlist(self, eventlist):
# create one dictionary containing all picks for all events (therefore modify station key)
global_picksdict = {}
for event in eventlist:
automanu = {'manu': event.pylot_picks,
'auto': event.pylot_autopicks}
for method, picksdict in automanu.items():
if not method in global_picksdict.keys():
global_picksdict[method] = {}
for station, picks in picksdict.items():
new_picksdict = global_picksdict[method]
# new id combining event and station in one dictionary for all events
id = '{}_{}'.format(event.pylot_id, station)
new_picksdict[id] = picks
for method, picksdict in global_picksdict.items():
self._pdfs[method] = PDFDictionary(picksdict)
names = list(global_picksdict.keys())
return names
def get(self, name):
return self._pdfs[name]

View File

@ -154,19 +154,19 @@ class ComparisonWidget(QWidget):
_phases_combobox.currentIndexChanged.connect(self.prepareplot)
self.widgets = _phases_combobox
_hist_checkbox = QCheckBox('Show histograms', self)
_hist_checkbox.setObjectName('histCheckBox')
_hist_checkbox.stateChanged.connect(self.plothist)
self.widgets = _hist_checkbox
self._hist_checkbox = QCheckBox('Show histograms', self)
self._hist_checkbox.setObjectName('histCheckBox')
self._hist_checkbox.stateChanged.connect(self.plothist)
self.widgets = self._hist_checkbox
_toolbar = QToolBar(self)
_toolbar.addWidget(_stats_combobox)
_toolbar.addWidget(_phases_combobox)
_toolbar.addWidget(_hist_checkbox)
self._toolbar = QToolBar(self)
self._toolbar.addWidget(_stats_combobox)
self._toolbar.addWidget(_phases_combobox)
self._toolbar.addWidget(self._hist_checkbox)
_innerlayout.addWidget(self.canvas)
_outerlayout.addWidget(_toolbar)
_outerlayout.addWidget(self._toolbar)
_outerlayout.addLayout(_innerlayout)
# finally layout the entire widget
@ -232,6 +232,15 @@ class ComparisonWidget(QWidget):
if name in self.widgets.keys():
self._widgets[name] = widget
def showToolbar(self):
self._toolbar.show()
def hideToolbar(self):
self._toolbar.hide()
def setHistboxChecked(self, bool):
self._hist_checkbox.setChecked(bool)
def clf(self):
self.canvas.figure.clf()
@ -2036,10 +2045,10 @@ class MultiEventWidget(QWidget):
'''
'''
def __init__(self, pickoptions=None, parent=None, windowflag=1):
def __init__(self, options=None, parent=None, windowflag=1):
QtGui.QWidget.__init__(self, parent, windowflag)
self.pickoptions = pickoptions
self.options = options
# self.pickoptions =[('current event', None),
# ('tune events', None),
# ('test events', None),
@ -2077,8 +2086,9 @@ class MultiEventWidget(QWidget):
self.start_button = QtGui.QPushButton('Start')
for index, (key, func) in enumerate(self.pickoptions):
for index, (key, func) in enumerate(self.options):
rb = QtGui.QRadioButton(key)
rb.toggled.connect(self.check_rb_selection)
if index == 0:
rb.setChecked(True)
self.rb_dict[key] = rb
@ -2088,12 +2098,12 @@ class MultiEventWidget(QWidget):
self.rb_layout.addWidget(self.start_button)
self.rb_layout.addWidget(QtGui.QWidget())
self.rb_layout.setStretch(len(self.pickoptions)+1, 1)
self.rb_layout.setStretch(len(self.options) + 1, 1)
self.main_layout.insertLayout(0, self.rb_layout)
def refresh_tooltips(self):
for key, func in self.pickoptions:
for key, func in self.options:
eventlist = func()
if not type(eventlist) == list:
eventlist = [eventlist]
@ -2107,6 +2117,13 @@ class MultiEventWidget(QWidget):
if not tooltip:
tooltip = 'No events for this selection'
self.rb_dict[key].setToolTip(tooltip)
self.check_rb_selection()
def check_rb_selection(self):
for rb in self.rb_dict.values():
if rb.isChecked():
check_events = (rb.toolTip() == 'No events for this selection')
self.start_button.setEnabled(not(check_events))
def enable(self, bool):
for rb in self.rb_dict.values():
@ -2120,8 +2137,8 @@ class AutoPickWidget(MultiEventWidget):
'''
'''
def __init__(self, parent, pickoptions):
MultiEventWidget.__init__(self, pickoptions, parent, 1)
def __init__(self, parent, options):
MultiEventWidget.__init__(self, options, parent, 1)
self.connect_buttons()
self.init_plot_layout()
self.init_log_layout()
@ -2205,8 +2222,8 @@ class CompareEventsWidget(MultiEventWidget):
'''
'''
def __init__(self, parent, pickoptions, eventdict, comparisons):
MultiEventWidget.__init__(self, pickoptions, parent, 1)
def __init__(self, parent, options, eventdict, comparisons):
MultiEventWidget.__init__(self, options, parent, 1)
self.eventdict = eventdict
self.comparisons = comparisons
self.init_eventbox()
@ -2216,6 +2233,7 @@ class CompareEventsWidget(MultiEventWidget):
def connect_buttons(self):
self.start_button.clicked.connect(self.run)
self.start_button.setText('Show Histograms')
def init_eventbox(self):
self.eventbox_layout = QtGui.QHBoxLayout()