Skip to content

Commit

Permalink
Make sure SkyCoord units are always correct
Browse files Browse the repository at this point in the history
  • Loading branch information
jobovy committed Oct 28, 2017
1 parent 3a6134f commit 6cc018b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion galpy/orbit_src/OrbitTop.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,9 +882,10 @@ def SkyCoord(self,*args,**kwargs):
HISTORY:
2015-06-02 - Written - Bovy (IAS)
"""
kwargs.pop('quantity',None) # rm useless keyword to no conflict later
_check_roSet(self,kwargs,'SkyCoord')
radec= self._radec(*args,**kwargs)
tdist= self.dist(*args,**kwargs)
tdist= self.dist(quantity=False,*args,**kwargs)
return coordinates.SkyCoord(radec[:,0]*units.degree,
radec[:,1]*units.degree,
distance=tdist*units.kpc,
Expand Down
21 changes: 21 additions & 0 deletions tests/test_quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4955,3 +4955,24 @@ def test_orbitmethodswunits_quantity_overrideusephysical_issue326():
assert isinstance(o.V(use_physical=False),units.Quantity), 'Orbit method ra does not return Quantity when called for orbit with _roSet = False / _voSet = False'
assert isinstance(o.W(use_physical=False),units.Quantity), 'Orbit method ra does not return Quantity when called for orbit with _roSet = False / _voSet = False'
return None

def test_SkyCoord_nodoubleunits_issue325():
# make sure that SkyCoord doesn't return distances with units like kpc^2
# which happened before, because it would use a distance with units of
# kpc and then again multiply with kpc
from galpy.orbit import Orbit
o = Orbit(vxvv=[0.,0.,0.,0.,0.,0.],radec=True)
# Check return units of SkyCoord
try:
o.SkyCoord().ra.to(units.deg)
except units.UnitConversionError:
raise AssertionError('Orbit method SkyCoord has the wrong units for the right ascension')
try:
o.SkyCoord().dec.to(units.deg)
except units.UnitConversionError:
raise AssertionError('Orbit method SkyCoord has the wrong units for the declination')
try:
o.SkyCoord().distance.to(units.kpc)
except units.UnitConversionError:
raise AssertionError('Orbit method SkyCoord has the wrong units for the distance')
return None

0 comments on commit 6cc018b

Please sign in to comment.