Skip to content

Commit e96db68

Browse files
authored
Merge pull request astropy#7387 from adrn/coordinates/sep3d-with-diffs
Fix bug with separation_3d failing when velocity data present
2 parents a8b1bf7 + 4c8c731 commit e96db68

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎CHANGES.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ astropy.convolution
277277
astropy.coordinates
278278
^^^^^^^^^^^^^^^^^^^
279279

280+
- Computing a 3D separation between two ``SkyCoord`` objects (with the
281+
``separation_3d`` method) now works with or without velocity data attached to
282+
the objects. [#7387]
283+
280284
astropy.cosmology
281285
^^^^^^^^^^^^^^^^^
282286

‎astropy/coordinates/sky_coordinate.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,9 @@ def separation_3d(self, other):
978978
raise ValueError('The other object does not have a distance; '
979979
'cannot compute 3d separation.')
980980

981-
return Distance((self.cartesian - other.cartesian).norm())
981+
c1 = self.cartesian.without_differentials()
982+
c2 = other.cartesian.without_differentials()
983+
return Distance((c1 - c2).norm())
982984

983985
def spherical_offsets_to(self, tocoord):
984986
r"""

‎astropy/coordinates/tests/test_sky_coord_velocities.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,17 @@ def test_position_angle(sc, sc_for_sep):
200200
def test_constellations(sc):
201201
const = sc.get_constellation()
202202
assert const == 'Pisces'
203+
204+
205+
def test_separation_3d_with_differentials():
206+
c1 = SkyCoord(ra=138*u.deg, dec=-17*u.deg, distance=100*u.pc,
207+
pm_ra_cosdec=5*u.mas/u.yr,
208+
pm_dec=-7*u.mas/u.yr,
209+
radial_velocity=160*u.km/u.s)
210+
c2 = SkyCoord(ra=138*u.deg, dec=-17*u.deg, distance=105*u.pc,
211+
pm_ra_cosdec=15*u.mas/u.yr,
212+
pm_dec=-74*u.mas/u.yr,
213+
radial_velocity=-60*u.km/u.s)
214+
215+
sep = c1.separation_3d(c2)
216+
assert_quantity_allclose(sep, 5*u.pc)

0 commit comments

Comments
 (0)