def test_prior_dates(self):
        pgoal_age_mean = 6726.8
        pgoal_age_std = 192.94564322687978

        pgoal_density_mean = 0.011642671907680679
        pgoal_density_std = 0.010893804880746285

        dgoal = np.array([77.5, 79.5, 99.5])
        dgoal_n = 40
        pgoal_n = dgoal_n

        chron = read_chron(os.path.join(here, 'MSB2K.csv'))
        d_target, p_target = Bacon.prior_dates(chron, **self.mcmc_kws)
        np.testing.assert_allclose(d_target[-3:], dgoal)
        np.testing.assert_equal(len(d_target), dgoal_n)

        np.testing.assert_allclose(np.mean(p_target[-1][:, 0]),
                                   pgoal_age_mean,
                                   atol=7)
        np.testing.assert_allclose(np.std(p_target[-1][:, 0]),
                                   pgoal_age_std,
                                   atol=2)
        np.testing.assert_equal(len(p_target), pgoal_n)

        np.testing.assert_allclose(np.mean(p_target[-1][:, 1]),
                                   pgoal_density_mean,
                                   atol=1e-2)
        np.testing.assert_allclose(np.std(p_target[-1][:, 1]),
                                   pgoal_density_std,
                                   atol=1e-2)
Exemple #2
0
    def test_run_baconmcmc(self):
        testcore_path = path.join(here, 'MSB2K.csv')
        c = snek.read_chron(testcore_path)
        fullrun_victim = baconwrap.run_baconmcmc(core_labid=c.labid, core_age=c.age, core_error=c.error,
                                                 core_depth=c.depth, depth_min=1.5, depth_max=99.5, cc=[1],
                                                 cc1='IntCal13', cc2='Marine13', cc3='SHCal13', cc4='ConstCal',
                                                 d_r=[0], d_std=[0], t_a=[3], t_b=[4], k=20,
                                                 minyr=-1000, maxyr=1e6, th01=4147, th02=4145,
                                                 acc_mean=20, acc_shape=1.5, mem_strength=4, mem_mean=0.7)

        niter_goal = 3432
        nsegs_goal = 20
        objective_mean_goal = 218.26212744522144
        theta_mean_goal = 4549.6406701631704
        w_mean_goal = 0.06277018029195805
        x0_mean_goal = 14.487713009032634
        xneg1_mean_goal = 15.65397709810606
        # Fuzzy to deal with vars across platforms.
        np.testing.assert_allclose(len(fullrun_victim['objective']), niter_goal, atol=50)
        np.testing.assert_allclose(len(fullrun_victim['w']), niter_goal, atol=50)
        np.testing.assert_allclose(len(fullrun_victim['x'][0]), niter_goal, atol=50)
        np.testing.assert_allclose(len(fullrun_victim['x'][-1]), niter_goal, atol=50)
        self.assertEqual(nsegs_goal, len(fullrun_victim['x']))
        np.testing.assert_allclose(fullrun_victim['objective'].mean(), objective_mean_goal, atol=1e-1)
        np.testing.assert_allclose(fullrun_victim['theta'].mean(), theta_mean_goal, atol=15)
        np.testing.assert_allclose(fullrun_victim['w'].mean(), w_mean_goal, atol=1e-2)
        np.testing.assert_allclose(fullrun_victim['x'][0].mean(), x0_mean_goal, atol=2)
        np.testing.assert_allclose(fullrun_victim['x'][-1].mean(), xneg1_mean_goal, atol=2)
Exemple #3
0
    def test_calibrate_dates(self):
        pgoal_age_mean = 6726.8
        pgoal_age_std = 192.94564322687978

        pgoal_density_mean = 0.011642671907680679
        pgoal_density_std = 0.010893804880746285

        dgoal = np.array([77.5, 79.5, 99.5])
        dgoal_n = 40
        pgoal_n = dgoal_n

        chron = read_chron(os.path.join(here, 'MSB2K.csv'))

        d_r = [0]
        d_std = [0]
        t_a = [3]
        t_b = [4]

        cc = [fetch_calibcurve('IntCal13')]

        d_target, p_target = calibrate_dates(chron,
                                             calib_curve=cc,
                                             d_r=d_r,
                                             d_std=d_std,
                                             t_a=t_a,
                                             t_b=t_b)
        np.testing.assert_allclose(d_target[-3:], dgoal)
        np.testing.assert_equal(len(d_target), dgoal_n)

        np.testing.assert_allclose(np.mean(p_target[-1][:, 0]),
                                   pgoal_age_mean,
                                   atol=7)
        np.testing.assert_allclose(np.std(p_target[-1][:, 0]),
                                   pgoal_age_std,
                                   atol=2)
        np.testing.assert_equal(len(p_target), pgoal_n)

        np.testing.assert_allclose(np.mean(p_target[-1][:, 1]),
                                   pgoal_density_mean,
                                   atol=1e-2)
        np.testing.assert_allclose(np.std(p_target[-1][:, 1]),
                                   pgoal_density_std,
                                   atol=1e-2)
Exemple #4
0
                cc3='SHCal13',
                cc4='ConstCal',
                d_r=[0],
                d_std=[0],
                t_a=[3],
                t_b=[4],
                k=20,
                minyr=-1000,
                maxyr=1e6,
                th01=4147,
                th02=4145,
                acc_mean=20,
                acc_shape=1.5,
                mem_strength=4,
                mem_mean=0.7)
fullrun_agemodel = AgeDepthModel(read_chron(path.join(here, 'MSB2K.csv')),
                                 mcmc_kws=mcmc_kws)


class TestAgeDepth(unittest.TestCase):
    def setUp(self):
        np.random.seed(123)
        self.testdummy = deepcopy(fullrun_agemodel)

    def test_init(self):
        goal_thick = 4.9
        goal_depthrange = (1.5, 99.5)
        goal_agemedian_edges = (4552.5750000000007, 6714.1464476499987)
        goal_agemedian_025 = (4430.3599999999997, 6582.4278499575012)
        goal_agemedian_975 = (4680.6210000000001, 6868.9317877499998)
        goal_ageensemble_shape = (99, 3232)
Exemple #5
0
import numpy as np

from snakebacon import read_chron
from snakebacon.mcmc import McmcResults, McmcSetup


here = path.abspath(path.dirname(__file__))


mcmc_kws = dict(depth_min=1.5, depth_max=99.5, cc=[1],
                   cc1='IntCal13', cc2='Marine13', cc3='SHCal13', cc4='ConstCal',
                   d_r=[0], d_std=[0], t_a=[3], t_b=[4], k=20,
                   minyr=-1000, maxyr=1e6, th01=4147, th02=4145,
                   acc_mean=20, acc_shape=1.5, mem_strength=4, mem_mean=0.7)
fullrun_setup = McmcSetup(read_chron(path.join(here, 'MSB2K.csv')), **mcmc_kws)
fullrun_victim = McmcResults(fullrun_setup)


class TestMcmcResults(unittest.TestCase):
    def setUp(self):
        self.testdummy = deepcopy(fullrun_victim)

    def test_init(self):
        niter_goal = 3432
        nsegs_goal = 20
        objective_mean_goal = 218.26212744522144
        theta_mean_goal = 4549.6406701631704
        w_mean_goal = 0.06277018029195805
        x0_mean_goal = 14.487713009032634
        xneg1_mean_goal = 15.65397709810606