Skip to content

Keep SkyCoord differentials the same in represent_as if possible - #11482

Merged
mhvk merged 3 commits into
astropy:masterfrom
mhvk:coordinates-keep-differentials-the-same-if-possible
Apr 6, 2021
Merged

mhvk merged 3 commits into
astropy:masterfrom
mhvk:coordinates-keep-differentials-the-same-if-possible

Conversation

@mhvk

@mhvk mhvk commented Apr 5, 2021

Copy link
Copy Markdown
Contributor

Fixes #11477 - a small annoyance. Milestoned 4.3 since I think this relies on other changes to the representations.

Before:

from astropy.coordinates import SkyCoord
from astropy import units as u

sc = SkyCoord(10*u.deg, 10*u.deg, radial_velocity=-10*u.km/u.s)
sc
<SkyCoord (ICRS): (ra, dec) in deg
    (10., 10.)
 (radial_velocity) in km / s
    (-10.,)>

sc.data.differentials
{'s': <RadialDifferential (d_distance) in km / s
     (-10.,)>}

sc.represent_as('spherical')
<SphericalRepresentation (lon, lat, distance) in (rad, rad, )
    (0.17453293, 0.17453293, 1.)
 (has differentials w.r.t.: 's')>

sc.represent_as('spherical').differentials
{'s': <SphericalDifferential (d_lon, d_lat, d_distance) in (km rad / s, km rad / s, km / s)
     (2.22044605e-16, -2.22044605e-16, -10.)>}

Now:

sc.represent_as('spherical')
<SphericalRepresentation (lon, lat, distance) in (rad, rad, )
    (0.17453293, 0.17453293, 1.)
 (has differentials w.r.t.: 's')>

c.represent_as('spherical').differentials
Out[3]: 
{'s': <RadialDifferential (d_distance) in km / s
     (-10.,)>}

For now, this is really just between Spherical and UnitSpherical.
@mhvk mhvk added this to the v4.3 milestone Apr 5, 2021
@mhvk
mhvk requested a review from adrn April 5, 2021 18:13
@mhvk
mhvk force-pushed the coordinates-keep-differentials-the-same-if-possible branch from b2f87a4 to 48f28de Compare April 5, 2021 18:14
@mhvk

mhvk commented Apr 5, 2021

Copy link
Copy Markdown
Contributor Author

cc @astrofrog as this makes the example for Spectral Coordinates quite a bit nicer! (see last commit)

@astrofrog astrofrog left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@adrn adrn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, great! No comments from me - LGTM

@mhvk

mhvk commented Apr 6, 2021

Copy link
Copy Markdown
Contributor Author

Failures are unrelated, so merging... Thanks!

@mhvk
mhvk merged commit 02e54d3 into astropy:master Apr 6, 2021
@mhvk
mhvk deleted the coordinates-keep-differentials-the-same-if-possible branch April 6, 2021 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SkyCoord/BaseFrame.represent_as does not treat differentials very logically

3 participants