[add] check for gaps and trim traces for one station

[change] restitute data only if necessary!
This commit is contained in:
Marcel Paffrath 2017-08-10 16:25:32 +02:00
parent fd2b82e978
commit 874fdd730a
4 changed files with 70 additions and 6 deletions

View File

@ -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):

View File

@ -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))

View File

@ -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:

View File

@ -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,