def test_gaussian_filter(self):
        from am_signal import gaussian_filter
        from obspy.signal.freqattributes import cfrequency
        import matplotlib.pyplot as plt

        dt = 0.01
        width = 1.0

        gauss1, t1 = gaussian_filter(width, 1.0, dt)
        gauss5, t5 = gaussian_filter(width, 5.0, dt)

        npts1 = len(gauss1)
        npts5 = len(gauss5)
        self.assertEquals(npts1, npts5)
        self.assertAlmostEquals(t1, t5)

        self.assertAlmostEquals(np.argmax(gauss1), t1 / dt)
        self.assertAlmostEquals(np.argmax(gauss5), t5 / dt)

        data_trace5 = self.data_trace.copy()
        data_trace5.data = np.real(
            np.convolve(data_trace5.data, gauss5, 'same'))

        cf5 = cfrequency(data_trace5.data, 1 / dt, 0, 0)
        self.assertAlmostEquals(cf5, 5.0, 0)
    def test_bp_filterbank(self):
        from obspy.signal.freqattributes import cfrequency

        st = Stream()
        fst = Stream()
        data_trace = self.data_trace.copy()
        dt = data_trace.stats.delta
        data_trace.data = np.zeros(400)
        data_trace.data[200] = 1 * 2 * np.pi
        freqmin = 1.0
        freqmax = 4.0
        freq_step = (freqmax - freqmin) / 2.0
        n_bank = 5
        for i in xrange(n_bank):
            dtrace = data_trace.copy()
            fr_min = freqmin + i * freq_step
            fr_max = freqmax + i * freq_step
            dtrace.filter('bandpass',
                          freqmin=fr_min,
                          freqmax=fr_max,
                          zerophase=True)
            st.append(dtrace)
            ftrace = self.data_trace.copy()
            ftrace.data = np.real(np.convolve(ftrace.data, dtrace.data,
                                              'same'))
            cf = cfrequency(ftrace.data, 1 / dt, 0, 0)
            self.assertTrue(cf > fr_min and cf < fr_max)
 def test_cfrequency(self):
     """
     """
     cfreq = freqattributes.cfrequency(self.data_win_bc, self.fs,
                                       self.smoothie, self.fk)
     rms = np.sqrt(np.sum((cfreq[0] - self.res[:, 18]) ** 2) /
                   np.sum(self.res[:, 18] ** 2))
     self.assertEqual(rms < 1.0e-5, True)
     rms = np.sqrt(np.sum((cfreq[1] - self.res[:, 19]) ** 2) /
                   np.sum(self.res[:, 19] ** 2))
     self.assertEqual(rms < 1.0e-5, True)
 def test_cfrequency(self):
     """
     """
     cfreq = freqattributes.cfrequency(self.data_win_bc, self.fs,
                                       self.smoothie, self.fk)
     rms = np.sqrt(
         np.sum(
             (cfreq[0] - self.res[:, 18])**2) / np.sum(self.res[:, 18]**2))
     self.assertEqual(rms < 1.0e-5, True)
     rms = np.sqrt(
         np.sum(
             (cfreq[1] - self.res[:, 19])**2) / np.sum(self.res[:, 19]**2))
     self.assertEqual(rms < 1.0e-5, True)
Exemple #5
0
    def test_bp_filterbank(self):
        from obspy.signal.freqattributes import cfrequency

        st=Stream()
        fst=Stream()
        data_trace=self.data_trace.copy()
        dt=data_trace.stats.delta
        data_trace.data=np.zeros(400)
        data_trace.data[200]=1*2*np.pi
        freqmin=1.0
        freqmax=4.0
        freq_step=(freqmax-freqmin)/2.0
        n_bank=5
        for i in xrange(n_bank):
            dtrace=data_trace.copy()
            fr_min=freqmin+i*freq_step
            fr_max=freqmax+i*freq_step
            dtrace.filter('bandpass',freqmin=fr_min, freqmax=fr_max, zerophase=True)
            st.append(dtrace)
            ftrace=self.data_trace.copy()
            ftrace.data=np.real(np.convolve(ftrace.data,dtrace.data,'same'))
            cf=cfrequency(ftrace.data,1/dt,0,0)
            self.assertTrue(cf > fr_min and cf < fr_max)
Exemple #6
0
    def test_gaussian_filter(self):
        from am_signal import gaussian_filter
        from obspy.signal.freqattributes import cfrequency
        import matplotlib.pyplot as plt

        dt=0.01
        width=1.0

        gauss1, t1=gaussian_filter(width, 1.0, dt)
        gauss5, t5=gaussian_filter(width, 5.0, dt)

        npts1=len(gauss1)
        npts5=len(gauss5)
        self.assertEquals(npts1,npts5)
        self.assertAlmostEquals(t1,t5)

        self.assertAlmostEquals(np.argmax(gauss1),t1/dt)
        self.assertAlmostEquals(np.argmax(gauss5),t5/dt)

        data_trace5=self.data_trace.copy()
        data_trace5.data=np.real(np.convolve(data_trace5.data,gauss5,'same'))

        cf5=cfrequency(data_trace5.data,1/dt,0,0)
        self.assertAlmostEquals(cf5,5.0,0)
 def test_cfrequency_no_win(self):
     cfreq = freqattributes.cfrequency(self.data_win_bc[0], self.fs,
                                       self.smoothie, self.fk)
     rms = (cfreq - self.res[0, 18]) / self.res[0, 18]
     self.assertTrue(rms < 1.0e-5)
 def test_cfrequency_no_win(self):
     cfreq = freqattributes.cfrequency(self.data_win_bc[0], self.fs,
                                       self.smoothie, self.fk)
     rms = (cfreq - self.res[0, 18]) / self.res[0, 18]
     self.assertTrue(rms < 1.0e-5)