def chopper_selected_traces(self, fallback=False, marker_selector=None, *args, **kwargs ): '''Iterate over selected traces. This is a shortcut to get all trace data contained in the selected markers in the running snuffler. For each selected marker, :py:meth:`pyrocko.pile.Pile.chopper` is called with the arguments *tmin*, *tmax*, and *trace_selector* set to values according to the marker. Additional arguments to the chopper are handed over from *\*args* and *\*\*kwargs*. :param fallback: if ``True``, if no selection has been marked, use the content currently visible in the viewer. :param marker_selector: if not ``None`` a callback to filter markers. ''' try: viewer = self.get_viewer() markers = viewer.selected_markers() if marker_selector is not None: markers = [ marker for marker in markers if marker_selector(marker) ] pile = self.get_pile() if markers: for marker in markers: if not marker.nslc_ids: trace_selector = None else: trace_selector = lambda tr: marker.match_nslc(tr.nslc_id) for traces in pile.chopper( tmin = marker.tmin, tmax = marker.tmax, trace_selector = trace_selector, *args, **kwargs): yield traces elif fallback: if 'trace_selector' not in kwargs: kwargs['trace_selector'] = viewer.trace_selector tmin, tmax = viewer.get_time_range() for traces in pile.chopper( tmin = tmin, tmax = tmax, *args, **kwargs): yield traces else: raise NoTracesSelected() except NoViewerSet: pile = self.get_pile() for traces in pile.chopper(*args, **kwargs): yield traces
def iter_prepare(self, pile, event, stations): stations_by_nsl = dict((get_nsl(s), s) for s in stations) nsl_avail = pile.gather_keys(gather=get_nsl) for nsl in nsl_avail: station = stations_by_nsl[nsl] tmin = self.get_tmin(event, station) tmax = self.get_tmax(event, station) tpad = self.get_tpad(event, station) for traces in pile.chopper( tmin=tmin, tmax=tmax, tpad=tpad, trace_selector=lambda tr: get_nsl(tr) == nsl, want_incomplete=False): if not traces: continue station = stations_by_nsl[nsl] prepared_traces = self.prepare_station_traces( traces, event, station) yield prepared_traces
def call(self): '''Main work routine of the snuffling.''' self.cleanup() swin, ratio = self.swin, self.ratio lwin = swin * ratio tpad = lwin/2. pile = self.get_pile() tmin, tmax = pile.get_tmin() + tpad, pile.get_tmax() - tpad if not self.apply_to_all: vtmin, vtmax = self.get_viewer().get_time_range() tmin = max(vtmin, tmin) tmax = min(vtmax, tmax) tinc = min(lwin * self.block_factor, tmax-tmin) show_level_traces = self.show_level_traces # if show_level_traces and tmax-tmin > lwin * 150: # self.error('Processing time window is longer than 50 x LTA window. Turning off display of level traces.') # show_level_traces = False markers = [] for traces in pile.chopper(tmin=tmin, tmax=tmax, tinc=tinc, tpad=tpad, want_incomplete=False): sumtrace = None isum = 0 for trace in traces: if self.lowpass is not None: trace.lowpass(4, self.lowpass, nyquist_exception=True) if self.highpass is not None: trace.highpass(4, self.highpass, nyquist_exception=True) trace.sta_lta_centered(swin, lwin, scalingmethod=scalingmethod_map[self.scalingmethod]) trace.chop(trace.wmin, min(trace.wmax,tmax)) trace.set_codes(location='cg') trace.meta = { 'tabu': True } #print trace.ydata.max() if sumtrace is None: sumtrace = trace.copy() sumtrace.set_codes(network='', station='SUM', location='cg', channel='') else: sumtrace.add(trace) isum += 1 if show_level_traces: self.add_traces(traces) if sumtrace is not None: tpeaks, apeaks = sumtrace.peaks(self.level*isum, swin) for t, a in zip(tpeaks, apeaks): mark = Marker([ ], t, t) print mark, a #'%s.%s.%s.%s' % ('', trace.station, '', trace.channel) markers.append(mark) if show_level_traces: self.add_trace(sumtrace) self.add_markers(markers)