From b191bd8cf44d723425e65ccf28317718334223b7 Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 15 Jan 2018 14:17:14 +0100 Subject: [PATCH] [update] warn/do not save picks with unknown phase ID --- pylot/RELEASE-VERSION | 2 +- pylot/core/util/utils.py | 2 ++ pylot/core/util/widgets.py | 58 ++++++++++++++++++-------------------- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/pylot/RELEASE-VERSION b/pylot/RELEASE-VERSION index d6e8b031..427df7f4 100644 --- a/pylot/RELEASE-VERSION +++ b/pylot/RELEASE-VERSION @@ -1 +1 @@ -44f63-dirty +4589-dirty diff --git a/pylot/core/util/utils.py b/pylot/core/util/utils.py index 9185f971..6de1e8e4 100644 --- a/pylot/core/util/utils.py +++ b/pylot/core/util/utils.py @@ -1169,6 +1169,8 @@ def identifyPhase(phase): # common phase suffix for P and S common_P = ['P', 'p', 'R'] common_S = ['S', 's'] + if phase is None: + return False if phase[-1] in common_P: return 'P' if phase[-1] in common_S: diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index 5595c1b5..e942dae3 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -1144,6 +1144,7 @@ class PickDlg(QDialog): self.arrivals = [] self.arrivalsText = [] self.cidpick = [] + self.cidpress = None settings = QSettings() pylot_user = getpass.getuser() self._user = settings.value('user/Login', pylot_user) @@ -1678,7 +1679,12 @@ class PickDlg(QDialog): def activatePicking(self): phase = self.currentPhase - color = pick_color_plt('manual', self.getPhaseID(phase)) + phaseID = self.getPhaseID(phase) + if not phaseID: + self.warn_unknown_phase(phase) + self.leave_picking_mode() + return + color = pick_color_plt('manual', phaseID) self.multicompfig.set_frame_color(color) self.multicompfig.set_frame_linewidth(1.5) if self.zoomAction.isChecked(): @@ -2020,39 +2026,27 @@ class PickDlg(QDialog): network=wfdata[0].stats.network, filteroptions=transformFilteroptions2String(filteroptions)) - try: - oldphasepick = self.picks[phase] - except KeyError: - self.picks[phase] = phasepicks - else: - self.picks[phase] = phasepicks - oepp = oldphasepick['epp'] - ompp = oldphasepick['mpp'] - olpp = oldphasepick['lpp'] - msg = """Warning old phase information for phase {phase} has been - altered.\n - New phase times:\n - earliest possible pick: {epp}\n - most probable pick: {mpp}\n - latest possible pick: {lpp}\n - \n - Old phase times (overwritten):\n - earliest possible pick: {oepp}\n - most probable pick: {ompp}\n - latest possible pick: {olpp}\n""".format(phase=phase, - epp=epp, - mpp=pick, - lpp=lpp, - oepp=oepp, - ompp=ompp, - olpp=olpp) + saved = self.savePick(phase, phasepicks, pick, epp, lpp) + if saved: + self.setDirty(True) self.disconnectPressEvent() self.enable_ar_buttons() self.zoomAction.setEnabled(True) #self.pick_block = self.togglePickBlocker() self.leave_picking_mode() - self.setDirty(True) + + def savePick(self, phase, phasepicks): + if not self.getPhaseID(phase): + self.warn_unknown_phase(phase) + return + + self.picks[phase] = phasepicks + return True + + def warn_unknown_phase(self, phase=None): + QtGui.QMessageBox.warning(self, 'Unknown phase ID', + 'Could not identify phase ID: {}.'.format(phase)) def disconnectPressEvent(self): self.multicompfig.mpl_disconnect(self.cidpress) @@ -2232,9 +2226,11 @@ class PickDlg(QDialog): def renamePhaseInDict(self, picks, phase_old, phase_new): if phase_new in picks: raise KeyError('New phase ID already assigned.') - picks[phase_new] = picks[phase_old].copy() - picks.pop(phase_old) - self.setDirty(True) + picks_new = picks[phase_old].copy() + saved = self.savePick(phase_new, picks_new) + if saved: + picks.pop(phase_old) + self.setDirty(True) def remove_pick_by_x(self, x): if not self.picks and not self.autopicks: