Commit 9f0488ee authored by Marius Kriegerowski's avatar Marius Kriegerowski
Browse files

lassie detection snuffling

parent 714af060
......@@ -6,3 +6,4 @@ from lassie.ifc import * # noqa
from lassie.core import * # noqa
from lassie.plot import * # noqa
from lassie.config import * # noqa
from lassie.snuffling import * # noqa
import copy
import numpy as num
from pyrocko import util, gui_util, model, orthodrome, pile, snuffler
from pyrocko.snuffling import Snuffling, Param, Choice, Switch
class LassieSnuffling(Snuffling):
'''
Scrutinize Lassie Detections and Re-Detect
'''
def __init__(self):
Snuffling.__init__(self)
self.config = None
def setup(self):
if self.config:
detector_default = self.config.detector_threshold
else:
detector_default = 100.
self.set_name('Lassie investigate')
self.add_parameter(Param('tsearch', 'tsearch', 1., 0.01, 100))
self.add_parameter(Param(
'threshold', 'detector_threshold', detector_default, 100., 10000.))
self.add_parameter(Switch('Level Trace', 'level_trace', False))
self.add_parameter(Choice(
'new marker kind', 'marker_kind', '1 (green)',
['1 (green)', '2 (blue)', '3 (orange)', '4 (purple)', '5 (brown)',
'0 (red)']))
self.set_live_update(False)
def call(self):
self.cleanup()
self.detections = []
for traces in self.chopper_selected_traces(
trace_selector=lambda x: x.station == "SMAX",
fallback=True):
for tr_stackmax in traces:
tpeaks, apeaks = tr_stackmax.peaks(
self.detector_threshold, self.tsearch)
if self.level_trace:
ltrace = tr_stackmax.copy(data=False)
ltrace.set_ydata(
num.ones(
tr_stackmax.data_len()) * self.detector_threshold)
self.add_trace(ltrace)
for t, a in zip(tpeaks, apeaks):
e = model.Event(time=t, name=str(a))
self.detections.append(
gui_util.EventMarker(
event=e, kind=int(self.marker_kind[0])))
self.add_markers(self.detections)
def __snufflings__():
return [LassieSnuffling()]
def snuffle(config):
global _lassie_config
_lassie_config = copy.deepcopy(config)
def load_snuffling(win):
s = LassieSnuffling()
s.config = _lassie_config
s.setup()
win.pile_viewer.viewer.add_snuffling(s)
receivers = config.get_receivers()
stations = set()
for r in receivers:
n, s, l = r.codes[:3]
stations.add(model.Station(lat=r.lat, lon=r.lon,
network=n, station=s, location=l))
markers = []
with open(config.detections_path, 'r') as f:
for line in f.readlines():
data = line.split()
i, t_d, t_t, apeak, latpeak, lonpeak, xpeak, ypeak, zpeak = data
lat, lon = orthodrome.ne_to_latlon(
float(latpeak), float(lonpeak), float(ypeak), float(xpeak))
t = util.str_to_time("%s %s" % (t_d, t_t))
label = "%s-%s" % (i, apeak)
e = model.Event(lat=lat, lon=lon, depth=float(zpeak)*1000.,
name=label, time=t)
m = gui_util.EventMarker(e)
markers.append(m)
paths = config.data_paths
paths.append('stackmax')
p = pile.make_pile(paths=paths, fileformat='detect')
snuffler.snuffle(p, markers=markers, stations=stations,
launch_hook=load_snuffling)
__all__ = [
'snuffle']
Supports Markdown
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