def test_masked_trace(self): """Test that processing a masked array works.""" st = self.st gap_starttime = st[0].stats.starttime + 1800 gap_endtime = st[0].stats.starttime + 1900 tr1 = st[0].copy().trim(st[0].stats.starttime, gap_starttime) tr2 = st[0].copy().trim(gap_endtime, st[0].stats.starttime + 3600) tr = tr1 + tr2 print(tr) processed = process(tr=tr, lowcut=0.1, highcut=0.4, filt_order=3, samp_rate=1, debug=0, starttime=False, clip=False, length=3600, seisan_chan_names=True, ignore_length=False) self.assertEqual(processed.stats.npts, 3601) self.assertFalse(isinstance(processed.data, np.ma.MaskedArray)) self.assertTrue(np.all( processed.trim(gap_starttime, gap_endtime).data) == 0) processed = process(tr=tr, lowcut=0.1, highcut=0.4, filt_order=3, samp_rate=1, debug=0, starttime=False, clip=False, length=3600, seisan_chan_names=True, ignore_length=False, fill_gaps=False) self.assertEqual(processed.stats.npts, 3601) self.assertTrue(isinstance(processed.data, np.ma.MaskedArray)) processed = process(tr=tr, lowcut=0.1, highcut=0.2, filt_order=3, samp_rate=0.5, debug=0, starttime=False, clip=False, length=3600, seisan_chan_names=True, ignore_length=False) self.assertEqual(processed.stats.npts, 1800) self.assertTrue(np.all( processed.trim(gap_starttime, gap_endtime).data) == 0)
def test_process_nyquist_fail(self): """Test a nyquist error is raised.""" with self.assertRaises(IOError): process(tr=self.st[0].copy(), lowcut=0.1, highcut=0.6, filt_order=3, samp_rate=1, debug=0, starttime=False, clip=False, length=86400, seisan_chan_names=True, ignore_length=False)
def test_short_data_fail(self): """Check that we don't allow too much missing data.""" with self.assertRaises(NotImplementedError): process(tr=self.st[0].copy(). trim(endtime=self.st[0].stats.endtime - 18000), lowcut=0.1, highcut=0.4, filt_order=3, samp_rate=1, debug=0, starttime=self.day_start, clip=True, length=86400, seisan_chan_names=True, ignore_length=False)
def test_process_bad_data(self): """Check that we won't allow data that are mostly zeros.""" not_daylong = self.st[0].copy().trim(self.st[0].stats.starttime, self.st[0].stats.starttime + 3600) not_daylong.data = np.append( not_daylong.data, np.zeros( 3602 * int(self.st[0].stats.sampling_rate))) with self.assertRaises(ValueError): process(tr=not_daylong, lowcut=0.1, highcut=0.4, filt_order=3, samp_rate=1, debug=0, starttime=False, clip=False, length=86400, seisan_chan_names=True, ignore_length=False)
def _internal_process(st, lowcut, highcut, filt_order, sampling_rate, first_length, stachan, i=0): tr = st.select(station=stachan[0], channel=stachan[1]) if len(tr) == 0: tr = Trace(np.zeros(int(first_length * sampling_rate))) tr.stats.station = stachan[0] tr.stats.channel = stachan[1] tr.stats.sampling_rate = sampling_rate tr.stats.starttime = st[0].stats.starttime # Do this to make more # sensible plots Logger.warning('Padding stream with zero trace for ' + 'station ' + stachan[0] + '.' + stachan[1]) elif len(tr) == 1: tr = tr[0] tr.detrend('simple') tr = pre_processing.process(tr=tr, lowcut=lowcut, highcut=highcut, filt_order=filt_order, samp_rate=sampling_rate, seisan_chan_names=False) else: raise IOError('Multiple channels for {0}.{1} in a single design ' 'stream.'.format(stachan[0], stachan[1])) return i, tr
def test_lowcut_debug(self): """Test a basic process implementation with just a highcut""" processed = process(tr=self.st[0].copy(), lowcut=0.1, highcut=None, filt_order=3, samp_rate=1, debug=2, starttime=False, clip=False, length=86400, seisan_chan_names=True, ignore_length=False) self.assertEqual(processed.stats.npts, 86400)
def test_process_datetime(self): """Test a basic process implementation.""" processed = process(tr=self.st[0].copy(), lowcut=0.1, highcut=0.4, filt_order=3, samp_rate=1, debug=0, starttime=self.day_start, clip=False, length=86400, seisan_chan_names=True, ignore_length=False) self.assertEqual(processed.stats.npts, 86400)
def test_process_with_debug(self): """Test the debug option of 2 for process.""" processed = process(tr=self.st[0].copy(), lowcut=0.1, highcut=0.4, filt_order=3, samp_rate=1, debug=2, starttime=False, clip=False, length=86400, seisan_chan_names=True, ignore_length=False) self.assertEqual(processed.stats.npts, 86400)
def test_short_data_pass(self): """Check that we do allow missing data if ignore_length is True.""" processed = process( tr=self.st[0].copy().trim(endtime=self. st[0].stats.endtime - 18000), lowcut=0.1, highcut=0.4, filt_order=3, samp_rate=1, debug=0, starttime=self.day_start, clip=True, length=86400, seisan_chan_names=True, ignore_length=True) self.assertEqual(processed.stats.npts, 86400)
def test_masked_array_resample(self): """Test that processing and resampling a masked array works.""" tr = self.gappy_trace processed = process(tr=tr, lowcut=0.1, highcut=0.2, filt_order=3, samp_rate=0.5, debug=0, starttime=False, clip=False, length=3600, seisan_chan_names=True, ignore_length=False) self.assertEqual(processed.stats.npts, 1800) self.assertTrue(np.all( processed.trim(self.gap_starttime, self.gap_endtime).data) == 0)
def test_masked_trace_no_fill(self): """Test that processing a masked array without filling gaps works.""" tr = self.gappy_trace processed = process(tr=tr, lowcut=0.1, highcut=0.4, filt_order=3, samp_rate=1, debug=0, starttime=False, clip=False, length=3600, seisan_chan_names=True, ignore_length=False, fill_gaps=False) self.assertEqual(processed.stats.npts, 3601) self.assertTrue(isinstance(processed.data, np.ma.MaskedArray))
def test_gap_overlength(self): """ Test that gappy data that are too long are processed correctly.""" tr_after = self.gappy_trace.copy() tr_after.stats.starttime += 3600 tr_before = self.gappy_trace.copy() tr_before.stats.starttime -= 3600 tr = tr_before + self.gappy_trace + tr_after processed = process( tr=tr, lowcut=0.1, highcut=0.4, filt_order=3, samp_rate=1, debug=0, starttime=self.gappy_trace.stats.starttime, clip=True, length=3600, seisan_chan_names=True, ignore_length=False) self.assertEqual(processed.stats.npts, 3600) self.assertFalse(isinstance(processed.data, np.ma.MaskedArray)) self.assertTrue(np.all( processed.trim(self.gap_starttime, self.gap_endtime).data) == 0)
def test_masked_trace(self): """Test that processing a masked array works.""" tr = self.gappy_trace processed = process(tr=tr, lowcut=0.1, highcut=0.4, filt_order=3, samp_rate=1, starttime=False, clip=False, length=3600, seisan_chan_names=True, ignore_length=False) self.assertEqual(processed.stats.npts, 3601) self.assertFalse(isinstance(processed.data, np.ma.MaskedArray)) self.assertTrue( np.all(processed.trim(self.gap_starttime, self.gap_endtime).data) == 0)