template_parallel
Marius Kriegerowski 6 years ago
parent b69de43db8
commit 4ee9647ed6

@ -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('-', '_')
@ -21,7 +21,7 @@ def d2u(d):
def str_to_time(s):
try:
return util.str_to_time(s)
except util.TimeStrError, e:
except util.TimeStrError as e:
raise lassie.LassieError(str(e))
@ -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):
@ -356,7 +356,7 @@ def command_search(args):
nparallel=nparallel,
bark=options.bark)
except lassie.LassieError, e:
except lassie.LassieError as e:
die(str(e))

@ -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:

@ -39,8 +39,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 = []
@ -92,7 +91,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
@ -130,6 +129,8 @@ def search(
run_path = fp(config.run_path)
print('xxx')
if op.exists(run_path):
if force:
shutil.rmtree(run_path)
@ -270,13 +271,14 @@ 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,
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,
trace_selector=lambda tr: tr.nslc_id[:3] in station_index):
print('xx', trs)
iwin += 1
trs_ok = []
for tr in trs:
if tr.ydata.size == 0:
@ -318,7 +320,6 @@ def search(
dataset = ifc.preprocess(
trs, wmin-tpeaksearch, wmax+tpeaksearch,
tshift_max - tshift_min, deltat_cf)
if not dataset:
continue
@ -505,7 +506,8 @@ def search(
io.save([tr_stackmax, tr_stackmax_indx], ifm_path_template)
del frames
print('dd')
logger.info('dd')
logger.info('end processing time window group: %s - %s' % (
util.time_to_str(tmin_win),
util.time_to_str(tmax_win)))

@ -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

@ -1,3 +1,4 @@
from __future__ import print_function
import logging
from collections import defaultdict
import numpy as num
@ -531,7 +532,7 @@ class ManualPickIFC(IFC):
nsl = tr.nslc_id[:3]
try:
index = nsl_to_index[nsl]
print nsl
print(nsl)
ts = picked_times[picked_index == index]
its = (num.round((ts - tr.tmin) / tr.deltat)).astype(num.int64)
its = its[num.logical_and(0 <= its, its < tr.data_len())]

@ -1,3 +1,4 @@
from builtins import range
import os
import numpy as num
@ -375,7 +376,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)

@ -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
@ -93,14 +93,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()

@ -117,8 +117,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)
@ -170,7 +170,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):
'''
@ -223,7 +223,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]

Loading…
Cancel
Save