From 420f382051ba64a9e0766bf1a5ea87ef9846f1b1 Mon Sep 17 00:00:00 2001 From: Sebastianw Wehling-Benatelli Date: Mon, 19 Sep 2016 11:42:52 +0200 Subject: [PATCH 1/2] [cherry-pick] merged conflicts after cherry-pick of commit [17585f93813bde0173cb6194c58cda7396d7b02b] --- QtPyLoT.py | 4 ++-- pylot/core/active/seismicshot.py | 4 ++-- pylot/core/io/data.py | 4 ++-- pylot/core/io/phases.py | 4 ++-- pylot/core/util/utils.py | 2 +- pylot/core/util/widgets.py | 6 +++--- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index f930e088..6090ec6e 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -55,7 +55,7 @@ from pylot.core.util.errors import FormatError, DatastructureError, \ OverwriteError from pylot.core.util.connection import checkurl from pylot.core.util.utils import fnConstructor, getLogin, \ - getGlobalTimes + full_range from pylot.core.io.location import create_creation_info, create_event from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \ WaveformWidget, PropertiesDlg, HelpForm, createAction, PickDlg, \ @@ -660,7 +660,7 @@ class MainWindow(QMainWindow): ans = self.data.setWFData(self.getWFFnames()) else: ans = False - self._stime = getGlobalTimes(self.get_data().getWFData())[0] + self._stime = full_range(self.get_data().getWFData())[0] if ans: self.plotWaveformData() return ans diff --git a/pylot/core/active/seismicshot.py b/pylot/core/active/seismicshot.py index 9f270c76..e74ecaed 100644 --- a/pylot/core/active/seismicshot.py +++ b/pylot/core/active/seismicshot.py @@ -740,11 +740,11 @@ class SeismicShot(object): self._drawCFs(traceID, folm) def _drawStream(self, traceID, refresh=False, ax=None): - from pylot.core.util.utils import getGlobalTimes + from pylot.core.util.utils import full_range from pylot.core.util.utils import prepTimeAxis stream = self.getSingleStream(traceID) - stime = getGlobalTimes(stream)[0] + stime = full_range(stream)[0] timeaxis = prepTimeAxis(stime, stream[0]) timeaxis -= stime diff --git a/pylot/core/io/data.py b/pylot/core/io/data.py index 0b49230f..c3ca8b85 100644 --- a/pylot/core/io/data.py +++ b/pylot/core/io/data.py @@ -10,7 +10,7 @@ from obspy.core.event import Event from pylot.core.io.phases import readPILOTEvent, picks_from_picksdict, \ picksdict_from_pilot, merge_picks from pylot.core.util.errors import FormatError, OverwriteError -from pylot.core.util.utils import fnConstructor, getGlobalTimes +from pylot.core.util.utils import fnConstructor, full_range class Data(object): @@ -133,7 +133,7 @@ class Data(object): """ - self.cuttimes = getGlobalTimes(self.getWFData()) + self.cuttimes = full_range(self.getWFData()) def getEventFileName(self): """ diff --git a/pylot/core/io/phases.py b/pylot/core/io/phases.py index bd255b34..d3064f6f 100644 --- a/pylot/core/io/phases.py +++ b/pylot/core/io/phases.py @@ -12,7 +12,7 @@ from pylot.core.io.inputs import AutoPickParameter from pylot.core.io.location import create_arrival, create_event, \ create_magnitude, create_origin, create_pick from pylot.core.pick.utils import select_for_phase -from pylot.core.util.utils import getOwner, getGlobalTimes, four_digits +from pylot.core.util.utils import getOwner, full_range, four_digits def readPILOTEvent(phasfn=None, locfn=None, authority_id='RUB', **kwargs): @@ -325,7 +325,7 @@ def reassess_pilot_event(root_dir, db_dir, event_id, out_dir=None, fn_param=None msg = 'no waveform data found for station {station}'.format(station=station) warnings.warn(msg, RuntimeWarning) continue - stime, etime = getGlobalTimes(sel_st) + stime, etime = full_range(sel_st) rel_pick = mpp - stime epp, lpp, spe = earllatepicker(sel_st, default.get('nfac{0}'.format(phase)), diff --git a/pylot/core/util/utils.py b/pylot/core/util/utils.py index b2ba044d..3c210da9 100644 --- a/pylot/core/util/utils.py +++ b/pylot/core/util/utils.py @@ -206,7 +206,7 @@ def four_digits(year): return year -def getGlobalTimes(stream): +def full_range(stream): ''' takes a stream object and returns the latest end and the earliest start time of all contained trace objects diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index b0c1a741..056c4553 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -32,7 +32,7 @@ from pylot.core.pick.utils import getSNR, earllatepicker, getnoisewin, \ 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, \ +from pylot.core.util.utils import prepTimeAxis, full_range, scaleWFData, \ demeanTrace, isSorted, findComboBoxIndex, clims, find_horizontals @@ -425,7 +425,7 @@ class WaveformWidget(FigureCanvas): noiselevel=None, scaleddata=False, mapping=True): self.getAxes().cla() self.clearPlotDict() - wfstart, wfend = getGlobalTimes(wfdata) + wfstart, wfend = full_range(wfdata) nmax = 0 for n, trace in enumerate(wfdata): channel = trace.stats.channel @@ -539,7 +539,7 @@ class PickDlg(QDialog): else: self.data = data - self.stime, self.etime = getGlobalTimes(self.getWFData()) + self.stime, self.etime = full_range(self.getWFData()) # initialize plotting widget self.multicompfig = WaveformWidget(self) From 84739ed8ab104a99f304f01af72efd523f48215e Mon Sep 17 00:00:00 2001 From: Sebastianw Wehling-Benatelli Date: Mon, 19 Sep 2016 11:32:00 +0200 Subject: [PATCH 2/2] [new] added new function to find common time window within a stream --- pylot/core/analysis/magnitude.py | 20 ++------------------ pylot/core/util/utils.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/pylot/core/analysis/magnitude.py b/pylot/core/analysis/magnitude.py index a22dbeba..8635fbc9 100644 --- a/pylot/core/analysis/magnitude.py +++ b/pylot/core/analysis/magnitude.py @@ -15,6 +15,7 @@ from scipy.optimize import curve_fit from scipy import integrate, signal from pylot.core.io.data import Data from pylot.core.util.dataprocessing import restitute_data +from pylot.core.util.utils import common_range class Magnitude(object): @@ -360,25 +361,8 @@ def calcsourcespec(wfstream, onset, inventory, vp, delta, azimuth, incidence, qp cordat_copy = cordat.copy() # get equal time stamps and lengths of traces # necessary for rotation of traces - tr0start = cordat_copy[0].stats.starttime - tr0start = tr0start.timestamp - tr0end = cordat_copy[0].stats.endtime - tr0end = tr0end.timestamp - tr1start = cordat_copy[1].stats.starttime - tr1start = tr1start.timestamp - tr1end = cordat_copy[1].stats.endtime - tr1end = tr1end.timestamp - tr2start = cordat_copy[2].stats.starttime - tr2start = tr2start.timestamp - tr2end = cordat_copy[0].stats.endtime - tr2end = tr2end.timestamp - trstart = UTCDateTime(max([tr0start, tr1start, tr2start])) - trend = UTCDateTime(min([tr0end, tr1end, tr2end])) + trstart, trend = common_range(cordat_copy) cordat_copy.trim(trstart, trend) - minlen = min([len(cordat_copy[0]), len(cordat_copy[1]), len(cordat_copy[2])]) - cordat_copy[0].data = cordat_copy[0].data[0:minlen] - cordat_copy[1].data = cordat_copy[1].data[0:minlen] - cordat_copy[2].data = cordat_copy[2].data[0:minlen] try: # rotate into LQT (ray-coordindate-) system using Obspy's rotate # L: P-wave direction diff --git a/pylot/core/util/utils.py b/pylot/core/util/utils.py index 3c210da9..5045d4b1 100644 --- a/pylot/core/util/utils.py +++ b/pylot/core/util/utils.py @@ -206,6 +206,24 @@ def four_digits(year): return year +def common_range(stream): + ''' + takes a stream object and returns the earliest end and the latest start + time of all contained trace objects + :param stream: seismological data stream + :type stream: `~obspy.core.stream.Stream` + :return: maximum start time and minimum end time + ''' + max_start = None + min_end = None + for trace in stream: + if max_start is None or trace.stats.starttime > max_start: + max_start = trace.stats.starttime + if min_end is None or trace.stats.endtime < min_end: + min_end = trace.stats.endtime + return max_start, min_end + + def full_range(stream): ''' takes a stream object and returns the latest end and the earliest start