You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Issue warning for (mis-)use of SkyCoord.separation with mixed frames #14812
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.
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.
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.
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.
Activity
pllim commentedon May 11, 2023
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.
StuartLittlefair commentedon May 11, 2023
Agreed - I think a warning in the docs is necessary but insufficient. Something along the lines of
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.
eerovaher commentedon May 11, 2023
This is related to #8505 and #12189. Apparently this is confusing enough for the users that raising a warning is justified.
pmaxted commentedon May 12, 2023
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.
mhvk commentedon May 12, 2023
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.