Exemplo n.º 1
0
def test_straight_overhead():
    """
    With a precise CIRS<->AltAz transformation this should give Alt=90 exactly

    If the CIRS self-transform breaks it won't, due to improper treatment of aberration
    """
    t = Time('J2010')
    obj = EarthLocation(-1 * u.deg, 52 * u.deg, height=10. * u.km)
    home = EarthLocation(-1 * u.deg, 52 * u.deg, height=0. * u.km)

    # An object that appears straight overhead - FOR A GEOCENTRIC OBSERVER.
    # Note, this won't be overhead for a topocentric observer because of
    # aberration.
    cirs_geo = obj.get_itrs(t).transform_to(CIRS(obstime=t))

    # now get the Geocentric CIRS position of observatory
    obsrepr = home.get_itrs(t).transform_to(CIRS(obstime=t)).cartesian

    # topocentric CIRS position of a straight overhead object
    cirs_repr = cirs_geo.cartesian - obsrepr

    # create a CIRS object that appears straight overhead for a TOPOCENTRIC OBSERVER
    topocentric_cirs_frame = CIRS(obstime=t, location=home)
    cirs_topo = topocentric_cirs_frame.realize_frame(cirs_repr)

    # Check AltAz (though Azimuth can be anything so is not tested).
    aa = cirs_topo.transform_to(AltAz(obstime=t, location=home))
    assert_allclose(aa.alt, 90 * u.deg, atol=1 * u.uas, rtol=0)

    # Check HADec.
    hd = cirs_topo.transform_to(HADec(obstime=t, location=home))
    assert_allclose(hd.ha, 0 * u.hourangle, atol=1 * u.uas, rtol=0)
    assert_allclose(hd.dec, 52 * u.deg, atol=1 * u.uas, rtol=0)
Exemplo n.º 2
0
def test_gcrs_hadec():
    """
    Check GCRS<->HADec transforms for round-tripping.  Has multiple paths
    """
    from astropy.coordinates import EarthLocation

    usph = golden_spiral_grid(128)
    gcrs = GCRS(usph, obstime='J2000')  # broadcast with times below

    # check array times sure N-d arrays work
    times = Time(np.linspace(2456293.25, 2456657.25, 51) * u.day,
                 format='jd')[:, np.newaxis]

    loc = EarthLocation(lon=10 * u.deg, lat=80. * u.deg)
    hdframe = HADec(obstime=times, location=loc)

    hd1 = gcrs.transform_to(hdframe)
    hd2 = gcrs.transform_to(ICRS()).transform_to(CIRS()).transform_to(hdframe)
    hd3 = gcrs.transform_to(ITRS()).transform_to(CIRS()).transform_to(hdframe)

    # make sure they're all consistent
    assert_allclose(hd1.dec, hd2.dec)
    assert_allclose(hd1.ha, hd2.ha)
    assert_allclose(hd1.dec, hd3.dec)
    assert_allclose(hd1.ha, hd3.ha)
Exemplo n.º 3
0
def test_cirs_to_hadec():
    """
    Check the basic CIRS<->HADec transforms.
    """
    from astropy.coordinates import EarthLocation

    usph = golden_spiral_grid(200)
    dist = np.linspace(0.5, 1, len(usph)) * u.pc
    cirs = CIRS(usph, obstime='J2000')
    crepr = SphericalRepresentation(lon=usph.lon, lat=usph.lat, distance=dist)
    cirscart = CIRS(crepr,
                    obstime=cirs.obstime,
                    representation_type=CartesianRepresentation)

    loc = EarthLocation(lat=0 * u.deg, lon=0 * u.deg, height=0 * u.m)
    hadecframe = HADec(location=loc, obstime=Time('J2005'))

    cirs2 = cirs.transform_to(hadecframe).transform_to(cirs)
    cirs3 = cirscart.transform_to(hadecframe).transform_to(cirs)

    # check round-tripping
    assert_allclose(cirs.ra, cirs2.ra)
    assert_allclose(cirs.dec, cirs2.dec)
    assert_allclose(cirs.ra, cirs3.ra)
    assert_allclose(cirs.dec, cirs3.dec)
def test_icrs_hadec_consistency():
    """
    Check ICRS<->HADec for consistency with ICRS<->CIRS<->HADec
    """
    usph = golden_spiral_grid(200)
    dist = np.linspace(0.5, 1, len(usph)) * u.km * 1e5
    icoo = SkyCoord(ra=usph.lon, dec=usph.lat, distance=dist)

    observer = EarthLocation(28*u.deg, 23*u.deg, height=2000.*u.km)
    obstime = Time('J2010')
    hd_frame = HADec(obstime=obstime, location=observer)

    # check we are going direct!
    trans = frame_transform_graph.get_transform(ICRS, HADec).transforms
    assert(len(trans) == 1)

    # check that ICRS-HADec and ICRS->CIRS->HADec are consistent
    aa1 = icoo.transform_to(hd_frame)
    aa2 = icoo.transform_to(CIRS()).transform_to(hd_frame)
    assert_allclose(aa1.separation_3d(aa2), 0*u.mm, atol=1*u.mm)

    # check roundtrip
    roundtrip = icoo.transform_to(hd_frame).transform_to(icoo)
    assert_allclose(roundtrip.separation_3d(icoo), 0*u.mm, atol=1*u.mm)

    # check there and back via CIRS mish-mash
    roundtrip = icoo.transform_to(hd_frame).transform_to(
        CIRS()).transform_to(icoo)
    assert_allclose(roundtrip.separation_3d(icoo), 0*u.mm, atol=1*u.mm)
Exemplo n.º 5
0
def test_aa_hd_high_precision():
    """These tests are provided by @mkbrewer - see issue #10356.

    The code that produces them agrees very well (<0.5 mas) with SkyField once Polar motion
    is turned off, but SkyField does not include polar motion, so a comparison to Skyfield
    or JPL Horizons will be ~1" off.

    The absence of polar motion within Skyfield and the disagreement between Skyfield and Horizons
    make high precision comparisons to those codes difficult.

    Updated 2020-11-29, after the comparison between codes became even better,
    down to 100 nas.

    NOTE: the agreement reflects consistency in approach between two codes,
    not necessarily absolute precision.  If this test starts failing, the
    tolerance can and should be weakened *if* it is clear that the change is
    due to an improvement (e.g., a new IAU precession model).

    """
    lat = -22.959748 * u.deg
    lon = -67.787260 * u.deg
    elev = 5186 * u.m
    loc = EarthLocation.from_geodetic(lon, lat, elev)
    # Note: at this level of precision for the comparison, we have to include
    # the location in the time, as it influences the transformation to TDB.
    t = Time('2017-04-06T00:00:00.0', location=loc)
    with solar_system_ephemeris.set('de430'):
        moon = get_body('moon', t, loc)
        moon_aa = moon.transform_to(AltAz(obstime=t, location=loc))
        moon_hd = moon.transform_to(HADec(obstime=t, location=loc))

    # Numbers from
    # https://github.com/astropy/astropy/pull/11073#issuecomment-735486271
    # updated in https://github.com/astropy/astropy/issues/11683
    TARGET_AZ, TARGET_EL = 15.032673509956 * u.deg, 50.303110133923 * u.deg
    TARGET_DISTANCE = 376252883.247239 * u.m
    assert_allclose(moon_aa.az, TARGET_AZ, atol=0.1 * u.uas, rtol=0)
    assert_allclose(moon_aa.alt, TARGET_EL, atol=0.1 * u.uas, rtol=0)
    assert_allclose(moon_aa.distance, TARGET_DISTANCE, atol=0.1 * u.mm, rtol=0)
    ha, dec = erfa.ae2hd(moon_aa.az.to_value(u.radian),
                         moon_aa.alt.to_value(u.radian),
                         lat.to_value(u.radian))
    ha = u.Quantity(ha, u.radian, copy=False)
    dec = u.Quantity(dec, u.radian, copy=False)
    assert_allclose(moon_hd.ha, ha, atol=0.1 * u.uas, rtol=0)
    assert_allclose(moon_hd.dec, dec, atol=0.1 * u.uas, rtol=0)
Exemplo n.º 6
0
lon, lat = 7, 48
RA, DEC = 15, 35

ra, dec = radec_to_tete(RA, DEC, t)

ha = get_ha(ra, dec, (lon, lat), t)

from astropy.coordinates import SkyCoord, EarthLocation, AltAz, HADec
from astropy.time import Time
from astropy import units as u

tt = Time(t)
c = SkyCoord(ra=ra, dec=dec, unit='deg')
#c = c.tete
me = EarthLocation(lon=lon, lat=lat)
hadec = HADec(location=me, obstime=tt)
cc = c.transform_to(hadec)

print('Behrouz Hour angle:', ha)
print('Astropy Hour angle:', cc.ha.deg)

from hypatie.transform import radec_to_altaz

az, alt = radec_to_altaz(ra, dec, (lon, lat), t)
print(az, alt)

aa = AltAz(location=me, obstime=tt)
ccc = c.transform_to(aa)
print(ccc.az.value, ccc.alt.value)
#===================================================
ast_ha = cc.ha.deg