Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move position_angle() from SkyCoord to BaseCoordinateFrame #15737

Merged
merged 2 commits into from Dec 15, 2023

Conversation

eerovaher
Copy link
Member

Description

The first commit implements a new private method in BaseCoordinateFrame that simplifies the implementation of separation() and position_angle() methods.

The second commit moves position_angle() from SkyCoord to BaseCoordinateFrame. The method remains accessible for SkyCoord instances because they have access to methods defined both in SkyCoord and in their underlying frame.

I felt it appropriate to create a new file for testing methods that are implemented in BaseCoordinateFrame, but are exposed also by SkyCoord instances. That file should also include tests for separation() and separation_3d(), but moving those tests over would be beyond the scope of this pull request, which is large enough as it is.

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

`BaseCoordinateFrame.separation()` and `SkyCoord.position_angle()`
perform many analogous computations, which are now implemented in
`BaseCoordinateFrame._prepare_unit_sphere_coords()`. This seems to lose
some error handling in `SkyCoord.position_angle()`, but the errors that
were meant to be caught there cannot be triggered.
Copy link

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • Is a milestone set? Milestone must be set but we cannot check for it on Actions; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

Copy link
Member

Choose a reason for hiding this comment

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

Isn't this more like api?

Copy link
Member Author

Choose a reason for hiding this comment

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

Previously BaseCoordinateFrame had no position_angle() method, but now it does. That looks like a new feature to me.

Copy link
Member

Choose a reason for hiding this comment

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

But... you are moving it from another class. @mhvk , what say you?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think from the user-perspective, there is no change of API for SkyCoord -- it is more like a refactoring -- while there now is a new feature on BaseFrame, so I think "enhancement" is most appropriate.

Copy link
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

Thanks! A nice little improvement, making things more logical.

I also like the new test file. Will you be doing a follow-up PR to move the separation methods?

-------
`~astropy.coordinates.Angle`
The (positive) position angle of the vector pointing from ``self``
to ``other``. If either ``self`` or ``other`` contain arrays, this
Copy link
Contributor

Choose a reason for hiding this comment

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

let's add ", measured East from North" to give people new to position angles a clue as to what to expect (though the examples help!)

>>> c2.position_angle(c1).degree
270.0
"""
from .angles import position_angle
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be on top? Or does it cause a circular import?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's a few functions here that import things locally and it would be good to have a separate pull request to clean them up. I thought this line could be included in that, but this line does not exist in this file before this pull request, so we can indeed avoid some code churn by having a module level import in this pull request already.

astropy/coordinates/baseframe.py Show resolved Hide resolved
The `position_angle()` method has been moved form `SkyCoord` to
`BaseCoordinateFrame`. The method is still accesible to `SkyCoord`
instances because they expose methods of their underlying frames.
@eerovaher
Copy link
Member Author

@mhvk asked:

I also like the new test file. Will you be doing a follow-up PR to move the separation methods?

I am planning to look at the relevant tests, and not just for the separation methods but for position angle too. For example, it is not clear to me if the tests in test_sky_coord_velocities.py are worth keeping:

def test_position_angle(sc, sc_for_sep):
sc.position_angle(sc_for_sep)

@mhvk
Copy link
Contributor

mhvk commented Dec 15, 2023

Thanks! Let's get it in.

@mhvk mhvk merged commit 586a144 into astropy:main Dec 15, 2023
29 of 32 checks passed
@eerovaher eerovaher deleted the unify-sep-pos-angle branch December 15, 2023 16:09
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.

None yet

3 participants