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
Fix a whole bunch of bugs to do with -TAB in wcsapi/fitswcs #13571
Conversation
👋 Thank you for your draft pull request! Do you know that you can use |
astropy/wcs/wcsapi/fitswcs.py
Outdated
# Very occasionally (TAB) wcs does not convert the units | ||
# We call set here to make sure any unit conversion which is | ||
# going to happen has been done. | ||
self.wcs.set() |
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 am not sure if this is really needed. Maybe @mcara knows?
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.
Not sure I understand the issue (i.e., what/when units do not get converted). As to when set()
needs to be called, basically never: if you already have a valid WCS object and set parameters in a "normal" way like using assignments like:
w.wcs.crval = [20, 30]
instead of
w.wcs.ctype[0] = 20
w.wcs.ctype[1] = 30
w.wcs.set()
then WCS code will automatically call set()
as needed. When you do weirder things like second approach above, the yes, you need to call WCS.Wcsprm.set()
. A full list of when set
should be called can be found here: https://www.atnf.csiro.au/people/mcalabre/WCS/wcslib/structwcsprm.html#a35bff8de85e5a8892e1b68db69ca7a68
This is a "mixin" class and I worry about your call to set
interacting with
Lines 548 to 549 in b6352e1
if _do_set: | |
self.wcs.set() |
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.
The issue I have seen before which I am kind of blindly solving here is that until you trigger a call to set()
(i.e. implicitly in pixel to world or whatever) w.wcs.cunit
can be in units of not-degrees however after set()
has been called they will be in degrees. Before I use the unit here I just wanted to make sure they had been changed if they were going to be changed.
I guess that by the time you get to here in this mixin you have already called pixel_to_world
or whatever so I guess that this is not needed.
P.S. Does calling set()
twice cause any issues?
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.
calling set
after it was already called will cause performance issues. It is an expensive operation. You may not feel it if it is done once during the initialization but if this is done repeatedly it will be felt. So it depends on the usage.
My main concern though was that it may call set
even when _do_set
is False
. I do not recall right now why _do_set
was introduced but there was a purpuse. Let me investigate...
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.
Another reason to avoid calling set
twice is that if there are warning messages, they may also appear twice (but I did not check whether this is indeed the case).
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 have removed it. I don't think that it's really needed, but I could be wrong
6a9535f
to
094afa7
Compare
I don't know if there is an easy way to test this without using a FITS file with a bunch-o-TAB in it? |
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 seems reasonable to me, though of course if there is some way to make a FITS file that reproduces the issue that would be great (but I'm not sure if we can generate such a file from astropy?)
Could you use https://github.com/astropy/astropy/blob/main/astropy/wcs/tests/data/tab-time-last-axis.fits ? Only 14KB. If you need |
Oh, well this is definitely a start. I shall have a go with that. To hit the bug for the celestial units I would need a tab file for spatial axes not in degrees. I could investigate making one, but that sounds like a lot of work. |
It's not that hard if you use this: https://gwcs.readthedocs.io/en/latest/api/gwcs.wcs.WCS.html#gwcs.wcs.WCS.to_fits_tab Choose largest sampling possible - you do not need too many data points for a test. You could start with https://github.com/spacetelescope/gwcs/blob/713a0bc710a80ff44ac711ceec1f02ceb51d591c/gwcs/tests/conftest.py#L247-L282 and just replace spectral frame with a temporal frame. |
Might need a rebase to pick up the new wcslib that Mihai just added to this repo? |
Hi humans 👋 - this pull request hasn't had any new commits for approximately 4 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then. In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary. If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock. If you believe I commented on this pull request incorrectly, please report this here. |
I'm going to close this pull request as per my previous message. If you think what is being added/fixed here is still important, please remember to open an issue to keep track of it. Thanks! If this is the first time I am commenting on this issue, or if you believe I closed this issue incorrectly, please report this here. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
90b6883
to
e8642a3
Compare
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.
LGTM, except maybe test function name could be (not sure) improved (but this is nitpicking).
@@ -1348,3 +1350,13 @@ def check_wcs(header): | |||
# Check fall back to scale='utc' | |||
del hdr["TIMESYS"] | |||
check_wcs(hdr) | |||
|
|||
|
|||
def test_all_fits_tab(): |
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.
Is all_fits_tab
an appropriate name? Is this what is being tested? Or is it that time has UTC and -TAB in ctype. What is more relevant for this test?
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 still need to polish this test. I ran out of time the other day.
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.
@Cadair , are you going to be done polishing by feature freeze?
69e057c
to
fea99d6
Compare
51a1a96
to
bf1b98b
Compare
@mcara This is now ready to go. |
@mcara , does your previous approval still stand? |
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.
Minor comments - feel free to ignore.
Suggestions implemented. |
Tweak the test a little more as mcara suggested. Include minor edits from pllim to fix test data usage. Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>
d0ab2bb
to
1cd29be
Compare
…in wcsapi/fitswcs
…in wcsapi/fitswcs
…571-on-v5.2.x Backport PR #13571 on branch v5.2.x (Fix a whole bunch of bugs to do with -TAB in wcsapi/fitswcs)
…571-on-v5.0.x Backport PR #13571 on branch v5.0.x (Fix a whole bunch of bugs to do with -TAB in wcsapi/fitswcs)
This is a grab bag of fixes of issues that cropped up using @tiagopereira's SST data in #12095