def test_relcal_sts2_vs_unknown(self): """ Test relative calibration of unknown instrument vs STS2 in the same time range. Window length is set to 20 s, smoothing rate to 10. """ st1 = read(os.path.join(self.path, 'ref_STS2')) st2 = read(os.path.join(self.path, 'ref_unknown')) calfile = os.path.join(self.path, 'STS2_simp.cal') freq, amp, phase = relcalstack(st1, st2, calfile, 20, smooth=10, save_data=False) # read in the reference responses un_resp = np.loadtxt(os.path.join(self.path, 'unknown.resp')) kn_resp = np.loadtxt(os.path.join(self.path, 'STS2.refResp')) # test if freq, amp and phase match the reference values np.testing.assert_array_almost_equal(freq, un_resp[:, 0], decimal=4) np.testing.assert_array_almost_equal(freq, kn_resp[:, 0], decimal=4) np.testing.assert_array_almost_equal(amp, un_resp[:, 1], decimal=4) np.testing.assert_array_almost_equal(phase, un_resp[:, 2], decimal=4)
def test_relcalUsingTraces(self): """ Tests using traces instead of stream objects as input parameters. """ st1 = read(os.path.join(self.path, 'ref_STS2')) st2 = read(os.path.join(self.path, 'ref_unknown')) calfile = os.path.join(self.path, 'STS2_simp.cal') # stream freq, amp, phase = relcalstack(st1, st2, calfile, 20, smooth=10, save_data=False) # traces freq2, amp2, phase2 = relcalstack(st1[0], st2[0], calfile, 20, smooth=10, save_data=False) np.testing.assert_array_almost_equal(freq, freq2, decimal=4) np.testing.assert_array_almost_equal(amp, amp2, decimal=4) np.testing.assert_array_almost_equal(phase, phase2, decimal=4)
def test_relcal_sts2_vs_unknown(self): """ Test relative calibration of unknown instrument vs STS2 in the same time range. Window length is set to 20 s, smoothing rate to 10. """ st1 = read(os.path.join(self.path, 'ref_STS2')) st2 = read(os.path.join(self.path, 'ref_unknown')) calfile = os.path.join(self.path, 'STS2_simp.cal') freq, amp, phase = relcalstack(st1, st2, calfile, 20, smooth=10, save_data=False) # read in the reference responses un_resp = np.loadtxt(os.path.join(self.path, 'unknown.resp')) kn_resp = np.loadtxt(os.path.join(self.path, 'STS2.refResp')) # bug resolved with 2f9876d, arctan was used which maps to # [-pi/2, pi/2]. arctan2 or np.angle shall be used instead # correct the test data by hand un_resp[:, 2] = np.unwrap(un_resp[:, 2] * 2) / 2 if False: import matplotlib.pyplot as plt plt.plot(freq, un_resp[:, 2], 'b', label='reference', alpha=.8) plt.plot(freq, phase, 'r', label='new', alpha=.8) plt.xlim(-10, None) plt.legend() plt.show() # test if freq, amp and phase match the reference values np.testing.assert_array_almost_equal(freq, un_resp[:, 0], decimal=4) np.testing.assert_array_almost_equal(freq, kn_resp[:, 0], decimal=4) np.testing.assert_array_almost_equal(amp, un_resp[:, 1], decimal=4) # TODO: unkown why the first frequency mismatches so much np.testing.assert_array_almost_equal(phase[1:], un_resp[1:, 2], decimal=4)
def test_relcal_sts2_vs_unknown(self): """ Test relative calibration of unknown instrument vs STS2 in the same time range. Window length is set to 20 s, smoothing rate to 10. """ st1 = read(os.path.join(self.path, 'ref_STS2')) st2 = read(os.path.join(self.path, 'ref_unknown')) calfile = os.path.join(self.path, 'STS2_simp.cal') freq, amp, phase = relcalstack(st1, st2, calfile, 20, smooth=10, save_data=False) # read in the reference responses un_resp = np.loadtxt(os.path.join(self.path, 'unknown.resp')) kn_resp = np.loadtxt(os.path.join(self.path, 'STS2.refResp')) # bug resolved with 2f9876d, arctan was used which maps to # [-pi/2, pi/2]. arctan2 or np.angle shall be used instead # correct the test data by hand un_resp[:, 2] = np.unwrap(un_resp[:, 2] * 2) / 2 if False: import matplotlib.pyplot as plt plt.plot(freq, un_resp[:, 2], 'b', label='reference', alpha=.8) plt.plot(freq, phase, 'r', label='new', alpha=.8) plt.xlim(-10, None) plt.legend() plt.show() # test if freq, amp and phase match the reference values np.testing.assert_array_almost_equal(freq, un_resp[:, 0], decimal=4) np.testing.assert_array_almost_equal(freq, kn_resp[:, 0], decimal=4) np.testing.assert_array_almost_equal(amp, un_resp[:, 1], decimal=4) # TODO: unknown why the first frequency mismatches so much np.testing.assert_array_almost_equal(phase[1:], un_resp[1:, 2], decimal=4)
st1 = read('%s/%s'%(cwd,known)) st1.merge() st2 = read('%s/%s'%(cwd,unknown)) st2.merge() st = UTCDateTime(start) ed = UTCDateTime(end) st1.trim(st,ed) st2.trim(st,ed) print st1 print st2 calfile = "%s/%s"%(cwd,calfile) freq, amp, phase = calibration.relcalstack(st1, st2, calfile, window, overlap_frac=0.5,smooth=sxm) # plot fig = plt.figure() # make a little extra space between the subplots plt.subplots_adjust(hspace=0.5) ax1 = plt.subplot(211) ax1.loglog(freq, amp) ax1.set_xlabel('Frequency [Hz]') ax1.set_ylabel('Amplitude') ax1.set_xlim(1,100) ax1.set_title('unknown transfer function') ax2 = plt.subplot(212) ax2.semilogx(freq, phase) ax2.set_xlim(1,100) ax2.set_xlabel('Frequency [Hz]')
import os from obspy.core import read from obspy.signal.calibration import relcalstack import matplotlib.pyplot as plt cwd = os.getcwd() st1 = read('%s/CA.STS2..EHZ.D.2011.046.2h' % (cwd)) st2 = read('%s/CA.0438..EHZ.D.2011.046.2h' % (cwd)) #st1 = read('%s/mb_new'%(cwd)) #st2 = read('%s/w_new'%(cwd)) #calfile = "%s/MB2005_simp.cal"%(cwd) calfile = "%s/STS2_simp.cal" % (cwd) freq, amp, phase = relcalstack(st1, st2, calfile, 600, smooth=0) # plot fig = plt.figure() # make a little extra space between the subplots plt.subplots_adjust(hspace=0.5) ax1 = plt.subplot(211) ax1.loglog(freq, amp) ax1.set_xlabel('Frequency [Hz]') ax1.set_ylabel('Amplitude') ax1.set_title('unknown transfer function') ax2 = plt.subplot(212) ax2.semilogx(freq, phase) ax2.set_xlabel('Frequency [Hz]') ax2.set_ylabel('Phase [rad]')
from obspy.core import read from obspy.signal.calibration import relcalstack import matplotlib.pyplot as plt cwd = os.getcwd() st1 = read('%s/CA.STS2..EHZ.D.2011.046.2h'%(cwd)) st2 = read('%s/CA.0438..EHZ.D.2011.046.2h'%(cwd)) #st1 = read('%s/mb_new'%(cwd)) #st2 = read('%s/w_new'%(cwd)) #calfile = "%s/MB2005_simp.cal"%(cwd) calfile = "%s/STS2_simp.cal"%(cwd) freq, amp, phase = relcalstack(st1, st2, calfile, 600, smooth=0) # plot fig = plt.figure() # make a little extra space between the subplots plt.subplots_adjust(hspace=0.5) ax1 = plt.subplot(211) ax1.loglog(freq, amp) ax1.set_xlabel('Frequency [Hz]') ax1.set_ylabel('Amplitude') ax1.set_title('unknown transfer function') ax2 = plt.subplot(212) ax2.semilogx(freq, phase) ax2.set_xlabel('Frequency [Hz]') ax2.set_ylabel('Phase [rad]')