예제 #1
0
 def test_sacpaz_from_resp(self):
     # The following two files were both extracted from a dataless
     # seed file using rdseed
     respfile = os.path.join(os.path.dirname(__file__),
                             'data', 'RESP.NZ.CRLZ.10.HHZ')
     sacpzfile = os.path.join(os.path.dirname(__file__),
                              'data', 'SAC_PZs_NZ_CRLZ_HHZ')
     # This is a rather lengthy test, in which the
     # poles, zeros and the gain of each instrument response file
     # are converted into the corresponding velocity frequency response
     # function which have to be sufficiently close. Possibly due to
     # different truncations in the RESP-formatted and SAC-formatted
     # response files the frequency response functions are not identical.
     tr1 = Trace()
     tr2 = Trace()
     attach_resp(tr1, respfile, torad=True, todisp=False)
     attach_paz(tr2, sacpzfile, torad=False, tovel=True)
     p1 = tr1.stats.paz.poles
     z1 = tr1.stats.paz.zeros
     g1 = tr1.stats.paz.gain
     t_samp = 0.01
     n = 32768
     fy = 1 / (t_samp * 2.0)
     # start at zero to get zero for offset/ DC of fft
     f = np.arange(0, fy + fy / n, fy / n)  # arange should includes fy
     w = f * 2 * np.pi
     s = 1j * w
     a1 = np.poly(p1)
     b1 = g1 * np.poly(z1)
     h1 = np.polyval(b1, s) / np.polyval(a1, s)
     h1 = np.conj(h1)
     h1[-1] = h1[-1].real + 0.0j
     p2 = tr2.stats.paz.poles
     z2 = tr2.stats.paz.zeros
     g2 = tr2.stats.paz.gain
     a2 = np.poly(p2)
     b2 = g2 * np.poly(z2)
     h2 = np.polyval(b2, s) / np.polyval(a2, s)
     h2 = np.conj(h2)
     h2[-1] = h2[-1].real + 0.0j
     amp1 = abs(h1)
     amp2 = abs(h2)
     phase1 = np.unwrap(np.arctan2(-h1.imag, h1.real))
     phase2 = np.unwrap(np.arctan2(-h2.imag, h2.real))
     np.testing.assert_almost_equal(phase1, phase2, decimal=4)
     rms = np.sqrt(np.sum((amp1 - amp2) ** 2) /
                   np.sum(amp2 ** 2))
     self.assertTrue(rms < 2.02e-06)
     self.assertTrue(tr1.stats.paz.t_shift, 0.4022344)
예제 #2
0
 def test_sacpaz_from_resp(self):
     # The following two files were both extracted from a dataless
     # seed file using rdseed
     respfile = os.path.join(os.path.dirname(__file__),
                             'data', 'RESP.NZ.CRLZ.10.HHZ')
     sacpzfile = os.path.join(os.path.dirname(__file__),
                              'data', 'SAC_PZs_NZ_CRLZ_HHZ')
     # This is a rather lengthy test, in which the
     # poles, zeros and the gain of each instrument response file
     # are converted into the corresponding velocity frequency response
     # function which have to be sufficiently close. Possibly due to
     # different truncations in the RESP-formatted and SAC-formatted
     # response files the frequency response functions are not identical.
     tr1 = Trace()
     tr2 = Trace()
     attach_resp(tr1, respfile, torad=True, todisp=False)
     attach_paz(tr2, sacpzfile, torad=False, tovel=True)
     p1 = tr1.stats.paz.poles
     z1 = tr1.stats.paz.zeros
     g1 = tr1.stats.paz.gain
     t_samp = 0.01
     n = 32768
     fy = 1 / (t_samp * 2.0)
     # start at zero to get zero for offset/ DC of fft
     f = np.arange(0, fy + fy / n, fy / n)  # arange should includes fy
     w = f * 2 * np.pi
     s = 1j * w
     a1 = np.poly(p1)
     b1 = g1 * np.poly(z1)
     h1 = np.polyval(b1, s) / np.polyval(a1, s)
     h1 = np.conj(h1)
     h1[-1] = h1[-1].real + 0.0j
     p2 = tr2.stats.paz.poles
     z2 = tr2.stats.paz.zeros
     g2 = tr2.stats.paz.gain
     a2 = np.poly(p2)
     b2 = g2 * np.poly(z2)
     h2 = np.polyval(b2, s) / np.polyval(a2, s)
     h2 = np.conj(h2)
     h2[-1] = h2[-1].real + 0.0j
     amp1 = abs(h1)
     amp2 = abs(h2)
     phase1 = np.unwrap(np.arctan2(-h1.imag, h1.real))
     phase2 = np.unwrap(np.arctan2(-h2.imag, h2.real))
     np.testing.assert_almost_equal(phase1, phase2, decimal=4)
     rms = np.sqrt(np.sum((amp1 - amp2) ** 2) /
                   np.sum(amp2 ** 2))
     self.assertTrue(rms < 2.02e-06)
     self.assertTrue(tr1.stats.paz.t_shift, 0.4022344)