예제 #1
0
파일: waveform.py 프로젝트: simondaout/bat
def filterWaveform(Config, wafeform, station):

    cfg = FilterCfg(self.Config)
    switch = cfg.filterswitch()  # 'filterswitch'

    if switch == 1:
        which = 'bandpass'
        waveform.filter(
            which,
            freqmin=cfg.flo(),  # ['flo']
            freqmax=cfg.fhi(),  # ['fhi']
            corners=cfg.ns(),  # ['ns']
            zerophase=bool(Config['zph']))
    elif switch == 2:
        which = "lowpass"
        waveform.filter(
            which,
            freq=cfg.l_fc(),  # ['l_fc']
            corners=cfg.l_ns(),  # ['l_ns']
            zerophase=bool(Config['l_zph']))
    elif switch == 3:
        which = 'highpass'
        waveform.filter(
            which,
            freq=cfg.h_fc(),  # ['h_fc']
            corners=cfg.h_ns(),  # ['h_ns']
            zerophase=bool(Config['h_zph']))
    else:
        return None

    Logfile.add('%s filtered stream for station %s ' % (which, i))
    return wafeform
예제 #2
0
    def filterWaveform(self, Waveform):

        Logfile.red('Filter Waveform: ')
        cfg = FilterCfg(self.Config)

        new_frequence = (cfg.newFrequency())

        st = Stream()
        for i in Waveform:
            Logfile.red('Downsampling to %s: from %d' %
                        (new_frequence, i.stats.sampling_rate))
            j = i.resample(new_frequence)
            switch = cfg.filterswitch()

            if switch == 1:
                Logfile.add('bandpass filtered \
                        stream for station %s ' % (i))

                j.filter('bandpass',
                         freqmin=cfg.flo(),
                         freqmax=cfg.fhi(),
                         corners=cfg.ns(),
                         zerophase=bool(self.Config['zph']))

            elif switch == 2:
                Logfile.add('bandpass filtered \
                        stream for station %s ' % (i))

                j.filter('bandpass',
                         freqmin=cfg.flo2(),
                         freqmax=cfg.fhi2(),
                         corners=cfg.ns2(),
                         zerophase=bool(self.Config['zph']))
            st.append(j)

        return st
예제 #3
0
파일: waveform.py 프로젝트: simondaout/bat
def processWaveforms(WaveformDict,
                     Config,
                     Folder,
                     network,
                     MetaDict,
                     Event,
                     Xcorr=None):

    Logfile.red('Start Processing')

    cfg = FilterCfg(Config)
    new_frequence = cfg.newFrequency()  #  ['new_frequence']

    vp, vs, rho = ttt.calcak135parameter(Event)

    for index, i in enumerate(WaveformDict):
        Logfile.add(
            '%s:%s -------------------------------------------------------------'
            % (index, i))

        if Config['export_unfiltered'].capitalize() == 'True':
            writeWaveform(Folder, i, WaveformDict[i], 'U', network)

        # TODO implement gain multiplication
        station = getStation(i, MetaDict)

        psign = 1

        #           print 'MetaDict ',MetaDict,station,station.takeoff
        #needs to be implemented correctly

        if cfg.Int('fm') == 1:
            print 'Event ', Event, Event.strike, Event.dip, Event.rake
            azi = ttt.bearing(Event, station)
            bazi = ttt.backazi(station, Event)
            psign = ttt.dubcup(rho, vp, vs, Event.strike, Event.dip,
                               Event.rake, azi, station.takeoff)

            #print 'Takeoff ',station.takeoff,' Azi ',azi,' Bazi ',bazi,' vp ',vp,' vs ',vs,' rho ',rho,' Psign ',psign
            msg = 'Takeoff ' + str(
                station.takeoff) + ' Azi ' + str(azi) + ' Bazi ' + str(bazi)
            msg += (' vp ' + str(vp) + ' vs ' + str(vs) + ' rho ' + str(rho) +
                    ' Psign ' + str(psign))
            Logfile.add(msg)
        '''
            if int(Config['xcorr']) == 1:
                #print Xcorr[i].value
                if Xcorr[i].value > 0:   psign = 1
                else:                    psign = -1
            '''
        Logfile.add(station.getName() + ' ' + station.lat + ' ' + station.lon +
                    ' ' + station.gain + ' PSIGN: ' + str(psign))

        if psign == -1:
            Logfile.add('correcting polarisation for station %s ' % (i))
            -1. * WaveformDict[i][0].data

        #remove offset
        WaveformDict[i].detrend(type='demean')

        #gain correctur
        gain = float(station.gain)

        if gain == 0.0 or gain == -1.0:
            gain = 1  #hs : gain missing in metafile

        WaveformDict[i][0].data * (1.0 / gain)

        #filtering
        switch = cfg.filterswitch()  # 'filterswitch'

        if switch == 1:
            Logfile.add('bandpass filtered stream for station %s ' % (i))

            WaveformDict[i].filter(
                'bandpass',
                freqmin=cfg.flo(),  # ['flo']
                freqmax=cfg.fhi(),  # ['fhi']
                corners=cfg.ns(),  # ['ns']
                zerophase=bool(Config['zph']))

        elif switch == 2:
            Logfile.add('lowpass filtered stream for station %s ' % (i))

            WaveformDict[i].filter(
                "lowpass",
                freq=cfg.l_fc(),  # ['l_fc']
                corners=cfg.l_ns(),  # ['l_ns']
                zerophase=bool(Config['l_zph']))
        elif switch == 3:
            Logfile.add('highpass filtered stream for station %s ' % (i))

            WaveformDict[i].filter(
                "highpass",
                freq=cfg.h_fc(),  # ['h_fc']
                corners=cfg.h_ns(),  # ['h_ns']
                zerophase=bool(Config['h_zph']))
        else:
            Logfile.add('no filter set for station %s ' % (i))

        if Config['export_filtered'].capitalize() == 'True':
            writeWaveform(Folder, i, WaveformDict[i], 'F', network)

        #resampling
        j = resampleWaveform(WaveformDict[i][0], new_frequence)
        WaveformDict[i] = j
        #Logfile.add (WaveformDict[i])

        if Config['export_resampled'].capitalize() == 'True':
            writeWaveform(Folder, i, WaveformDict[i], 'R', network)
    #endfor

    return WaveformDict
예제 #4
0
    def filterWaveform(self, Waveform):

        Logfile.red('Filter Waveform: ')
        cfg = FilterCfg(self.Config)

        #new_frequence = int (self.Config['new_frequence'])
        new_frequence = int(cfg.newFrequency())
        st = Stream()

        for i in Waveform:
            Logfile.red('Downsampling to %d: from %d' %
                        (new_frequence, i.stats.sampling_rate))

            j = self.resampleWaveform(i, new_frequence)
            j.detrend(type='demean')

            old = True  #???

            if old:
                switch = cfg.filterswitch()  # ['filterswitch']

                if switch == 1:
                    Logfile.add('bandpass filtered stream for station %s ' %
                                (i))

                    j.filter(
                        'bandpass',
                        freqmin=cfg.flo(),  # ['flo']
                        freqmax=cfg.fhi(),  # ['fhi']
                        corners=cfg.ns(),  # ['ns']
                        zerophase=bool(self.Config['zph']))

                elif switch == 2:
                    Logfile.add('lowpass filtered stream for station %s ' %
                                (i))

                    j.filter(
                        "lowpass",
                        freq=cfg.l_fc(),  # ['l_fc']
                        corners=cfg.l_ns(),  # ['l_ns']
                        zerophase=bool(self.Config['l_zph']))

                elif switch == 3:
                    Logfile.add('highpass filtered stream for station %s ' %
                                (i))

                    j.filter(
                        "highpass",
                        freq=cfg.h_fc(),  # ['h_fc']
                        corners=cfg.h_ns(),  # ['h_ns']
                        zerophase=bool(self.Config['h_zph']))
                else:
                    dummy = 1
                    #Logfile.add ('bandpass filtered stream for station %s '% (i))

                    #j.filter ("bandpass", freqmin=0.4, freqmax=3,
                    #           corners=3, zerophase=False)
                st.append(j)

            else:
                j1 = filterWaveform_2(Config, j, i)
                st.append(j1)

        #endfor

        return st