Skip to content

Planetary WCS implementation in Astropy  #11170

Closed

Description

@cmarmo

Description

In the framework of the EuroplanetH2020 some work has been done to define planetary standards for WCS.
Several research communities are involved in planetary coordinate standardization.
In particular Geologists and Remote Sensing specialists move from Earth to Planets using Geographical Information Systems (GIS) and proj based descriptions (if not ESRI!).
Astronomers move from Sky to Planets, using World Coordinate System and the Unit Sphere.
To improve interoperability between those two worlds we proposed a basic implementation of planetary WCS in GDAL (the FITS driver was already there and has been improved thereafter thanks to CNES funding). Planetary WCS are not yet a FITS standard but asking around (fitsbits list, IVOA workshops,...) everybody agrees on a pragmatic approach: once implemented in GDAL,
astropy and WCSlib they will just become a standard... :)
I like this approach... and after reading #5898, I'm reaching out to see if this is doable.

The novelties introduced with respect to the current WCS standard (which already support planetary coordinates in some way) are:

  • the mapping of the xy suffix for xyLN - xyLT CTYPE to the OBJECT keyword
  • the definition of a linear CTYPE xyPX - xyPY (Projected X - Projected Y) which units are meters
  • the definition of the three keywords A_RADIUS, B_RADIUS, C_RADIUS to describe the shape of the reference system (DATUM)
  • Ideally a switch between planetographic and planetocentric coordinates using the WCSNAME keyword value.

I'm an astropy user not a contributor (yet), but I will be happy to take care of this with some guidance if the team would like to consider it for integration.

Additional context

ping @thareUSGS and @Erard as co-authors of the paper and directly involved in the definition of planetary standards on GIS and IVOA side

Activity

  1. cmarmo commented on Mar 17, 2023

    @cmarmo
    MemberAuthor

    Dear maintainers, I may be able to be funded to work on this issue in the next months. I would be happy to offer some pull requests upstream if you are interested in.
    I need a step-by-step approach to the issue (as suggested in #5898 (comment)). I have figured out some actions that would be useful to move forward, and I would be grateful for any comment and suggestion.

    1. Integration of some of the most used planetary standard ellipsoids in the erfa library (eg MARS_IAU2000): those are used in historical planetary imagery and defined in the reports of the IAU/IAG Working Group on Cartographic Coordinates and Rotational Elements of the Planets and Satellites. I see @mhvk is one of the liberfa maintainers, and, as he kindly answered to my question, may I ask if this is acceptable and a pull request will be considered there?
    2. Create a BodyLocation class similar to the EarthLocation one
    3. Create a body_fixed built-in frame

    Is this an acceptable starting point?
    Thank you so much for your attention.

  2. mhvk commented on Mar 17, 2023

    @mhvk
    Contributor

    This sounds great! While rereading some of the discussion, it also occurred to me that sunpy surely has gone through something similar, so let me also ping @Cadair and @ayshih to see if they can provide some guidance of integrating coordinates on a body with WCS, etc.

  3. cmarmo commented on Apr 21, 2023

    @cmarmo
    MemberAuthor

    Hello, thanks for the answer and sorry for the long silence: administrative details took more time than expected.
    I have open a first pull request liberfa/erfa#94 to address item 1.

  4. mhvk commented on Apr 27, 2023

    @mhvk
    Contributor

    Further to my comment over at erfa - liberfa/erfa#94 (comment) - my sense is that the first step from the astropy side is to enable a general PlanetLocation class that can take user-supplied data to provide -centric to -detic conversions.

    Let me also try pinging @Cadair and @ayshih again to see if they can point us to equivalent things for the Sun - it would be nice to have something consistent!

    p.s. I think I would start not with EarthLocation, but rather the BaseGeodeticRepresentation in astropy.coordinates.earth - I think that itself could start depending instead on a new base class that implements conversion to Cartesian with the general erfa routines. I think in that case, one likely wants a new subclass for every planet one wants to model.

  5. cmarmo commented on Apr 27, 2023

    @cmarmo
    MemberAuthor

    @mhvk thanks for your answer.
    I've already started working on a BodyLocation class as a generalization of the EarthLocation, but I was leveraging my pull request to erfa.
    I'm going to put on hold liberfa/erfa#94, and offer a draft PR on astropy following your suggestion.
    But at some point the question about where the constants should be hosted will come up again.

    Rocky bodies are really close to the Earth implementation in astropy, and less challenging than the Sun: while ad hoc spheroid radii and flattening are nice to have, most of the time rocky planets surface projections will make use of standard spheroids.

  6. mhvk commented on Apr 28, 2023

    @mhvk
    Contributor

    @cmarmo - sounds good! I must say I also think that once we have BodyLocation, it makes little sense not to have the appropriate constants as well - for where to put those, it does seem mostly a choice between ERFA and astropy.

  7. cmarmo commented on May 11, 2023

    @cmarmo
    MemberAuthor

    As #14763 seems on its way in, next step would be the implementation of BodyLocation itself as suggested here.
    While Earth standards about latitudes and longitudes are quite clear and homogeneous, in planetary applications multiple conventions are used.

    • Longitude may run from -180 to 180 or from 0 to 360, and may be be East or West positive.
    • Planetocentric latitudes may be used rather than planetodetic.

    The Gazetteer of Planetary Nomenclature provides all the possible conventions for each planetary feature (see eg for Abalos Mensa on Mars).

    My plan was to add new parameters (east or west positive, odetic-ocenter,...) to the BodyLocation methods, so that the user may chose the convention for the output. EarthLocation will inherit the methods with default parameters, so its behavior will not change.
    Another possibility could be to keep BodyLocation simple and then create a SolarSystemBodyLocation which add the new parameters.
    I have a slight preference for the first solution: please let me know if this is ok the maintainers.
    Thanks for your attention.

  8. mhvk commented on May 11, 2023

    @mhvk
    Contributor

    @cmarmo - I think those changes are really differences in representation, and are most simply implemented as such. Certainly, using planetocentric latitudes is, as it needs a different conversion formula to cartesian - since erfa does not provide that, I guess we'd have to provide this ourselves.

    In principle, a different orientation (east or west positive) effectively implies different transformation formulae and thus would seem most logically implemented as a different representation (just like we have PhysicsSphericalRepresentation, which differs from SphericalRepresentation only in swapping in latitude for co-latitude. For the different wrap_angle, this should really not be necessary, but it still would seem most logically be done at the representation level. Indeed, this is a long-standing request - see #11767.

    Now for the bigger picture: I don't think EarthLocation is necessarily the best model to use here. There is a long-standing issue #4261 about making it more like a BaseFrame. Whether that is best, I'm not sure, but it would seem more logical to not convert coordinates to Cartesian upon creation, but rather as needed, i.e., be much more like a BaseFrame with its represent_as method. Also, I think there really is little reason for it to be a Quantity subclass - most of the Quantity methods do not make much sense for it!

    So, I would suggest taking this as an opportunity to think through what a PlanetLocation class really needs to provide, and how it should allow transformations to other frames, etc. Specifically, it may be good to start with thinking about implementing the WCS transformations you mentioned at the head of this issue! What would they need?

  9. cmarmo commented on May 11, 2023

    @cmarmo
    MemberAuthor

    So, I would suggest taking this as an opportunity to think through what a PlanetLocation class really needs to provide, and how it should allow transformations to other frames, etc. Specifically, it may be good to start with thinking about implementing the WCS transformations you mentioned at the head of this issue! What would they need?

    The current funding should lead to the definition of a "body-fixed" coordinate system frame which I would like to use when reading or writing planetary FITS images. Ideally, I would like to instantiate body-fixed frames reading the RADIUS_? in the FITS header, the choice between planetodetic or planetocentric representation would be also determined by a specific keyword.
    Also If I understand correctly a BodyLocation will prepare the transformation between the body-fixed frame and something like a planetary Alt-Az: this was my understanding for what is currently done for the Earth, that's why I am trying so hard in that direction... :)
    Happy to follow any other path as long as it'll lead me at the right place.
    Have I answered to your question? Or at least facilitated a solution?

  10. mhvk commented on May 11, 2023

    @mhvk
    Contributor

    The first item you mention, of having a nice coordinate system which can be used to read/write FITS images of planetary bodies using various coordinate systems, seems the more pressing and perhaps also the easier, since surely this is a solved problem for the Sun! Indeed, certainly the sunpy documentation suggests so: https://docs.sunpy.org/en/stable/guide/coordinates.html

    But obviously what you are hoping to do is to implement the basics needed to generalize such coordinates to other bodies. I think this would need to be some type of mash-up of how astropy converts WCS to sky images and how sunpy creates its Map instances. I'm not very familiar with either, so perhaps best is to ping @Cadair and @ayshih to ask if they can give pointers - indeed, maybe for sunpy it would be helpful if some of there machinery (and overrides) could move upstream to astropy...

  11. mhvk commented on May 11, 2023

    @mhvk
    Contributor

    Your second aim we have thought a bit about, but right now there is no clear solution. Apart from #4261, there is a lot more discussion in #10996 about how we can generalize the location attribute in coordinates away from EarthLocation (which is what would be needed for something like a Mars AltAz). From that issue, I think the best approach would again be to follow sunpy and introduce a more general observer attribute; see #10996 (comment) - in many ways, this is like a regular coordinate frame, but I think it somehow keeps track of what it is fixed to. The discussion in #10996 was really quite good, and I haven't really caught back up to it...

  12. cmarmo commented on May 12, 2023

    @cmarmo
    MemberAuthor

    Thanks @mhvk for your comments and the pointers: they are really helpful!
    I have open #14820 as draft pull request, to move on on the implementation of the body-fixed reference system.
    This is still work-in-progress and tests do not pass.
    It is more to show that I have been able to progress thanks to your follow-up... :)
    Obviously, any comment, suggestion, improvement is welcome, from anyone interested in the topic.

  13. cmarmo commented on May 18, 2023

    @cmarmo
    MemberAuthor

    Dear maintainers,
    it is my understanding that sunpy makes use of the auxiliary information available in the auxprm structure from WCSLIB.
    Its documentation states that "It is anticipated that this struct will expand in future to accomodate additional parameters."
    Right now it contains parameters related to the Sun and its observation, eg, the reference radius.
    I have been in contact with Mark Calabretta in the past and he was open to suggestions about planetary WCS implementation. Wouldn't be reasonable to have there the radii of the planetary body and the position of the observer?

  14. mhvk commented on May 18, 2023

    @mhvk
    Contributor

    Dear maintainers,
    it is my understanding that sunpy makes use of the auxiliary information available in the auxprm structure from WCSLIB.
    Its documentation states that "It is anticipated that this struct will expand in future to accomodate additional parameters."
    Right now it contains parameters related to the Sun and its observation, eg, the reference radius.
    I have been in contact with Mark Calabretta in the past and he was open to suggestions about planetary WCS implementation. Wouldn't be reasonable to have there the radii of the planetary body and the position of the observer?

    Certainly seems reasonable, but let me ping the WCS maintainers, @mcara and @nden, as well as again @Cadair and @ayshih.

  15. cmarmo commented on May 19, 2023

    @cmarmo
    MemberAuthor

    While experimenting with planetary fits images working on the WCS extraction, I realized that I really needed some planetary options in the BaseGeodeticRepresentation, in order to efficiently move forward.
    Following @mhvk suggestion, I have open #14851. Thanks for considering it.

  16. cmarmo commented on May 24, 2023

    @cmarmo
    MemberAuthor

    I've taken the liberty of interpreting the 👍 by @Cadair as a green light to contact Mark Calabretta: I'm preparing the list of keywords and corresponding additional parameters to be added to the auxiliary WCS structure.

  17. cmarmo commented on May 25, 2023

    @cmarmo
    MemberAuthor

    For those interested, the list of additional parameters, together with the related Planetary Data System (PDS) version 3 and 4 is available here.

  18. nden commented on Jun 3, 2023

    @nden
    Contributor

    This all looks reasonable to me. Sorry for the late response.

  19. cmarmo commented on Jun 24, 2023

    @cmarmo
    MemberAuthor

    I have marked #14820 ready for review: the shape of the spheroid is still missing.
    Mark Calabretta already added the keywords described here in a beta release of wcslib. I'm planning to implement the reading of the shape of the spheroid in a subsequent pull request (as I am still having issues in the compilation of astropy with an external wcslib...). Thanks for your patience.

  20. cmarmo commented on Jul 6, 2023

    @cmarmo
    MemberAuthor

    Linking here #14990 as part of the same path towards reference frames for planetary bodies.

  21. mhvk commented on Sep 28, 2023

    @mhvk
    Contributor

    @cmarmo - I think we managed to do everything for this issue, right? If so, let's close it! (If not, list what still needs to be done here or in a new issue...)

  22. cmarmo commented on Sep 28, 2023

    @cmarmo
    MemberAuthor

    There are two "nice-to-have"s related to this issue:

    • the transformations East/West longitudes and 0-360/-180-180 longitudes
    • the implementation of linear WCS (CTYPE xyPX - xyPY (Projected X - Projected Y) which units are meters)

    The first should be quite easy, just needs some time allocation.
    The second is more challenging.
    I feel better when I close issues... :)
    Perhaps I may open two issues about the previous.

    Related to #5898 , transformations between reference frames would be wonderful to have ... but they need some funding... :)

  23. mhvk commented on Oct 4, 2023

    @mhvk
    Contributor

    @cmarmo - belatedly: I agree with closing issues, and think the two leftovers are better as new issues, as they are quite concrete and will not be easily found here. So, if you can raise those issues, that would be great! And then close this one, obviously!

  24. cmarmo commented on Oct 5, 2023

    @cmarmo
    MemberAuthor

    I have opened #15437 and #15438 to keep track of the remaining issues.
    Hence, I'm closing this one.

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