From 55a54ae154b94e61d2684f17dd37ea0c8f364e2b Mon Sep 17 00:00:00 2001 From: marcel Date: Mon, 21 Aug 2017 14:50:18 +0200 Subject: [PATCH 1/6] [rename] getQualityFromUncertainty --- QtPyLoT.py | 6 +++--- pylot/core/pick/utils.py | 2 +- pylot/core/util/widgets.py | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index ec2a9325..f647f205 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -64,7 +64,7 @@ from pylot.core.io.data import Data from pylot.core.io.inputs import FilterOptions, PylotParameter from autoPyLoT import autoPyLoT from pylot.core.pick.compare import Comparison -from pylot.core.pick.utils import symmetrize_error, getQualityfromUncertainty +from pylot.core.pick.utils import symmetrize_error, getQualityFromUncertainty from pylot.core.io.phases import picksdict_from_picks import pylot.core.loc.nll as nll from pylot.core.util.defaults import FILTERDEFAULTS, SetChannelComponents @@ -1998,10 +1998,10 @@ class MainWindow(QMainWindow): # get quality classes if self.getPhaseID(phase) == 'P': - quality = getQualityfromUncertainty(picks['spe'], self._inputs['timeerrorsP']) + quality = getQualityFromUncertainty(picks['spe'], self._inputs['timeerrorsP']) phaseID = 'P' elif self.getPhaseID(phase) == 'S': - quality = getQualityfromUncertainty(picks['spe'], self._inputs['timeerrorsS']) + quality = getQualityFromUncertainty(picks['spe'], self._inputs['timeerrorsS']) phaseID = 'S' mpp = picks['mpp'] - stime diff --git a/pylot/core/pick/utils.py b/pylot/core/pick/utils.py index 9322f64a..cc7b80ce 100644 --- a/pylot/core/pick/utils.py +++ b/pylot/core/pick/utils.py @@ -1098,7 +1098,7 @@ def checkZ4S(X, pick, zfac, checkwin, iplot, fig=None): return returnflag -def getQualityfromUncertainty(uncertainty, Errors): +def getQualityFromUncertainty(uncertainty, Errors): '''Script to transform uncertainty into quality classes 0-4 regarding adjusted time errors Errors. ''' diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index 62a6dd80..cb38443d 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -44,7 +44,7 @@ from obspy.taup.utils import get_phase_names from pylot.core.io.data import Data from pylot.core.io.inputs import FilterOptions, PylotParameter from pylot.core.pick.utils import getSNR, earllatepicker, getnoisewin, \ - getResolutionWindow, getQualityfromUncertainty + getResolutionWindow, getQualityFromUncertainty from pylot.core.pick.compare import Comparison from pylot.core.util.defaults import OUTPUTFORMATS, FILTERDEFAULTS, \ SetChannelComponents @@ -1714,10 +1714,10 @@ class PickDlg(QDialog): # get quality classes if self.getPhaseID(phase) == 'P': - quality = getQualityfromUncertainty(picks['spe'], self.parameter['timeerrorsP']) + quality = getQualityFromUncertainty(picks['spe'], self.parameter['timeerrorsP']) phaseID = 'P' elif self.getPhaseID(phase) == 'S': - quality = getQualityfromUncertainty(picks['spe'], self.parameter['timeerrorsS']) + quality = getQualityFromUncertainty(picks['spe'], self.parameter['timeerrorsS']) phaseID = 'S' mpp = picks['mpp'] - self.getStartTime() From 2b0aa38b37a6a1cc2cb29f7eb3a30adf144c23e7 Mon Sep 17 00:00:00 2001 From: marcel Date: Mon, 21 Aug 2017 14:59:28 +0200 Subject: [PATCH 2/6] [change] restructure identifyPhase functions --- QtPyLoT.py | 4 ++-- pylot/core/pick/autopick.py | 6 +++--- pylot/core/util/utils.py | 3 +++ pylot/core/util/widgets.py | 5 +++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index f647f205..0d52073f 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -74,7 +74,7 @@ from pylot.core.util.connection import checkurl from pylot.core.util.dataprocessing import read_metadata, restitute_data from pylot.core.util.utils import fnConstructor, getLogin, \ full_range, readFilterInformation, trim_station_components, check4gaps, make_pen, pick_color_plt, \ - pick_linestyle_plt, identifyPhase, loopIdentifyPhase, remove_underscores, check4doubled + pick_linestyle_plt, remove_underscores, check4doubled, identifyPhaseID 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, \ @@ -865,7 +865,7 @@ class MainWindow(QMainWindow): return fnames def getPhaseID(self, phase): - return identifyPhase(loopIdentifyPhase(phase)) + return identifyPhaseID(phase) def get_current_event(self, eventbox=None): ''' diff --git a/pylot/core/pick/autopick.py b/pylot/core/pick/autopick.py index 3b281f9c..7bea990e 100644 --- a/pylot/core/pick/autopick.py +++ b/pylot/core/pick/autopick.py @@ -18,8 +18,8 @@ from pylot.core.pick.charfuns import HOScf, AICcf, ARZcf, ARHcf, AR3Ccf from pylot.core.pick.picker import AICPicker, PragPicker from pylot.core.pick.utils import checksignallength, checkZ4S, earllatepicker, \ getSNR, fmpicker, checkPonsets, wadaticheck -from pylot.core.util.utils import getPatternLine, gen_Pool, identifyPhase, loopIdentifyPhase, \ - real_Bool +from pylot.core.util.utils import getPatternLine, gen_Pool,\ + real_Bool, identifyPhaseID from obspy.taup import TauPyModel @@ -254,7 +254,7 @@ def autopickstation(wfstream, pickparam, verbose=False, phases = {'P': [], 'S': []} for arr in arrivals: - phases[identifyPhase(loopIdentifyPhase(arr.phase.name))].append(arr) + phases[identifyPhaseID(arr.phase.name)].append(arr) # get first P and S onsets from arrivals list arrP, estFirstP = min([(arr, arr.time) for arr in phases['P']], key = lambda t: t[1]) diff --git a/pylot/core/util/utils.py b/pylot/core/util/utils.py index c51f6599..426c966d 100644 --- a/pylot/core/util/utils.py +++ b/pylot/core/util/utils.py @@ -806,6 +806,9 @@ def identifyPhase(phase): return False +def identifyPhaseID(phase): + return identifyPhase(loopIdentifyPhase(phase)) + if __name__ == "__main__": diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index cb38443d..08b8e003 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -21,7 +21,8 @@ except: pg = None from matplotlib.figure import Figure -from pylot.core.util.utils import find_horizontals, identifyPhase, loopIdentifyPhase, trim_station_components +from pylot.core.util.utils import find_horizontals, identifyPhase, loopIdentifyPhase, trim_station_components, \ + identifyPhaseID try: from matplotlib.backends.backend_qt4agg import FigureCanvas @@ -1285,7 +1286,7 @@ class PickDlg(QDialog): self.currentPhase = str(self.s_button.text()) def getPhaseID(self, phase): - return identifyPhase(loopIdentifyPhase(phase)) + return identifyPhaseID(phase) def set_button_color(self, button, color=None): if type(color) == QtGui.QColor: From 50e7b8381222c1884cef03ae58bb6fdabb2c8697 Mon Sep 17 00:00:00 2001 From: marcel Date: Mon, 21 Aug 2017 15:11:07 +0200 Subject: [PATCH 3/6] [new] new function to exclude picks by quality --- QtPyLoT.py | 2 +- pylot/core/util/utils.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index 0d52073f..031214fd 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -74,7 +74,7 @@ from pylot.core.util.connection import checkurl from pylot.core.util.dataprocessing import read_metadata, restitute_data from pylot.core.util.utils import fnConstructor, getLogin, \ full_range, readFilterInformation, trim_station_components, check4gaps, make_pen, pick_color_plt, \ - pick_linestyle_plt, remove_underscores, check4doubled, identifyPhaseID + pick_linestyle_plt, remove_underscores, check4doubled, identifyPhaseID, excludeQualityClasses 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, \ diff --git a/pylot/core/util/utils.py b/pylot/core/util/utils.py index 426c966d..24ad261e 100644 --- a/pylot/core/util/utils.py +++ b/pylot/core/util/utils.py @@ -71,6 +71,37 @@ def gen_Pool(ncores=0): return pool +def excludeQualityClasses(picks, qClasses, timeerrorsP, timeerrorsS): + ''' + takes PyLoT picks dictionary and returns a new dictionary with certain classes excluded. + :param picks: PyLoT picks dictionary + :param qClasses: list (or int) of quality classes (0-4) to exclude + :param timeerrorsP: time errors for classes (0-4) for P + :param timeerrorsS: time errors for classes (0-4) for S + :return: new picks dictionary + ''' + from pylot.core.pick.utils import getQualityFromUncertainty + + if type(qClasses) in [int, float]: + qClasses = [qClasses] + + picksdict_new = {} + + phaseError = {'P': timeerrorsP, + 'S': timeerrorsS} + + for station, phases in picks.items(): + for phase, pick in phases.items(): + pickerror = phaseError[identifyPhaseID(phase)] + quality = getQualityFromUncertainty(pick['spe'], pickerror) + if not quality in qClasses: + if not station in picksdict_new: + picksdict_new[station] = {} + picksdict_new[station][phase] = pick + + return picksdict_new + + def clims(lim1, lim2): """ takes two pairs of limits and returns one pair of common limts From b30ab69ad223d9cb0430436220c1d499d413ee2c Mon Sep 17 00:00:00 2001 From: marcel Date: Mon, 21 Aug 2017 15:33:00 +0200 Subject: [PATCH 4/6] [bugfix] teach comparison to cope without pick --- pylot/core/util/widgets.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index 08b8e003..87978ea1 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -271,6 +271,10 @@ class ComparisonDialog(QDialog): # _axes.cla() station = self.plotprops['station'] phase = self.plotprops['phase'] + if not phase in self.data.comparison[station]: + _axes.set_title('No pick found for phase {}.'.format(phase)) + self.canvas.draw() + return pdf = self.data.comparison[station][phase] x, y, std, exp = pdf.axis, pdf.data, pdf.standard_deviation(), \ pdf.expectation() From b185ce72b134f0e430c6f869e7297d55b8f88aec Mon Sep 17 00:00:00 2001 From: marcel Date: Mon, 21 Aug 2017 15:33:19 +0200 Subject: [PATCH 5/6] [add] exclude quality class 4 from comparison --- QtPyLoT.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index 031214fd..d53e4906 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -1215,7 +1215,11 @@ class MainWindow(QMainWindow): def comparePicks(self): if self.check4Comparison(): - co = Comparison(auto=self.getPicks('auto'), manu=self.getPicks()) + autopicks = excludeQualityClasses(self.getPicks('auto'), [4], + self._inputs['timeerrorsP'], self._inputs['timeerrorsS']) + manupicks = excludeQualityClasses(self.getPicks('manual'), [4], + self._inputs['timeerrorsP'], self._inputs['timeerrorsS']) + co = Comparison(auto=autopicks, manu=manupicks) compare_dlg = ComparisonDialog(co, self) compare_dlg.exec_() From ed994e987f5aebe91ae5ea2f61dff3a676f9b544 Mon Sep 17 00:00:00 2001 From: marcel Date: Mon, 21 Aug 2017 16:07:57 +0200 Subject: [PATCH 6/6] [change] ComparisonDlg -> ComparisonWidget --- QtPyLoT.py | 6 +++--- pylot/core/util/widgets.py | 12 ++++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index d53e4906..e4e54691 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -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, ComparisonDialog, TuneAutopicker, PylotParaBox, AutoPickDlg + getDataType, ComparisonWidget, TuneAutopicker, PylotParaBox, AutoPickDlg from pylot.core.util.map_projection import map_projection from pylot.core.util.structure import DATASTRUCTURE from pylot.core.util.thread import Thread, Worker @@ -1220,8 +1220,8 @@ class MainWindow(QMainWindow): manupicks = excludeQualityClasses(self.getPicks('manual'), [4], self._inputs['timeerrorsP'], self._inputs['timeerrorsS']) co = Comparison(auto=autopicks, manu=manupicks) - compare_dlg = ComparisonDialog(co, self) - compare_dlg.exec_() + compare_dlg = ComparisonWidget(co, self) + compare_dlg.show() def getPlotWidget(self): return self.dataPlot diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index 87978ea1..1a32fa12 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -119,7 +119,7 @@ def createAction(parent, text, slot=None, shortcut=None, icon=None, return action -class ComparisonDialog(QDialog): +class ComparisonWidget(QWidget): def __init__(self, c, parent=None): self._data = c self._stats = c.stations @@ -129,8 +129,9 @@ class ComparisonDialog(QDialog): histCheckBox=None) self._phases = 'PS' self._plotprops = dict(station=list(self.stations)[0], phase=list(self.phases)[0]) - super(ComparisonDialog, self).__init__(parent) + super(ComparisonWidget, self).__init__(parent, 1) self.setupUI() + self.resize(1280, 720) self.plotcomparison() def setupUI(self): @@ -162,17 +163,12 @@ class ComparisonDialog(QDialog): _toolbar.addWidget(_phases_combobox) _toolbar.addWidget(_hist_checkbox) - _buttonbox = QDialogButtonBox(QDialogButtonBox.Close) - _innerlayout.addWidget(self.canvas) - _innerlayout.addWidget(_buttonbox) _outerlayout.addWidget(_toolbar) _outerlayout.addLayout(_innerlayout) - _buttonbox.rejected.connect(self.reject) - - # finally layout the entire dialog + # finally layout the entire widget self.setLayout(_outerlayout) @property