def test_lowpassCheby2(self): """ Check magnitudes of basic lowpass cheby2 """ df = 200 # Hz b, a = lowpassCheby2(data=None, freq=50, df=df, maxorder=12, ba=True) nyquist = 200 * 0.5 # calculate frequency response w, h = sg.freqz(b, a, int(nyquist)) freq = w / np.pi * nyquist h_db = 20 * np.log10(abs(h)) # be smaller than -96dB above lowpass frequency self.assertTrue(h_db[freq > 50].max() < -96) # be 0 (1dB ripple) before filter ramp self.assertTrue(h_db[freq < 25].min() > -1)
def test_decimate(self): """ Tests the decimate method of the Trace object. """ # create test Trace tr = Trace(data=np.arange(20)) tr_bkp = deepcopy(tr) # some test that should fail and leave the original trace alone self.assertRaises(ValueError, tr.decimate, 7, strict_length=True) self.assertRaises(ValueError, tr.decimate, 9, strict_length=True) self.assertRaises(ArithmeticError, tr.decimate, 18) # some tests in place tr.decimate(4, no_filter=True) np.testing.assert_array_equal(tr.data, np.arange(0, 20, 4)) self.assertEqual(tr.stats.npts, 5) self.assertEqual(tr.stats.sampling_rate, 0.25) self.assertTrue("decimate" in tr.stats.processing[0]) self.assertTrue("factor=4" in tr.stats.processing[0]) tr = tr_bkp.copy() tr.decimate(10, no_filter=True) np.testing.assert_array_equal(tr.data, np.arange(0, 20, 10)) self.assertEqual(tr.stats.npts, 2) self.assertEqual(tr.stats.sampling_rate, 0.1) self.assertTrue("decimate" in tr.stats.processing[0]) self.assertTrue("factor=10" in tr.stats.processing[0]) # some tests with automatic prefiltering tr = tr_bkp.copy() tr2 = tr_bkp.copy() tr.decimate(4) df = tr2.stats.sampling_rate tr2.data, fp = lowpassCheby2(data=tr2.data, freq=df * 0.5 / 4.0, df=df, maxorder=12, ba=False, freq_passband=True) # check that iteratively determined pass band frequency is correct self.assertAlmostEqual(0.0811378285461, fp, places=7) tr2.decimate(4, no_filter=True) np.testing.assert_array_equal(tr.data, tr2.data)