def test_nan(self): """ Ensure NaNs eval equal if equal_nan is used, else they do not. """ tr1, tr2 = read()[0], read()[0] tr1.data[0], tr2.data[0] = np.NaN, np.NaN assert traces_almost_equal(tr1, tr2, equal_nan=True) assert not traces_almost_equal(tr1, tr2, equal_nan=False)
def test_not_a_trace(self): """ Ensure comparing to someething that is not a trace returns False. """ tr1 = read()[0] assert not traces_almost_equal(tr1, 1) assert not traces_almost_equal(tr1, None) assert not traces_almost_equal(tr1, 'not a trace')
def test_different_stats_no_processing(self): """ If only the stats are different traces should not be considered almost equal. """ tr1 = Trace(header=dict(network='UU', station='TMU', channel='HHZ')) tr2 = Trace(header=dict(network='UU', station='TMU', channel='HHN')) assert not traces_almost_equal(tr1, tr2) assert not traces_almost_equal(tr2, tr1)
def test_identical_traces(self): """ Should return True on identical streams but false if a value is greatly changed. """ tr1, tr2 = read()[0], read()[0] assert traces_almost_equal(tr1, tr2) # when one number is changed significantly it should return False tr1.data[0] = (tr1.data[0] + 1) * 1000 assert not traces_almost_equal(tr1, tr2)
def test_processing(self): """ Differences in processing attr of stats should only count if processing is True. """ tr1, tr2 = read()[0], read()[0] # Detrend each traces once, then second trace twice for two entries # in processing. tr1.detrend() tr2.detrend() tr1.detrend() assert traces_almost_equal(tr1, tr2, default_stats=True) assert not traces_almost_equal(tr1, tr2, default_stats=False)
def test_unequal_trace_lengths(self): """ Ensure traces with different lengths are not almost equal. """ tr1, tr2 = read()[0], read()[0] tr2.data = tr2.data[:-1] assert not traces_almost_equal(tr1, tr2)
def test_evalresp_file_like_object(self): """ Test evalresp with file like object """ rawf = os.path.join(self.path, 'CRLZ.HHZ.10.NZ.SAC') respf = os.path.join(self.path, 'RESP.NZ.CRLZ.10.HHZ') tr1 = read(rawf)[0] tr2 = read(rawf)[0] date = UTCDateTime(2003, 11, 1, 0, 0, 0) seedresp = { 'filename': respf, 'date': date, 'units': 'VEL', 'network': 'NZ', 'station': 'CRLZ', 'location': '10', 'channel': 'HHZ' } tr1.data = simulate_seismometer(tr1.data, tr1.stats.sampling_rate, seedresp=seedresp) with open(respf, 'rb') as fh: stringio = io.BytesIO(fh.read()) seedresp['filename'] = stringio tr2.data = simulate_seismometer(tr2.data, tr2.stats.sampling_rate, seedresp=seedresp) self.assertTrue(traces_almost_equal(tr1, tr2))
def test_slightly_modified_data(self): """ Traces that are "close" should be considered almost equal. """ tr1, tr2 = read()[0], read()[0] # alter one trace's data slightly tr1.data *= (1. + 1e-6) assert traces_almost_equal(tr1, tr2)
def test_empty_traces(self): """ Empty traces should be considered almost equal. """ tr1, tr2 = Trace(), Trace() assert traces_almost_equal(tr1, tr2)