Created
August 17, 2016 14:53
-
-
Save calvin-brizzi/973e16c9aa7f31d3b79d338fa5ee13da to your computer and use it in GitHub Desktop.
Convert FITS data cube to JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requires astropy ("pip install astropy") | |
# Creates HUGE files 42MB > 430MB in my test | |
from astropy.io import fits | |
import json | |
# Change to your fits file | |
hdulist = fits.open("in.fits") | |
# My fits file only had one data cube in it | |
scidata = hdulist[0].data | |
z, x, y = scidata.shape | |
mn = scidata.min() | |
mx = scidata.max() | |
scidata -= mn | |
scidata /= (mx - mn) | |
datal = scidata.tolist() | |
exdata = {"x": x, "y":y, "z":z, "data": datal} | |
with open ('data.json', 'w') as fp: | |
json.dump(exdata, fp, indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment