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

Merge branch 'deluxe_merge' into 'deluxe'

Deluxe merge

See merge request !9
parents ee88bdef dc12eced
......@@ -24,30 +24,51 @@ class Detection(Object):
ifm = Float.T()
def check_data_consistency(p, receivers):
def check_data_consistency(p, config):
receivers = config.get_receivers()
nslc_ids = p.nslc_ids.keys()
nsl_ids = [nslc_id[:3] for nslc_id in nslc_ids]
r_ids = [ for r in receivers]
r_not_in_p = []
t_not_in_r = []
to_be_blacklisted = []
for r in receivers:
if[:3] not in nsl_ids:
if '.'.join([:3]) in config.blacklist:
for nsl_id in nsl_ids:
if nsl_id not in r_ids:
if len(r_not_in_p) != 0.:
logger.warn('following receivers have no traces in data set:')
logger.warn('Following receivers have no traces in data set:')
for nsl_id in r_not_in_p:
logger.warn(' %s' % '.'.join(nsl_id))
logger.warn('-' * 40)
if len(t_not_in_r) != 0.:
logger.warn('following traces have no associated receivers:')
logger.warn('Following traces have no associated receivers:')
for nsl_id in t_not_in_r:
logger.warn(' %s' % '.'.join(nsl_id))
logger.warn('-' * 40)
if len(to_be_blacklisted):'Blacklisted receivers:')
for code in to_be_blacklisted:' %s' % code)'-' * 40)
if len(config.blacklist) and\
len(to_be_blacklisted) != len(config.blacklist):
logger.warn('Blacklist NSL codes that did not match any receiver:')
for code in config.blacklist:
if code not in to_be_blacklisted:
logger.warn(' %s' % code)'-' * 40)
def zero_fill(trs, tmin, tmax):
......@@ -191,7 +212,7 @@ def scan(
if p.is_empty():
raise common.LassieError('no usable waveforms found')
check_data_consistency(p, receivers)
check_data_consistency(p, config)
deltat_cf = max(p.deltats.keys())
assert deltat_cf > 0.0
......@@ -325,9 +346,7 @@ def scan(
for tr in trs_selected],
w = num.array(
[station_weights.get(nsl, 1.0) for nsl in nsls_selected],
w = ifc.get_weights(nsls_selected)
weights = num.ones((ngridpoints, nstations_selected))
weights *= w[num.newaxis, :]
......@@ -403,7 +422,7 @@ def scan(
tr_stackmax_indx = tr_stackmax.copy(data=False)
imaxs = num.zeros(len(frames))
for iframe, frame in enumerate(frames):
for iframe, frame in enumerate(frames.T):
imaxs[iframe] = num.argmax(frame)
......@@ -3,7 +3,7 @@ import logging
from collections import defaultdict
import numpy as num
from scipy.signal import fftconvolve
from pyrocko.guts import Object, String, Float, Bool, StringChoice
from pyrocko.guts import Object, String, Float, Bool, StringChoice, List, Dict
from pyrocko import trace, autopick, util, model, gui_util
from pyrocko import marker as pmarker
from lassie import shifter, common, geo
......@@ -13,11 +13,45 @@ logger = logging.getLogger('lassie.ifc')
guts_prefix = 'lassie'
class TraceSelector(Object):
Filter traces used in an IFC using NSLC-id lists and/or lists of regular
white_list = List.T(optional=True, default=[])
white_list_regex = List.T(String.T(default=[]))
def __call__(self, trs):
matched = []
for tr in trs:
nslc = '.'.join(tr.nslc_id)
if self.white_list and nslc in self.white_list:
if self.white_list_regex and util.match_nslc(
self.white_list_regex, nslc):
return matched
def __str__(self):
return '%s:\n wl: %s\n wlre: %s\n' % (
self.__class__.__name__, self.white_list, self.white_list_regex)
class IFC(Object):
'''Image function contribution.'''
name = String.T()
weight = Float.T(default=1.0)
weights = Dict.T(
help='weight selected traces')
fmin = Float.T()
fmax = Float.T()
shifter = shifter.Shifter.T(optional=True)
......@@ -48,6 +82,22 @@ class IFC(Object):
def preprocess(self, trs, wmin, wmax, tpad_new, deltat_cf):
def get_weights(self, nsls):
if self.weights is None:
return num.ones(len(nsls), dtype=num.float)
weights = num.empty(len(nsls))
selectors = self.weights.keys()
for insl, nsl in enumerate(nsls):
weights[insl] = 1.
for selector in selectors:
if util.match_nslc(selector, nsl):
weights[insl] = self.weights[selector]
return weights
class WavePacketIFC(IFC):
......@@ -150,7 +200,7 @@ class OnsetIFC(IFC):
def get_fsmooth(self):
if self.fsmooth is None and self.fsmooth_factor is None:
raise LassieError('must use fsmooth or fsmooth_factor')
raise comming.LassieError('must use fsmooth or fsmooth_factor')
if self.fsmooth is not None:
return self.fsmooth
......@@ -159,7 +209,7 @@ class OnsetIFC(IFC):
def get_fnormalize(self):
if self.fnormalize is None and self.fnormalize_factor is None:
raise LassieError('must use fnormalize or fnormalize_factor')
raise common.LassieError('must use fnormalize or fnormalize_factor')
if self.fnormalize is not None:
return self.fnormalize
import copy
import os
import numpy as num
from pyrocko import util, gui_util, model, orthodrome, pile, snuffler
from pyrocko.snuffling import Snuffling, Param, Choice, Switch
......@@ -253,10 +254,13 @@ def snuffle(config):
win.pile_viewer.viewer.add_snuffling(s, reloaded=True)
for bl in _lassie_config.blacklist:
win.pile_viewer.viewer.add_blacklist_pattern('%s.*' % bl)
s.detections = detections_to_event_markers(
if os.path.exists(_lassie_config.detections_path):
s.detections = detections_to_event_markers(
receivers = config.get_receivers()
stations = set()
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