Exemplo n.º 1
0
def test_model():
    df0 = df.iloc[0]
    xyz, vxyz = av.simple_calc_vxyz(df0.ra, df0.dec, 1./df0.parallax,
                                    df0.pmra, df0.pmdec, df0.radial_velocity)
    vx, vy, vz = vxyz.value
    pos = [df0.ra, df0.dec, df0.parallax]

    pm, rv = av.proper_motion_model([vx, vy, vz, np.log(1./df0.parallax)],
                                    pos)

    assert np.isclose(pm[0].value, df0.pmra, atol=1e-3)
    assert np.isclose(pm[1].value, df0.pmdec, atol=1e-3)
    assert np.isclose(rv.value, df0.radial_velocity, atol=1e-3)
Exemplo n.º 2
0
def test_similar_distributions():

    np.random.seed(42)

    # Calculate prior parameters from vx, vy, vz distributions
    df = pd.read_csv("../data/gaia_mc5_velocities.csv")
    m = df.radial_velocity.values != 0
    df = df.iloc[m]

    # Calculate covariance between velocities
    VX = np.stack((df.basic_vx.values, df.basic_vy.values,
                   df.basic_vz.values, np.log(1./df.parallax.values)), axis=0)
    mean = np.mean(VX, axis=1)
    cov = np.cov(VX)

    Nstars = 1000
    vxs, vys, vzs, lnds = np.random.multivariate_normal(mean, cov, Nstars).T

    ra = np.random.uniform(280, 300, Nstars)
    dec = np.random.uniform(36, 52, Nstars)

    pms, rvs = np.zeros((Nstars, 2)), np.zeros(Nstars)
    for i in range(Nstars):
        params = [vxs[i], vys[i], vzs[i], lnds[i]]
        pos = [ra[i], dec[i], 1./np.exp(lnds[i])]
        pm, rv = av.proper_motion_model(params, pos)
        pms[i, :] = pm.value
        rvs[i] = rv.value

    assert np.isclose(np.mean(df.radial_velocity), np.mean(rvs), atol=2)
    assert np.isclose(np.mean(df.pmra), np.mean(pms[:, 0]), atol=2)
    assert np.isclose(np.mean(df.pmdec), np.mean(pms[:, 1]), atol=2)

    assert np.isclose(np.std(df.radial_velocity), np.std(rvs), atol=2)
    assert np.isclose(np.std(df.pmra), np.std(pms[:, 0]), atol=2)
    assert np.isclose(np.std(df.pmdec), np.std(pms[:, 1]), atol=2)
Exemplo n.º 3
0
df1 = vels.iloc[m]

df2 = pd.merge(df1, df, on="kepid", how="right")

# Calculate vx vz and vy from the data and rv and pm from the inferred params.
vx_true, vy_true, vz_true = [], [], []
pmra_inf, pmdec_inf, rv_inf = [], [], []
for i in trange(len(df2)):
    params = [
        df2.vx_inferred.values[i], df2.vy_inferred.values[i],
        df2.vz_inferred.values[i], df2.lndistance_inferred.values[i]
    ]
    pos = [df2.ra.values[i], df2.dec.values[i], df2.parallax.values[i]]
    # pos = [df2.ra.values[i], df2.dec.values[i],
    #        1./np.exp(df2.lndistance_inferred.values[i])]
    _pm, _rv = av.proper_motion_model(params, pos)
    pmra_inf.append(_pm[0].value)
    pmdec_inf.append(_pm[1].value)
    rv_inf.append(_rv.value)

    xyz, vxyz = av.simple_calc_vxyz(df2.ra[i], df2.dec[i],
                                    1. / df2.parallax[i], df2.pmra[i],
                                    df2.pmdec[i], df2.radial_velocity[i])
    vx_true.append(vxyz.value[0])
    vy_true.append(vxyz.value[1])
    vz_true.append(vxyz.value[2])

df2["vx_true"] = np.array(vx_true)
df2["vy_true"] = np.array(vy_true)
df2["vz_true"] = np.array(vz_true)
df2["pmra_inferred"] = np.array(pmra_inf)
Exemplo n.º 4
0
def test_model():

    # Test the function by transforming a coordinate to galactocentric
    # coords and back:
    c = coord.SkyCoord(ra=61.342 * u.deg,
                       dec=17 * u.deg,
                       distance=3 * u.kpc,
                       pm_ra_cosdec=4.2 * u.mas / u.yr,
                       pm_dec=-7.2 * u.mas / u.yr,
                       radial_velocity=17 * u.km / u.s)

    test_galcen = c.transform_to(galcen_frame)

    test_pm, test_rv = av.get_icrs_from_galactocentric(
        test_galcen.data.xyz, test_galcen.velocity.d_xyz, R_gal, sun_xyz,
        sun_vxyz)

    vx = test_galcen.velocity.d_xyz[0].value
    vy = test_galcen.velocity.d_xyz[1].value
    vz = test_galcen.velocity.d_xyz[2].value
    params = [vx, vy, vz, np.log(3)]
    pos = [61.342, 17, 1. / 3]
    pm_from_v, rv_from_v = av.proper_motion_model(params, pos)

    assert np.isclose(4.2, test_pm[0].value, atol=1e-4)
    assert np.isclose(4.2, pm_from_v[0].value, atol=1e-4)
    assert np.isclose(-7.2, test_pm[1].value, atol=1e-4)
    assert np.isclose(-7.2, pm_from_v[1].value, atol=1e-4)
    assert np.isclose(17, test_rv.value, atol=1e-4)
    assert np.isclose(17, rv_from_v.value, atol=1e-4)

    df0 = pd.read_csv("../data/gaia_mc5_velocities.csv")
    m = np.isfinite(df0.vz.values)
    df = df0.iloc[m]

    i = 0
    df1 = df.iloc[i]

    ra, dec, plx = df1.ra, df1.dec, df1.parallax
    ra_err, dec_err, plx_err = df1.ra_error, df1.dec_error, df1.parallax_error
    pmra, pmdec, rv = df1.pmra, df1.pmdec, df1.radial_velocity
    pmra_err, pmdec_err, rv_err = df1.pmra_error, df1.pmdec_error, \
            df1.radial_velocity_error

    #Test the function by transforming a coordinate to galactocentric and back:
    c = coord.SkyCoord(ra=ra * u.deg,
                       dec=dec * u.deg,
                       distance=(1. / plx) * u.kpc,
                       pm_ra_cosdec=pmra * u.mas / u.yr,
                       pm_dec=pmdec * u.mas / u.yr,
                       radial_velocity=rv * u.km / u.s)

    test_galcen = c.transform_to(galcen_frame)
    test_pm, test_rv = av.get_icrs_from_galactocentric(
        test_galcen.data.xyz, test_galcen.velocity.d_xyz, R_gal, sun_xyz,
        sun_vxyz)

    vx = test_galcen.velocity.d_xyz[0].value
    vy = test_galcen.velocity.d_xyz[1].value
    vz = test_galcen.velocity.d_xyz[2].value

    xyz, vxyz = av.simple_calc_vxyz(ra, dec, 1. / plx, pmra, pmdec, rv)
    _vx, _vy, _vz = vxyz

    params = [vx, vy, vz, np.log(1. / plx)]
    pos = [ra, dec, 1. / plx]
    pm_from_v, rv_from_v = av.proper_motion_model(params, pos)
    vpars = [
        df1.basic_vx, df1.basic_vy, df1.basic_vz,
        np.log(1. / df1.parallax)
    ]
    pm2, rv2 = av.proper_motion_model(vpars, pos)

    assert np.isclose(pmra, test_pm[0].value, atol=1e-4)
    assert np.isclose(pmra, pm_from_v[0].value, atol=1e-4)
    assert np.isclose(pmra, pm2[0].value, atol=1e-4)
    assert np.isclose(pmdec, test_pm[1].value, atol=1e-4)
    assert np.isclose(pmdec, pm_from_v[1].value, atol=1e-4)
    assert np.isclose(pmdec, pm2[1].value, atol=1e-4)
    assert np.isclose(rv, test_rv.value, atol=1e-4)
    assert np.isclose(rv, rv_from_v.value, atol=1e-4)
    assert np.isclose(rv, rv2.value, atol=1e-4)