Browse Source

Merge branch 'master' of gitext:heimann/lassie

Conflicts:
	src/config.py
	src/plot.py
weighting
Sebastian Heimann 3 years ago
parent
commit
91a9853309
9 changed files with 44 additions and 37 deletions
  1. +6
    -6
      apps/lassie
  2. +1
    -1
      src/common.py
  3. +2
    -2
      src/config.py
  4. +6
    -11
      src/core.py
  5. +2
    -1
      src/grid.py
  6. +4
    -2
      src/ifc.py
  7. +4
    -2
      src/plot.py
  8. +7
    -5
      src/shifter.py
  9. +12
    -7
      src/snuffling.py

+ 6
- 6
apps/lassie View File

@ -13,7 +13,7 @@ logger = logging.getLogger('main')
def d2u(d):
if isinstance(d, dict):
return dict((k.replace('-', '_'), v) for (k, v) in d.iteritems())
return dict((k.replace('-', '_'), v) for (k, v) in d.items())
else:
return d.replace('-', '_')
@ -83,7 +83,7 @@ def cl_parse(command, args, setup=None):
usage = subcommand_usages[command]
descr = subcommand_descriptions[command]
if isinstance(usage, basestring):
if isinstance(usage, str):
usage = [usage]
susage = '%s %s' % (program_name, usage[0])
@ -147,7 +147,7 @@ def command_init(args):
else:
stations_path = 'STATIONS_PATH'
print '''%%YAML 1.1
print('''%%YAML 1.1
--- !lassie.Config
## Configuration file for Lassie, your friendly earthquake detector
@ -242,7 +242,7 @@ detector_threshold: 150.
## directory
save_figures: true
## Mapping of phase ID to phase definition in cake syntax (used e.g. in the
## Mapping of phase ID to phase definition in cake syntax (used e.g. in the
## CakePhaseShifter config sections)
tabulated_phases:
- !pf.TPDef
@ -252,7 +252,7 @@ tabulated_phases:
id: 's'
definition: 'S,s'
## Mapping of earthmodel ID to the actual earth model in nd format (used in
## Mapping of earthmodel ID to the actual earth model in nd format (used in
## the CakePhaseShifter config sections)
earthmodels:
- !lassie.CakeEarthmodel
@ -280,7 +280,7 @@ earthmodels:
120.0 8.15 4.57 3.3
''' % dict(
stations_path=stations_path,
s_data_paths=s_data_paths)
s_data_paths=s_data_paths))
def command_search(args):


+ 1
- 1
src/common.py View File

@ -107,7 +107,7 @@ class HasPaths(Object):
if path is None:
return None
elif isinstance(path, basestring):
elif isinstance(path, str):
return extra(
op.normpath(xjoin(self._basepath, xjoin(path_prefix, path))))
else:


+ 2
- 2
src/config.py View File

@ -3,7 +3,7 @@ import os.path as op
from pyrocko.guts import String, Float, Timestamp, List, Bool, Int
from pyrocko import model, guts
from pyrocko.fdsn import station as fs
from pyrocko.io import stationxml
from pyrocko.gf import TPDef
from lassie import receiver, ifc, grid, geo
@ -194,7 +194,7 @@ class Config(HasPaths):
z=station.depth))
if self.stations_stationxml_path:
sx = fs.load_xml(filename=fp(self.stations_stationxml_path))
sx = stationxml.load_xml(filename=fp(self.stations_stationxml_path))
for station in sx.get_pyrocko_stations():
self._receivers.append(
receiver.Receiver(


+ 6
- 11
src/core.py View File

@ -40,8 +40,7 @@ class Detection(Object):
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]
nsl_ids = [nslc_id[:3] for nslc_id in p.nslc_ids.keys()]
r_ids = [r.codes for r in receivers]
r_not_in_p = []
@ -93,7 +92,7 @@ def zero_fill(trs, tmin, tmax):
d[tr.nslc_id].append(tr)
trs_out = []
for nslc, trs_group in d.iteritems():
for nslc, trs_group in d.items():
if not all(tr.deltat == trs_group[0].deltat for tr in trs_group):
logger.warn('inconsistent sample rate, cannot merge traces')
continue
@ -273,13 +272,11 @@ def search(
100.0*2.0*tpad / (tinc+2.0*tpad)))
iwin = -1
for trs in p.chopper(
tmin=tmin_win, tmax=tmax_win, tinc=tinc, tpad=tpad,
for trs in p.chopper(tmin=tmin_win, tmax=tmax_win, tinc=tinc, tpad=tpad,
want_incomplete=config.fill_incomplete_with_zeros,
trace_selector=lambda tr: tr.nslc_id[:3] in station_index):
iwin += 1
trs_ok = []
for tr in trs:
if tr.ydata.size == 0:
@ -325,7 +322,6 @@ def search(
dataset = ifc.preprocess(
trs, wmin-tpeaksearch, wmax+tpeaksearch,
tshift_max - tshift_min, deltat_cf)
if not dataset:
continue
@ -443,9 +439,9 @@ def search(
num.max(ydata_window),
num.median(ydata_window)))
tpeaks, apeaks = zip(*[(tpeak, apeak) for (tpeak, apeak) in zip(
tpeaks, apeaks = list(zip(*[(tpeak, apeak) for (tpeak, apeak) in zip(
*tr_stackmax.peaks(config.detector_threshold, tpeaksearch)) if
wmin <= tpeak and tpeak < wmax]) or ([], [])
wmin <= tpeak and tpeak < wmax])) or ([], [])
tr_stackmax_indx = tr_stackmax.copy(data=False)
tr_stackmax_indx.set_ydata(frame_argmaxs.astype(num.int32))
@ -566,7 +562,6 @@ def search(
io.save([tr_stackmax, tr_stackmax_indx], ifm_path_template)
del frames
logger.info('end processing time window group: %s - %s' % (
util.time_to_str(tmin_win),
util.time_to_str(tmax_win)))


+ 2
- 1
src/grid.py View File

@ -1,3 +1,4 @@
from builtins import range
import math
import numpy as num
from pyrocko.guts import Object, Float
@ -184,7 +185,7 @@ def geometrical_normalization(grid, receivers):
ngridpoints, nstations = distances.shape
norm_map = num.zeros(ngridpoints)
for istation in xrange(nstations):
for istation in range(nstations):
dists_station = distances[:, istation]
dist_min = num.floor(num.min(dists_station) / delta_ring) * delta_ring


+ 4
- 2
src/ifc.py View File

@ -1,9 +1,11 @@
from __future__ import print_function
import logging
from collections import defaultdict
import numpy as num
from collections import defaultdict
from scipy.signal import fftconvolve
from pyrocko.guts import Object, String, Float, Bool, StringChoice, List, Dict
from pyrocko import trace, autopick, util, model, gui_util
from pyrocko import trace, autopick, util, model
from pyrocko.gui import util as gui_util
from pyrocko import marker as pmarker
from lassie import shifter, common, geo


+ 4
- 2
src/plot.py View File

@ -1,6 +1,8 @@
from builtins import range
import numpy as num
from pyrocko import automap, plot, util
from pyrocko.plot import automap
from pyrocko import plot, util
from lassie import grid as gridmod, geo
km = 1000.
@ -373,7 +375,7 @@ def plot_detection(
if movie:
ani = FuncAnimation(
fig, update,
frames=list(xrange(iframe_min, iframe_max+1))[::10] + [None],
frames=list(range(iframe_min, iframe_max+1))[::10] + [None],
interval=20.,
repeat=False,
blit=True)


+ 7
- 5
src/shifter.py View File

@ -1,9 +1,9 @@
import logging
import hashlib
from StringIO import StringIO
from io import BytesIO
import os.path as op
import numpy as num
from pyrocko.guts import Object, Float, String
from pyrocko.guts import Object, Float, String # noqa
from pyrocko import cake, spit, util
from pyrocko.gf import meta
from lassie import geo
@ -96,14 +96,16 @@ class CakePhaseShifter(Shifter):
return op.join(self._cache_path, ehash + '.spit')
def ttt_hash(self, earthmodel, phases, x_bounds, x_tolerance, t_tolerance):
f = StringIO()
f = BytesIO()
earthmodel.profile('z').dump(f)
earthmodel.profile('vp').dump(f)
earthmodel.profile('vs').dump(f)
earthmodel.profile('rho').dump(f)
f.write(','.join(phase.definition() for phase in phases))
f.write(b','.join(phase.definition().encode() for phase in phases))
x_bounds.dump(f)
x_tolerance.dump(f)
f.write('%f' % t_tolerance)
f.write(str(t_tolerance).encode())
s = f.getvalue()
h = hashlib.sha1(s).hexdigest()
f.close()


+ 12
- 7
src/snuffling.py View File

@ -1,9 +1,11 @@
import copy
import os
import numpy as num
from pyrocko import util, gui_util, model, orthodrome, pile, snuffler, \
marker as pmarker
from pyrocko.snuffling import Snuffling, Param, Choice, Switch
from pyrocko import util, model, orthodrome, pile
from pyrocko.gui import snuffler
from pyrocko.gui import marker as pmarker
from pyrocko.gui import util as gui_util
from pyrocko.gui.snuffling import Snuffling, Param, Choice, Switch
from lassie import geo, ifc
@ -96,6 +98,7 @@ class LassieSnuffling(Snuffling):
# self.add_trigger('read Lassie config', self.fail)
self.set_live_update(True)
self.markers_compare = []
self.detections = []
self.fig = None
self.fframe = None
self.grid = self.config.get_grid()
@ -118,8 +121,8 @@ class LassieSnuffling(Snuffling):
mode='all',
trace_selector=lambda x: x.station == "SMAX",
fallback=True):
tr_smax = filter(lambda x: x.location == '', traces)
tr_i = filter(lambda x: x.location == 'i', traces)
tr_smax = [tr for tr in traces if tr.location == '']
tr_i = [tr for tr in traces if tr.location == 'i']
if not tr_i:
tr_i = [None] * len(tr_smax)
@ -171,7 +174,7 @@ class LassieSnuffling(Snuffling):
def filter_visible(self, markers):
vtmin, vtmax = self.get_viewer().get_time_range()
return filter(lambda x: vtmin < x.tmin < vtmax, markers)
return [x for x in markers if vtmin < x.tmin < vtmax]
def show_comparison(self):
'''
@ -224,7 +227,7 @@ class LassieSnuffling(Snuffling):
self.fig = self.fframe.gcf()
ax = self.fig.add_subplot(111)
compare_events = map(lambda x: x.get_event(), markers_compare)
compare_events = [x.get_event() for x in markers_compare]
associated_events = [compare_events[a[1]] for a in detections_success]
magnitudes = [e.get_event().magnitude for e in markers_compare]
detected_magnitudes = [e.magnitude for e in associated_events]
@ -253,6 +256,8 @@ def __snufflings__():
def snuffle(config):
global _lassie_config
_lassie_config = copy.deepcopy(config)
for _ifc in _lassie_config.image_function_contributions:
_ifc.setup(config)
def load_snuffling(win):
s = LassieSnuffling()


Loading…
Cancel
Save