[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'])} s_filter['order'])}
self.loc = False 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): def setupUi(self):
try: try:
self.startTime = min( self.startTime = min(
@ -1038,6 +1030,8 @@ class MainWindow(QMainWindow):
# if pick widget is open, refresh tooltips as well # if pick widget is open, refresh tooltips as well
if hasattr(self, 'apw'): if hasattr(self, 'apw'):
self.apw.refresh_tooltips() self.apw.refresh_tooltips()
if hasattr(self, 'cmpw'):
self.cmpw.refresh_tooltips()
if not eventBox: if not eventBox:
eventBox = self.eventBox eventBox = self.eventBox
@ -1253,13 +1247,36 @@ class MainWindow(QMainWindow):
eventdict[event.pylot_id] = event eventdict[event.pylot_id] = event
if len(eventdict) < 1: if len(eventdict) < 1:
return return
pickoptions = self.pickoptions.copy()
pickoptions.pop(-1) # init event selection options for autopick
pickoptions.pop(0) self.compareoptions =[('tune events', self.get_ref_events),
compare_multi = CompareEventsWidget(self, pickoptions, eventdict, comparisons) ('test events', self.get_test_events),
compare_multi.show() ('all (picked) events', self.get_manu_picked_events)]
#compare_dlg = ComparisonWidget(comparisons[self.get_current_event_name()], self)
#compare_dlg.show() 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): def getPlotWidget(self):
return self.dataPlot return self.dataPlot
@ -1955,6 +1972,13 @@ class MainWindow(QMainWindow):
"No autoPyLoT output declared!") "No autoPyLoT output declared!")
return 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.listWidget = QListWidget()
self.setDirty(True) self.setDirty(True)
self.apw = AutoPickWidget(self, self.pickoptions) self.apw = AutoPickWidget(self, self.pickoptions)

View File

@ -27,16 +27,8 @@ class Comparison(object):
""" """
def __init__(self, **kwargs): def __init__(self, **kwargs):
names = list()
self._pdfs = dict() self._pdfs = dict()
for name, fn in kwargs.items(): names = self.iter_kwargs(kwargs)
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)
if len(names) > 2: if len(names) > 2:
raise ValueError('Comparison is only defined for two ' raise ValueError('Comparison is only defined for two '
'arguments!') 'arguments!')
@ -48,6 +40,40 @@ class Comparison(object):
return False return False
return True 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): def get(self, name):
return self._pdfs[name] return self._pdfs[name]

View File

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