Skip to content

Cannot identify .fits file #6972

Closed
@rychalm

Description

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions