Commit acd970c3 authored by Sebastian Heimann's avatar Sebastian Heimann
Browse files

add possibility to fill incomplete traces with zeros

parent e4f0b06c
......@@ -79,6 +79,11 @@ class Config(Object):
default=200.,
help='threshold on detector function')
fill_incomplete_with_zeros = Bool.T(
default=False,
help='fill incomplete trace time windows with zeros '
'(and let edge effects ruin your day)')
def __init__(self, *args, **kwargs):
Object.__init__(self, *args, **kwargs)
self._receivers = None
......@@ -166,6 +171,7 @@ def read_config(file_path):
conf = load(filename=file_path)
return conf
__all__ = [
'Config',
'read_config',
......
......@@ -3,6 +3,8 @@ import logging
import os.path as op
import shutil
from collections import defaultdict
import numpy as num
from pyrocko import pile, trace, util, io
......@@ -39,6 +41,35 @@ def check_data_consistency(p, receivers):
logger.warn(nsl_id)
def zero_fill(trs, tmin, tmax):
trs = trace.degapper(trs)
d = defaultdict(list)
for tr in trs:
d[tr.nslc_id].append(tr)
trs_out = []
for nslc, trs_group in d.iteritems():
if not all(tr.deltat == trs_group[0].deltat for tr in trs_group):
logger.warn('inconsistent sample rate, cannot merge traces')
continue
if not all(tr.ydata.dtype == trs_group[0].ydata.dtype
for tr in trs_group):
logger.warn('inconsistent data type, cannot merge traces')
continue
tr_combi = trs_group[0].copy()
tr_combi.extend(tmin, tmax, fillmethod='zeros')
for tr in trs_group[1:]:
tr_combi.add(tr)
trs_out.append(tr_combi)
return trs_out
def scan(
config,
......@@ -137,9 +168,28 @@ def scan(
for tmin_win, tmax_win in twindows:
for trs in p.chopper(
tmin=tmin_win, tmax=tmax_win, tinc=tinc, tpad=tpad,
want_incomplete=False,
want_incomplete=config.fill_incomplete_with_zeros,
trace_selector=lambda tr: tr.nslc_id[:3] in station_index):
trs_ok = []
for tr in trs:
if tr.ydata.size == 0:
logger.warn(
'skipping empty trace: %s.%s.%s.%s' % tr.nslc_id)
continue
if not num.all(num.isfinite(tr.ydata)):
logger.warn(
'skipping trace because of invalid values: '
'%s.%s.%s.%s' % tr.nslc_id)
continue
trs_ok.append(tr)
trs = trs_ok
if not trs:
continue
......@@ -150,6 +200,9 @@ def scan(
wmin = trs[0].wmin
wmax = trs[0].wmax
if config.fill_incomplete_with_zeros:
trs = zero_fill(trs, wmin - tpad, wmax + tpad)
frames = None
pdata = []
trs_debug = []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment