def test_icrs_consistency(): """ Check ICRS<->AltAz for consistency with ICRS<->CIRS<->AltAz The latter is extensively tested in test_intermediate_transformations.py """ ra, dec, dist = randomly_sample_sphere(200) icoo = SkyCoord(ra=ra, dec=dec, distance=dist * u.km * 1e5) observer = EarthLocation(28 * u.deg, 23 * u.deg, height=2000. * u.km) obstime = Time('J2010') aa_frame = AltAz(obstime=obstime, location=observer) # check we are going direct! trans = frame_transform_graph.get_transform(ICRS, AltAz).transforms assert (len(trans) == 1) # check that ICRS-AltAz and ICRS->CIRS->AltAz are consistent aa1 = icoo.transform_to(aa_frame) aa2 = icoo.transform_to(CIRS()).transform_to(aa_frame) assert_allclose(aa1.separation_3d(aa2), 0 * u.mm, atol=1 * u.mm) # check roundtrip roundtrip = icoo.transform_to(aa_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(aa_frame).transform_to( CIRS()).transform_to(icoo) assert_allclose(roundtrip.separation_3d(icoo), 0 * u.mm, atol=1 * u.mm)
def test_gcrs_cirs(): """ Check GCRS<->CIRS transforms for round-tripping. More complicated than the above two because it's multi-hop """ ra, dec, _ = randomly_sample_sphere(200) gcrs = GCRS(ra=ra, dec=dec, obstime='J2000') gcrs6 = GCRS(ra=ra, dec=dec, obstime='J2006') gcrs2 = gcrs.transform_to(CIRS()).transform_to(gcrs) gcrs6_2 = gcrs6.transform_to(CIRS()).transform_to(gcrs) assert_allclose(gcrs.ra, gcrs2.ra) assert_allclose(gcrs.dec, gcrs2.dec) assert not allclose(gcrs.ra, gcrs6_2.ra) assert not allclose(gcrs.dec, gcrs6_2.dec) # now try explicit intermediate pathways and ensure they're all consistent gcrs3 = gcrs.transform_to(ITRS()).transform_to(CIRS()).transform_to( ITRS()).transform_to(gcrs) assert_allclose(gcrs.ra, gcrs3.ra) assert_allclose(gcrs.dec, gcrs3.dec) gcrs4 = gcrs.transform_to(ICRS()).transform_to(CIRS()).transform_to( ICRS()).transform_to(gcrs) assert_allclose(gcrs.ra, gcrs4.ra) assert_allclose(gcrs.dec, gcrs4.dec)
def test_cirs_to_altaz(): """ Check the basic CIRS<->AltAz transforms. More thorough checks implicitly happen in `test_iau_fullstack` """ from astropy.coordinates import EarthLocation ra, dec, dist = randomly_sample_sphere(200) cirs = CIRS(ra=ra, dec=dec, obstime='J2000') crepr = SphericalRepresentation(lon=ra, lat=dec, 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) altazframe = AltAz(location=loc, obstime=Time('J2005')) cirs2 = cirs.transform_to(altazframe).transform_to(cirs) cirs3 = cirscart.transform_to(altazframe).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_gcrs_altaz(): """ Check GCRS<->AltAz transforms for round-tripping. Has multiple paths """ from astropy.coordinates import EarthLocation ra, dec, _ = randomly_sample_sphere(1) gcrs = GCRS(ra=ra[0], dec=dec[0], obstime='J2000') # check array times sure N-d arrays work times = Time(np.linspace(2456293.25, 2456657.25, 51) * u.day, format='jd') loc = EarthLocation(lon=10 * u.deg, lat=80. * u.deg) aaframe = AltAz(obstime=times, location=loc) aa1 = gcrs.transform_to(aaframe) aa2 = gcrs.transform_to(ICRS()).transform_to(CIRS()).transform_to(aaframe) aa3 = gcrs.transform_to(ITRS()).transform_to(CIRS()).transform_to(aaframe) # make sure they're all consistent assert_allclose(aa1.alt, aa2.alt) assert_allclose(aa1.az, aa2.az) assert_allclose(aa1.alt, aa3.alt) assert_allclose(aa1.az, aa3.az)
def test_interpolation_broadcasting(): from astropy.coordinates.tests.utils import randomly_sample_sphere from astropy.coordinates import SkyCoord, EarthLocation, AltAz from astropy.time import Time import astropy.units as u from astropy.coordinates.erfa_astrom import erfa_astrom, ErfaAstromInterpolator # 1000 random locations on the sky ra, dec, _ = randomly_sample_sphere(100) coord = SkyCoord(ra, dec) # 30 times over the space of 1 hours times = Time('2020-01-01T20:00') + np.linspace(-0.5, 0.5, 30) * u.hour lst1 = EarthLocation( lon=-17.891498 * u.deg, lat=28.761443 * u.deg, height=2200 * u.m, ) # note the use of broadcasting so that 300 times are broadcast against 1000 positions aa_frame = AltAz(obstime=times[:, np.newaxis], location=lst1) aa_coord = coord.transform_to(aa_frame) with erfa_astrom.set(ErfaAstromInterpolator(300 * u.s)): aa_coord_interp = coord.transform_to(aa_frame) assert aa_coord.shape == aa_coord_interp.shape assert np.all(aa_coord.separation(aa_coord_interp) < 1 * u.microarcsecond)
def test_cirs_itrs(): """ Check basic CIRS<->ITRS transforms for round-tripping. """ ra, dec, _ = randomly_sample_sphere(200) cirs = CIRS(ra=ra, dec=dec, obstime='J2000') cirs6 = CIRS(ra=ra, dec=dec, obstime='J2006') cirs2 = cirs.transform_to(ITRS()).transform_to(cirs) cirs6_2 = cirs6.transform_to(ITRS()).transform_to(cirs) # different obstime # just check round-tripping assert_allclose(cirs.ra, cirs2.ra) assert_allclose(cirs.dec, cirs2.dec) assert not allclose(cirs.ra, cirs6_2.ra) assert not allclose(cirs.dec, cirs6_2.dec)
def test_icrs_cirs(): """ Check a few cases of ICRS<->CIRS for consistency. Also includes the CIRS<->CIRS transforms at different times, as those go through ICRS """ ra, dec, dist = randomly_sample_sphere(200) inod = ICRS(ra=ra, dec=dec) iwd = ICRS(ra=ra, dec=dec, distance=dist * u.pc) cframe1 = CIRS() cirsnod = inod.transform_to(cframe1) # uses the default time # first do a round-tripping test inod2 = cirsnod.transform_to(ICRS()) assert_allclose(inod.ra, inod2.ra) assert_allclose(inod.dec, inod2.dec) # now check that a different time yields different answers cframe2 = CIRS(obstime=Time('J2005')) cirsnod2 = inod.transform_to(cframe2) assert not allclose(cirsnod.ra, cirsnod2.ra, rtol=1e-8) assert not allclose(cirsnod.dec, cirsnod2.dec, rtol=1e-8) # parallax effects should be included, so with and w/o distance should be different cirswd = iwd.transform_to(cframe1) assert not allclose(cirswd.ra, cirsnod.ra, rtol=1e-8) assert not allclose(cirswd.dec, cirsnod.dec, rtol=1e-8) # and the distance should transform at least somehow assert not allclose(cirswd.distance, iwd.distance, rtol=1e-8) # now check that the cirs self-transform works as expected cirsnod3 = cirsnod.transform_to(cframe1) # should be a no-op assert_allclose(cirsnod.ra, cirsnod3.ra) assert_allclose(cirsnod.dec, cirsnod3.dec) cirsnod4 = cirsnod.transform_to(cframe2) # should be different assert not allclose(cirsnod4.ra, cirsnod.ra, rtol=1e-8) assert not allclose(cirsnod4.dec, cirsnod.dec, rtol=1e-8) cirsnod5 = cirsnod4.transform_to(cframe1) # should be back to the same assert_allclose(cirsnod.ra, cirsnod5.ra) assert_allclose(cirsnod.dec, cirsnod5.dec)
def test_gcrs_itrs(): """ Check basic GCRS<->ITRS transforms for round-tripping. """ ra, dec, _ = randomly_sample_sphere(200) gcrs = GCRS(ra=ra, dec=dec, obstime='J2000') gcrs6 = GCRS(ra=ra, dec=dec, obstime='J2006') gcrs2 = gcrs.transform_to(ITRS()).transform_to(gcrs) gcrs6_2 = gcrs6.transform_to(ITRS()).transform_to(gcrs) assert_allclose(gcrs.ra, gcrs2.ra) assert_allclose(gcrs.dec, gcrs2.dec) assert not allclose(gcrs.ra, gcrs6_2.ra) assert not allclose(gcrs.dec, gcrs6_2.dec) # also try with the cartesian representation gcrsc = gcrs.realize_frame(gcrs.data) gcrsc.representation_type = CartesianRepresentation gcrsc2 = gcrsc.transform_to(ITRS()).transform_to(gcrsc) assert_allclose(gcrsc.spherical.lon.deg, gcrsc2.ra.deg) assert_allclose(gcrsc.spherical.lat, gcrsc2.dec)
# now check that the cirs self-transform works as expected cirsnod3 = cirsnod.transform_to(cframe1) # should be a no-op assert_allclose(cirsnod.ra, cirsnod3.ra) assert_allclose(cirsnod.dec, cirsnod3.dec) cirsnod4 = cirsnod.transform_to(cframe2) # should be different assert not allclose(cirsnod4.ra, cirsnod.ra, rtol=1e-8) assert not allclose(cirsnod4.dec, cirsnod.dec, rtol=1e-8) cirsnod5 = cirsnod4.transform_to(cframe1) # should be back to the same assert_allclose(cirsnod.ra, cirsnod5.ra) assert_allclose(cirsnod.dec, cirsnod5.dec) ra, dec, dist = randomly_sample_sphere(200) icrs_coords = [ ICRS(ra=ra, dec=dec), ICRS(ra=ra, dec=dec, distance=dist * u.pc) ] gcrs_frames = [GCRS(), GCRS(obstime=Time('J2005'))] @pytest.mark.parametrize('icoo', icrs_coords) def test_icrs_gcrs(icoo): """ Check ICRS<->GCRS for consistency """ gcrscoo = icoo.transform_to(gcrs_frames[0]) # uses the default time # first do a round-tripping test icoo2 = gcrscoo.transform_to(ICRS())
vmin = -0.5 vmax = 0.5 ## Area calc. Area = 0.0 nrand = np.int(5e5) ## LSST FOV radius in deg. LSST_rad = 3.5 / 2. field_cat = SkyCoord(ra=[hitmap[field]['RA'] * u.degree for field in inLSST],\ dec=[hitmap[field]['DEC'] * u.degree for field in inLSST]) rand_ra, rand_dec, _ = randomly_sample_sphere(nrand) rand_ra = rand_ra.to(u.deg) rand_dec = rand_dec.to(u.deg) rand_cat = SkyCoord(ra=rand_ra, dec=rand_dec) idxc, idxcatalog, d2d, _ = rand_cat.search_around_sky( field_cat, LSST_rad * u.deg) nrand_inlsst = len(rand_cat[idxcatalog]) ## Can check by plotting random distribution. ## ## for i, x in enumerate(rand_cat[idxcatalog]): ## x, y = radec2project(x.ra.value, x.dec.value)