def test_dump_load(self): r = trace.FrequencyResponse() r = trace.PoleZeroResponse([0j, 0j], [1j, 2j, 1 + 3j, 1 - 3j], 1.0) r.regularize() r2 = guts.load_string(r.dump()) assert cnumeq(r.poles, r2.poles, 1e-6) assert cnumeq(r.zeros, r2.zeros, 1e-6) assert numeq(r.constant, r2.constant) r = trace.SampledResponse([0., 1., 5., 10.], [0., 1., 1., 0.]) r.regularize() r2 = guts.load_string(r.dump()) assert numeq(r.frequencies, r2.frequencies, 1e-6) assert cnumeq(r.values, r2.values, 1e-6) r = trace.IntegrationResponse(2, 5.0) r2 = guts.load_string(r.dump()) assert numeq(r.n, r2.n) assert numeq(r.gain, r2.gain, 1e-6) r = trace.DifferentiationResponse(2, 5.0) r2 = guts.load_string(r.dump()) assert numeq(r.n, r2.n) assert numeq(r.gain, r2.gain, 1e-6) r = trace.AnalogFilterResponse(a=[1.0, 2.0, 3.0], b=[2.0, 3.0]) r2 = guts.load_string(r.dump()) assert numeq(r.a, r2.a, 1e-6) assert numeq(r.b, r2.b, 1e-6)
def testMisfitOfSameTracesZero(self): y = num.random.random(10000) y -= max(y) * 0.5 t1 = trace.Trace(tmin=0, ydata=y, deltat=0.01) t2 = trace.Trace(tmin=0, ydata=y, deltat=0.01) # ttraces = [t2] fresponse = trace.FrequencyResponse() taper = trace.CosFader(xfade=2.) norms = [1, 2] domains = ['time_domain', 'frequency_domain', 'envelope', 'absolute'] setups = [ trace.MisfitSetup(norm=n, taper=taper, domain=domain, filter=fresponse) for domain in domains for n in norms ] for setup in setups: m, n, tr, tc = t1.misfit(candidate=t2, setup=setup, debug=True) if isinstance(tr, trace.Trace): self.assertEqual(tr.tmin, tc.tmin) self.assertTrue(all(tr.get_ydata() == tc.get_ydata())) else: self.assertTrue(all(tc == tr)) self.assertEqual(m, 0., 'misfit\'s m of equal traces is != 0')
def testMisfitOfSameTracesDtDifferentShifted(self): """ Tests: Different length Different delta t Shifted L2-Norm L1-Norm time- and frequency-domain """ test_file = os.path.join(os.path.dirname(__file__), '../examples/1989.072.evt.mseed') p = pile.make_pile(test_file, show_progress=False) rt = p.all()[0] tt = rt.copy() # make downsampled, chopped copies: deltats = [0.5, 1.0, 2.0] tt.chop(tmin=rt.tmin + 10, tmax=rt.tmax - 15) tts = [tt.copy() for i in range(len(deltats))] [t.downsample_to(deltats[i]) for i, t in enumerate(tts)] # shift traces: t_shifts = [1.0, 0.49999, 0.5] for ts in t_shifts: tts_shifted = [t.copy() for t in tts] map(lambda x: x.shift(ts), tts_shifted) tts.extend(tts_shifted) a = rt.tmin d = rt.tmax b = a + (d - a) / 10 c = d - (d - a) / 10 taper = trace.CosTaper(a, b, c, d) fresponse = trace.FrequencyResponse() norms = [1, 2] domains = ['time_domain', 'frequency_domain', 'envelope', 'absolute'] setups = [ trace.MisfitSetup(norm=n, taper=taper, domain=domain, filter=fresponse) for domain in domains for n in norms ] for cand in tts: for setup in setups: m, n = rt.misfit(candidate=cand, setup=setup) self.assertNotEqual(m, None, 'misfit\'s m is None')