Skip to content

Modifications to transforming frames with data as opposed to SkyCoord - #10475

Merged
adrn merged 4 commits into
astropy:masterfrom
ayshih:coord
Aug 19, 2020
Merged

adrn merged 4 commits into
astropy:masterfrom
ayshih:coord

Conversation

@ayshih

@ayshih ayshih commented Jun 9, 2020 •

Copy link
Copy Markdown
Contributor

The coordinates transformation framework is currently a bit confusing/inconsistent because users can work with either SkyCoord instances or frame instances with data. Frame instances with data behave differently from SkyCoord because they lack the ability to merge frame attributes across a transformation path. This is particularly confusing when transforming a frame instance with data to a frame class, because the behavior is significantly different from the seemingly analogous call when using SkyCoord. See the discussion in #10453.

This PR makes the following changes:

  1. Modify CoordinateAttribute so that it always uses SkyCoord for the internal transformation (with the default setting of merge_attributes=True).
  2. Revise any documentation examples that instantiate frames directly with data to instead use SkyCoord, unless there is some strong reason to avoid using SkyCoord.
  3. Deprecate being able to pass a class to BaseCoordinateFrame.transform_to(), and point users to SkyCoord.

To do:

  • Add tests for the new behavior of CoordinateAttribute
  • Find all of the examples of non-use of SkyCoord
  • Add changelog entries

@pllim
pllim requested review from StuartLittlefair and mhvk June 9, 2020 15:13
@pllim pllim added the API change PRs and issues that change an existing API, possibly requiring a deprecation period label Jun 9, 2020
@pllim pllim added this to the v4.2 milestone Jun 9, 2020

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks very good, the solution feels very much right! One very minor suggestion for the warning text. Other than that, I think
https://docs.astropy.org/en/latest/coordinates/frames.html#transforming-between-frames
has one more instance of using an uninstantiated class (possibly the cause of the CI failure?)

More generally, perhaps that particular page could do with a slight rewrite nearer the top, where it might suggest more strongly that SkyCoord is the way to go and that the page is mainly about defining new coordinate systems. But overall the documentation is actually quite clear that one should use SkyCoord, so this is not critical for this PR.

Beyond that, this will obviously need entries in CHANGES.rst, in particular about the API change!

@adrn, @eteq - this PR makes changes that I think you should have input on. See the linked PR on top for an earlier attempt and discussion, as well as @StuartLittlefair's suggestion to go this route (which @ayshih and I agreed with).

Comment thread astropy/coordinates/baseframe.py Resolved
def test_transform_to():
for frame in (FK5, FK5(equinox=Time('J1975.0')),
FK4, FK4(equinox=Time('J1975.0')),
for frame in (FK5(), FK5(equinox=Time('J1975.0')),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a test where it is truly obvious this is an improvement!

@ayshih

ayshih commented Jun 9, 2020

Copy link
Copy Markdown
Contributor Author

As I was adding the empty parentheses to explicitly instantiate destination frames, I amusingly discovered that there was a smattering of occurrences of empty parentheses already being used, possibly because the writer wanted to make explicit what the destination frame was.

@ayshih

ayshih commented Jun 10, 2020

Copy link
Copy Markdown
Contributor Author

I don't know if other packages would find these changes to be disruptive, but at least for SunPy, only ten lines need to be fixed.

@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.

Overall, I am 👍 to this idea - thanks for the discussion in the previous PR and for this PR, @ayshih!

RE: API change - this will require me to make some minor changes in my gala package, but nothing disruptive.

"explicitly instantiate the target frame, or first convert the source "
"frame instance to a `astropy.coordinates.SkyCoord` and use its "
"`transform_to()` method.",
AstropyDeprecationWarning)

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.

Good! Let's also remember to make an issue to remove this warning and functionality.

Comment thread docs/coordinates/frames.rst Resolved
@ayshih

ayshih commented Jun 15, 2020

Copy link
Copy Markdown
Contributor Author

Okay, PR updated:

  • Changelog entry (API) for transform_to() deprecation
  • Tests and changelog entry (bugfix) for CoordinateAttribute
  • Fixed all the examples that I could find where a frame with data was used instead of a SkyCoord
  • Other minor stuff

@ayshih
ayshih marked this pull request as ready for review June 15, 2020 14:51

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks all good to me! I'm approving, though won't merge yet as maybe @eteq still wants to have a look.

@ayshih

ayshih commented Aug 19, 2020

Copy link
Copy Markdown
Contributor Author

I just realized that this PR hadn't been merged yet... I've now rebased it against the latest.

@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.

The travis failure is unrelated, so I think this is ready to merge!

@adrn
adrn merged commit eb63a70 into astropy:master Aug 19, 2020
@adrn

adrn commented Aug 19, 2020

Copy link
Copy Markdown
Member

Thanks very much @ayshih !

@ayshih
ayshih deleted the coord branch August 20, 2020 04:28
@pllim

pllim commented Aug 20, 2020

Copy link
Copy Markdown
Member

This code in Ginga (modified so you can run it outside of Ginga) now raises deprecation warning with astropy dev.

import numpy as np
from astropy import coordinates, units

coordsys = 'fk5'
system = 'icrs'
wcspt = np.array([[0.1234, -34.34], [0.4567, 42.42]])

frame_class = coordinates.frame_transform_graph.lookup_name(coordsys)
ra_deg = wcspt[:, 0]
dec_deg = wcspt[:, 1]
coord = frame_class(ra_deg * units.degree, dec_deg * units.degree)
to_class = coordinates.frame_transform_graph.lookup_name(system)

coord = coord.transform_to(to_class)  # Deprecation warning here

Is this the correct solution?

coord = coord.transform_to(to_class())

@mhvk

mhvk commented Aug 20, 2020

Copy link
Copy Markdown
Contributor

Yes, that is correct! The idea was that down at the frame level one should be specific.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API change PRs and issues that change an existing API, possibly requiring a deprecation period coordinates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants