0

I am currently trying to convert a .cr2 into .fits file. I am currently unable to create .fits as any file I create doesn't open or work because of the wrong shape of fits.

I have tried using the solution Write 3d Numpy array to FITS file with Astropy but, still, it doesn't work.

import numpy as np
from astropy.io import fits
im = imageio.imread(r'E:\FYP\cr.cr2', format="RAW-FI")
a = np.array(im)
print (a.shape)
hdu = fits.PrimaryHDU(a)
hdulist = fits.HDUList([hdu])
hdulist.writeto(r'E:\FYPcr.fits')

It successfully creates the .fits file but, gives an error when opened "Cannot read fits file". Whenever I try to open a fits file created from another software it opens without any problem.

  • 1
    You didn't specify exactly what gives an error "Cannot read fits file". What can't read the file? Note, also, because you're on Windows you should probably use raw strings for paths like `r'E\FYPcr.fits'`, since otherwise the `\\` can be misinterpreted as part of an escape sequence. See [this answer](https://stackoverflow.com/a/2953843/982257) for more details. It's probably not your problem but stranger things have happened. – Iguananaut Sep 09 '19 at 14:04
  • Any software that reads .fits images. Such as CCDStack which I currently use do not recognize the shape of this .fits file. – Burhan Khan Sep 09 '19 at 17:58
  • 1
    You could simply use **ImageMagick** in the Terminal `magick input.cr2 output.fits` Replace `magick` with `convert` if using v6 rather than v7. – Mark Setchell Sep 09 '19 at 20:31
  • Well, what is the shape? In your example you have `print(a.shape)` but you didn't actually tell us what it is. Maybe CCDStack can't work with arbitrary-dimensional FITS data. – Iguananaut Sep 10 '19 at 07:38

0 Answers0