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

Ensure at least one pixel in header #586

Merged
merged 5 commits into from
Mar 13, 2025
Merged

Conversation

teutoburg
Copy link
Contributor

@teutoburg teutoburg commented Mar 11, 2025

Fixes #584. Not sure if there would be any unexpected negative consequences, so I included the log msg so it can be tracked down if weird things start occuring.

@teutoburg teutoburg self-assigned this Mar 11, 2025
@teutoburg teutoburg added the bugfix PR resolving one or more bugs label Mar 11, 2025
@teutoburg teutoburg marked this pull request as ready for review March 11, 2025 10:50
@teutoburg teutoburg requested review from hugobuddel and oczoske March 11, 2025 10:52
Copy link

codecov bot commented Mar 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.79%. Comparing base (7823ad4) to head (d85c45f).
Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #586      +/-   ##
==========================================
- Coverage   76.85%   76.79%   -0.06%     
==========================================
  Files          69       69              
  Lines        8571     8575       +4     
==========================================
- Hits         6587     6585       -2     
- Misses       1984     1990       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@oczoske oczoske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change should be alright, although I cannot really judge the consequences either. The legacy code is weird, though. In line 213, ctype is set to RA---TAN if a sky WCS is to be constructed. In line 227, the WCS keyword is set to 2 * [ctype], which means the sky WCS will have two right-ascension axes and no declination axis. That hardly makes sense and shouldn't work if the WCS is used by an actual wcs routine. Line 213 should read
ctype = ["LINEAR", "LINEAR"] if wcs_suffix in "DX" else ["RA---TAN", "DEC--TAN"]

@teutoburg
Copy link
Contributor Author

In line 213, ctype is set to RA---TAN if a sky WCS is to be constructed. In line 227, the WCS keyword is set to 2 * [ctype], which means the sky WCS will have two right-ascension axes and no declination axis. That hardly makes sense and shouldn't work if the WCS is used by an actual wcs routine.

Yeah, the same realisation occurred to me shortly after submitting the PR. The function in question is used all the time in ScopeSim. I believe somehow assumed (without ever actually conforming this 🤦‍♂️) that the WCS interface is smart enough to change the second axis to DEC--TAN, as it also performs some other checks and transformations (unlike setting WCS head keywords manually). But it doesn't.

However, I now checked what's actually happening: The default value for the WCS suffix is an empty string (as appropriate for the 0th (sky) WCS in the header). But the check wcs_suffix in "DX"` (which is supposed to catch both "D" and "X" suffices) also is True for the empty string. So, in the (default) case of no suffix for the sky WCS, the resulting CTYPEn is "LINEAR" for both axes. Which is fine because ScopeSim still assumes a linear sky anyway. But that's still not what that function was supposed to do. So yeah, some test should have caught that 🙃

@teutoburg
Copy link
Contributor Author

So probably something like

ctype = ["LINEAR", "LINEAR"] if wcs_suffix and wcs_suffix in "DX" else ["RA---TAN", "DEC--TAN"]

should do the trick...

@teutoburg
Copy link
Contributor Author

Or perhaps rather

ctype = ["LINEAR", "LINEAR"] if wcs_suffix in {"D", X"} else ["RA---TAN", "DEC--TAN"]

But I'd have to check what that does for an empty string (typing on mobile, sadly no Python interpreter here...).

@teutoburg
Copy link
Contributor Author

Further explanation about the "DX": the "D" is obviously the detector WCS in mm, as used in ScopeSim. The "X" was added by me (I believe in the context of the off-by-one fix) as a placeholder for a "LINEAR but deg/arcsec (and not mm)" WCS, that is useful to simplify test cases. As in, once ScopeSim eventually realises that is sky is, in fact, nonlinear, we can still use this key to create simplified HDUs for testing purposes.

@teutoburg teutoburg requested review from oczoske and hugobuddel March 13, 2025 12:47
logger.debug("NAXISn == 0, using minimum of 1.")
naxis = np.ones_like(naxis)
naxis[naxis == 0] = 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 205 is not needed, 208 shouldn't do any harm in any case, but it might be better to be safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, but I wanted to include the log message to catch any potential weird cases. I thought of going with a masked array (like we did for the NaN check) and emit the log msg based on the mask, but that seemed overkill...

@teutoburg teutoburg merged commit 81f38ef into main Mar 13, 2025
39 of 40 checks passed
@teutoburg teutoburg deleted the fh/atleastonepixelinheader branch March 13, 2025 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix PR resolving one or more bugs
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Weird behavior for trivial table header
3 participants