Skip to content

Conversation

@radarhere
Copy link
Member

Resolves #4054, adding reading of FITS files by upgrading the FITS plugin from a StubImageFile to an ImageFile.

I have updated the hopper FITS test image. The original was similar, but not equal, to hopper("L"), so I generated this new file with Pillow and ImageMagick. The updated file is still L mode, like the original.

if _handler is None or not hasattr("_handler", "save"):
raise OSError("FITS save handler not installed")
_handler.save(im, fp, filename)
offset = math.ceil(self.fp.tell() / 2880) * 2880
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 documentation mentioned that the offset for the image data was a multiple of 2880.

https://fits.gsfc.nasa.gov/fits_primer.html

Each header or data unit is a multiple of 2880 bytes long. If necessary, the header or data unit is padded out to the required length with ASCII blanks or NULLs depending on the type of unit.

The data unit, if present, immediately follows the last 2880-byte block in the header unit.

@radarhere radarhere mentioned this pull request Feb 15, 2022
Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

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

Let's also add to release notes.

Do we need to worry about the removed FITSStubImageFile class?

@radarhere
Copy link
Member Author

Ok, I've figured out how to deprecate FitsStubImagePlugin.

  • If a FITS image is opened, FitsImagePlugin is used
  • If a FitsStubImagePlugin handler is registered, then a deprecation warning is raised. The handler is used, and FitsImagePlugin is not.

Since this PR is only adding support for reading, you might wonder what someone is supposed to do if they were saving images using FitsStubImagePlugin. Well, it turns out, that's not actually a concern - there is a bug (#6071) that means they can't have been saving images using FitsStubImagePlugin.

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

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

Looks good, couple of little docs autolink nits.

@radarhere
Copy link
Member Author

The links to FitsImagePlugin are now there - but I discovered I couldn't link to FitsStubImagePlugin, because I removed it from the documentation to prevent new users from finding it.

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

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

Makes sense, let's just code format it then.

Co-authored-by: Hugo van Kemenade <[email protected]>
@hugovk hugovk added the automerge Automatically merge PRs that are ready label Feb 20, 2022
@mergify mergify bot merged commit c58d281 into python-pillow:main Feb 20, 2022
@radarhere radarhere deleted the fits branch February 20, 2022 21:51
@hugovk hugovk changed the title Added FITS reading Added FITS reading, deprecate FitsStubImagePlugin Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge Automatically merge PRs that are ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reading FITS images

2 participants