コード例 #1
0
ファイル: stalta.py プロジェクト: megies/pyrocko
    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)
コード例 #2
0
ファイル: gui_util.py プロジェクト: valeryTech/pyrocko
    def draw_trace(self, viewer, p, trace, time_projection, track_projection, gain, outline_label=False):
        if self.nslc_ids and not self.match_nslc(trace.nslc_id): return
        
        color = self.select_color(self.color_b)
        pen = QPen(QColor(*color))
        pen.setWidth(2)
        p.setPen(pen)
        p.setBrush(Qt.NoBrush)
        def drawpoint(t,y):
            u = time_projection(t)
            v = track_projection(y)
            rect = QRectF(u-2,v-2,4,4)
            p.drawRect(rect)
            
        def drawline(t):
            u = time_projection(t)
            v0, v1 = track_projection.get_out_range()
            line = QLineF(u,v0,u,v1)
            p.drawLine(line)

        try:
            snippet = trace.chop(self.tmin, self.tmax, inplace=False, include_last=True, snap=(math.ceil,math.floor))
            
            vdata = track_projection( gain*snippet.get_ydata() )
            udata_min = float(time_projection(snippet.tmin))
            udata_max = float(time_projection(snippet.tmin+snippet.deltat*(vdata.size-1)))
            udata = num.linspace(udata_min, udata_max, vdata.size)
            qpoints = make_QPolygonF( udata, vdata )
            pen.setWidth(1)
            p.setPen(pen)
            p.drawPolyline( qpoints )
            pen.setWidth(2)
            p.setPen(pen)
            drawpoint(*trace(self.tmin, clip=True, snap=math.ceil))
            drawpoint(*trace(self.tmax, clip=True, snap=math.floor))
            
        except pyrocko.trace.NoData:
            pass
            
        color = self.select_color(self.color_b)
        pen = QPen(QColor(*color))
        pen.setWidth(2)
        p.setPen(pen)

        drawline(self.tmin)
        drawline(self.tmax)

        label = self.get_label()
        if label:
            label_bg = QBrush( QColor(255,255,255) )
            
            u = time_projection(self.tmin)
            v0, v1 = track_projection.get_out_range()
            if outline_label:
                du = -7
            else:
                du = -5
            draw_label( p, u+du, v0, label, label_bg, 'TR', outline=outline_label)

        if self.tmin == self.tmax:
            try: drawpoint(self.tmin, trace.interpolate(self.tmin))
            except IndexError: pass