astropy.coordinates.SkyCoord reports error when distance is added ("Differential data units are not compatible withtime-derivative of representation data units")
See original GitHub issueDescription
Dear astropy team,
I have looked for a similar issue to my problem, but the closest one I could find was this one. In this issue the user had a problem transforming his/hers coordinates to galactic ones. I see the same error message, but still in the previous line, when I call SkyCoord.
In my particular case, I have a set of data that I am importing via pandas and everything works well untill I address the distance variable. Everything else works. So, my code is:
from astropy.coordinates import SkyCoord as astro_coord
from astropy.time import Time as astro_time
from astropy import units as astro_units
my_coord = astro_coord(ra=data['ra'].iloc[0]*astro_units.degree, dec=data['dec'].iloc[0]*astro_units.degree, pm_ra_cosdec=data['pmra'].iloc[0]*astro_units.mas/astro_units.year, pm_dec=data['pmdec'].iloc[0]*astro_units.mas/astro_units.year, radial_velocity=data['VRAD'].iloc[0]*astro_units.mas/astro_units.year, frame='icrs', obstime=astro_time("J2016.0", format="jyear_str"))
Which works (note that distance
is commented). When I print my_coord
, this is what I have:
print(my_coord)
<SkyCoord (ICRS): (ra, dec) in deg (0.00043534, -54.92963798) (pm_ra_cosdec, pm_dec, radial_velocity) in mas / yr (7.35487918, 0.17977949, -40.48)>
When I run it with the distance (that has a value of 979 pc):
my_coord = astro_coord(ra=data['ra'].iloc[0]*astro_units.degree, dec=data['dec'].iloc[0]*astro_units.degree, pm_ra_cosdec=data['pmra'].iloc[0]*astro_units.mas/astro_units.year, pm_dec=data['pmdec'].iloc[0]*astro_units.mas/astro_units.year, radial_velocity=data['VRAD'].iloc[0]*astro_units.mas/astro_units.year, distance=979*astro_units.pc, frame='icrs', obstime=astro_time("J2016.0", format="jyear_str"))
I get the following error message:
ValueError Traceback (most recent call last) /tmp/ipykernel_255896/1195732307.py in <module> 1 # the following command has a problem with ra, dec units combined with distance in parsec – check why 2 ----> 3 my_coord = astro_coord(ra=data[‘ra’].iloc[0]*astro_units.degree, 4 dec=data[‘dec’].iloc[0]*astro_units.degree, 5 pm_ra_cosdec=data[‘pmra’].iloc[0]*astro_units.mas/astro_units.year,
/work/mlldantas/anaconda3/lib/python3.8/site-packages/astropy/coordinates/sky_coordinate.py in init(self, copy, *args, **kwargs) 328 # Finally make the internal coordinate object. 329 frame_kwargs.update(components) –> 330 self._sky_coord_frame = frame_cls(copy=copy, **frame_kwargs) 331 332 if not self._sky_coord_frame.has_data:
/work/mlldantas/anaconda3/lib/python3.8/site-packages/astropy/coordinates/baseframe.py in init(self, copy, representation_type, differential_type, *args, **kwargs) 324 325 self._representation = self._infer_representation(representation_type, differential_type) –> 326 self._data = self._infer_data(args, copy, kwargs) # possibly None. 327 328 # Set frame attributes, if any
/work/mlldantas/anaconda3/lib/python3.8/site-packages/astropy/coordinates/baseframe.py in _infer_data(self, args, copy, kwargs) 550 current_diff_unit = differential_data.units[f’d{comp}'] 551 if not current_diff_unit.is_equivalent(current_repr_unit / u.s): –> 552 raise ValueError( 553 “Differential data units are not compatible with” 554 “time-derivative of representation data units”)
ValueError: Differential data units are not compatible withtime-derivative of representation data units
Expected behavior
I expected my_coord
to accept the distance in parsecs (which, by the way, also does not work with kpc). I would like SkyCoord to understand the distance and print it along with the other variables, such as:
<SkyCoord (ICRS): (ra, dec) in deg (0.00043534, -54.92963798) (pm_ra_cosdec, pm_dec, radial_velocity) in mas / yr (7.35487918, 0.17977949, -40.48) (distance) in pc (979)>
Actual behavior
As I have described above.
Steps to Reproduce
By substituting my variables with the actual values, you can reproduce my problem:
from astropy.coordinates import SkyCoord as astro_coord
from astropy.time import Time as astro_time
from astropy import units as astro_units
my_coord = astro_coord(ra=0.00043534*astro_units.degree,
dec=-54.92963798*astro_units.degree,
pm_ra_cosdec=7.35487918*astro_units.mas/astro_units.year,
pm_dec=0.17977949*astro_units.mas/astro_units.year,
radial_velocity=-40.48*astro_units.mas/astro_units.year,
distance=979*astro_units.pc,
frame='icrs', obstime=astro_time("J2016.0", format="jyear_str"))
EDIT: Syntax highlighting
Is there something I am missing that is not correct? Or is it an actual bug?
System Details
Linux-5.4.0-66-generic-x86_64-with-glibc2.17 Python 3.8.11 (default, Aug 3 2021, 15:09:35) [GCC 7.5.0] Numpy 1.20.3 pyerfa 2.0.0 astropy 4.3.1 Scipy 1.7.1 Matplotlib 3.4.2
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Updating the error message so that it would be more explicit about the physical types of the units involved sounds like a good idea.
If you do that then creating the
SkyCoord
object does succeed. However, I don’t see how such aSkyCoord
could be used for anything meaningful. Are you sure your radial velocities are inmas/yr
?