Commit afa541a6 authored by Sebastian Heimann's avatar Sebastian Heimann
Browse files

fix issues with HasPaths

parent a145ea33
......@@ -60,13 +60,22 @@ class HasPaths(Object):
self._basepath = None
self._parent_path_prefix = None
def ichildren(self):
for (prop, val) in self.T.ipropvals(self):
if isinstance(val, HasPaths):
yield val
elif prop.multivalued and val is not None:
for ele in val:
if isinstance(ele, HasPaths):
yield ele
def set_basepath(self, basepath, parent_path_prefix=None):
self._basepath = basepath
self._parent_path_prefix = parent_path_prefix
for (prop, val) in self.T.ipropvals(self):
if isinstance(val, HasPaths):
val.set_basepath(
basepath, self.path_prefix or self._parent_path_prefix)
for val in self.ichildren():
val.set_basepath(
basepath, self.path_prefix or self._parent_path_prefix)
def get_basepath(self):
assert self._basepath is not None
......@@ -81,10 +90,9 @@ class HasPaths(Object):
self.path_prefix = op.normpath(xjoin(xrelpath(
self._basepath, new_basepath), self.path_prefix))
for val in self.T.ivals(self):
if isinstance(val, HasPaths):
val.change_basepath(
new_basepath, self.path_prefix or self._parent_path_prefix)
for val in self.ichildren():
val.change_basepath(
new_basepath, self.path_prefix or self._parent_path_prefix)
self._basepath = new_basepath
......@@ -119,6 +127,7 @@ def expand_template(template, d):
raise LassieError(
'malformed placeholder in template: "%s"' % template)
def bark():
import subprocess
subprocess.call(['aplay', data_file('bark.wav')])
......
......@@ -473,29 +473,35 @@ class ManualPickIFC(IFC):
def __init__(self, *args, **kwargs):
IFC.__init__(self, *args, **kwargs)
self._picks_data = None
markers = pmarker.load_markers(self.expand_path(self.picks_path))
nsl_to_index = {}
picked_index = []
picked_times = []
index = -1
for marker in markers:
if isinstance(marker, pmarker.PhaseMarker) \
and marker.get_phasename() == self.picks_phasename:
def get_picks_data(self):
if not self._picks_data:
markers = pmarker.load_markers(self.expand_path(self.picks_path))
nsl_to_index = {}
picked_index = []
picked_times = []
index = -1
for marker in markers:
if isinstance(marker, pmarker.PhaseMarker) \
and marker.get_phasename() == self.picks_phasename:
nsl = marker.one_nslc()[:3]
if nsl not in nsl_to_index:
index += 1
nsl_to_index[nsl] = index
nsl = marker.one_nslc()[:3]
if nsl not in nsl_to_index:
index += 1
nsl_to_index[nsl] = index
ind = nsl_to_index[nsl]
ind = nsl_to_index[nsl]
picked_index.append(ind)
picked_times.append((marker.tmin + marker.tmax) * 0.5)
picked_index.append(ind)
picked_times.append((marker.tmin + marker.tmax) * 0.5)
self._picks_data = (
nsl_to_index,
num.array(picked_index, dtype=num.int64),
num.array(picked_times, dtype=num.float))
self._nsl_to_index = nsl_to_index
self._picked_index = num.array(picked_index, dtype=num.int64)
self._picked_times = num.array(picked_times, dtype=num.float)
return self._picks_data
def get_fsmooth(self):
return self.fsmooth
......@@ -506,15 +512,17 @@ class ManualPickIFC(IFC):
def preprocess(self, trs, wmin, wmax, tpad_new, deltat_cf):
fsmooth = self.get_fsmooth()
nsl_to_index, picked_index, picked_times = self.get_picks_data()
if not trs:
return []
mask = num.logical_and(
wmin <= self._picked_times,
wmax >= self._picked_times)
wmin <= picked_times,
wmax >= picked_times)
picked_times = self._picked_times[mask]
picked_index = self._picked_index[mask]
picked_times = picked_times[mask]
picked_index = picked_index[mask]
trs_filt = []
for orig_tr in trs:
......@@ -522,7 +530,7 @@ class ManualPickIFC(IFC):
nsl = tr.nslc_id[:3]
try:
index = self._nsl_to_index[nsl]
index = nsl_to_index[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())]
......
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