Skip to content

Instantly share code, notes, and snippets.

@rickbassham
Created February 11, 2018 19:00
Show Gist options
  • Save rickbassham/b02e7c4f095e173c220da2b216bd476c to your computer and use it in GitHub Desktop.
Save rickbassham/b02e7c4f095e173c220da2b216bd476c to your computer and use it in GitHub Desktop.
Convert FIT to TIFF Python
from astropy.io import fits
from PIL import Image
import numpy
import sys
import os
filepath = 'test.fit'
name, ext = os.path.splitext(filepath)
img = fits.open(filepath)
img.info()
data = img[0].data
width = data.shape[1]
height = data.shape[0]
outputArray = numpy.array(data, dtype=numpy.int16)
output = Image.fromarray(outputArray.reshape((height, width)), "I;16")
output.save(name + ".tif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment