Skip to content

Instantly share code, notes, and snippets.

@pllim
Created June 5, 2019 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pllim/fd5af4a7ef44cce2d0b3d82ae526697b to your computer and use it in GitHub Desktop.
Save pllim/fd5af4a7ef44cce2d0b3d82ae526697b to your computer and use it in GitHub Desktop.
DSII TESS cube memory profiling with FITS memmap
"""
Modify the amount of sub-cube you wish to extract in the
``fits_mmap()`` function. Then run this::
python measure_memory.py
My results below. This shows that memory mapping should only
consume the memory used in accessed sub-cube, not the entire cube.
Trying to calculate the mean of the entire cube did not work,
as expected.
Line # Mem usage Increment Line Contents
================================================
6 41.7 MiB 41.7 MiB @profile
7 def fits_mmap():
8 # ImageHDU (2, 1282, 2136, 2078) float32
9 41.7 MiB 0.0 MiB with fits.open('tess-s0001-1-1-cube.fits', memmap=True) as pf:
10 47.5 MiB 5.7 MiB data = pf[1].data[0, 0, :10, :10]
11 47.6 MiB 0.2 MiB print(data.mean())
12 47.6 MiB 0.0 MiB return data
Line # Mem usage Increment Line Contents
================================================
6 41.7 MiB 41.7 MiB @profile
7 def fits_mmap():
8 # ImageHDU (2, 1282, 2136, 2078) float32
9 41.7 MiB 0.0 MiB with fits.open('tess-s0001-1-1-cube.fits', memmap=True) as pf:
10 47.5 MiB 5.7 MiB data = pf[1].data[0, :, :100, :100]
11 57.5 MiB 10.1 MiB print(data.mean())
12 57.5 MiB 0.0 MiB return data
"""
from astropy.io import fits
from memory_profiler import profile
@profile
def fits_mmap():
# ImageHDU (2, 1282, 2136, 2078) float32
with fits.open('tess-s0001-1-1-cube.fits', memmap=True) as pf:
data = pf[1].data[0, 0, :100, :100]
print(data.mean())
return data
if __name__ == '__main__':
fits_mmap()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment