Assume an image stack in file
FITS files do not memory map except in special cases.
Usually FITS files are under 2 GB, making it feasible to work with the whole image stack on a modern PC.
That is, 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
Newer image formats HDF5 and NetCDF4 can have effectively unlimited file sizes, and easily store arbitrary organizations of variables, data, and metadata.
Related: read FITS image stack in Matlab