コード例 #1
0
ファイル: test_api.py プロジェクト: vandalt/radvel
def test_priors():
    """
    Test basic functionality of all Priors
    """

    params = radvel.Parameters(1, 'per tc secosw sesinw logk')
    params['per1'] = radvel.Parameter(10.0)
    params['tc1'] = radvel.Parameter(0.0)
    params['secosw1'] = radvel.Parameter(0.0)
    params['sesinw1'] = radvel.Parameter(0.0)
    params['logk1'] = radvel.Parameter(1.5)

    vector = radvel.Vector(params)

    testTex = r'Delta Function Prior on $\sqrt{e}\cos{\omega}_{b}$'

    def userdef_prior_func(inp_list):
        if inp_list[0] >= 0. and inp_list[0] < 1.:
            return 0.
        else:
            return -np.inf

    prior_tests = {
        radvel.prior.EccentricityPrior(1):
        1 / .99,
        radvel.prior.EccentricityPrior([1]):
        1 / .99,
        radvel.prior.PositiveKPrior(1):
        1.0,
        radvel.prior.Gaussian('per1', 9.9, 0.1):
        scipy.stats.norm(9.9, 0.1).pdf(10.),
        radvel.prior.HardBounds('per1', 1.0, 9.0):
        0.,
        radvel.prior.HardBounds('per1', 1.0, 11.0):
        1. / 10.,
        radvel.prior.Jeffreys('per1', 0.1, 100.0):
        (1. / 10.) / np.log(100. / 0.1),
        radvel.prior.ModifiedJeffreys('per1', 0.1, 100.0, 0.):
        (1. / 10.) / np.log(100. / 0.1),
        radvel.prior.ModifiedJeffreys('per1', 2., 100.0, 1.):
        (1. / 9.) / np.log(99.),
        radvel.prior.SecondaryEclipsePrior(1, 5.0, 10.0):
        1. / np.sqrt(2. * np.pi),
        radvel.prior.NumericalPrior(['sesinw1'], np.random.randn(1, 5000000)):
        scipy.stats.norm(0, 1).pdf(0.),
        radvel.prior.UserDefinedPrior(['secosw1'], userdef_prior_func, testTex):
        1.0,
        radvel.prior.InformativeBaselinePrior('per1', 5.0, duration=1.0):
        6. / 10.
    }

    for prior, val in prior_tests.items():
        print(prior.__repr__())
        print(prior.__str__())
        tolerance = .01
        print(abs(np.exp(prior(params, vector))))
        print(val)
        assert abs(np.exp(prior(params, vector)) - val) < tolerance, \
            "Prior output does not match expectation"
コード例 #2
0
ファイル: test_api.py プロジェクト: vandalt/radvel
def test_basis():
    """
    Test basis conversions
    """

    basis_list = radvel.basis.BASIS_NAMES
    default_basis = 'per tc e w k'

    anybasis_params = radvel.Parameters(1, basis=default_basis)

    anybasis_params['per1'] = radvel.Parameter(value=20.885258)
    anybasis_params['tc1'] = radvel.Parameter(value=2072.79438)
    anybasis_params['e1'] = radvel.Parameter(value=0.01)
    anybasis_params['w1'] = radvel.Parameter(value=1.6)
    anybasis_params['k1'] = radvel.Parameter(value=10.0)

    anybasis_params['dvdt'] = radvel.Parameter(value=0.0)
    anybasis_params['curv'] = radvel.Parameter(value=0.0)

    anybasis_params['gamma_j'] = radvel.Parameter(1.0)
    anybasis_params['jit_j'] = radvel.Parameter(value=2.6)

    for new_basis in basis_list:
        iparams = radvel.basis._copy_params(anybasis_params)
        ivector = radvel.Vector(iparams)
        if new_basis != default_basis:
            new_vector = iparams.basis.v_to_any_basis(ivector, new_basis)
            new_params = iparams.basis.to_any_basis(iparams, new_basis)
            tmpv = new_vector.copy()
            tmp = radvel.basis._copy_params(new_params)

            old_vector = tmp.basis.v_to_any_basis(tmpv, default_basis)
            old_params = tmp.basis.to_any_basis(tmp, default_basis)

            for par in iparams:
                before = iparams[par].value
                after = old_params[par].value
                assert (before - after) <= 1e-5,\
                    "Parameters do not match after basis conversion: \
{}, {} != {}"             .format(par, before, after)

            for i in range(ivector.vector.shape[0]):
                before = ivector.vector[i][0]
                after = old_vector[i][0]
                assert (before - after) <= 1e-5, \
                    "Vectors do not match after basis conversion: \
{} row, {} != {}"                 .format(i, before, after)