Fix bug for integer compressed images with blanks#16550
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
There was a problem hiding this comment.
Welcome to Astropy 👋 and congratulations on your first pull request! 🎉
A project member will respond to you as soon as possible; in the meantime, please have a look over the Checklist for Contributed Code and make sure you've addressed as many of the questions there as possible.
If you feel that this pull request has not been responded to in a timely manner, please send a message directly to the development mailing list. If the issue is urgent or sensitive in nature (e.g., a security vulnerability) please send an e-mail directly to the private e-mail [email protected].
I fixed the formatting and added a changelog entry. Let me know if you see other changes that are required. I'm working on creating a small compressed image that can be used for testing. |
|
@neutrinoceros I'm testing this fix on various images and am beginning to wonder whether I have the correct fix for this issue. Currently if we read a FITS file with an uncompressed integer image that has a With my version of the code, a FITS file with a compressed integer image that has a I think for consistency with the uncompressed image behavior, this should instead convert the array to This was a bit tricky to discover because the Pan-STARRS images in the original bug report also have I do think this is important to fix soon! Currently it simply dies with an exception when one of these images is opened. That is clearly bad. |
I can see both ways as satisfying solutions, albeit non ideal. I think @saimn and/or @astrofrog should weigh in here. |
|
@neutrinoceros I figured out the right place to make this change. The code that applies the I updated the description to reflect these additional changes. This version should have the correct behavior (as similar to uncompressed image HDUs as possible). There is room for improvement to the handling of errors in compressed image headers. I have not tried to make these changes because the code in
|
|
@neutrinoceros I made some further improvements in the code that cleaned up some remaining issues with unusual file formats. I believe this patch is complete now. I added new tests in the I believe this is very close to complete, so if you or others can help get it through the final stages, that would be very helpful. |
|
Thanks @pllim ! I fixed some filename typos in my test code, and now the patch coverage is 100% complete. All checks now pass. |
|
Alas, we just updated branch protection rules due to matplotlib bump. Would you mind rebasing? Thanks! |
|
@pllim Ah crap, I think I screwed that up. This is very much out of my comfort zone in git! I'll see if I can fix it. If not I may have to start over. |
|
Maybe try this? And see if the history looks better before you force push? |
ecbaf19 to
d468389
Compare
|
Whew, thanks! That did the trick. I think things look like they will be OK now. I'm just waiting to confirm the checks are all still OK. |
There was a problem hiding this comment.
First of, I want to point out this seems like great work to me, though again I'm no authority when it comes to io.fits, but your work is greatly appreciated.
Since you added tests (which is great) alongside some binary files, it would be important to also include the code that was used to generate them if possible. See
#16371 for context.
@neutrinoceros @pllim I have the code ready to check in but need some guidance before I can complete the process. |
9870dab to
1080b7d
Compare
|
I squashed everything into a single commit and changed the fix to be against the |
Co-authored-by: Nathaniel Starkman <[email protected]>
Change the value used for the BLANK keyword to -16384 instead of using the default value of -32768. That could catch errors in the default assignment. Add an additional test using an image with a ZBLANK column plus a BLANK keyword in the header. That is a standard configuration and is processed without any warnings.
|
I haven't been following the convo. The failure isn't from change log, @dhomeier . It is because this PR is opened against v6.1.x and not main. If that is intentional, then close and re-open the PR to re-run the checks. So, this means that this patch is only going into the next v6.1 series and WILL NOT be in v7.0.0. Is that correct? |
|
Yes, it is intentional – see #16550 (comment) for the rationale. |
|
Thank you for your contribution and your patience throughout our review process, @rlwastro! FITS code is something we approach only with great care and caution. ;-) |
…6550 to main) Co-authored-by: Rick White <[email protected]>
Backport #16550 to main: Fix bug for integer compressed images with blanks
…6550 to main) Co-authored-by: Rick White <[email protected]>
Description
This pull request is to address a bug that raises an exception when some compressed images are read.
In
_tiled_compression.py:decompress_image_data_section(), blanked pixels are assigned the valuenp.nan. That is incorrect for integer datatypes and raises an exception becausenp.nancannot be converted to an integer.The fix is to use the
BLANKkeyword from the header. If noBLANKorZBLANKkeyword is found for integer datatypes, the most negative integer (as determined byZBITPIX) is used as a fill value. That should not happen if pixel-blanking is specified (otherwise why isZBLANKthere at all?). AnAstropyUserWarningis issued in that case.This also fixes a bug in
decompress_image_data_section()for the case whereBLANKis specified in the header butZBLANKis not. The FITS standard recommends thatBLANKshould be used instead ofZBLANKfor integer images. For images withBLANKbut notZBLANK, the current code would not work correctly. The new version handles integer compressed images that specify eitherBLANKorZBLANK(or both).In the
compressed.pymodule, integer images with blanks are converted to floats withNaNvalues. Previously that conversion happened only ifBZERO/BSCALEkeywords were also specified. The new code does the conversion even ifBZEROandBSCALEare not defined. The new behavior is consistent with the handling of these keywords in uncompressed image HDUs.Test code is included.
Fixes #15236