How to minimally save a deep_coadd cutout into a fits file?

Suppose I get a deep_coadd image using butler.get() (and then take a cutout, does not matter). Now I want to save it to a fits file. cutout.writeFits() does the job but write a lot of long tables those are not necessary for me, and it makes the fits file unnecessarily large (up to ~100 MB/cutout sometimes).

  1. Is there a simple way to use writeFits to only write PRIMARY , IMAGE , MASK ,VARIANCE , not the rest of the HDUs?
  2. If not, what are my other options?

I see a writeFits() function here
https://pipelines.lsst.io/py-api/lsst.meas.algorithms.writeFits.html#lsst.meas.algorithms.writeFits
Is it the same function as ExposureF.writeFits() that I used above, or there are multiple functions with the same name?
Feedback: A lot of confusions, it would be helpful to demonstrate in a tutorial how to save the images/cutouts (ExposureF) efficiently!
Thanks in advance.

Hi @deltasata, thank you for your question.

Here is the simplest approach you could try:

import lsst.afw.display as afw_display
afw_display.writeFitsImage('yourFitsFileName.fits',  ExposureF.maskedImage,  wcs=ExposureF.wcs)

In your case, you can replace ExposureF with cutout. This will save only the Image, Mask, and Variance HDUs, with the WCS recorded in the Primary HDU. Also, I recommend referring to the guidance on using WCSs in DP1.

Note that ExposureF.writeFits is completely different from the writeFits helper function in lsst.meas.algorithms, which is designed specifically for writing stamps.

I think this should fully resolve your issue, so I’m marking this post as the solution. If your issue persists please reply in thread, or if you encounter new issues please open new Topics at any time.