def test_in_place(self): self.sr = 10 # sampling rate st = AttribDict({'sampling_rate': self.sr}) testtro = Trace(np.ones(1000), header=st) testtr = testtro.copy() self.assertEqual(testtr, testtro) pu.cos_taper(testtr, 5, False) self.assertNotEqual(testtr, testtro)
def setUp(self): self.sr = 10 # sampling rate st = AttribDict({'sampling_rate': self.sr}) self.testtr = Trace(np.ones(1000), header=st) tl = np.random.randint(1, high=20) self.tls = tl * self.sr # taper len in samples self.tr_res = pu.cos_taper(self.testtr.copy(), tl, False) self.tr_resl = pu.cos_taper(self.testtr.copy(), tl, False, side='left') self.tr_resr = pu.cos_taper(self.testtr.copy(), tl, False, side='right')
def test_masked_value(self): tr0 = read()[0] tr1 = tr0.copy() tr1.stats.starttime += 240 st = Stream([tr0, tr1]) tr = st.merge()[0] tl = np.random.randint(1, high=5) ttr = pu.cos_taper(tr, tl, True) # Check that ends reduce to 0 self.assertAlmostEqual(ttr.data[0], 0) self.assertAlmostEqual(ttr.data[-1], 0) self.assertAlmostEqual(ttr.data[tr0.count() - 1], 0) self.assertAlmostEqual(ttr.data[-tr1.count()], 0) # Also the mask should be retained self.assertEqual(len(ttr.data[ttr.data.mask]), ttr.count() - tr0.count() - tr1.count())
def test_invalid_taper_len(self): with self.assertRaises(ValueError): pu.cos_taper(self.testtr.copy(), np.random.randint(-100, 0), False) with self.assertRaises(ValueError): pu.cos_taper(self.testtr.copy(), 501 * self.sr, False)
def test_empty_trace(self): testtr = Trace(np.array([]), header=self.testtr.stats) with self.assertRaises(ValueError): pu.cos_taper(testtr, 10, False)