Exemple #1
0
    def test_phase_misfit(self):
        """
        Tests all tf misfits with a signal that has phase misfit
        """
        s1 = self.s1
        s1p = self.s1p
        t = self.t
        dt = self.dt

        fmin = self.fmin
        fmax = self.fmax
        nf = self.nf

        tfem_11p_ref = np.loadtxt(self.path + os.sep + 'TFEM_11p.dat')
        tfpm_11p_ref = np.loadtxt(self.path + os.sep + 'TFPM_11p.dat')
        tem_11p_ref = np.loadtxt(self.path + os.sep + 'TEM_11p.dat')
        fem_11p_ref = np.loadtxt(self.path + os.sep + 'FEM_11p.dat')
        fpm_11p_ref = np.loadtxt(self.path + os.sep + 'FPM_11p.dat')
        tpm_11p_ref = np.loadtxt(self.path + os.sep + 'TPM_11p.dat')
        em_11p_ref = np.loadtxt(self.path + os.sep + 'EM_11p.dat')
        pm_11p_ref = np.loadtxt(self.path + os.sep + 'PM_11p.dat')

        tfem_11p = tfem(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        tfpm_11p = tfpm(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        tem_11p = tem(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        fem_11p = fem(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        fpm_11p = fpm(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        tpm_11p = tpm(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        em_11p = em(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        pm_11p = pm(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)

        tol = 1e-5
        atol_min = 1e-15

        self.assertTrue(np.allclose(tfem_11p, tfem_11p_ref, rtol=tol,
                        atol=np.abs(tfem_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(tfpm_11p, tfpm_11p_ref, rtol=tol,
                        atol=np.abs(tfpm_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(tem_11p, tem_11p_ref, rtol=tol,
                        atol=np.abs(tem_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(fem_11p, fem_11p_ref, rtol=tol,
                        atol=np.abs(fem_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(fpm_11p, fpm_11p_ref, rtol=tol,
                        atol=np.abs(fpm_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(tpm_11p, tpm_11p_ref, rtol=tol,
                        atol=np.abs(tpm_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(em_11p, em_11p_ref, rtol=tol,
                        atol=np.abs(em_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(pm_11p, pm_11p_ref, rtol=tol,
                        atol=np.abs(pm_11p_ref).max() * tol + atol_min))
Exemple #2
0
    def test_phase_misfit(self):
        """
        Tests all tf misfits with a signal that has phase misfit
        """
        S1 = self.S1
        s1p = self.s1p
        t = self.t
        dt = self.dt

        fmin = self.fmin
        fmax = self.fmax
        nf = self.nf

        TFEM_11p_ref = np.loadtxt(self.path + os.sep + 'TFEM_11p.dat')
        TFPM_11p_ref = np.loadtxt(self.path + os.sep + 'TFPM_11p.dat')
        TEM_11p_ref = np.loadtxt(self.path + os.sep + 'TEM_11p.dat')
        FEM_11p_ref = np.loadtxt(self.path + os.sep + 'FEM_11p.dat')
        FPM_11p_ref = np.loadtxt(self.path + os.sep + 'FPM_11p.dat')
        TPM_11p_ref = np.loadtxt(self.path + os.sep + 'TPM_11p.dat')
        EM_11p_ref = np.loadtxt(self.path + os.sep + 'EM_11p.dat')
        PM_11p_ref = np.loadtxt(self.path + os.sep + 'PM_11p.dat')

        TFEM_11p = tfem(s1p, S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        TFPM_11p = tfpm(s1p, S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        TEM_11p = tem(s1p, S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        FEM_11p = fem(s1p, S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        FPM_11p = fpm(s1p, S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        TPM_11p = tpm(s1p, S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        EM_11p = em(s1p, S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        PM_11p = pm(s1p, S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)

        tol = 1e-5
        atol_min = 1e-15

        self.assertTrue(np.allclose(TFEM_11p, TFEM_11p_ref, rtol=tol,
                        atol=np.abs(TFEM_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(TFPM_11p, TFPM_11p_ref, rtol=tol,
                        atol=np.abs(TFPM_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(TEM_11p, TEM_11p_ref, rtol=tol,
                        atol=np.abs(TEM_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(FEM_11p, FEM_11p_ref, rtol=tol,
                        atol=np.abs(FEM_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(FPM_11p, FPM_11p_ref, rtol=tol,
                        atol=np.abs(FPM_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(TPM_11p, TPM_11p_ref, rtol=tol,
                        atol=np.abs(TPM_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(EM_11p, EM_11p_ref, rtol=tol,
                        atol=np.abs(EM_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(PM_11p, PM_11p_ref, rtol=tol,
                        atol=np.abs(PM_11p_ref).max() * tol + atol_min))
    def test_phase_misfit(self):
        """
        Tests all tf misfits with a signal that has phase misfit
        """
        s1 = self.s1
        s1p = self.s1p
        t = self.t
        dt = self.dt

        fmin = self.fmin
        fmax = self.fmax
        nf = self.nf

        tfem_11p_ref = np.loadtxt(self.path + os.sep + 'TFEM_11p.dat')
        tfpm_11p_ref = np.loadtxt(self.path + os.sep + 'TFPM_11p.dat')
        tem_11p_ref = np.loadtxt(self.path + os.sep + 'TEM_11p.dat')
        fem_11p_ref = np.loadtxt(self.path + os.sep + 'FEM_11p.dat')
        fpm_11p_ref = np.loadtxt(self.path + os.sep + 'FPM_11p.dat')
        tpm_11p_ref = np.loadtxt(self.path + os.sep + 'TPM_11p.dat')
        em_11p_ref = np.loadtxt(self.path + os.sep + 'EM_11p.dat')
        pm_11p_ref = np.loadtxt(self.path + os.sep + 'PM_11p.dat')

        tfem_11p = tfem(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        tfpm_11p = tfpm(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        tem_11p = tem(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        fem_11p = fem(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        fpm_11p = fpm(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        tpm_11p = tpm(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        em_11p = em(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        pm_11p = pm(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)

        tol = 1e-5
        atol_min = 1e-15

        self.assertTrue(np.allclose(tfem_11p, tfem_11p_ref, rtol=tol,
                        atol=np.abs(tfem_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(tfpm_11p, tfpm_11p_ref, rtol=tol,
                        atol=np.abs(tfpm_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(tem_11p, tem_11p_ref, rtol=tol,
                        atol=np.abs(tem_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(fem_11p, fem_11p_ref, rtol=tol,
                        atol=np.abs(fem_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(fpm_11p, fpm_11p_ref, rtol=tol,
                        atol=np.abs(fpm_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(tpm_11p, tpm_11p_ref, rtol=tol,
                        atol=np.abs(tpm_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(em_11p, em_11p_ref, rtol=tol,
                        atol=np.abs(em_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(pm_11p, pm_11p_ref, rtol=tol,
                        atol=np.abs(pm_11p_ref).max() * tol + atol_min))
Exemple #4
0
    def test_phase_misfit(self):
        """
        Tests all tf misfits with a signal that has phase misfit
        """
        S1 = self.S1
        s1p = self.s1p
        t = self.t
        dt = self.dt

        fmin = self.fmin
        fmax = self.fmax
        nf = self.nf

        TFEM_11p_ref = np.loadtxt(self.path + os.sep + 'TFEM_11p.dat')
        TFPM_11p_ref = np.loadtxt(self.path + os.sep + 'TFPM_11p.dat')
        TEM_11p_ref = np.loadtxt(self.path + os.sep + 'TEM_11p.dat')
        FEM_11p_ref = np.loadtxt(self.path + os.sep + 'FEM_11p.dat')
        FPM_11p_ref = np.loadtxt(self.path + os.sep + 'FPM_11p.dat')
        TPM_11p_ref = np.loadtxt(self.path + os.sep + 'TPM_11p.dat')
        EM_11p_ref = np.loadtxt(self.path + os.sep + 'EM_11p.dat')
        PM_11p_ref = np.loadtxt(self.path + os.sep + 'PM_11p.dat')

        TFEM_11p = tfem(s1p, S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        TFPM_11p = tfpm(s1p, S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        TEM_11p = tem(s1p, S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        FEM_11p = fem(s1p, S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        FPM_11p = fpm(s1p, S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        TPM_11p = tpm(s1p, S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        EM_11p = em(s1p, S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        PM_11p = pm(s1p, S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)

        tol = 1e-5
        atol_min = 1e-15

        self.assertTrue(np.allclose(TFEM_11p, TFEM_11p_ref, rtol=tol,
                        atol=np.abs(TFEM_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(TFPM_11p, TFPM_11p_ref, rtol=tol,
                        atol=np.abs(TFPM_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(TEM_11p, TEM_11p_ref, rtol=tol,
                        atol=np.abs(TEM_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(FEM_11p, FEM_11p_ref, rtol=tol,
                        atol=np.abs(FEM_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(FPM_11p, FPM_11p_ref, rtol=tol,
                        atol=np.abs(FPM_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(TPM_11p, TPM_11p_ref, rtol=tol,
                        atol=np.abs(TPM_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(EM_11p, EM_11p_ref, rtol=tol,
                        atol=np.abs(EM_11p_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(PM_11p, PM_11p_ref, rtol=tol,
                        atol=np.abs(PM_11p_ref).max() * tol + atol_min))
Exemple #5
0
    def test_envelope_misfit(self):
        """
        Tests all tf misfits with a signal that has envelope misfit
        """
        S1 = self.S1
        S1a = self.S1a
        t = self.t
        dt = self.dt

        fmin = self.fmin
        fmax = self.fmax
        nf = self.nf

        TFEM_11a_ref = np.loadtxt(self.path + os.sep + "TFEM_11a.dat")
        TFPM_11a_ref = np.loadtxt(self.path + os.sep + "TFPM_11a.dat")
        TEM_11a_ref = np.loadtxt(self.path + os.sep + "TEM_11a.dat")
        FEM_11a_ref = np.loadtxt(self.path + os.sep + "FEM_11a.dat")
        FPM_11a_ref = np.loadtxt(self.path + os.sep + "FPM_11a.dat")
        TPM_11a_ref = np.loadtxt(self.path + os.sep + "TPM_11a.dat")
        EM_11a_ref = np.loadtxt(self.path + os.sep + "EM_11a.dat")
        PM_11a_ref = np.loadtxt(self.path + os.sep + "PM_11a.dat")

        TFEM_11a = tfem(S1a(t), S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        TFPM_11a = tfpm(S1a(t), S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        TEM_11a = tem(S1a(t), S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        TPM_11a = tpm(S1a(t), S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        FEM_11a = fem(S1a(t), S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        FPM_11a = fpm(S1a(t), S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        EM_11a = em(S1a(t), S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        PM_11a = pm(S1a(t), S1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)

        tol = 1e-5
        atol_min = 1e-15

        self.assertTrue(np.allclose(TFEM_11a, TFEM_11a_ref, rtol=tol, atol=np.abs(TFEM_11a_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(TFPM_11a, TFPM_11a_ref, rtol=tol, atol=np.abs(TFPM_11a_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(TEM_11a, TEM_11a_ref, rtol=tol, atol=np.abs(TEM_11a_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(FEM_11a, FEM_11a_ref, rtol=tol, atol=np.abs(FEM_11a_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(FPM_11a, FPM_11a_ref, rtol=tol, atol=np.abs(FPM_11a_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(TPM_11a, TPM_11a_ref, rtol=tol, atol=np.abs(TPM_11a_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(EM_11a, EM_11a_ref, rtol=tol, atol=np.abs(EM_11a_ref).max() * tol + atol_min))
        self.assertTrue(np.allclose(PM_11a, PM_11a_ref, rtol=tol, atol=np.abs(PM_11a_ref).max() * tol + atol_min))
Exemple #6
0
def comp_obspy_tf_misfit(model,
                         site_name,
                         dt,
                         comps='XYZ',
                         fmin=0.15,
                         fmax=5,
                         nf=128,
                         vel=None,
                         vel_rec=None,
                         plot=False):
    """See doc in `comp_obspy_tf_misfits` for details
    """
    if vel is None:
        with open('results/vel_syn.pickle', 'rb') as fid:
            vel_syn = pickle.load(fid)
        vel = vel_syn[model][site_name]
        vel_rec = vel_syn["rec"][site_name]

    resize(vel, vel_rec, dt)
    res = {}
    res['dt'] = dt
    res['f'] = np.logspace(np.log10(fmin), np.log10(fmax), nf)

    for comp in comps:
        res[comp] = {}
        res[comp]['syn'] = vel[comp]
        res[comp]['rec'] = vel_rec[comp]
        res[comp]['em'] = em(vel[comp], vel_rec[comp], dt, fmin, fmax, nf)
        res[comp]['pm'] = pm(vel[comp], vel_rec[comp], dt, fmin, fmax, nf)
        res[comp]['tfem'] = tfem(vel[comp], vel_rec[comp], dt, fmin, fmax, nf)
        res[comp]['tfpm'] = tfpm(vel[comp], vel_rec[comp], dt, fmin, fmax, nf)
        res[comp]['tem'] = tem(vel[comp], vel_rec[comp], dt, fmin, fmax, nf)
        res[comp]['tpm'] = tpm(vel[comp], vel_rec[comp], dt, fmin, fmax, nf)
        res[comp]['fem'] = fem(vel[comp], vel_rec[comp], dt, fmin, fmax, nf)
        res[comp]['fpm'] = fpm(vel[comp], vel_rec[comp], dt, fmin, fmax, nf)
    res['t'] = np.arange(res[comp]['tem'].shape[-1]) * dt
    if plot:
        plot_obspy_tf_misfit(res, comps=comps)
    return res
Exemple #7
0
    def test_phase_misfit(self, state):
        """
        Tests all tf misfits with a signal that has phase misfit
        """
        s1 = state['s1']
        s1p = state['s1p']
        t = state['t']
        dt = state['dt']

        fmin = state['fmin']
        fmax = state['fmax']
        nf = state['nf']

        tfem_11p_ref = np.loadtxt(self.path + os.sep + 'TFEM_11p.dat')
        tfpm_11p_ref = np.loadtxt(self.path + os.sep + 'TFPM_11p.dat')
        tem_11p_ref = np.loadtxt(self.path + os.sep + 'TEM_11p.dat')
        fem_11p_ref = np.loadtxt(self.path + os.sep + 'FEM_11p.dat')
        fpm_11p_ref = np.loadtxt(self.path + os.sep + 'FPM_11p.dat')
        tpm_11p_ref = np.loadtxt(self.path + os.sep + 'TPM_11p.dat')
        em_11p_ref = np.loadtxt(self.path + os.sep + 'EM_11p.dat')
        pm_11p_ref = np.loadtxt(self.path + os.sep + 'PM_11p.dat')

        tfem_11p = tfem(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        tfpm_11p = tfpm(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        tem_11p = tem(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        fem_11p = fem(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        fpm_11p = fpm(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        tpm_11p = tpm(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        em_11p = em(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)
        pm_11p = pm(s1p, s1(t), dt=dt, fmin=fmin, fmax=fmax, nf=nf)

        tol = 1e-5
        atol_min = 1e-15

        assert np.allclose(tfem_11p,
                           tfem_11p_ref,
                           rtol=tol,
                           atol=np.abs(tfem_11p_ref).max() * tol + atol_min)
        assert np.allclose(tfpm_11p,
                           tfpm_11p_ref,
                           rtol=tol,
                           atol=np.abs(tfpm_11p_ref).max() * tol + atol_min)
        assert np.allclose(tem_11p,
                           tem_11p_ref,
                           rtol=tol,
                           atol=np.abs(tem_11p_ref).max() * tol + atol_min)
        assert np.allclose(fem_11p,
                           fem_11p_ref,
                           rtol=tol,
                           atol=np.abs(fem_11p_ref).max() * tol + atol_min)
        assert np.allclose(fpm_11p,
                           fpm_11p_ref,
                           rtol=tol,
                           atol=np.abs(fpm_11p_ref).max() * tol + atol_min)
        assert np.allclose(tpm_11p,
                           tpm_11p_ref,
                           rtol=tol,
                           atol=np.abs(tpm_11p_ref).max() * tol + atol_min)
        assert np.allclose(em_11p,
                           em_11p_ref,
                           rtol=tol,
                           atol=np.abs(em_11p_ref).max() * tol + atol_min)
        assert np.allclose(pm_11p,
                           pm_11p_ref,
                           rtol=tol,
                           atol=np.abs(pm_11p_ref).max() * tol + atol_min)