Skip to content

Unexpected behavior with SkyCoord.separation method #6633

Closed

Description

@petigura

Dear Astropy,

Thanks for such a useful project!

I noticed an unexpected behavior when computing separations between two sets of SkyCoords. When one of the SkyCoods is an array and the other is a single value, array.separation(value) produces the correct result but value.separation(array) does not. Here's a simple example involving computing the distance between the Kepler field and the moon.

Cheers,

Erik

%pylab inline
from astropy.time import Time
import astropy.coordinates
from astropy.coordinates import SkyCoord, EarthLocation
from astropy import units as u

loc = EarthLocation.of_site('KPNO')

t0 = Time('2017-01-01 00:00:00', scale='utc')
t = t0 + np.arange(0.,365,1) * u.day
moon = astropy.coordinates.get_moon(t,location=loc)
kepler = SkyCoord('19h22m', '+44d30m', frame='icrs')

sep = moon.separation(kepler)
plot(t.datetime, sep.degree)

sep = kepler.separation(moon)
plot(t.datetime, sep.degree)

image

Activity

  1. adrn commented on Oct 1, 2017

    @adrn
    Member

    Hi Erik --

    FYI: I updated your comment above to add loc = EarthLocation.of_site('KPNO') (which was undefined before) - the exact site doesn't really matter, just need some Earth location to pass to get_moon().

    In any case, yes, I can confirm that I see what you see in the plot! No immediate solution or explanation, but will take a look.

    cc @eteq @mhvk

  2. adrn commented on Oct 1, 2017

    @adrn
    Member

    On second thought, I have an idea for what's going on, but haven't yet looked at .separation() to be sure (will get back to you shortly).

    get_moon() returns the Moon's position in the GCRS frame, which is axis-aligned with the ICRS frame but is centered on the Earth's center of mass. I suspect that when you do moon.separation(kepler), it's converting the kepler ICRS position to the GCRS frame, then computing the separation in this time-dependent frame. When you do kepler.separation(moon), it's converting the GCRS moon position to the ICRS frame, and computing the separation there. It's not immediately obvious to me why the resulting curves look the way they do, but this small test seems to confirm: if I do this instead

    sep = moon.transform_to(coord.ICRS).separation(kepler)
    plt.plot(t.datetime, sep.degree, marker='', linestyle='-', color='r')
    
    sep = kepler.separation(moon)
    plt.plot(t.datetime, sep.degree, marker='', linestyle='--')

    I get:
    image

  3. StuartLittlefair commented on Oct 1, 2017

    @StuartLittlefair
    Contributor

    @adrn is right. It may not be particularly intuitive - I’ve been bitten by this myself in the past - but this is the expected, and I think correct, behaviour.

    posA.separation(posB) calculates the separation of A and B, in the frame of object A. The mistake is to think that separation gives the separation on the sky, when it does not.

  4. petigura commented on Oct 1, 2017

    @petigura
    Author
  5. adrn commented on Oct 1, 2017

    @adrn
    Member

    I totally agree! This is a documentation fail. Thanks for bringing this up!

  6. ricozan commented on Dec 28, 2017

    @ricozan

    I just want to clarify that when dealing with the moon and a target, e.g for preparing observations one should use:

    moon.separation( target )

    thanks! I was also puzzled by this and I'm glad I found this post.

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