def test_concatenate_representations_different_units(): from astropy.coordinates.funcs import concatenate_representations from astropy.coordinates import representation as r reps = [r.CartesianRepresentation([1, 2, 3.]*u.pc), r.CartesianRepresentation([1, 2, 3.]*u.kpc)] concat = concatenate_representations(reps) assert concat.shape == (2,) assert np.all(concat.xyz == ([[1., 2., 3.], [1000., 2000., 3000.]] * u.pc).T)
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])