Skip to content

Issue warning for (mis-)use of SkyCoord.separation with mixed frames #14812

Closed

Description

@pmaxted

What is the problem this feature will solve?

The calculation of the separation of my target from the Moon was wrong despite the code looking reasonable and no warning being printed.

Here is an example of inconsistent target-moon separations being calculated ...

>>> from astropy.coordinates import SkyCoord, get_moon
>>> from astropy.time import Time
>>> target_coo = SkyCoord.from_name('Kelt-11')
>>> time = Time('2020-03-09T14:50:41',scale='utc',format='isot')
>>> moon_coo = get_moon(time)
>>> print(moon_coo.separation(target_coo).degree,target_coo.separation(moon_coo).degree)
20.63726192992106 15.98210433623633

The first value is correct, but it is far from obvious that the second why to calculate this value will not give the correct value for an observer at the geocentre.

Describe the desired outcome

A warning should be printed if SkyCoord.separation() is doing a coordinate transformation for one of the coordinates due to inconsistent reference frames.

Additional context

No response

Activity

  1. pllim commented on May 11, 2023

    @pllim
    Member

    It feels like different people keep getting bitten by this. Perhaps we need a warning box in https://docs.astropy.org/en/latest/coordinates/matchsep.html#separations ? cc @StuartLittlefair @adrn @eteq @eerovaher @mhvk

    I thought we had a PR to clarify the docs but I cannot find it now. Maybe I misremember.

  2. StuartLittlefair commented on May 11, 2023

    @StuartLittlefair
    Contributor

    Agreed - I think a warning in the docs is necessary but insufficient. Something along the lines of

    c1.separation(c2) will calculate the separation of the two coordinates in the frame of c1. This can lead to unintended consequences if you do not pay attention to the frame of c1. For example, if you want to find the separation of two targets for an Earth-bound observer, c1 must be in an Earth-based frame like GCRS. If c1 is in the ICRS frame c1.separation(c2) will give the separation of the two coordinates, as seen from the solar system barycentre

    Since people may not read the docs too closely, I also suggest raising a warning along similar lines if the two coordinates do not share the same frame.

  3. eerovaher commented on May 11, 2023

    @eerovaher
    Member

    This is related to #8505 and #12189. Apparently this is confusing enough for the users that raising a warning is justified.

  4. pmaxted commented on May 12, 2023

    @pmaxted
    Author

    Is it worthwhile to define a new class "Separation" based on Angle but that includes information on the origin of the frame in which the separation is measured? It would be easier to spot this type of problem if this class were returned instead of an angle.

  5. mhvk commented on May 12, 2023

    @mhvk
    Contributor

    Maybe it is better if there is an exception if the frames are not the same - let the user transform if they want to -- or add a keyword argument that can be set to exception, warning, or silent.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions