def test_is_frame_attr_default(): """ Check that the `is_frame_attr_default` machinery works as expected """ from astropy.time import Time from astropy.coordinates.builtin_frames import FK5 c1 = FK5(ra=1 * u.deg, dec=1 * u.deg) c2 = FK5(ra=1 * u.deg, dec=1 * u.deg, equinox=FK5.get_frame_attr_names()['equinox']) c3 = FK5(ra=1 * u.deg, dec=1 * u.deg, equinox=Time('J2001.5')) assert c1.equinox == c2.equinox assert c1.equinox != c3.equinox assert c1.is_frame_attr_default('equinox') assert not c2.is_frame_attr_default('equinox') assert not c3.is_frame_attr_default('equinox') c4 = c1.realize_frame(r.UnitSphericalRepresentation(3 * u.deg, 4 * u.deg)) c5 = c2.realize_frame(r.UnitSphericalRepresentation(3 * u.deg, 4 * u.deg)) assert c4.is_frame_attr_default('equinox') assert not c5.is_frame_attr_default('equinox')
def test_create_data_frames(): from astropy.coordinates.builtin_frames import ICRS # from repr i1 = ICRS(r.SphericalRepresentation(1 * u.deg, 2 * u.deg, 3 * u.kpc)) i2 = ICRS(r.UnitSphericalRepresentation(lon=1 * u.deg, lat=2 * u.deg)) # from preferred name i3 = ICRS(ra=1 * u.deg, dec=2 * u.deg, distance=3 * u.kpc) i4 = ICRS(ra=1 * u.deg, dec=2 * u.deg) assert i1.data.lat == i3.data.lat assert i1.data.lon == i3.data.lon assert i1.data.distance == i3.data.distance assert i2.data.lat == i4.data.lat assert i2.data.lon == i4.data.lon # now make sure the preferred names work as properties assert_allclose(i1.ra, i3.ra) assert_allclose(i2.ra, i4.ra) assert_allclose(i1.distance, i3.distance) with pytest.raises(AttributeError): i1.ra = [11.] * u.deg
def test_concatenate_representations(): from astropy.coordinates.funcs import concatenate_representations from astropy.coordinates import representation as r reps = [r.CartesianRepresentation([1, 2, 3.]*u.kpc), r.SphericalRepresentation(lon=1*u.deg, lat=2.*u.deg, distance=10*u.pc), r.UnitSphericalRepresentation(lon=1*u.deg, lat=2.*u.deg), r.CartesianRepresentation(np.ones((3, 100)) * u.kpc), r.CartesianRepresentation(np.ones((3, 16, 8)) * u.kpc)] reps.append(reps[0].with_differentials( r.CartesianDifferential([1, 2, 3.] * u.km/u.s))) reps.append(reps[1].with_differentials( r.SphericalCosLatDifferential(1*u.mas/u.yr, 2*u.mas/u.yr, 3*u.km/u.s))) reps.append(reps[2].with_differentials( r.SphericalCosLatDifferential(1*u.mas/u.yr, 2*u.mas/u.yr, 3*u.km/u.s))) reps.append(reps[2].with_differentials( r.UnitSphericalCosLatDifferential(1*u.mas/u.yr, 2*u.mas/u.yr))) reps.append(reps[2].with_differentials( {'s': r.RadialDifferential(1*u.km/u.s)})) reps.append(reps[3].with_differentials( r.CartesianDifferential(*np.ones((3, 100)) * u.km/u.s))) reps.append(reps[4].with_differentials( r.CartesianDifferential(*np.ones((3, 16, 8)) * u.km/u.s))) # Test that combining all of the above with itself succeeds for rep in reps: if not rep.shape: expected_shape = (2, ) else: expected_shape = (2 * rep.shape[0], ) + rep.shape[1:] tmp = concatenate_representations((rep, rep)) assert tmp.shape == expected_shape if 's' in rep.differentials: assert tmp.differentials['s'].shape == expected_shape # Try combining 4, just for something different for rep in reps: if not rep.shape: expected_shape = (4, ) else: expected_shape = (4 * rep.shape[0], ) + rep.shape[1:] tmp = concatenate_representations((rep, rep, rep, rep)) assert tmp.shape == expected_shape if 's' in rep.differentials: assert tmp.differentials['s'].shape == expected_shape # Test that combining pairs fails with pytest.raises(TypeError): concatenate_representations((reps[0], reps[1])) with pytest.raises(ValueError): concatenate_representations((reps[0], reps[5])) # Check that passing in a single object fails with pytest.raises(TypeError): concatenate_representations(reps[0])
# Check that if frame somehow gets through to transformation, multiple # differentials are caught c = TCoo1(rep.without_differentials()) c._data = c._data.with_differentials({'s': dif1, 's2': dif2}) with pytest.raises(ValueError): c.transform_to(TCoo2()) trans.unregister(frame_transform_graph) # A matrix transform of a unit spherical with differentials should work @pytest.mark.parametrize('rep', [ r.UnitSphericalRepresentation(lon=15*u.degree, lat=-11*u.degree, differentials=r.SphericalDifferential(d_lon=15*u.mas/u.yr, d_lat=11*u.mas/u.yr, d_distance=-110*u.km/u.s)), r.UnitSphericalRepresentation(lon=15*u.degree, lat=-11*u.degree, differentials={'s': r.RadialDifferential(d_distance=-110*u.km/u.s)}), r.SphericalRepresentation(lon=15*u.degree, lat=-11*u.degree, distance=150*u.pc, differentials={'s': r.RadialDifferential(d_distance=-110*u.km/u.s)}) ]) def test_unit_spherical_with_differentials(rep): c = TCoo1(rep) # register and do the transformation and check against expected trans = t.AffineTransform(transfunc.just_matrix, TCoo1, TCoo2) trans.register(frame_transform_graph) c2 = c.transform_to(TCoo2())