The fits file is an image file format used for exploration data and astronomical data, and consists of a part called a header that contains various information such as time and posture, and an array part of image size (for example, 1024x1024). There is also a cube-shaped fits file, which consists of n headers and an image array. https://ja.wikipedia.org/wiki/FITS About reading and displaying fits data using the Python library astropy.io.fits. There is DS9 etc. as a viewer of fits.
PDS Planetary Data System NASA exploration data archive. Anyone can use it for free. If you download the data from here, you can see the image of your favorite planet! Images are published in the fits file format.
For example, the data for Hayabusa is here. All image data taken by Hayabusa is open to the public.
Install with anaconda.
conda install astropy
Read the 0th data. The image consists of a header + an image array.
import astropy.io.fits as fits
import matplotlib.pyplot as plt
hdulist=pyfits.open('file.fits')
hdu=hdulist[0]
data=hdu.data #data=fits.getdata('file.fits',0)But you can.
header=hdu.header
plt.imshow(data)
plt.show()
When retrieving header items, such as TI_0
print header["TI_0"]
Specifying the X and Yth pixels
data[Y][X]
hdu = fits.PrimaryHDU(im)
hdulist = fits.HDUList([hdu])
hdulist.writeto('new.fits',overwrite=True)
fits is one set (hdu) with header and image array. It consists of hdu = PrimaryHDU (data, header)
. When using a large number of extensions, create multiple second and subsequent hdu with fits.ImageHDU
, and use one like HDUList ([hdu1, hdu2, hdu3])
Make it a file. That is, it is possible to save a plurality of images in one file.
It can be overwritten by setting overwrite = True.
hdu.header['NEWKEYWORD']='something'
Recommended Posts