Commit 4ee9647e authored by Marius Kriegerowski's avatar Marius Kriegerowski
Browse files

wip py3

parent b69de43d
...@@ -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:
......
...@@ -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
...@@ -130,6 +129,8 @@ def search( ...@@ -130,6 +129,8 @@ def search(
run_path = fp(config.run_path) run_path = fp(config.run_path)
print('xxx')
if op.exists(run_path): if op.exists(run_path):
if force: if force:
shutil.rmtree(run_path) shutil.rmtree(run_path)
...@@ -270,13 +271,14 @@ def search( ...@@ -270,13 +271,14 @@ 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, print(tmin_win, tmax_win, tinc, 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):
print('xx', trs)
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:
...@@ -318,7 +320,6 @@ def search( ...@@ -318,7 +320,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
...@@ -505,7 +506,8 @@ def search( ...@@ -505,7 +506,8 @@ 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
print('dd')
logger.info('dd')
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 from collections import defaultdict
import numpy as num import numpy as num
...@@ -531,7 +532,7 @@ class ManualPickIFC(IFC): ...@@ -531,7 +532,7 @@ class ManualPickIFC(IFC):
nsl = tr.nslc_id[:3] nsl = tr.nslc_id[:3]
try: try:
index = nsl_to_index[nsl] index = nsl_to_index[nsl]
print nsl print(nsl)
ts = picked_times[picked_index == index] ts = picked_times[picked_index == index]
its = (num.round((ts - tr.tmin) / tr.deltat)).astype(num.int64) its = (num.round((ts - tr.tmin) / tr.deltat)).astype(num.int64)
its = its[num.logical_and(0 <= its, its < tr.data_len())] its = its[num.logical_and(0 <= its, its < tr.data_len())]
......
from builtins import range
import os import os
import numpy as num import numpy as num
...@@ -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
...@@ -93,14 +93,16 @@ class CakePhaseShifter(Shifter): ...@@ -93,14 +93,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()
......
...@@ -117,8 +117,8 @@ class LassieSnuffling(Snuffling): ...@@ -117,8 +117,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)
...@@ -170,7 +170,7 @@ class LassieSnuffling(Snuffling): ...@@ -170,7 +170,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):
''' '''
...@@ -223,7 +223,7 @@ class LassieSnuffling(Snuffling): ...@@ -223,7 +223,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]
......
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