예제 #1
0
def test_venus_position2():
    # *******************************************************************************
    # Target body name: Venus (299)                     {source: CHANDRA_MERGED}
    # Center body name: Chandra Observatory (spacecraft) (-151) {source: CHANDRA_MERGED}
    # Center-site name: BODYCENTRIC
    # *******************************************************************************
    # Start time      : A.D. 2020-Jan-01 00:00:00.0000 UT
    # Stop  time      : A.D. 2020-Jun-01 00:00:00.0000 UT
    # Step-size       : 21600 minutes
    # *******************************************************************************

    txt = """
        date                   ra         dec
        2020-01-01T00:00     21:08:43.02 -18:22:41.8
        2020-01-16T00:00     22:19:56.31 -12:03:15.4
        2020-01-31T00:00     23:26:25.34 -04:40:18.3
        2020-02-15T00:00     00:29:55.07 +03:09:41.1
        2020-03-01T00:00     01:31:42.96 +10:46:02.6
        2020-03-16T00:00     02:32:52.02 +17:25:28.9
        2020-03-31T00:00     03:32:39.01 +22:40:58.7
        2020-04-15T00:00     04:26:52.03 +26:10:57.3
        2020-04-30T00:00     05:07:55.28 +27:38:30.8
        2020-05-15T00:00     05:22:08.73 +27:05:38.1
        2020-05-30T00:00     04:59:36.37 +24:14:26.9
    """
    dat = ascii.read(txt)
    date = CxoTime(dat['date'])
    sc = SkyCoord(dat['ra'], dat['dec'], unit=(u.hr, u.deg))

    eci = get_planet_chandra('venus', date)
    ra, dec = eci_to_radec(eci)

    dist = sphere_dist(ra, dec, sc.ra.to_value(u.deg), sc.dec.to_value(u.deg)) * 3600
    assert np.all(dist < 4.0)
예제 #2
0
def _test_agasc(ra, dec, radius=1.4, agasc_file=None):
    stars1 = agasc.get_agasc_cone(ra, dec, radius=radius, agasc_file=agasc_file,
                                  date='2000:001')
    stars1.sort('AGASC_ID')

    stars2 = mp_get_agasc(ra, dec, radius)
    stars2.sort('AGASC_ID')

    # First make sure that the common stars are identical
    agasc_ids = set(stars1['AGASC_ID']).intersection(set(stars2['AGASC_ID']))
    for agasc_id in agasc_ids:
        star1 = stars1[np.searchsorted(stars1['AGASC_ID'], agasc_id)]
        star2 = stars2[np.searchsorted(stars2['AGASC_ID'], agasc_id)]
        for colname in AGASC_COLNAMES:
            if star1[colname].dtype.kind == 'f':
                assert np.all(np.abs(star1[colname] - star2[colname]) < 1e-4)
            else:
                assert star1[colname] == star2[colname]

    # Second make sure that the non-common stars are all just at the edge
    # of the faint mag limit, due to precision loss in mp_get_agasc
    for s1, s2 in ((stars1, stars2),
                   (stars2, stars1)):
        mm1 = set(s1['AGASC_ID']) - set(s2['AGASC_ID'])
        for agasc_id in mm1:
            idx = np.flatnonzero(s1['AGASC_ID'] == agasc_id)[0]
            star = s1[idx]
            bad_is_star1 = s1 is stars1
            rad = agasc.sphere_dist(ra, dec, star['RA'], star['DEC'])
            adj_mag = star['MAG_ACA'] - 3.0 * star['MAG_ACA_ERR'] / 100.0
            if adj_mag < 11.5 * 0.99:
                # Allow for loss of precision in output of mp_get_agasc
                print('Bad star', agasc_id, rad, adj_mag, bad_is_star1)
                assert False
예제 #3
0
def get_planet_angular_sep(body: str,
                           ra: float,
                           dec: float,
                           time=None,
                           observer_position: str = 'earth') -> float:
    """Get angular separation between planet ``body`` and target ``ra``, ``dec``.

    Valid values for the ``observer_position`` argument are:

    - 'earth' (default, approximate, fastest)
    - 'chandra' (reasonably accurate fast, requires fetching ephemeris)
    - 'chandra-horizons' (most accurate, slow, requires internet access)

    :param body: str
        Body name (lower case planet name)
    :param ra: float
        RA in degrees
    :param dec: float
        Dec in degrees
    :param time: CxoTime-compatible object
        Time or times of observation
    :param observer_position: str
        Observer position ('earth', 'chandra', or 'chandra-horizons')

    :returns: angular separation (deg)
    """
    from agasc import sphere_dist
    if not isinstance(time, CxoTime):
        time = CxoTime(time)

    if observer_position == 'earth':
        eci = get_planet_eci(body, time)
        body_ra, body_dec = eci_to_radec(eci)
    elif observer_position == 'chandra':
        eci = get_planet_chandra(body, time)
        body_ra, body_dec = eci_to_radec(eci)
    elif observer_position == 'chandra-horizons':
        if time.shape == ():
            time = CxoTime([time, time + 1000 * u.s])
            is_scalar = True
        else:
            is_scalar = False
        pos = get_planet_chandra_horizons(body,
                                          time[0],
                                          time[1],
                                          n_times=len(time))
        body_ra = pos['ra']
        body_dec = pos['dec']
        if is_scalar:
            body_ra = body_ra[0]
            body_dec = body_dec[0]
    else:
        raise ValueError(f'{observer_position} is not an allowed value: '
                         f'("earth", "chandra", or "chandra-horizons")')

    sep = sphere_dist(ra, dec, body_ra, body_dec)
    return sep
예제 #4
0
def mp_get_agasc(ra, dec, radius):
    cmd = 'mp_get_agasc -r {!r} -d {!r} -w {!r}'.format(ra, dec, radius * 1.5)
    lines = Ska.Shell.tcsh(cmd, env=ascds_env)
    dat = ascii.read(lines, Reader=ascii.NoHeader, names=AGASC_COLNAMES)

    ok1 = agasc.sphere_dist(ra, dec, dat['RA'], dat['DEC']) <= radius
    ok2 = dat['MAG_ACA'] - 3.0 * dat['MAG_ACA_ERR'] / 100.0 < 11.5
    dat = dat[ok1 & ok2]

    return dat
예제 #5
0
def test_planet_positions_array():
    bary = get_planet_barycentric('saturn', ['2020:324:11:44:00', '2020:324:11:44:01'])
    assert bary.shape == (2, 3)

    eci = get_planet_eci('saturn', ['2020:324:11:44:00', '2020:324:11:44:01'])
    assert eci.shape == (2, 3)

    eci = get_planet_chandra('saturn', ['2020:324:11:44:00', '2020:324:11:44:01'])
    assert eci.shape == (2, 3)
    ra, dec = eci_to_radec(eci)

    # Value from JPL Horizons (Saturn from Chandra Observatory -151)
    ra2, dec2 = 299.27358333, -21.07644444

    assert np.all(sphere_dist(ra, dec, ra2, dec2) * 3600 < 1.0)
예제 #6
0
def make_ras_decs_stars_list():
    """
    Messed up a bit in make_ra_dec_stars list.  Should have added radii and pickled
    a more sensible object.  Fix this here.
    """
    ra_dec_stars_list = pickle.load(open('ra_dec_stars_list.pkl', 'rb'))
    ras = np.array([x[0] for x in ra_dec_stars_list])
    decs = np.array([x[1] for x in ra_dec_stars_list])
    stars_list = []
    for ra, dec, stars in ra_dec_stars_list:
        sys.stdout.write('{:9.3f} {:9.3f}\r'.format(ra, dec))
        radii = agasc.sphere_dist(ra, dec, stars['RA'], stars['DEC'])
        stars = Table(stars)
        stars.add_column(Column(name='radius', data=radii))
        stars_list.append(np.array(stars))
    sys.stdout.write('\n\n')
    pickle.dump([ras, decs, stars_list], open('ras_decs_stars_list.pkl', 'rb'), protocol=-1)
예제 #7
0
def test_venus_position1():
    """Obsid 18695 starcat at 2017:010:05:07:20.875, approx obs star 0510z"""

    # Output from JPL Horizons for Venus from Chandra
    date = CxoTime('2017-01-10T05:10')
    sc = SkyCoord('22:36:02.59', '-09:39:07.2', unit=(u.hr, u.deg))
    q_att = [-0.54137601, 0.17071483, -0.10344611, 0.81674192]

    eci = get_planet_chandra('venus', date)
    ra, dec = eci_to_radec(eci)
    yag, zag = radec_to_yagzag(ra, dec, q_att)
    # Confirm yag value is on "left side" of CCD, opposite all stars in 18695
    assert np.isclose(yag, 210.20, rtol=0, atol=0.01)
    assert np.isclose(zag, 69.45, rtol=0, atol=0.01)

    dist = sphere_dist(ra, dec, sc.ra.to_value(u.deg), sc.dec.to_value(u.deg)) * 3600
    assert np.all(dist < 4.0)
예제 #8
0
def test_planet_positions():
    # Test basic functionality and include regression values (not an independent
    # functional test)
    bary = get_planet_barycentric('saturn', '2020:324:11:44:00')
    assert np.allclose(bary, [7.92469846e+08, -1.15786689e+09, -5.12388561e+08])

    eci = get_planet_eci('saturn', '2020:324:11:44:00')
    assert np.allclose(eci, [7.13565053e+08, -1.27291136e+09, -5.62273593e+08])

    eci = get_planet_chandra('saturn', '2020:324:11:44')
    assert np.allclose(eci, [7.13516810e+08, -1.27285190e+09, -5.62368753e+08])

    # Independent functional test to compare with JPL Horizons (Saturn from
    # Chandra Observatory -151)
    ra, dec = eci_to_radec(eci)
    ra2, dec2 = 299.27358333, -21.07644444

    assert sphere_dist(ra, dec, ra2, dec2) * 3600 < 1.0