Skip to content
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

Merged
merged 1 commit into from Apr 19, 2023

Conversation

Cadair
Copy link
Member

@Cadair Cadair commented Aug 24, 2022

This is a grab bag of fixes of issues that cropped up using @tiagopereira's SST data in #12095

@Cadair Cadair linked an issue Aug 24, 2022 that may be closed by this pull request
@github-actions
Copy link

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

# 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()
Copy link
Member Author

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?

Copy link
Contributor

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

astropy/astropy/wcs/wcs.py

Lines 548 to 549 in b6352e1

if _do_set:
self.wcs.set()

Copy link
Member Author

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?

Copy link
Contributor

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...

Copy link
Contributor

@mcara mcara Aug 26, 2022

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).

Copy link
Member Author

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

@pllim pllim added Bug 💤 backport-v5.0.x on-merge: backport to v5.0.x 💤 backport-v5.1.x on-merge: backport to v5.1.x labels Aug 24, 2022
@pllim pllim added this to the v5.0.5 milestone Aug 24, 2022
@Cadair Cadair changed the title Fix a whole bunch of bugs todo with -TAB in wcsapi/fitswcs Fix a whole bunch of bugs to do with -TAB in wcsapi/fitswcs Aug 24, 2022
@Cadair Cadair marked this pull request as ready for review August 29, 2022 07:00
@Cadair Cadair requested a review from astrofrog as a code owner August 29, 2022 07:00
@Cadair
Copy link
Member Author

Cadair commented Sep 5, 2022

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?

Copy link
Member

@astrofrog astrofrog left a 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?)

@mcara
Copy link
Contributor

mcara commented Sep 5, 2022

Could you use https://github.com/astropy/astropy/blob/main/astropy/wcs/tests/data/tab-time-last-axis.fits ? Only 14KB. If you need UTC instead of TIME, you can edit the header.

@Cadair
Copy link
Member Author

Cadair commented Sep 5, 2022

Could you use https://github.com/astropy/astropy/blob/main/astropy/wcs/tests/data/tab-time-last-axis.fits ? Only 14KB. If you need UTC instead of TIME, you can edit the header.

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.

@mcara
Copy link
Contributor

mcara commented Sep 5, 2022

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.

@pllim
Copy link
Member

pllim commented Sep 13, 2022

Might need a rebase to pick up the new wcslib that Mihai just added to this repo?

@pllim pllim modified the milestones: v5.0.5, v5.0.6 Oct 21, 2022
@saimn saimn removed the 💤 backport-v5.1.x on-merge: backport to v5.1.x label Oct 24, 2022
@github-actions
Copy link

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.

@github-actions
Copy link

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.

@pllim

This comment was marked as resolved.

@pllim

This comment was marked as resolved.

@pllim pllim added 💤 backport-v5.2.x on-merge: backport to v5.2.x and removed keep-open labels Mar 14, 2023
Copy link
Contributor

@mcara mcara left a 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():
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member

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?

@saimn saimn modified the milestones: v5.0.6, v5.0.7 Mar 29, 2023
@Cadair Cadair force-pushed the fix_time_ctype_detection branch 2 times, most recently from 51a1a96 to bf1b98b Compare April 19, 2023 09:26
@Cadair
Copy link
Member Author

Cadair commented Apr 19, 2023

@mcara This is now ready to go.

@pllim
Copy link
Member

pllim commented Apr 19, 2023

@mcara , does your previous approval still stand?

Copy link
Contributor

@mcara mcara left a 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.

astropy/wcs/wcsapi/tests/test_fitswcs.py Outdated Show resolved Hide resolved
astropy/wcs/wcsapi/tests/test_fitswcs.py Outdated Show resolved Hide resolved
@Cadair
Copy link
Member Author

Cadair commented Apr 19, 2023

Suggestions implemented.

setup.cfg Outdated Show resolved Hide resolved
pllim

This comment was marked as resolved.

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>
@pllim pllim dismissed their stale review April 19, 2023 18:16

I pushed changes here.

@pllim pllim enabled auto-merge April 19, 2023 18:31
@pllim pllim merged commit db362dc into astropy:main Apr 19, 2023
25 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/astropy that referenced this pull request Apr 19, 2023
meeseeksmachine pushed a commit to meeseeksmachine/astropy that referenced this pull request Apr 19, 2023
pllim added a commit that referenced this pull request Apr 19, 2023
…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)
pllim added a commit that referenced this pull request Apr 19, 2023
…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)
@Cadair Cadair deleted the fix_time_ctype_detection branch April 20, 2023 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug wcs.wcsapi 💤 backport-v5.0.x on-merge: backport to v5.0.x 💤 backport-v5.2.x on-merge: backport to v5.2.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem using WCS.pixel_to_world with WCS tab file
5 participants