core.py 18.5 KB
Newer Older
1
import math
Sebastian Heimann's avatar
Sebastian Heimann committed
2
3
import logging
import os.path as op
4
import shutil
5
import time
Sebastian Heimann's avatar
Sebastian Heimann committed
6

7
8
from collections import defaultdict

Sebastian Heimann's avatar
Sebastian Heimann committed
9
10
import numpy as num

Sebastian Heimann's avatar
Sebastian Heimann committed
11
from pyrocko import pile, trace, util, io, model
Marius Kriegerowski's avatar
Marius Kriegerowski committed
12
from pyrocko.parstack import parstack, argmax as pargmax
13

14
from pyrocko.guts import Object, Timestamp, String, Float
Sebastian Heimann's avatar
Sebastian Heimann committed
15

Sebastian Heimann's avatar
flake8    
Sebastian Heimann committed
16
from lassie import common, plot, grid as gridmod, geo
Sebastian Heimann's avatar
Sebastian Heimann committed
17
from lassie.config import write_config
Sebastian Heimann's avatar
Sebastian Heimann committed
18
19
20
21

logger = logging.getLogger('lassie.core')


22
23
24
25
26
27
class Detection(Object):
    id = String.T()
    time = Timestamp.T()
    location = geo.Point.T()
    ifm = Float.T()

Sebastian Heimann's avatar
Sebastian Heimann committed
28
29
30
31
32
33
34
35
36
37
38
39
    def get_event(self):
        lat, lon = geo.point_coords(self.location, system='latlon')

        event = model.Event(
            lat=lat,
            lon=lon,
            depth=self.location.z,
            time=self.time,
            name='%s (%g)' % (self.id, self.ifm))

        return event

40

41
42
def check_data_consistency(p, config):
    receivers = config.get_receivers()
Marius Kriegerowski's avatar
wip py3    
Marius Kriegerowski committed
43
    nsl_ids = [nslc_id[:3] for nslc_id in p.nslc_ids.keys()]
44
45
46
47
    r_ids = [r.codes for r in receivers]

    r_not_in_p = []
    t_not_in_r = []
48
49
    to_be_blacklisted = []

50
51
52
    for r in receivers:
        if r.codes[:3] not in nsl_ids:
            r_not_in_p.append(r.codes)
53
54
        if '.'.join(r.codes[:3]) in config.blacklist:
            to_be_blacklisted.append('.'.join(r.codes))
55
56
57
58
59
60

    for nsl_id in nsl_ids:
        if nsl_id not in r_ids:
            t_not_in_r.append(nsl_id)

    if len(r_not_in_p) != 0.:
61
        logger.warn('Following receivers have no traces in data set:')
62
        for nsl_id in r_not_in_p:
63
64
            logger.warn('  %s' % '.'.join(nsl_id))
        logger.warn('-' * 40)
65
66

    if len(t_not_in_r) != 0.:
67
        logger.warn('Following traces have no associated receivers:')
68
        for nsl_id in t_not_in_r:
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
            logger.warn('  %s' % '.'.join(nsl_id))
        logger.warn('-' * 40)

    if len(to_be_blacklisted):
        logger.info('Blacklisted receivers:')
        for code in to_be_blacklisted:
            logger.info('  %s' % code)
        logger.info('-' * 40)

    if len(config.blacklist) and\
            len(to_be_blacklisted) != len(config.blacklist):
        logger.warn('Blacklist NSL codes that did not match any receiver:')
        for code in config.blacklist:
            if code not in to_be_blacklisted:
                logger.warn('  %s' % code)
        logger.info('-' * 40)
85
86


87
88
89
90
91
92
93
94
def zero_fill(trs, tmin, tmax):
    trs = trace.degapper(trs)

    d = defaultdict(list)
    for tr in trs:
        d[tr.nslc_id].append(tr)

    trs_out = []
Marius Kriegerowski's avatar
wip py3    
Marius Kriegerowski committed
95
    for nslc, trs_group in d.items():
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
        if not all(tr.deltat == trs_group[0].deltat for tr in trs_group):
            logger.warn('inconsistent sample rate, cannot merge traces')
            continue

        if not all(tr.ydata.dtype == trs_group[0].ydata.dtype
                   for tr in trs_group):

            logger.warn('inconsistent data type, cannot merge traces')
            continue

        tr_combi = trs_group[0].copy()
        tr_combi.extend(tmin, tmax, fillmethod='zeros')

        for tr in trs_group[1:]:
            tr_combi.add(tr)

        trs_out.append(tr_combi)

    return trs_out

116

Sebastian Heimann's avatar
Sebastian Heimann committed
117
def search(
Sebastian Heimann's avatar
Sebastian Heimann committed
118
        config,
119
120
        override_tmin=None,
        override_tmax=None,
Sebastian Heimann's avatar
Sebastian Heimann committed
121
122
        show_detections=False,
        show_movie=False,
123
        show_window_traces=False,
Sebastian Heimann's avatar
Sebastian Heimann committed
124
        force=False,
Marius Kriegerowski's avatar
Marius Kriegerowski committed
125
        stop_after_first=False,
Sebastian Heimann's avatar
bark    
Sebastian Heimann committed
126
127
        nparallel=None,
        bark=False):
Sebastian Heimann's avatar
Sebastian Heimann committed
128

Sebastian Heimann's avatar
Sebastian Heimann committed
129
    fp = config.expand_path
Sebastian Heimann's avatar
Sebastian Heimann committed
130

Sebastian Heimann's avatar
Sebastian Heimann committed
131
132
133
134
135
136
137
138
139
140
141
142
143
    run_path = fp(config.run_path)

    if op.exists(run_path):
        if force:
            shutil.rmtree(run_path)
        else:
            raise common.LassieError(
                'run directory already exists: %s' %
                run_path)

    util.ensuredir(run_path)

    write_config(config, op.join(run_path, 'config.yaml'))
144

Sebastian Heimann's avatar
Sebastian Heimann committed
145
146
147
148
    ifm_path_template = config.get_ifm_path_template()
    detections_path = config.get_detections_path()
    events_path = config.get_events_path()
    figures_path_template = config.get_figures_path_template()
149

150
    config.setup_image_function_contributions()
151
152
    ifcs = config.image_function_contributions

Sebastian Heimann's avatar
Sebastian Heimann committed
153
154
155
156
157
    grid = config.get_grid()
    receivers = config.get_receivers()

    norm_map = gridmod.geometrical_normalization(grid, receivers)

Sebastian Heimann's avatar
Sebastian Heimann committed
158
159
    data_paths = fp(config.data_paths)
    for data_path in fp(data_paths):
160
161
162
163
        if not op.exists(data_path):
            raise common.LassieError(
                'waveform data path does not exist: %s' % data_path)

Sebastian Heimann's avatar
Sebastian Heimann committed
164
    p = pile.make_pile(data_paths, fileformat='detect')
165
166
167
168
169
    if p.is_empty():
        raise common.LassieError('no usable waveforms found')

    for ifc in ifcs:
        ifc.prescan(p)
170

Sebastian Heimann's avatar
Sebastian Heimann committed
171
    shift_tables = []
172
    tshift_minmaxs = []
173
    for ifc in ifcs:
174
        shift_tables.append(ifc.get_table(grid, receivers))
175
176
        tshift_minmaxs.append(num.nanmin(shift_tables[-1]))
        tshift_minmaxs.append(num.nanmax(shift_tables[-1]))
Sebastian Heimann's avatar
Sebastian Heimann committed
177

178
179
    fsmooth_min = min(ifc.get_fsmooth() for ifc in ifcs)

180
181
    tshift_min = min(tshift_minmaxs)
    tshift_max = max(tshift_minmaxs)
Sebastian Heimann's avatar
Sebastian Heimann committed
182

183
184
185
186
    if config.detector_tpeaksearch is not None:
        tpeaksearch = config.detector_tpeaksearch
    else:
        tpeaksearch = (tshift_max - tshift_min) + 1.0 / fsmooth_min
Sebastian Heimann's avatar
Sebastian Heimann committed
187

188
189
    tpad = max(ifc.get_tpad() for ifc in ifcs) + \
        (tshift_max - tshift_min) + tpeaksearch
Sebastian Heimann's avatar
Sebastian Heimann committed
190

191
    tinc = (tshift_max - tshift_min) * 10. + 3.0 * tpad
192
193
194
195
196
197
198
199
    tavail = p.tmax - p.tmin
    tinc = min(tinc, tavail - 2.0 * tpad)

    if tinc <= 0:
        raise common.LassieError(
            'available waveforms too short \n'
            'required: %g s\n'
            'available: %g s\n' % (2.*tpad, tavail))
Sebastian Heimann's avatar
Sebastian Heimann committed
200
201

    blacklist = set(tuple(s.split('.')) for s in config.blacklist)
202
203
204
205
    whitelist = set(tuple(s.split('.')) for s in config.whitelist)

    distances = grid.distances(receivers)
    distances_to_grid = num.min(distances, axis=0)
Sebastian Heimann's avatar
Sebastian Heimann committed
206

207
208
209
    distance_min = num.min(distances)
    distance_max = num.max(distances)

Sebastian Heimann's avatar
Sebastian Heimann committed
210
211
    station_index = dict(
        (rec.codes, i) for (i, rec) in enumerate(receivers)
212
213
214
215
        if rec.codes not in blacklist and (
            not whitelist or rec.codes in whitelist) and (
            config.distance_max is None or
                distances_to_grid[i] <= config.distance_max))
Sebastian Heimann's avatar
Sebastian Heimann committed
216

Marius Kriegerowski's avatar
Marius Kriegerowski committed
217
    check_data_consistency(p, config)
218

219
220
221
222
223
224
225
226
227
    deltat_cf = max(p.deltats.keys())
    assert deltat_cf > 0.0

    while True:
        if not all(ifc.deltat_cf_is_available(deltat_cf * 2) for ifc in ifcs):
            break

        deltat_cf *= 2

228
229
    logger.info('CF sampling interval (rate): %g s (%g Hz)' % (
        deltat_cf, 1.0/deltat_cf))
230

Sebastian Heimann's avatar
Sebastian Heimann committed
231
232
    ngridpoints = grid.size()

233
234
235
236
237
238
    logger.info('number of grid points: %i' % ngridpoints)
    logger.info('minimum source-receiver distance: %g m' % distance_min)
    logger.info('maximum source-receiver distance: %g m' % distance_max)
    logger.info('minimum travel-time: %g s' % tshift_min)
    logger.info('maximum travel-time: %g s' % tshift_max)

Sebastian Heimann's avatar
Sebastian Heimann committed
239
240
    idetection = 0

241
242
    tmin = override_tmin or config.tmin or p.tmin + tpad
    tmax = override_tmax or config.tmax or p.tmax - tpad
Sebastian Heimann's avatar
Sebastian Heimann committed
243

244
245
246
247
248
249
    events = config.get_events()
    twindows = []
    if events is not None:
        for ev in events:
            if tmin <= ev.time <= tmax:
                twindows.append((
250
251
252
253
                    ev.time + tshift_min - (tshift_max - tshift_min) *
                    config.event_time_window_factor,
                    ev.time + tshift_min + (tshift_max - tshift_min) *
                    config.event_time_window_factor))
Sebastian Heimann's avatar
Sebastian Heimann committed
254

255
256
    else:
        twindows.append((tmin, tmax))
Sebastian Heimann's avatar
Sebastian Heimann committed
257

258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
    for iwindow_group, (tmin_win, tmax_win) in enumerate(twindows):

        nwin = int(math.ceil((tmax_win - tmin_win) / tinc))

        logger.info('start processing time window group %i/%i: %s - %s' % (
            iwindow_group + 1, len(twindows),
            util.time_to_str(tmin_win),
            util.time_to_str(tmax_win)))

        logger.info('number of time windows: %i' % nwin)
        logger.info('time window length: %g s' % (tinc + 2.0*tpad))
        logger.info('time window payload: %g s' % tinc)
        logger.info('time window padding: 2 x %g s' % tpad)
        logger.info('time window overlap: %g%%' % (
            100.0*2.0*tpad / (tinc+2.0*tpad)))

        iwin = -1
Marius Kriegerowski's avatar
wip py3    
Marius Kriegerowski committed
275
276

        for trs in p.chopper(tmin=tmin_win, tmax=tmax_win, tinc=tinc, tpad=tpad,
277
                want_incomplete=config.fill_incomplete_with_zeros,
278
                trace_selector=lambda tr: tr.nslc_id[:3] in station_index):
279
            iwin += 1
280
281
282
283
284
            trs_ok = []
            for tr in trs:
                if tr.ydata.size == 0:
                    logger.warn(
                        'skipping empty trace: %s.%s.%s.%s' % tr.nslc_id)
Sebastian Heimann's avatar
Sebastian Heimann committed
285

286
                    continue
Sebastian Heimann's avatar
Sebastian Heimann committed
287

288
289
290
291
                if not num.all(num.isfinite(tr.ydata)):
                    logger.warn(
                        'skipping trace because of invalid values: '
                        '%s.%s.%s.%s' % tr.nslc_id)
Sebastian Heimann's avatar
Sebastian Heimann committed
292

293
                    continue
Sebastian Heimann's avatar
Sebastian Heimann committed
294

295
                trs_ok.append(tr)
Sebastian Heimann's avatar
Sebastian Heimann committed
296

297
            trs = trs_ok
Sebastian Heimann's avatar
Sebastian Heimann committed
298

299
            if not trs:
Sebastian Heimann's avatar
Sebastian Heimann committed
300
301
                continue

302
303
            logger.info('processing time window %i/%i: %s - %s' % (
                iwin + 1, nwin,
304
305
                util.time_to_str(trs[0].wmin),
                util.time_to_str(trs[0].wmax)))
Sebastian Heimann's avatar
Sebastian Heimann committed
306

307
308
            wmin = trs[0].wmin
            wmax = trs[0].wmax
Sebastian Heimann's avatar
Sebastian Heimann committed
309

310
311
            if config.fill_incomplete_with_zeros:
                trs = zero_fill(trs, wmin - tpad, wmax + tpad)
Sebastian Heimann's avatar
Sebastian Heimann committed
312

313
314
315
316
317
            t0 = math.floor(wmin / deltat_cf) * deltat_cf
            iwmin = int(round((wmin-tpeaksearch-t0) / deltat_cf))
            iwmax = int(round((wmax+tpeaksearch-t0) / deltat_cf))
            lengthout = iwmax - iwmin + 1

318
319
            pdata = []
            trs_debug = []
320
            parstack_params = []
321
            for iifc, ifc in enumerate(ifcs):
322
                dataset = ifc.preprocess(
323
                    trs, wmin-tpeaksearch, wmax+tpeaksearch,
324
                    tshift_max - tshift_min, deltat_cf)
325
326
                if not dataset:
                    continue
Sebastian Heimann's avatar
Sebastian Heimann committed
327

328
                nstations_selected = len(dataset)
Sebastian Heimann's avatar
Sebastian Heimann committed
329

330
                nsls_selected, trs_selected = zip(*dataset)
Sebastian Heimann's avatar
Sebastian Heimann committed
331

Sebastian Heimann's avatar
Sebastian Heimann committed
332
333
334
                for tr in trs_selected:
                    tr.meta = {'tabu': True}

335
                trs_debug.extend(trs + list(trs_selected))
Sebastian Heimann's avatar
Sebastian Heimann committed
336

337
338
339
                istations_selected = num.array(
                    [station_index[nsl] for nsl in nsls_selected],
                    dtype=num.int)
Sebastian Heimann's avatar
Sebastian Heimann committed
340

341
                arrays = [tr.ydata.astype(num.float) for tr in trs_selected]
Sebastian Heimann's avatar
Sebastian Heimann committed
342

343
344
345
346
                offsets = num.array(
                    [int(round((tr.tmin-t0) / deltat_cf))
                     for tr in trs_selected],
                    dtype=num.int32)
Sebastian Heimann's avatar
Sebastian Heimann committed
347

Marius Kriegerowski's avatar
Marius Kriegerowski committed
348
                w = ifc.get_weights(nsls_selected)
Sebastian Heimann's avatar
Sebastian Heimann committed
349

350
351
352
                weights = num.ones((ngridpoints, nstations_selected))
                weights *= w[num.newaxis, :]
                weights *= ifc.weight
353

354
                shift_table = shift_tables[iifc]
Sebastian Heimann's avatar
Sebastian Heimann committed
355

Sebastian Heimann's avatar
Sebastian Heimann committed
356
357
358
                ok = num.isfinite(shift_table[:, istations_selected])
                bad = num.logical_not(ok)

359
360
361
                shifts = -num.round(
                    shift_table[:, istations_selected] /
                    deltat_cf).astype(num.int32)
Sebastian Heimann's avatar
Sebastian Heimann committed
362

Sebastian Heimann's avatar
Sebastian Heimann committed
363
364
365
                weights[bad] = 0.0
                shifts[bad] = num.max(shifts[ok])

366
                pdata.append((list(trs_selected), shift_table, ifc))
Sebastian Heimann's avatar
Sebastian Heimann committed
367

368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
                parstack_params.append((arrays, offsets, shifts, weights))

            if config.stacking_blocksize is not None:
                ipstep = config.stacking_blocksize
                frames = None
            else:
                ipstep = lengthout
                frames = num.zeros((ngridpoints, lengthout))

            twall_start = time.time()
            frame_maxs = num.zeros(lengthout)
            frame_argmaxs = num.zeros(lengthout, dtype=num.int)
            ipmin = iwmin
            while ipmin < iwmin+lengthout:
                ipsize = min(ipstep, iwmin + lengthout - ipmin)
                if ipstep == lengthout:
                    frames_p = frames
                else:
                    frames_p = num.zeros((ngridpoints, ipsize))

                for (arrays, offsets, shifts, weights) in parstack_params:
                    frames_p, _ = parstack(
                        arrays, offsets, shifts, weights, 0,
                        offsetout=ipmin,
                        lengthout=ipsize,
                        result=frames_p,
                        nparallel=nparallel,
                        impl='openmp')

                if config.sharpness_normalization:
                    frame_p_maxs = frames_p.max(axis=0)
                    frame_p_means = num.abs(frames_p).mean(axis=0)
                    frames_p *= (frame_p_maxs / frame_p_means)[num.newaxis, :]
                    frames_p *= norm_map[:, num.newaxis]

                if config.ifc_count_normalization:
                    frames_p *= 1.0 / len(ifcs)

                frame_maxs[ipmin-iwmin:ipmin-iwmin+ipsize] = \
                    frames_p.max(axis=0)
                frame_argmaxs[ipmin-iwmin:ipmin-iwmin+ipsize] = \
                    pargmax(frames_p)

                ipmin += ipstep
                del frames_p

            twall_end = time.time()

            logger.info('wallclock time for stacking: %g s' % (
                twall_end - twall_start))

            tmin_frames = t0 + iwmin * deltat_cf
Sebastian Heimann's avatar
Sebastian Heimann committed
420

421
422
423
424
425
            tr_stackmax = trace.Trace(
                '', 'SMAX', '', '',
                tmin=tmin_frames,
                deltat=deltat_cf,
                ydata=frame_maxs)
Sebastian Heimann's avatar
Sebastian Heimann committed
426

Sebastian Heimann's avatar
Sebastian Heimann committed
427
428
            tr_stackmax.meta = {'tabu': True}

429
            trs_debug.append(tr_stackmax)
Sebastian Heimann's avatar
Sebastian Heimann committed
430

431
432
            if show_window_traces:
                trace.snuffle(trs_debug)
Sebastian Heimann's avatar
Sebastian Heimann committed
433

434
435
            ydata_window = tr_stackmax.chop(
                wmin, wmax, inplace=False).get_ydata()
Sebastian Heimann's avatar
Sebastian Heimann committed
436

437
438
439
440
            logger.info('CF stats: min %g, max %g, median %g' % (
                num.min(ydata_window),
                num.max(ydata_window),
                num.median(ydata_window)))
441

442
            tpeaks, apeaks = list(zip(*[(tpeak, apeak) for (tpeak, apeak) in zip(
443
                *tr_stackmax.peaks(config.detector_threshold, tpeaksearch)) if
444
                wmin <= tpeak and tpeak < wmax])) or ([], [])
445

446
            tr_stackmax_indx = tr_stackmax.copy(data=False)
447
            tr_stackmax_indx.set_ydata(frame_argmaxs.astype(num.int32))
448
449
            tr_stackmax_indx.set_location('i')

450
            for (tpeak, apeak) in zip(tpeaks, apeaks):
Sebastian Heimann's avatar
Sebastian Heimann committed
451

452
453
                iframe = int(round((tpeak - tmin_frames) / deltat_cf))
                imax = frame_argmaxs[iframe]
Sebastian Heimann's avatar
Sebastian Heimann committed
454

455
456
                latpeak, lonpeak, xpeak, ypeak, zpeak = \
                    grid.index_to_location(imax)
Sebastian Heimann's avatar
Sebastian Heimann committed
457

458
                idetection += 1
Sebastian Heimann's avatar
Sebastian Heimann committed
459

460
461
462
463
464
465
466
467
468
469
470
                detection = Detection(
                    id='%06i' % idetection,
                    time=tpeak,
                    location=geo.Point(
                        lat=float(latpeak),
                        lon=float(lonpeak),
                        x=float(xpeak),
                        y=float(ypeak),
                        z=float(zpeak)),
                    ifm=float(apeak))

Sebastian Heimann's avatar
bark    
Sebastian Heimann committed
471
472
473
                if bark:
                    common.bark()

474
475
                logger.info('detection: %s' % str(detection))

Sebastian Heimann's avatar
Sebastian Heimann committed
476
477
478
479
480
481
482
483
                f = open(detections_path, 'a')
                f.write('%06i %s %g %g %g %g %g %g\n' % (
                    idetection,
                    util.time_to_str(
                        tpeak,
                        format='%Y-%m-%d %H:%M:%S.6FRAC'),
                    apeak,
                    latpeak, lonpeak, xpeak, ypeak, zpeak))
Sebastian Heimann's avatar
Sebastian Heimann committed
484

Sebastian Heimann's avatar
Sebastian Heimann committed
485
                f.close()
Sebastian Heimann's avatar
Sebastian Heimann committed
486

Sebastian Heimann's avatar
Sebastian Heimann committed
487
488
489
490
491
492
                ev = detection.get_event()
                f = open(events_path, 'a')
                model.dump_events([ev], stream=f)
                f.close()

                if show_detections or config.save_figures:
493
494
                    fmin = min(ifc.fmin for ifc in ifcs)
                    fmax = min(ifc.fmax for ifc in ifcs)
Sebastian Heimann's avatar
Sebastian Heimann committed
495
496
497
498
499
500
501

                    fn = figures_path_template % {
                        'id': idetection,
                        'format': 'png'}

                    util.ensuredirs(fn)

502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
                    if frames is not None:
                        frames_p = frames
                        tmin_frames_p = tmin_frames
                        iframe_p = iframe

                    else:
                        iframe_min = max(
                            0,
                            int(round(iframe - tpeaksearch/deltat_cf)))
                        iframe_max = min(
                            lengthout-1,
                            int(round(iframe + tpeaksearch/deltat_cf)))

                        ipsize = iframe_max - iframe_min + 1
                        frames_p = num.zeros((ngridpoints, ipsize))
                        tmin_frames_p = tmin_frames + iframe_min*deltat_cf
                        iframe_p = iframe - iframe_min

                        for (arrays, offsets, shifts, weights) \
                                in parstack_params:

                            frames_p, _ = parstack(
                                arrays, offsets, shifts, weights, 0,
                                offsetout=iwmin+iframe_min,
                                lengthout=ipsize,
                                result=frames_p,
                                nparallel=nparallel,
                                impl='openmp')

                        if config.sharpness_normalization:
                            frame_p_maxs = frames_p.max(axis=0)
                            frame_p_means = num.abs(frames_p).mean(axis=0)
                            frames_p *= (
                                frame_p_maxs/frame_p_means)[num.newaxis, :]
                            frames_p *= norm_map[:, num.newaxis]

                        if config.ifc_count_normalization:
                            frames_p *= 1.0 / len(ifcs)

                    plot.plot_detection(
                        grid, receivers, frames_p, tmin_frames_p,
                        deltat_cf, imax, iframe_p, xpeak, ypeak,
                        zpeak,
                        tr_stackmax, tpeaks, apeaks,
                        config.detector_threshold,
                        wmin, wmax,
                        pdata, trs, fmin, fmax, idetection,
                        tpeaksearch,
                        movie=show_movie,
                        show=show_detections,
                        save_filename=fn)

                    del frames_p

556
557
                if stop_after_first:
                    return
558

559
            tr_stackmax.chop(wmin, wmax)
560
            tr_stackmax_indx.chop(wmin, wmax)
561

Sebastian Heimann's avatar
Sebastian Heimann committed
562
            io.save([tr_stackmax, tr_stackmax_indx], ifm_path_template)
563

Sebastian Heimann's avatar
Sebastian Heimann committed
564
            del frames
565
566
567
568
        logger.info('end processing time window group: %s - %s' % (
            util.time_to_str(tmin_win),
            util.time_to_str(tmax_win)))

Sebastian Heimann's avatar
Sebastian Heimann committed
569
570

__all__ = [
Sebastian Heimann's avatar
Sebastian Heimann committed
571
    'search',
Sebastian Heimann's avatar
Sebastian Heimann committed
572
]