From 874fdd730a37ecbd0ea0841cef27581ad1c3cc03 Mon Sep 17 00:00:00 2001 From: marcel Date: Thu, 10 Aug 2017 16:25:32 +0200 Subject: [PATCH 1/2] [add] check for gaps and trim traces for one station [change] restitute data only if necessary! --- QtPyLoT.py | 6 +++- autoPyLoT.py | 14 ++++++---- pylot/core/pick/autopick.py | 1 + pylot/core/util/utils.py | 55 +++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 6 deletions(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index 2e9474c6..43ec8670 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -73,7 +73,7 @@ from pylot.core.util.errors import FormatError, DatastructureError, \ 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 + full_range, readFilterInformation, trim_station_components, check4gaps 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, \ @@ -1365,6 +1365,10 @@ class MainWindow(QMainWindow): # ans = False self.fnames = self.getWFFnames_from_eventbox() self.data.setWFData(self.fnames) + wfdat = self.data.getWFData() # all available streams + check4gaps(wfdat) + # trim station components to same start value + trim_station_components(wfdat, trim_start=True, trim_end=False) self._stime = full_range(self.get_data().getWFData())[0] def connectWFplotEvents(self): diff --git a/autoPyLoT.py b/autoPyLoT.py index 7ff5040e..5cf942c7 100755 --- a/autoPyLoT.py +++ b/autoPyLoT.py @@ -22,12 +22,11 @@ from pylot.core.analysis.magnitude import MomentMagnitude, LocalMagnitude from pylot.core.io.data import Data from pylot.core.io.inputs import PylotParameter from pylot.core.pick.autopick import autopickevent, iteratepicker -from pylot.core.util.dataprocessing import restitute_data, read_metadata, \ - remove_underscores +from pylot.core.util.dataprocessing import restitute_data, read_metadata from pylot.core.util.defaults import SEPARATOR from pylot.core.util.event import Event from pylot.core.util.structure import DATASTRUCTURE -from pylot.core.util.utils import real_None +from pylot.core.util.utils import real_None, remove_underscores, trim_station_components, check4gaps from pylot.core.util.version import get_git_version as _getVersionString __version__ = _getVersionString() @@ -239,9 +238,14 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even print('Could not find station {}. STOP!'.format(station)) return wfdat = remove_underscores(wfdat) + # trim components for each station to avoid problems with different trace starttimes for one station + wfdat = check4gaps(wfdat) + wfdat = trim_station_components(wfdat, trim_start=True, trim_end=False) metadata = read_metadata(parameter.get('invdir')) - print("Restitute data ...") - corr_dat = restitute_data(wfdat.copy(), *metadata, ncores=ncores) + corr_dat = None + if locflag: + print("Restitute data ...") + corr_dat = restitute_data(wfdat.copy(), *metadata, ncores=ncores) if not corr_dat and locflag: locflag = 2 print('Working on event %s. Stations: %s' % (eventpath, station)) diff --git a/pylot/core/pick/autopick.py b/pylot/core/pick/autopick.py index 168cf5d8..17209378 100644 --- a/pylot/core/pick/autopick.py +++ b/pylot/core/pick/autopick.py @@ -197,6 +197,7 @@ def autopickstation(wfstream, pickparam, verbose=False, if len(ndat) == 0: # check for other components ndat = wfstream.select(component="1") + wfstart, wfend = full_range(wfstream) if algoP == 'HOS' or algoP == 'ARZ' and zdat is not None: diff --git a/pylot/core/util/utils.py b/pylot/core/util/utils.py index 3442b89a..7c451411 100644 --- a/pylot/core/util/utils.py +++ b/pylot/core/util/utils.py @@ -470,6 +470,61 @@ def remove_underscores(data): return data +def trim_station_components(data, trim_start=True, trim_end=True): + ''' + cut a stream so only the part common to all three traces is kept to avoid dealing with offsets + :param data: stream of seismic data + :type data: `obspy.core.stream.Stream` + :param trim_start: trim start of stream + :type trim_start: bool + :param trim_end: trim end of stream + :type trim_end: bool + :return: data stream + ''' + starttime = {False: None} + endtime = {False: None} + + stations = get_stations(data) + + print('trim_station_components: Will trim stream for trim_start: {} and for ' + 'trim_end: {}.'.format(trim_start, trim_end)) + for station in stations: + wf_station = data.select(station=station) + starttime[True] = max([trace.stats.starttime for trace in wf_station]) + endtime[True] = min([trace.stats.endtime for trace in wf_station]) + wf_station.trim(starttime=starttime[trim_start], endtime=endtime[trim_end]) + + return data + + +def check4gaps(data): + ''' + check for gaps in Stream and remove them + :param data: stream of seismic data + :return: data stream + ''' + stations = get_stations(data) + + for station in stations: + wf_station = data.select(station=station) + if wf_station.get_gaps(): + for trace in wf_station: + data.remove(trace) + print('check4gaps: Found gaps and removed station {} from waveform data.'.format(station)) + + return data + + +def get_stations(data): + stations = [] + for tr in data: + station = tr.stats.station + if not station in stations: + stations.append(station) + + return stations + + def scaleWFData(data, factor=None, components='all'): """ produce scaled waveforms from given waveform data and a scaling factor, From 942b606fcac9982edcdc240f2e2644a035a0c363 Mon Sep 17 00:00:00 2001 From: marcel Date: Fri, 11 Aug 2017 10:14:47 +0200 Subject: [PATCH 2/2] [change] workaround reinit tuneAutopicker widget --- QtPyLoT.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index 43ec8670..a8ccdfb5 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -1798,18 +1798,18 @@ class MainWindow(QMainWindow): fig = Figure() self.fig_dict[key] = fig - if not self.tap: - # init TuneAutopicker object - self.tap = TuneAutopicker(self) - # first call of update to init tabs with empty canvas - self.update_autopicker() - # connect update signal of TuneAutopicker with update function - # creating and filling figure canvas - self.tap.update.connect(self.update_autopicker) - self.tap.figure_tabs.setCurrentIndex(0) - else: - self.update_autopicker() - self.tap.fill_eventbox() + #if not self.tap: + # init TuneAutopicker object + self.tap = TuneAutopicker(self) + # first call of update to init tabs with empty canvas + self.update_autopicker() + # connect update signal of TuneAutopicker with update function + # creating and filling figure canvas + self.tap.update.connect(self.update_autopicker) + self.tap.figure_tabs.setCurrentIndex(0) + #else: + # self.update_autopicker() + # self.tap.fill_eventbox() self.tap.show() def update_autopicker(self):