MultiHDU FITS Files

For some years now I have been using astropy to reduce and combine my master reduction frames. Suddenly for the past month or so, with no changes to my programs, I it is producing FITS files with 3 HDUs. Looks like one is the uncertainty, and the other is a mask, all zeros. I have never used the uncertainty (yes, I will try to learn what to do with it) or the mask (eventually I will use it to mask hot/dead pixels?) How do I prevent their appearance in my FITS files?
Thanks

Can you elaborate a bit more on what “Suddenly […] with no changes to my programs” means? Clearly something changed… Did you upgrade either astropy or CCDproc or a similar package that you use?
Can you post (or link to) an example of the code you use to write the files, so we can see what the input to your program is? It’s hard to find out what’s going on without seeing the code.

Astropy and/or ccdproc have been updated on my system within the past month or so. It is my own programs which use astropy/ccdproc functions which have not changed. What I am looking for is a setting in ccdproc.combine() to prevent the two extra HDUs from being created. Or, second best would be a method to remove them before writing to disk.

Here is code that reproduces my problem:

files = glob.glob(‘ASASSN-V_J082218.33-001824.3*.fit’)
stack = ccdp.combine(files, method=‘average’,
sigma_clip=True, sigma_clip_low_thresh=3, sigma_clip_high_thresh=3,
sigma_clip_func=np.ma.median, sigma_clip_dev_func=mad_std,
mem_limit=4e9)
stack.write(‘test.fit’, overwrite=True)

I get the following extra two HDUs in each combined image:

HDU number = 2
XTENSION= 'IMAGE ’ / Image extension
BITPIX = 8 / array data type
NAXIS = 2 / number of array dimensions
NAXIS1 = 3326
NAXIS2 = 2504
PCOUNT = 0 / number of parameters
GCOUNT = 1 / number of groups
EXTNAME = 'MASK ’ / extension name
END

HDU number = 3
XTENSION= 'IMAGE ’ / Image extension
BITPIX = -64 / array data type
NAXIS = 2 / number of array dimensions
NAXIS1 = 3326
NAXIS2 = 2504
PCOUNT = 0 / number of parameters
GCOUNT = 1 / number of groups
UTYPE = ‘StdDevUncertainty’
EXTNAME = 'UNCERT ’ / extension name
END

I did not run this code, because I don’t have CCD images handy to try it on, however, in general you can delete elements from a HDUList, e.g. like so:

stack = ccdp.combine(files, method=‘average’,
sigma_clip=True, sigma_clip_low_thresh=3, sigma_clip_high_thresh=3,
sigma_clip_func=np.ma.median, sigma_clip_dev_func=mad_std,
mem_limit=4e9)
i_dont_want_this_1 = stack.pop()
i_dont_want_this_2 = stack.pop()
stack.write(‘test.fit’, overwrite=True)

I think this won’t work directly on stack as it is a CCDData object, not an HDUList, but it looks like you could also get rid of the extra HDUs sort of on the fly by changing the default parameters:

stack.to_hdu(hdu_mask=None, hdu_uncertainty=None).writeto(‘test.fit’, overwrite=True)

Thanks hamogu - I’m a little nervous about popping the hdus in case I pop the image one instead of one of the extras even though it worked when I tried it in a Jupyter notebook. But it’s good to know about this facility.
Thanks dhomeier - this is exactly what I was looking for - prevent the extra hdus from being created in the first place.

1 Like