Skip to content

Should coordinates be given in "preferred units" or as passed in by user #4903

Closed

Description

@mhvk

This separates out the more contentious question in #4883, whether it is a "good thing" that coordinates are automatically converted to preferred units for presentation in c.ra, etc. The main argument pro seems to be that some people may now count on coordinates always being in degrees; the main arguments counter are that for large arrays, this is a non-trivial memory overhead for no useful purpose (as the original input is what is actually used in any calculations); and that typically you if you enter something in some units, you should expect to get your data back that same way if that is trivially possible, i.e., SkyCoord(ra, dec).ra is ra (or at least the underlying memory is shared).

For reference, currently:

In [6]: t = SkyCoord(ra=np.arange(10) * u.hourangle, dec=np.arange(10) * u.deg)

In [7]: t.frame.data.lon  # this is the original data
Out[7]: <Longitude [ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.] hourangle>

In [8]: t.ra  # converted for me without my request
Out[8]: <Longitude [   0.,  15.,  30.,  45.,  60.,  75.,  90., 105., 120., 135.] deg>

Activity

  1. taldcroft commented on May 27, 2016

    @taldcroft
    Member

    @mhvk - the big downside in my mind to your proposal is for the very common use case of inputting a coordinate in sexigesimal format, in which case the ra attribute would end up being in hourangle. This would be very inconvenient and annoying to me, and I imagine many users. I believe that degrees is far and away the most common unit for decimal representation of sky coordinates in astronomy.

    Maybe we could add an attribute raw_repr or something that disables this conversion for memory-intensive applications?

  2. taldcroft commented on May 27, 2016

    @taldcroft
    Member

    Or plan B would just be documenting this behavior and saying "if you have a memory-intensive application then you should consider using coord.data.lon/lat instead of coord.ra to avoid making a copy of the coordinate values".

  3. mhvk commented on May 27, 2016

    @mhvk
    ContributorAuthor

    Obviously, a matter of taste: I do like hour angles... I know where I am along the galactic plane in hours, but not in degrees... I'd say that most reasonable is to have a default of staying as close as possible to what the user put. But of course this harkens back to your comment that really one should display things the way they were put in...

    But failing that, I don't have any problem with converting to degrees if one has to convert dtype anyway (from string, tuple, etc). I just don't think that what the code uses internally should be hidden... Plus it causes unnecessary overheads. For instance, in reshape, etc., I now have to remove items from _rep_cache (or delete and recreate it).

  4. mhvk commented on May 27, 2016

    @mhvk
    ContributorAuthor

    Also, to be a bit more specific: is it the fact that the values of .ra are in hourangle that is annoying to you, or the fact that it is displayed in hour angle? I.e., would your annoyance be solved by having a way to set the default repr, or do you feel the actual values should be in degrees? I ask because I very much share your wish in having proper format support for angles and coordinates -- I would like repr(sc) to be able to give me RA in hms strings (I love the flexibility we have for that in Time).

  5. taldcroft commented on May 27, 2016

    @taldcroft
    Member

    The fact that the values of .ra would be in hourangle would be annoying to me. But more importantly, astropy.coordinates has been stable since astropy 0.4, and that includes the API decision at the time that .ra will have a default and consistent unit of degrees. Changing this is a big deal and will break a lot of code in the wild. Even though you and I know better, I have no doubt that you would find plenty of lines like ra = coord.ra.value out there.

    So adding support for formats is (in my opinion) the only reasonable path forward at this point, especially since what you really want is HMS-style default repr. I think that even right now you can change your default repr unit for a particular instance or via subclass, though it's been a while since I looked at this.

    One question about the need for manipulating _rep_cache in reshape -- shouldn't coord.reshape(...) return a new SkyCoord with an already-empty _rep_cache? So why do you need to fiddle with it? Sorry I'm being too lazy to go and look at the code, but I did remind myself how Time works and basically it's not required there for the scale and format caching because _replicate does not propagate the cache to the new object.

  6. eteq commented on May 28, 2016

    @eteq
    Member

    I agree with @taldcroft here about the "API is stable" bit. I recall plenty of debating about this (although I honestly don't even recall what, if any, my opinion was at the time...), and unless something else has actually changed in the meantime, I don't think altering this is wise.

    But if I'm understanding right there are now two items under discussion:

    1. A way to prevent the rescaling that currently comes from doing sc.ra if you've decided you don't care about the units - this is to improve performance. I agree this is something we should try to address, but it should either be "opt-in" (to prevent the API-breaking), or something like what @taldcroft suggested in the direction of "clearer documentation".
    2. Support for "formats". I'm not sure I fully understand what you both mean by this - are you thinking something like this?
    >>> sc = SkyCoord(15*u.deg, 2*u.deg)
    >>> sc.format = u.deg
    >>> sc
    <SkyCoord frame=ICRS 15 deg, 2 deg>
    >>> sc.format = 'hmsdms'
    >>> sc
    <SkyCoord frame=ICRS 1h00m00s 2d00m00s>
    

    (I presume it wouldn't look exactly like that because of the need for frame info, array support, and such, but is that the general idea?)

  7. eteq commented on May 28, 2016

    @eteq
    Member

    Oh, and here's an idea for the #1 I have above: what about something like .raw_ra/.raw_dec? Those could be made on-the-fly just the way .ra/.dec are right now, but the key difference would be they are in whatever the underlying units are, with no rescaling.

  8. adrn commented on Jun 12, 2017

    @adrn
    Member

    A possible solution, as @eteq just mentioned, could be to add an optional kwarg (convert_to_preferred_units?)

  9. mhvk commented on Jun 12, 2017

    @mhvk
    ContributorAuthor

    closing in favour of #6184

  10. taldcroft commented on Jun 12, 2017

    @taldcroft
    Member

    @mhvk @adrn @eteq @taldcroft agreed that we are not willing to change this default behavior at this point, so closing now.

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