예제 #1
0
def test_convertLSRXYZUVWToAstrometry():
    """Checks Beta Pictoris is accurately handled"""
    astr_bp = [  # astrometry from wikiepdia
        86.82125,  #deg
        -51.0664,  #deg
        51.44,  #mas
        4.65,  #mas/yr
        83.1,  #mas/yr
        20.0  #km/s
    ]
    xyzuvw_bp_helio = np.array([-3.4, -16.4, -9.9, -11.0, -16.0, -9.1])
    xyzuvw_bp_lsr = cc.convert_helio2lsr(xyzuvw_bp_helio)

    calculated_astr_bp = cc.convert_lsrxyzuvw2astrometry(xyzuvw_bp_lsr)
    assert np.allclose(astr_bp, calculated_astr_bp, rtol=1e-2)

    calculated_xyzuvw_bp_lsr = cc.convert_astrometry2lsrxyzuvw(astr_bp)
    assert np.allclose(calculated_xyzuvw_bp_lsr, xyzuvw_bp_lsr, rtol=0.15)

    calculated_astr_bp2 = cc.convert_lsrxyzuvw2astrometry(xyzuvw_bp_lsr)
    calculated_xyzuvw_bp_lsr2 = cc.convert_astrometry2lsrxyzuvw(
        calculated_astr_bp2)
    assert np.allclose(calculated_xyzuvw_bp_lsr2, xyzuvw_bp_lsr)
예제 #2
0
def test_convertLSRXYZUVWToAstrometry():
    """Checks Beta Pictoris is accurately handled"""
    astr_bp = [ # astrometry from wikiepdia
        86.82125, #deg
        -51.0664, #deg
        51.44,  #mas
        4.65,  #mas/yr
        83.1,   #mas/yr
        20.0      #km/s
    ]
    xyzuvw_bp_helio = np.array([-3.4, -16.4, -9.9, -11.0, -16.0, -9.1])
    xyzuvw_bp_lsr = cc.convert_helio2lsr(xyzuvw_bp_helio)

    calculated_astr_bp = cc.convert_lsrxyzuvw2astrometry(xyzuvw_bp_lsr)
    assert np.allclose(astr_bp, calculated_astr_bp, rtol=1e-2)

    calculated_xyzuvw_bp_lsr = cc.convert_astrometry2lsrxyzuvw(astr_bp)
    assert np.allclose(calculated_xyzuvw_bp_lsr, xyzuvw_bp_lsr, rtol=0.15)

    calculated_astr_bp2 = cc.convert_lsrxyzuvw2astrometry(xyzuvw_bp_lsr)
    calculated_xyzuvw_bp_lsr2 = cc.convert_astrometry2lsrxyzuvw(
        calculated_astr_bp2
    )
    assert np.allclose(calculated_xyzuvw_bp_lsr2, xyzuvw_bp_lsr)
예제 #3
0
def test_convertAstrometryToLSRXYZUVW():
    """Check edge case of nearby sun, also compare with output of astropy"""
    # pick an astrometry which should be right near the sun
    sun_astro = (0., 90., 1e15, 0., 0., 0.)
    sun_xyzuvw_lsr = (0., 0., 25., 11.1, 12.24, 7.25)
    assert np.allclose(cc.convert_astrometry2lsrxyzuvw(sun_astro),
                       sun_xyzuvw_lsr)

    # TODO: compare astropy coordinates
    # will do this when upgraded to python 3
    star_astros = np.array([
        [86.82, -51.067, 51.44, 4.65, 83.1, 20],  # beta Pic
        [165.466, -34.705, 18.62, -66.19, -13.9, 13.4],  # TW Hya
        [82.187, -65.45, 65.93, 33.16, 150.83, 32.4],  # AB Dor
        [100.94, -71.977, 17.17, 6.17, 61.15, 20.7]  # HIP 32235
    ])
예제 #4
0
def test_convertAstrometryToLSRXYZUVW():
    """Check edge case of nearby sun, also compare with output of astropy"""
    # pick an astrometry which should be right near the sun
    sun_astro = (0., 90., 1e15, 0.,0.,0.)
    sun_xyzuvw_lsr = (0., 0., 25., 11.1, 12.24, 7.25)
    assert np.allclose(
        cc.convert_astrometry2lsrxyzuvw(sun_astro), sun_xyzuvw_lsr
    )

    # TODO: compare astropy coordinates
    # will do this when upgraded to python 3
    star_astros = np.array([
        [86.82, -51.067, 51.44, 4.65, 83.1, 20],        # beta Pic
        [165.466, -34.705, 18.62, -66.19, -13.9, 13.4], # TW Hya
        [82.187, -65.45, 65.93, 33.16, 150.83, 32.4],   # AB Dor
        [100.94, -71.977, 17.17, 6.17, 61.15, 20.7]     # HIP 32235
    ])
예제 #5
0
def convertRowToCartesian(row, row_ix=None, nrows=None):
    dim=6
    cart_col_names = ['X', 'Y', 'Z', 'U', 'V', 'W',
                      'dX', 'dY', 'dZ', 'dU', 'dV', 'dW',
                      'c_XY', 'c_XZ', 'c_XU', 'c_XV', 'c_XW',
                              'c_YZ', 'c_YU', 'c_YV', 'c_YW',
                                      'c_ZU', 'c_ZV', 'c_ZW',
                                              'c_UV', 'c_UW',
                                                      'c_VW']
    try:
        if row_ix % 100 == 0:
            print("{:010.7f}% done".format(row_ix / float(nrows) * 100.))
    except TypeError:
        pass
    astr_mean, astr_cov = datatool.convertRecToArray(row)
    xyzuvw_mean = coordinate.convert_astrometry2lsrxyzuvw(astr_mean)
    xyzuvw_cov = transform.transform_covmatrix(
        astr_cov,
        coordinate.convert_astrometry2lsrxyzuvw,
        astr_mean,
        dim=dim,
    )
    # fill in cartesian mean
    for col_ix, col_name in enumerate(cart_col_names[:6]):
        row[col_name] = xyzuvw_mean[col_ix]

    # fill in standard deviations
    xyzuvw_stds = np.sqrt(xyzuvw_cov[np.diag_indices(dim)])
    for col_ix, col_name in enumerate(cart_col_names[6:12]):
        row[col_name] = xyzuvw_stds[col_ix]

    correl_matrix = xyzuvw_cov / xyzuvw_stds / xyzuvw_stds.reshape(6, 1)
    # fill in correlations
    for col_ix, col_name in enumerate(cart_col_names[12:]):
        row[col_name] = correl_matrix[
            np.triu_indices(dim, k=1)[0][col_ix],
            np.triu_indices(dim, k=1)[1][col_ix]
        ]
예제 #6
0
    star_tab['radial_velocity'] = 16.44
    star_tab['radial_velocity_error'] = 1.

if np.isnan(star_tab['radial_velocity']):
    print("Its nan")

# extend proper motion uncertainty
star_tab['pmra_error'] *= 100.
star_tab['pmdec_error'] *= 100.
# star_tab['radial_velocity_error'] *= 10

astr_mean, astr_cov = dt.convertRecToArray(star_tab[0])

xyzuvw_cov = cv.transformAstrCovsToCartesian(np.array([astr_cov]),
                                             np.array([astr_mean])
                                             )[0]
xyzuvw = cc.convert_astrometry2lsrxyzuvw(astr_mean)

ln_bg_ols = dt.getKernelDensities(gaia_xyzuvw_file, [xyzuvw])

star_pars = {'xyzuvw':np.array([xyzuvw]),
             'xyzuvw_cov':np.array([xyzuvw_cov])}
nbp_stars = 100
ln_bp_ols = np.log(nbp_stars) + chronostar.likelihood.get_lnoverlaps(beta_fit.getInternalSphericalPars(), star_pars)

combined_lnols = np.hstack((ln_bp_ols, ln_bg_ols))

membership_probs = em.calc_membership_probs(combined_lnols)
print(membership_probs)

예제 #7
0
    cart_col_names = [
        'X', 'Y', 'Z', 'U', 'V', 'W', 'dX', 'dY', 'dZ', 'dU', 'dV', 'dW',
        'c_XY', 'c_XZ', 'c_XU', 'c_XV', 'c_XW', 'c_YZ', 'c_YU', 'c_YV', 'c_YW',
        'c_ZU', 'c_ZV', 'c_ZW', 'c_UV', 'c_UW', 'c_VW'
    ]

    # insert empty columns
    for col_name in cart_col_names:
        gt[col_name] = empty_col

    for row_ix, gt_row in enumerate(gt):
        dim = 6
        if row_ix % 10 == 0:
            print("{:02.2f}% done".format(row_ix / float(nrows) * 100.))
        astr_mean, astr_cov = gc.convertRecToArray(gt_row)
        xyzuvw_mean = coord.convert_astrometry2lsrxyzuvw(astr_mean)
        xyzuvw_cov = tf.transform_covmatrix(
            astr_cov,
            coord.convert_astrometry2lsrxyzuvw,
            astr_mean,
            dim=dim,
        )
        # fill in cartesian mean
        for col_ix, col_name in enumerate(cart_col_names[:6]):
            gt_row[col_name] = xyzuvw_mean[col_ix]

        # fill in standard deviations
        xyzuvw_stds = np.sqrt(xyzuvw_cov[np.diag_indices(dim)])
        for col_ix, col_name in enumerate(cart_col_names[6:12]):
            gt_row[col_name] = xyzuvw_stds[col_ix]
예제 #8
0
                      'c_XY', 'c_XZ', 'c_XU', 'c_XV', 'c_XW',
                              'c_YZ', 'c_YU', 'c_YV', 'c_YW',
                                      'c_ZU', 'c_ZV', 'c_ZW',
                                              'c_UV', 'c_UW',
                                                      'c_VW']

    # insert empty columns
    for col_name in cart_col_names:
        gt[col_name] = empty_col

    for row_ix, gt_row in enumerate(gt):
        dim = 6
        if row_ix%10 == 0:
            print("{:02.2f}% done".format(row_ix / float(nrows) * 100.))
        astr_mean, astr_cov = gc.convertRecToArray(gt_row)
        xyzuvw_mean = coord.convert_astrometry2lsrxyzuvw(astr_mean)
        xyzuvw_cov = tf.transform_covmatrix(
            astr_cov,
            coord.convert_astrometry2lsrxyzuvw,
            astr_mean,
            dim=dim,
        )
        # fill in cartesian mean
        for col_ix, col_name in enumerate(cart_col_names[:6]):
            gt_row[col_name] = xyzuvw_mean[col_ix]


        # fill in standard deviations
        xyzuvw_stds = np.sqrt(xyzuvw_cov[np.diag_indices(dim)])
        for col_ix, col_name in enumerate(cart_col_names[6:12]):
            gt_row[col_name] = xyzuvw_stds[col_ix]
예제 #9
0
    star_tab['radial_velocity'] = 16.44
    star_tab['radial_velocity_error'] = 1.

if np.isnan(star_tab['radial_velocity']):
    print("Its nan")

# extend proper motion uncertainty
star_tab['pmra_error'] *= 100.
star_tab['pmdec_error'] *= 100.
# star_tab['radial_velocity_error'] *= 10

astr_mean, astr_cov = dt.convertRecToArray(star_tab[0])

xyzuvw_cov = cv.transformAstrCovsToCartesian(np.array([astr_cov]),
                                             np.array([astr_mean]))[0]
xyzuvw = cc.convert_astrometry2lsrxyzuvw(astr_mean)

ln_bg_ols = dt.getKernelDensities(gaia_xyzuvw_file, [xyzuvw])

star_pars = {
    'xyzuvw': np.array([xyzuvw]),
    'xyzuvw_cov': np.array([xyzuvw_cov])
}
nbp_stars = 100
ln_bp_ols = np.log(nbp_stars) + chronostar.likelihood.get_lnoverlaps(
    beta_fit.getInternalSphericalPars(), star_pars)

combined_lnols = np.hstack((ln_bp_ols, ln_bg_ols))

membership_probs = em.calc_membership_probs(combined_lnols)
print(membership_probs)