Ejemplo n.º 1
0
def test_stationary_comp():
    """
    Tests an ellip comp fit with no traceforward, i.e. no evolution of stars or
    component
    """
    # log_filename = 'logs/compfitter_stationary.log'
    # synth_data_savefile = 'temp_data/compfitter_stationary_synthdata.fits'

    burnin_step = 1000

    true_comp_mean = np.zeros(6)
    true_comp_dx = 10.
    true_comp_dy = 5.
    true_comp_du = 2.
    true_comp_dv = 4.
    true_comp_roll = 0.
    true_comp_pitch = 0.
    true_comp_yaw = 0.
    true_comp_cov_xv = 0.4
    true_comp_age = 1e-10

    true_comp_pars = np.hstack([
        true_comp_mean,
        true_comp_dx,
        true_comp_dy,
        true_comp_du,
        true_comp_dv,
        true_comp_roll,
        true_comp_pitch,
        true_comp_yaw,
        true_comp_cov_xv,
        true_comp_age,
    ])

    true_comp = EllipComponent(true_comp_pars)

    nstars = 100
    measurement_error = 1e-10

    best_comp, chain, lnprob = run_fit_helper(
        true_comp=true_comp,
        starcounts=nstars,
        measurement_error=measurement_error,
        run_name='stationary',
        burnin_step=burnin_step,
        trace_orbit_func=dummy_trace_orbit_func,
    )

    assert np.allclose(true_comp.get_mean(), best_comp.get_mean(), atol=1.0)
    assert np.allclose(true_comp.get_age(), best_comp.get_age(), atol=1.0)
    assert np.allclose(true_comp.get_covmatrix(),
                       best_comp.get_covmatrix(),
                       atol=2.0)
Ejemplo n.º 2
0
def test_any_age_comp(age=32):
    """
    Tests an ellip component fit with age as a parameter
    """
    # log_filename = 'logs/compfitter_stationary.log'
    # synth_data_savefile = 'temp_data/compfitter_stationary_synthdata.fits'

    burnin_step = 2000

    true_comp_mean = [0., 0., 0., 2., 2., 2.]
    true_comp_dx = 8.
    true_comp_dy = 3.
    true_comp_du = 6.
    true_comp_dv = 3.
    true_comp_roll = 0.
    true_comp_pitch = 0.5
    true_comp_yaw = 1.
    true_comp_cov_xv = 2.5
    true_comp_age = age

    true_comp_pars = np.hstack([
        true_comp_mean,
        true_comp_dx,
        true_comp_dy,
        true_comp_du,
        true_comp_dv,
        true_comp_roll,
        true_comp_pitch,
        true_comp_yaw,
        true_comp_cov_xv,
        true_comp_age,
    ])

    true_comp = EllipComponent(true_comp_pars)

    nstars = 100
    measurement_error = 1e-10

    best_comp, chain, lnprob = run_fit_helper(
        true_comp=true_comp,
        starcounts=nstars,
        measurement_error=measurement_error,
        run_name='priorTest_11_age_%.1e' % true_comp_age,
        burnin_step=burnin_step,
        trace_orbit_func=trace_epicyclic_orbit,
    )
    print("Age: --~~~~~~~~~~~~~~~~", best_comp.get_age())

    # old_pars = best_comp.get_pars()
    # edited_init_pars = np.copy(old_pars)
    # # edited_init_pars[10] = old_pars[10]+(np.pi/2)
    # # edited_init_pars[11] = old_pars[11]+(np.pi/2)
    # edited_init_pars[12] = old_pars[12]+(np.pi/2)
    #
    # edited_best_comp, edited_chain, edited_lnprob = run_fit_helper(
    #         true_comp=true_comp, starcounts=nstars,
    #         measurement_error=measurement_error,
    #         run_name='priorTest_01_Edited_age_%.1e'%true_comp_age,
    #         burnin_step=burnin_step,
    #         trace_orbit_func=trace_epicyclic_orbit,
    #         init_pars=edited_init_pars
    # )
    # if lnprob.max() < edited_lnprob.max():
    #     print("lnProb - max", lnprob.max())
    #     print("edited _ lnProb - max", edited_lnprob.max())
    #
    #     print("-------------------------------------------------------")
    #     print("Pi/2 Error, A second fit was run and is set as best fit")
    #     print("-------------------------------------------------------")
    # print("New Age: --~~~~~~~~~~~~~~~~", edited_best_comp.get_age())

    assert np.allclose(true_comp.get_mean(), best_comp.get_mean(), atol=1.0)
    assert np.allclose(true_comp.get_age(), best_comp.get_age(), atol=1.0)
    assert np.allclose(true_comp.get_covmatrix(),
                       best_comp.get_covmatrix(),
                       atol=2.0)