From 9632ecf41faf7808617ee52368f2aab105de7081 Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Wed, 7 Sep 2016 11:10:51 +0200 Subject: [PATCH 1/3] [bugfix] cover all possible cases (some correct components have been dropped before) --- pylot/core/util/widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index 0139e457..63458d80 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -779,7 +779,7 @@ class PickDlg(QDialog): trace = selectTrace(trace, '12') if trace: wfdata.append(trace) - elif component == 'Z': + else: wfdata = self.getWFData().select(component=component) return wfdata From d9536094195842f99ca3038e34cb1f0a05c84d8d Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Wed, 7 Sep 2016 12:17:51 +0200 Subject: [PATCH 2/3] [bugfix] just parse filter options if available --- pylot/core/util/widgets.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index 63458d80..7c3c7690 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -942,7 +942,8 @@ class PickDlg(QDialog): # copy and filter data for earliest and latest possible picks wfdata = self.getWFData().copy().select(channel=channel) - wfdata.filter(**filteroptions) + if filteroptions: + wfdata.filter(**filteroptions) # get earliest and latest possible pick and symmetric pick error [epp, lpp, spe] = earllatepicker(wfdata, 1.5, (5., .5, 2.), pick) From 49b07163ad0c16e15eecd4ac4d0cd11a7c58fa99 Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Thu, 8 Sep 2016 09:54:43 +0200 Subject: [PATCH 3/3] [bugfix] saving data did not work properly due to changed variable signature; picking on just one horizontal component now possible, crash was caused by mismatching component labels -> new function added to find these labels from the available data --- QtPyLoT.py | 33 +++++++++++++++++++++++++-------- pylot/core/util/utils.py | 25 ++++++++++++++++++++++++- pylot/core/util/widgets.py | 13 ++++--------- 3 files changed, 53 insertions(+), 18 deletions(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index ed98662d..c771e940 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -493,18 +493,18 @@ class MainWindow(QMainWindow): fname = str(action.data().toString()) return fname - def get_fnames(self): - return self.fname + def get_fnames(self, type='manual'): + return self.fname[type] def set_fname(self, fname, type): - if self.get_fnames()[type] is not None: - self.add_recentfile(self.get_fnames()) + if self.get_fnames(type) is not None: + self.add_recentfile(self.get_fnames(type)) self.fname[type] = fname - def getEventFileName(self): - if self.get_fnames() is None: - self.set_fname(self.get_data().getEventFileName()) - return self.get_fnames() + def getEventFileName(self, type='manual'): + if self.get_fnames(type) is None: + self.set_fname(self.get_data().getEventFileName(), type) + return self.get_fnames(type) def saveData(self): @@ -551,9 +551,26 @@ class MainWindow(QMainWindow): fbasename, exform = getSavePath(e) except AttributeError as e: fbasename, exform = getSavePath(e) + + # catch all possible cases before going on if not fbasename: return False + # warn overwriting + elif os.path.exists(fbasename + exform): + ans = QMessageBox.question(self, self.tr("Overwrite file..."), + self.tr("File already exists: {0}\n".format(fbasename + exform) + \ + "Overwrite file anyway?"), + QMessageBox.Cancel, QMessageBox.Yes | QMessageBox.No, + QMessageBox.Cancel) + # only negative answers have to be caught + if ans == QMessageBox.No: + self.saveData() + elif ans == QMessageBox.Cancel: + return False + + # export to given path self.get_data().exportEvent(fbasename, exform) + # all files save (ui clean) self.setDirty(False) self.update_status('Event saved as %s' % (fbasename + exform)) return True diff --git a/pylot/core/util/utils.py b/pylot/core/util/utils.py index 8aafbd9b..259ba91b 100644 --- a/pylot/core/util/utils.py +++ b/pylot/core/util/utils.py @@ -8,7 +8,7 @@ import os import pwd import re import subprocess -from obspy.core import UTCDateTime +from obspy import UTCDateTime, read def _pickle_method(m): @@ -354,6 +354,29 @@ def prepTimeAxis(stime, trace): return time_ax +def find_horizontals(data): + """ + takes `obspy.core.stream.Stream` object and returns a list containing the component labels of the horizontal components available + :param data: waveform data + :type data: `obspy.core.stream.Stream` + :return: components list + :rtype: list + + ..example:: + + >>> st = read() + >>> find_horizontals(st) + [u'N', u'E'] + """ + rval = [] + for tr in data: + if tr.stats.channel[-1].upper() in ['Z', '3']: + continue + else: + rval.append(tr.stats.channel[-1].upper()) + return rval + + def scaleWFData(data, factor=None, components='all'): """ produce scaled waveforms from given waveform data and a scaling factor, diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index 7c3c7690..b0c1a741 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -33,7 +33,7 @@ from pylot.core.pick.compare import Comparison from pylot.core.util.defaults import OUTPUTFORMATS, FILTERDEFAULTS, LOCTOOLS, \ COMPPOSITION_MAP from pylot.core.util.utils import prepTimeAxis, getGlobalTimes, scaleWFData, \ - demeanTrace, isSorted, findComboBoxIndex, clims + demeanTrace, isSorted, findComboBoxIndex, clims, find_horizontals def getDataType(parent): @@ -898,14 +898,9 @@ class PickDlg(QDialog): inoise = getnoisewin(t, ini_pick, noise_win, gap_win) trace = demeanTrace(trace, inoise) - # account for non-oriented horizontal waveforms - try: - horiz_comp = ('n', 'e') - data = scaleWFData(data, noiselevel * 2.5, horiz_comp) - except IndexError as e: - print('warning: {0}'.format(e)) - horiz_comp = ('1', '2') - data = scaleWFData(data, noiselevel * 2.5, horiz_comp) + # scale waveform for plotting + horiz_comp = find_horizontals(data) + data = scaleWFData(data, noiselevel * 2.5, horiz_comp) x_res = getResolutionWindow(snr)