Beispiel #1
0
class PipelineTest(unittest.TestCase):        
    
    def assertModelEquals(self, actual, expected):
        # np.testing.assert_array_equal() will accept floats, ints etc.
        np.testing.assert_array_almost_equal(actual.vs, expected.vs)
        np.testing.assert_array_almost_equal(actual.all_deps, expected.all_deps)
        np.testing.assert_array_almost(actual.idep, expected.idep) # integers
        self.assertAlmostEqual(actual.std_rf, expected.std_rf)
        self.assertAlmostEqual(actual.lam_rf, expected.lam_rf)
        self.assertAlmostEqual(actual.std_swd, expected.std_swd)
    
        
    
    
    #  Test initial model 
    deps = np.append(np.arange(0,60,1), np.arange(60,201,5))
    normdist =  np.random.normal(0,0.5,1000) # Gaussian distribution, std = 0.5
    
    @parameterized.expand([
        ("Seed == 1", normdist, 1,
             pipeline.Model(vs = np.array(1.17), all_deps = deps, idep = np.array(8), 
                            std_rf = 0.5, lam_rf = 0.2, std_swd = 0.15)),       
        ("Seed == 10", normdist, 10, 
             pipeline.Model(vs = 3.36, all_deps = deps, idep = 54, 
                            std_rf = 0.5, lam_rf = 0.2, std_swd = 0.15)),
    ])
       
    def test_InitialModel(self, name, normdist, random_seed, expected):
        model= pipeline.InitialModel(normdist,random_seed)
        self.assertModelEquals(model, expected)
        
    del deps, normdist
    
    # Test checking prior
    deps = np.append(np.arange(0,60,1), np.arange(60,201,5))
    lims = pipeline.Limits(
            vs = (0.5,5), dep = (0,200), std_rf = (0.005,0.5), 
            lam_rf = (0.05,0.5), std_swd = (0.01,0.2),
            )  
    model = pipeline.Model(
            vs = np.array([1.4,4,5]), all_deps = deps, idep = np.array([0,42,64]), 
            std_rf = 0.15, lam_rf = 0.2, std_swd = 0.15,
            )
    
    @parameterized.expand([
            ("Should work", lims, model, True),
            ("Vs too small", lims, model._replace(vs = np.array([0.4,1.4,4])), False),
            ("Vs too big", lims, model._replace(vs = np.array([0.5,1.4,5.6])), False),
            ("Vs lims", lims._replace(vs = (1.5,5)), model, False), 
            ("Dep ind wrong", lims, model._replace(idep = np.array([-1,42,89])), False),
            ("Dep lims", lims._replace(dep = (50, 100)), model, False),
            ("Std_rf", lims, model._replace(std_rf = 0.51),False),
            ("Std_swd", lims._replace(std_swd = (0,0.1)), model, False),
            ("Lam_rf", lims, model._replace(lam_rf = 1), False),
            ])
    
    def test_CheckPrior(self,name,lims,model,expected):
        self.assertEqual(expected,pipeline.CheckPrior(model,lims))
    
    del deps, lims, model
Beispiel #2
0
out = pipeline.JointInversion(rf_obs, swd_obs, all_lims, max_it, rnd_sd)

#actual_model = pipeline.SaveModel(pipeline.MakeFullModel(model),out[1][:,0])
#%%
all_models = np.load('testsave.npy')

good_mods = all_models[:, np.where(all_models[0, ] > 0)[0]]
nit = good_mods.shape[1]
good_mods = good_mods[:, -int(nit / 5):]
mean_mod = np.mean(good_mods, axis=1)
std_mod = np.std(good_mods, axis=1)

good_mod = pipeline.Model(vs=mean_mod,
                          all_deps=all_models[:, 0],
                          idep=np.arange(0, mean_mod.size),
                          lam_rf=0,
                          std_rf=0,
                          std_swd=0)
fullmodel = pipeline.MakeFullModel(good_mod)

fig1 = plt.figure()

ax1 = plt.subplot(131)
for k in range(all_models[1, ].size - 1):
    colstr = str(0.75 - k / 2 / all_models[1, ].size)
    ax1.plot(all_models[:, k],
             all_models[:, 0],
             '-',
             linewidth=1,
             color=colstr)
ax1.set_ylim((195, 0))
Beispiel #3
0
import pstats
import cProfile

pr = cProfile.Profile()
pr.enable()

#def try_running():
max_it = 200000
rnd_sd = 1

deps = np.concatenate(
    (np.arange(0, 10, 0.2), np.arange(10, 60, 1), np.arange(60, 201, 5)))
model = pipeline.Model(
    vs=np.arange(3.5, 4.8, 0.1),
    all_deps=deps,
    idep=np.array([25, 50, 60, 70, 80, 90, 100, 102, 104, 106, 108, 110, 112]),
    std_rf=0,
    lam_rf=0,
    std_swd=0)

#model = pipeline.Model(vs = np.array([1.8, 2.4, 3.4, 4.5, 4.7, 4.65]), all_deps = deps,
#                       idep = np.array([10, 32, 41, 60, 96, 120]),
#                       std_rf = 0, lam_rf = 0, std_swd = 0)
#model = pipeline.Model(vs = np.array([3.4, 4.5]), all_deps = deps,
#                       idep = np.array([60, 96]),
#                       std_rf = 0, lam_rf = 0, std_swd = 0)

rf_obs = pipeline.SynthesiseRF(pipeline.MakeFullModel(model))
swd_obs = pipeline.SynthesiseSWD(pipeline.MakeFullModel(model),
                                 1 / np.arange(0.02, 0.1, 0.01), 1e6)
all_lims = pipeline.Limits(vs=(0.5, 5.5),
Beispiel #4
0
import matplotlib.pyplot as plt
import pstats
import cProfile

pr = cProfile.Profile()
pr.enable()

#def try_running():
max_it = 20000
rnd_sd = 1

deps = np.concatenate(
    (np.arange(0, 10, 0.2), np.arange(10, 60, 1), np.arange(60, 201, 5)))
model = pipeline.Model(vs=np.array([1.8, 2.4, 3.4, 4.5, 4.7, 4.65]),
                       all_deps=deps,
                       idep=np.array([10, 32, 41, 60, 96, 120]),
                       std_rf=0,
                       lam_rf=0,
                       std_swd=0)

rf_obs = pipeline.SynthesiseRF(pipeline.MakeFullModel(model))
swd_obs = pipeline.SynthesiseSWD(pipeline.MakeFullModel(model),
                                 1 / np.arange(0.02, 0.1, 0.01))
all_lims = pipeline.Limits(vs=(0.5, 5.5),
                           dep=(0, 200),
                           std_rf=(0, 0.05),
                           lam_rf=(0.05, 0.5),
                           std_swd=(0, 0.15))

out = pipeline.JointInversion(rf_obs, swd_obs, all_lims, max_it, rnd_sd)

actual_model = pipeline.SaveModel(pipeline.MakeFullModel(model), out[1][:, 0])
Beispiel #5
0
import numpy as np
import os

rf_phase = 'Both'  #'Sp' # 'Ps' # 'Both'
weight_by = 'rf2'  # 'even' 'rf2'

basedir = 'D:/Scattered_Waves/RJMCMC/'
#'C:/Users/Emily/Documents/RJMCMC/'
savename = open(os.path.join(basedir, 'input_data.py'), mode='w')

deps = np.concatenate(
    (np.arange(0, 10, 0.2), np.arange(10, 60, 1), np.arange(60, 201, 5)))

model = pipeline.Model(vs=np.array([3.7, 4.3, 4.7, 4.6]),
                       all_deps=deps,
                       idep=np.array([10, 30, 90, 110]),
                       std_rf_sc=1,
                       lam_rf=0.2,
                       std_swd_sc=1)

fullmodel = pipeline.MakeFullModel(model)
savemodel = pipeline.SaveModel(fullmodel, deps)

stdsw = np.array([
    0.7880, 0.3990, 0.5520, 0.4860, 0.3620, 0.2210, 0.0070, 0.0120, 0.0130,
    0.0160, 0.0150, 0.0100
])
swd_in = pipeline.SurfaceWaveDisp(
    period=np.array([
        9,
        10.12,
        11.57,