question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

astropy.coordinates.SkyCoord reports error when distance is added ("Differential data units are not compatible withtime-derivative of representation data units")

See original GitHub issue

Description

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:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
eerovahercommented, Oct 19, 2021

I would like to suggest adding more information in the error message so that it can be a little bit more clear when it happens.

Updating the error message so that it would be more explicit about the physical types of the units involved sounds like a good idea.

1reaction
eerovahercommented, Oct 19, 2021

Alright, I see! So if I add the parallax instead of the calculated distance (which is an angle), the following code should work, is that correct?

If you do that then creating the SkyCoord object does succeed. However, I don’t see how such a SkyCoord could be used for anything meaningful. Are you sure your radial velocities are in mas/yr?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Source code for astropy.coordinates.baseframe
if differential_data: # Check that differential data provided has units compatible # with time-derivative of representation data. # NOTE: there is no ......
Read more >
Bug in SkyCoord unit kwarg when distance is specified #10725
I believe I've found a bug with the unit argument of SkyCoord. Specifying unit and distance to the SkyCoord constructor results in a ......
Read more >
astropy.coordinates.representation — gala v1.3
In this module, we define the coordinate representation classes, which are used to ... or differential with ``method`` applied to the component data....
Read more >
In astropy.coordinates.SkyCoord, how can I use it with data ...
the SkyCoord is only allowed 'deg' data, but my data's unit is just 'pix' ... I faced ERROR(UnitTypeError: Distance instances require units ......
Read more >
poliastro.frames.ecliptic
It stores anything that should be computed from the coordinate data (not ... from astropy import units as u >>> from astropy.coordinates import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found