New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement APE 14 low-level FITS-WCS API and high-level WCS class #7326
Conversation
Hi there @astrofrog 👋 - thanks for the pull request! I'm just a friendly 🤖 that checks for issues related to the changelog and making sure that this pull request is milestoned and labeled correctly. This is mainly intended for the maintainers, so if you are not a maintainer you can ignore this, and a maintainer will let you know if any action is required on your part 😃. Everything looks good from my point of view! 👍 If there are any issues with this message, please report them here. |
218d300
to
27c9fb3
Compare
astropy/wcs/fitswcs_low_level_api.py
Outdated
return False | ||
|
||
|
||
def _get_components_and_classes(wcs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be worth putting functools.LRUCache
on this or something, so it's not always computed twice per use in the high level API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG. @Cadair, you've just blown my mind by pointing out the existence of functools.lru_cache
. Where has this been all my life??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! Though the issue is that WCS objects are mutable, and it looks like the hash returned for the object doesn't change when the content of the WCS does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd like to delay this to another PR because of the subtleties of mutable WCS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added caching here, but not using LRUCache
astropy/wcs/fitswcs_low_level_api.py
Outdated
|
||
kwargs = {} | ||
kwargs['frame'] = frame | ||
kwargs['unit'] = u.deg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be hardcoded to degree right? If there is no projection then WCS will return in native units and not in deg. Unfortunately the only way I have found to reliably determine the output units is post-transform (https://github.com/sunpy/sunpy/blob/master/sunpy/map/mapbase.py#L871)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will has_celestial
be True
in that case though? My understanding was that if WCS interprets the projection as celestial (which is what this branch is) then the units are degrees.
A few items while doing some experimentation:
And a bigger question for @astrofrog: is it possible to make the Right now it's a lot of layers of indirection, so I'm pretty sure most users who actually understand WCS's would say "why would I bother, it's too hard to take control when I need it". So changing it to just one layer I think reaps a lot of rewards. Put another way: right now to access the "real" fits wcs object, the user has to do |
dfcf5c2
to
d36b96c
Compare
a97cda6
to
c4b99de
Compare
54187ae
to
f400149
Compare
@nden - I've pushed some fixes - does it seem ok now? Note that I've added a new property |
I've also added more tests so the coverage of the First though, one question - are we comfortable adding the new API to the WCS object, or do we want to make that opt-in for one version? (it's apparently possible/easy to add inheritance to a class once it's initialized). So that would take the form:
or something like that. Or shall we just go all in and have it be available by default straight away? (but not necessarily document it in the narrative docs yet) The main reason I'm suggesting this is that some aspects of the API are not stable - e.g. |
Does anyone understand why docstrings are not inherited from parent classes in the API docs? I thought this was supposed to work, but apparently not. |
…object_classes properties
…ctly wit/without distortions
efc09e0
to
8e7e342
Compare
@astrofrog I'd say let's go with Does |
I think we should just add it, no opt-in needed. If we are concerned we should put a red-box warning in the docs that the API will change, but this won't present an immediate backward compatibility problem since the methods are all new, right? I don't see the problem of eventually returning |
@eteq - I added a warning. It turns out that WCSLIB 6.1 has just been released and includes support for Time, so we may be able to fix this sooner rather than later. |
@astrofrog - just to clarify: you don't mean sooner as in in this PR, right? |
I've added caching of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple minor things so I'm approving on the basis that basically it's all here.
One thing that's missing but I suspect might be planned as a second PR: a docs update that shows this functionality. I think we do need to at least demonstrate that this now works at a minimum, but I also think the following two things are probably needed as "detail" bits as well:
- a discussion of the pixel conventions - i.e. the "array index" vs "pixel" meaning.
- a bit on the
custom_ctype_to_ucd_mapping
decorator since it's conceptually rather complex
Do you plan to make that PR, @astrofrog? I get that it might be better to do that as a follow-on PR (and am fine with), but I think making those docs are a release blocker (which again I'm fine with as long as we can get it done soon after feature freeze).
@eteq - yes I can do the documentation improvements as a separate PR after this one. I think I've addressed your other requests. |
The failing tests are unrelated so... Merging! 🎆 🍾 |
About
APE 14 describes a common low-level API for inter-operability, and #7325 adds the abstract base class to astropy.wcs. The aim of this pull request is to add the implementation of the low-level API for FITS-WCS (aka astropy.wcs.WCS) as well as the high-level class.
Current status
Example of use with the current PR:
Future work
Rebase this once Added base class for low-level WCS API from APE 14 #7325 is merged
I need to try and implement world_axis_object_components/classes for time and spectral axes. The latter requires a decision in terms of what classes to use (see Decisions required).This will be done in a future PRThis needs tests. A lot of tests. In particular I think it would be good if people could contribute examples of headers and what the output should be for the different properties.
A changelog entry of course :)