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
ENDHDU 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.