Here we assume an image stack in file
FITS do not memory map except in special cases, and usually they are under 2 GB so you can work with the whole image stack on a modern PC.
That is, you normally can’t just load a single image from an image stack, you load the whole image stack and then index the 3-D array in RAM.
from astropy.io import fits fn = 'myimg.fits' with fits.open(fn, mode='readonly') as h: img = h.data lat = h.header['GLAT'] lon = h.header['GLON']
The header contained location metadata that we assigned to
Avoid using FITS
FITS is an old workhorse format, but generally one should avoid using FITS unless colleagues/boss demand FITS. Newer image formats are much more efficient and robust such as NetCDF4 and HDF5. HDF5 and NetCDF4 can have enormous, effectively unlimited file sizes, and easily store arbitrary organizations of variables, data, and metadata.