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

Cannot identify .fits file #6972

Closed
rychalm opened this issue Feb 25, 2023 · 3 comments · Fixed by #6973
Closed

Cannot identify .fits file #6972

rychalm opened this issue Feb 25, 2023 · 3 comments · Fixed by #6973

Comments

@rychalm
Copy link

rychalm commented Feb 25, 2023

What did you do?

Tried using pillow for opening/handling a .fits file for training a machine learning model. According to the documentation opening/reading fits files should be enabled? Or am I misunderstanding how a fits file should be opened?

From Issue 4054/ PR 6056

I've created PR #6056 to resolve this. If that is merged, you should no longer have to worry about register_handler(), but can instead just Image.open("sample.fits").

What did you expect to happen?

Not recieving a "cannot identify error" while using Image.open. Expected the function to work as with other supported file formats. The .fits files in question are not corrupted, and can be opened as normal with other software.

What happened?

from PIL import Image
with Image.open('example.fits') as im:
    im.verify()
---------------------------------------------------------------------------
UnidentifiedImageError                    Traceback (most recent call last)
Cell In [38], line 2
      1 from PIL import FitsImagePlugin, ImageFile
----> 2 with Image.open('example.fits') as im:
      3     im.verify()

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PIL\Image.py:3186, in open(fp, mode, formats)
   3184 for message in accept_warnings:
   3185     warnings.warn(message)
-> 3186 raise UnidentifiedImageError(
   3187     "cannot identify image file %r" % (filename if filename else fp)
   3188 )

UnidentifiedImageError: cannot identify image file 'example.fits'

What are your OS, Python and Pillow versions?

  • OS: windows 10
  • Python: 3.10
  • Pillow: 9.3.0
@radarhere
Copy link
Member

It should be working as you understand it, yes.

Here's a test FITS image that we have - https://github.com/python-pillow/Pillow/blob/main/Tests/images/hopper.fits. If you download it, are you able to open it with Pillow?

  • If so, then there is something different about your file that we will need to check. Are you able to upload a copy of the file in question?
  • If not, then there is something odd happening with your installation. Are you quite sure you are running Pillow >= 9.1.0? From within your code, could you run
from PIL import __version__
print(__version__)

to check?

@rychalm
Copy link
Author

rychalm commented Feb 25, 2023

The hopper.fits works properly on my end. Here's the example file https://github.com/rychalm/example.fits/blob/main/example.fits Looks like the header is somewhat different between the files. Maybe there's some issue there?

Using the code provided gives me version 9.3.0

Edit to add: The example file was generated from original raw data, using astropy. That original file does not work either (none of my fits files work with pillow). Cannot really upload it as it is multiple gigabytes.

@radarhere
Copy link
Member

Thanks. I apparently didn't consider that there might be comments in the header in my previous PR.

I've created PR #6973 to resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants