Commit 17ed489b authored by Marius Kriegerowski's avatar Marius Kriegerowski
Browse files

Merge branch 'python3' into ma_py3_merge

parents 3ff5f56e 32b0a745
...@@ -13,7 +13,7 @@ logger = logging.getLogger('main') ...@@ -13,7 +13,7 @@ logger = logging.getLogger('main')
def d2u(d): def d2u(d):
if isinstance(d, dict): 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: else:
return d.replace('-', '_') return d.replace('-', '_')
...@@ -21,7 +21,7 @@ def d2u(d): ...@@ -21,7 +21,7 @@ def d2u(d):
def str_to_time(s): def str_to_time(s):
try: try:
return util.str_to_time(s) return util.str_to_time(s)
except util.TimeStrError, e: except util.TimeStrError as e:
raise lassie.LassieError(str(e)) raise lassie.LassieError(str(e))
...@@ -83,7 +83,7 @@ def cl_parse(command, args, setup=None): ...@@ -83,7 +83,7 @@ def cl_parse(command, args, setup=None):
usage = subcommand_usages[command] usage = subcommand_usages[command]
descr = subcommand_descriptions[command] descr = subcommand_descriptions[command]
if isinstance(usage, basestring): if isinstance(usage, str):
usage = [usage] usage = [usage]
susage = '%s %s' % (program_name, usage[0]) susage = '%s %s' % (program_name, usage[0])
...@@ -147,7 +147,7 @@ def command_init(args): ...@@ -147,7 +147,7 @@ def command_init(args):
else: else:
stations_path = 'STATIONS_PATH' stations_path = 'STATIONS_PATH'
print '''%%YAML 1.1 print('''%%YAML 1.1
--- !lassie.Config --- !lassie.Config
## Configuration file for Lassie, your friendly earthquake detector ## Configuration file for Lassie, your friendly earthquake detector
...@@ -242,7 +242,7 @@ detector_threshold: 150. ...@@ -242,7 +242,7 @@ detector_threshold: 150.
## directory ## directory
save_figures: true 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) ## CakePhaseShifter config sections)
tabulated_phases: tabulated_phases:
- !pf.TPDef - !pf.TPDef
...@@ -252,7 +252,7 @@ tabulated_phases: ...@@ -252,7 +252,7 @@ tabulated_phases:
id: 's' id: 's'
definition: 'S,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) ## the CakePhaseShifter config sections)
earthmodels: earthmodels:
- !lassie.CakeEarthmodel - !lassie.CakeEarthmodel
...@@ -280,7 +280,7 @@ earthmodels: ...@@ -280,7 +280,7 @@ earthmodels:
120.0 8.15 4.57 3.3 120.0 8.15 4.57 3.3
''' % dict( ''' % dict(
stations_path=stations_path, stations_path=stations_path,
s_data_paths=s_data_paths) s_data_paths=s_data_paths))
def command_search(args): def command_search(args):
...@@ -356,7 +356,7 @@ def command_search(args): ...@@ -356,7 +356,7 @@ def command_search(args):
nparallel=nparallel, nparallel=nparallel,
bark=options.bark) bark=options.bark)
except lassie.LassieError, e: except lassie.LassieError as e:
die(str(e)) die(str(e))
......
...@@ -107,7 +107,7 @@ class HasPaths(Object): ...@@ -107,7 +107,7 @@ class HasPaths(Object):
if path is None: if path is None:
return None return None
elif isinstance(path, basestring): elif isinstance(path, str):
return extra( return extra(
op.normpath(xjoin(self._basepath, xjoin(path_prefix, path)))) op.normpath(xjoin(self._basepath, xjoin(path_prefix, path))))
else: else:
......
import logging import logging
import os.path as op import os.path as op
from pyrocko.guts import Object, String, Float, Timestamp, List, Bool from pyrocko.guts import String, Float, Timestamp, List, Bool
from pyrocko import model, guts from pyrocko import model, guts
from pyrocko.fdsn import station as fs from pyrocko.io import stationxml
from pyrocko.gf import TPDef from pyrocko.gf import TPDef
from lassie import receiver, ifc, grid, geo from lassie import receiver, ifc, grid, geo
...@@ -182,7 +182,7 @@ class Config(HasPaths): ...@@ -182,7 +182,7 @@ class Config(HasPaths):
z=station.depth)) z=station.depth))
if self.stations_stationxml_path: 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(): for station in sx.get_pyrocko_stations():
self._receivers.append( self._receivers.append(
receiver.Receiver( receiver.Receiver(
......
...@@ -39,8 +39,7 @@ class Detection(Object): ...@@ -39,8 +39,7 @@ class Detection(Object):
def check_data_consistency(p, config): def check_data_consistency(p, config):
receivers = config.get_receivers() receivers = config.get_receivers()
nslc_ids = p.nslc_ids.keys() nsl_ids = [nslc_id[:3] for nslc_id in p.nslc_ids.keys()]
nsl_ids = [nslc_id[:3] for nslc_id in nslc_ids]
r_ids = [r.codes for r in receivers] r_ids = [r.codes for r in receivers]
r_not_in_p = [] r_not_in_p = []
...@@ -92,7 +91,7 @@ def zero_fill(trs, tmin, tmax): ...@@ -92,7 +91,7 @@ def zero_fill(trs, tmin, tmax):
d[tr.nslc_id].append(tr) d[tr.nslc_id].append(tr)
trs_out = [] 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): if not all(tr.deltat == trs_group[0].deltat for tr in trs_group):
logger.warn('inconsistent sample rate, cannot merge traces') logger.warn('inconsistent sample rate, cannot merge traces')
continue continue
...@@ -272,13 +271,11 @@ def search( ...@@ -272,13 +271,11 @@ def search(
100.0*2.0*tpad / (tinc+2.0*tpad))) 100.0*2.0*tpad / (tinc+2.0*tpad)))
iwin = -1 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, want_incomplete=config.fill_incomplete_with_zeros,
trace_selector=lambda tr: tr.nslc_id[:3] in station_index): trace_selector=lambda tr: tr.nslc_id[:3] in station_index):
iwin += 1 iwin += 1
trs_ok = [] trs_ok = []
for tr in trs: for tr in trs:
if tr.ydata.size == 0: if tr.ydata.size == 0:
...@@ -320,7 +317,6 @@ def search( ...@@ -320,7 +317,6 @@ def search(
dataset = ifc.preprocess( dataset = ifc.preprocess(
trs, wmin-tpeaksearch, wmax+tpeaksearch, trs, wmin-tpeaksearch, wmax+tpeaksearch,
tshift_max - tshift_min, deltat_cf) tshift_max - tshift_min, deltat_cf)
if not dataset: if not dataset:
continue continue
...@@ -507,7 +503,6 @@ def search( ...@@ -507,7 +503,6 @@ def search(
io.save([tr_stackmax, tr_stackmax_indx], ifm_path_template) io.save([tr_stackmax, tr_stackmax_indx], ifm_path_template)
del frames del frames
logger.info('end processing time window group: %s - %s' % ( logger.info('end processing time window group: %s - %s' % (
util.time_to_str(tmin_win), util.time_to_str(tmin_win),
util.time_to_str(tmax_win))) util.time_to_str(tmax_win)))
......
from builtins import range
import math import math
import numpy as num import numpy as num
from pyrocko.guts import Object, Float from pyrocko.guts import Object, Float
...@@ -184,7 +185,7 @@ def geometrical_normalization(grid, receivers): ...@@ -184,7 +185,7 @@ def geometrical_normalization(grid, receivers):
ngridpoints, nstations = distances.shape ngridpoints, nstations = distances.shape
norm_map = num.zeros(ngridpoints) norm_map = num.zeros(ngridpoints)
for istation in xrange(nstations): for istation in range(nstations):
dists_station = distances[:, istation] dists_station = distances[:, istation]
dist_min = num.floor(num.min(dists_station) / delta_ring) * delta_ring dist_min = num.floor(num.min(dists_station) / delta_ring) * delta_ring
......
from __future__ import print_function
import logging import logging
from collections import defaultdict
import numpy as num import numpy as num
from collections import defaultdict
from scipy.signal import fftconvolve from scipy.signal import fftconvolve
from pyrocko.guts import Object, String, Float, Bool, StringChoice, List, Dict 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 pyrocko import marker as pmarker
from lassie import shifter, common, geo from lassie import shifter, common, geo
......
import os from builtins import range
import numpy as num 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 from lassie import grid as gridmod, geo
km = 1000. km = 1000.
...@@ -375,7 +376,7 @@ def plot_detection( ...@@ -375,7 +376,7 @@ def plot_detection(
if movie: if movie:
ani = FuncAnimation( ani = FuncAnimation(
fig, update, fig, update,
frames=list(xrange(iframe_min, iframe_max+1))[::10] + [None], frames=list(range(iframe_min, iframe_max+1))[::10] + [None],
interval=20., interval=20.,
repeat=False, repeat=False,
blit=True) blit=True)
......
import logging import logging
import hashlib import hashlib
from StringIO import StringIO from io import BytesIO
import os.path as op import os.path as op
import numpy as num 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 import cake, spit, util
from pyrocko.gf import meta from pyrocko.gf import meta
from lassie import geo from lassie import geo
...@@ -96,14 +96,16 @@ class CakePhaseShifter(Shifter): ...@@ -96,14 +96,16 @@ class CakePhaseShifter(Shifter):
return op.join(self._cache_path, ehash + '.spit') return op.join(self._cache_path, ehash + '.spit')
def ttt_hash(self, earthmodel, phases, x_bounds, x_tolerance, t_tolerance): 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('vp').dump(f)
earthmodel.profile('vs').dump(f) earthmodel.profile('vs').dump(f)
earthmodel.profile('rho').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_bounds.dump(f)
x_tolerance.dump(f) x_tolerance.dump(f)
f.write('%f' % t_tolerance) f.write(str(t_tolerance).encode())
s = f.getvalue() s = f.getvalue()
h = hashlib.sha1(s).hexdigest() h = hashlib.sha1(s).hexdigest()
f.close() f.close()
......
import copy import copy
import os import os
import numpy as num import numpy as num
from pyrocko import util, gui_util, model, orthodrome, pile, snuffler, \ from pyrocko import util, model, orthodrome, pile
marker as pmarker from pyrocko.gui import snuffler
from pyrocko.snuffling import Snuffling, Param, Choice, Switch 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 from lassie import geo, ifc
...@@ -96,6 +98,7 @@ class LassieSnuffling(Snuffling): ...@@ -96,6 +98,7 @@ class LassieSnuffling(Snuffling):
# self.add_trigger('read Lassie config', self.fail) # self.add_trigger('read Lassie config', self.fail)
self.set_live_update(True) self.set_live_update(True)
self.markers_compare = [] self.markers_compare = []
self.detections = []
self.fig = None self.fig = None
self.fframe = None self.fframe = None
self.grid = self.config.get_grid() self.grid = self.config.get_grid()
...@@ -118,8 +121,8 @@ class LassieSnuffling(Snuffling): ...@@ -118,8 +121,8 @@ class LassieSnuffling(Snuffling):
mode='all', mode='all',
trace_selector=lambda x: x.station == "SMAX", trace_selector=lambda x: x.station == "SMAX",
fallback=True): fallback=True):
tr_smax = filter(lambda x: x.location == '', traces) tr_smax = [tr for tr in traces if tr.location == '']
tr_i = filter(lambda x: x.location == 'i', traces) tr_i = [tr for tr in traces if tr.location == 'i']
if not tr_i: if not tr_i:
tr_i = [None] * len(tr_smax) tr_i = [None] * len(tr_smax)
...@@ -171,7 +174,7 @@ class LassieSnuffling(Snuffling): ...@@ -171,7 +174,7 @@ class LassieSnuffling(Snuffling):
def filter_visible(self, markers): def filter_visible(self, markers):
vtmin, vtmax = self.get_viewer().get_time_range() 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): def show_comparison(self):
''' '''
...@@ -224,7 +227,7 @@ class LassieSnuffling(Snuffling): ...@@ -224,7 +227,7 @@ class LassieSnuffling(Snuffling):
self.fig = self.fframe.gcf() self.fig = self.fframe.gcf()
ax = self.fig.add_subplot(111) 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] associated_events = [compare_events[a[1]] for a in detections_success]
magnitudes = [e.get_event().magnitude for e in markers_compare] magnitudes = [e.get_event().magnitude for e in markers_compare]
detected_magnitudes = [e.magnitude for e in associated_events] detected_magnitudes = [e.magnitude for e in associated_events]
...@@ -253,6 +256,8 @@ def __snufflings__(): ...@@ -253,6 +256,8 @@ def __snufflings__():
def snuffle(config): def snuffle(config):
global _lassie_config global _lassie_config
_lassie_config = copy.deepcopy(config) _lassie_config = copy.deepcopy(config)
for _ifc in _lassie_config.image_function_contributions:
_ifc.setup(config)
def load_snuffling(win): def load_snuffling(win):
s = LassieSnuffling() s = LassieSnuffling()
......
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