Skip to content

SkyCoord.separation not symmetric #5185

Closed

Description

@StuartLittlefair

When calculating separations between SkyCoords in AltAz and ICRS frames, it matters which way round you calculate the separation! For example:

In [1]: from astropy import coordinates as coord, units as u
In [2]: from astropy.time import Time
In [3]: time = Time('2003-04-05 06:07:08')
In [4]: loc = coord.EarthLocation(*(-1463969.3018517173,
                                                            -5166673.342234327,
                                                            3434985.7120456537)*u.m)
In [5]: altaz_frame = coord.AltAz(location=loc, obstime=time)
In [6]: moon = coord.get_moon(time, location=loc).transform_to(altaz_frame)
In [7]: one_deg_away = coord.SkyCoord(az=moon.az, alt=moon.alt+1*u.deg, frame=moon.frame)
In [8]: icrs_coord = one_deg_away.icrs
In [9]: icrs_coord.separation(moon)
Out[9]: <Angle 0.9999999999666758 deg>
In [10]: moon.separation(icrs_coord)
Out[10]: <Angle 141.88054031044086 deg>

Activity

  1. adrn commented on Jul 18, 2016

    @adrn
    Member

    Hm. I suspect this is because information about the (GCRS) moon frame is lost when you get an ICRS frame for the moon, e.g., one_deg_away.icrs

    If you instead do (with the SkyCoord):

    >>> one_deg_away.separation(moon), moon.separation(one_deg_away)
    (<Angle 0.9999999999815695 deg>, <Angle 1.0000000000192837 deg>)
  2. StuartLittlefair commented on Jul 18, 2016

    @StuartLittlefair
    ContributorAuthor

    Indeed, and the case above is rather artificial since the conversion to ICRS is not necessary.

    However, I do have a use case where the conversion to ICRS first is quite necessary. It's not that information is lost: the obstime is the crucial piece of information and that is stored in the ICRS SkyCoord. It's just that it's being ignored; I suspect that there's an assumption of obstime=Time('J2000') or similar for all ICRS SkyCoords.

    But essentially I think the snippet above should work if all was operating as expected.

  3. StuartLittlefair commented on Jul 28, 2016

    @StuartLittlefair
    ContributorAuthor

    I'm closing this issue. There are two things going on here. The first is that I ignored the distance and should have written

    one_deg_away = coord.SkyCoord(az=moon.az, alt=moon.alt+1*u.deg, 
                                  distance=moon.distance, frame=moon.frame)

    The second is that

    icrs_coord.separation(moon)

    transforms the icrs_coord to an altaz (Earth-centered) frame and computes the separation, whilst

    moon.separation(icrs_coord)

    transforms the moon to the ICRS frame and computes the separation.

    In other words, both calculate the angular separation between two coordinates, but from different points of view. Whilst this is a bit counter-intuitive the code does the correct thing I think.

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