示例#1
0
 def remove_resp(self, trace, paz=None):
     
     # removing response...
     if paz:
         # ...using paz:
         if trace.stats.sampling_rate > 10.0:
             # decimating large trace, else fft crashes
             factor = int(np.ceil(trace.stats.sampling_rate / 10))
             trace.decimate(factor=factor, no_filter=True)
         trace.simulate(paz_remove=paz,
                        paz_simulate=obspy.signal.cornFreq2Paz(0.01),
                        remove_sensitivity=True,
                        simulate_sensitivity=True,
                        nfft_pow2=True)
     else:
         # ...using StationXML:
         # first band-pass to downsample data before removing response
         # (else remove_response() method is slow or even hangs)
         trace.filter(type="bandpass",
                      freqmin=self.freqmin,
                      freqmax=self.freqmax,
                      corners=self.corners,
                      zerophase=self.zerophase)
         psutils.resample(trace, dt_resample=self.period_resample)
         trace.remove_response(output="VEL", zero_mean=True)
     return trace
示例#2
0
    def time_norm(self, trace, trcopy):
        # normalization of the signal by the running mean
        # in the earthquake frequency band
        trcopy.filter(type="bandpass",
                      freqmin=self.freqmin_earthquake,
                      freqmax=self.freqmax_earthquake,
                      corners=self.corners,
                      zerophase=self.zerophase)
        # decimating trace
        psutils.resample(trcopy, self.period_resample)

        # Time-normalization weights from smoothed abs(data)
        # Note that trace's data can be a masked array
        halfwindow = int(round(self.window_time*trcopy.stats.sampling_rate/2))
        mask = ~trcopy.data.mask if np.ma.isMA(trcopy.data) else None
        tnorm_w = psutils.moving_avg(np.abs(trcopy.data),
                                     halfwindow=halfwindow,
                                     mask=mask)
        if np.ma.isMA(trcopy.data):
            # turning time-normalization weights into a masked array
            s = "[warning: {}.{} trace's data is a masked array]"
            print s.format(trace.stats.network, trace.stats.station),
            tnorm_w = np.ma.masked_array(tnorm_w, trcopy.data.mask)

        if np.any((tnorm_w == 0.0) | np.isnan(tnorm_w)):
            # illegal normalizing value -> skipping trace
            raise pserrors.CannotPreprocess("Zero or NaN normalisation \
                                            weight")

        # time-normalization
        trace.data /= tnorm_w
        
        return trace
示例#3
0
    def trace_downsample(self, trace):

        # downsampling trace if not already done
        if abs(1.0 / trace.stats.sampling_rate - self.period_resample) > EPS:
            psutils.resample(trace, dt_resample=self.period_resample)
            
        return trace
示例#4
0
    def remove_resp(self, trace, paz=None):

        # removing response...
        if paz:
            # ...using paz:
            if trace.stats.sampling_rate > 10.0:
                # decimating large trace, else fft crashes
                factor = int(np.ceil(trace.stats.sampling_rate / 10))
                trace.decimate(factor=factor, no_filter=True)
            trace.simulate(paz_remove=paz,
                           paz_simulate=obspy.signal.cornFreq2Paz(0.01),
                           remove_sensitivity=True,
                           simulate_sensitivity=True,
                           nfft_pow2=True)
        else:
            # ...using StationXML:
            # first band-pass to downsample data before removing response
            # (else remove_response() method is slow or even hangs)
            trace.filter(type="bandpass",
                         freqmin=self.freqmin,
                         freqmax=self.freqmax,
                         corners=self.corners,
                         zerophase=self.zerophase)
            psutils.resample(trace, dt_resample=self.period_resample)
            trace.remove_response(output="VEL", zero_mean=True)
        return trace
示例#5
0
    def time_norm(self, trace, trcopy):
        # normalization of the signal by the running mean
        # in the earthquake frequency band
        trcopy.filter(type="bandpass",
                      freqmin=self.freqmin_earthquake,
                      freqmax=self.freqmax_earthquake,
                      corners=self.corners,
                      zerophase=self.zerophase)
        # decimating trace
        psutils.resample(trcopy, self.period_resample)

        # Time-normalization weights from smoothed abs(data)
        # Note that trace's data can be a masked array
        halfwindow = int(
            round(self.window_time * trcopy.stats.sampling_rate / 2))
        mask = ~trcopy.data.mask if np.ma.isMA(trcopy.data) else None
        tnorm_w = psutils.moving_avg(np.abs(trcopy.data),
                                     halfwindow=halfwindow,
                                     mask=mask)
        if np.ma.isMA(trcopy.data):
            # turning time-normalization weights into a masked array
            s = "[warning: {}.{} trace's data is a masked array]"
            print s.format(trace.stats.network, trace.stats.station),
            tnorm_w = np.ma.masked_array(tnorm_w, trcopy.data.mask)

        if np.any((tnorm_w == 0.0) | np.isnan(tnorm_w)):
            # illegal normalizing value -> skipping trace
            raise pserrors.CannotPreprocess("Zero or NaN normalisation \
                                            weight")

        # time-normalization
        trace.data /= tnorm_w

        return trace
示例#6
0
    def trace_downsample(self, trace):

        # downsampling trace if not already done
        if abs(1.0 / trace.stats.sampling_rate - self.period_resample) > EPS:
            psutils.resample(trace, dt_resample=self.period_resample)

        return trace