ccdproc icon indicating copy to clipboard operation
ccdproc copied to clipboard

ImageFileCollection.ccds(return_fname=True) does not return the header

Open janerigby opened this issue 4 years ago • 1 comments

From the documentation for the method ImageFileCollection.ccds(), it seems that if return_fname=True, then it should return "the tuple (header, file_name)" instead of just header. I cannot figure out how to do that in practice.
Iterating like this: for ccd, fname in image_collection.ccds(return_fname=True) : does return the CCDData object in question, and its filename, but not the header. I can't figure out how to get the header. Instead I had to do a clunky workaround, that puts the data in a np array and then converts it to a CCDData object, since there doesn't seem to be a way to do hdu.ccd :

for hdu, fname in image_collection.hdus(return_fname=True) :   

    header = hdu.header

    data = hdu.data

    data_ccd = CCDData(hdu.data, unit='MJy/sr', header=header) # clunky.  Needed to iterate all of header, data, filename

    subtracted = data_ccd.subtract(combined_image, handle_meta='first_found') # This saves the header from data_ccd

    newname=sub('_cbcd.fits', '_bcbcd.fits', fname)

    subtracted.write(outdir + newname, overwrite=True) 

janerigby avatar Feb 03 '21 15:02 janerigby

@janerigby The header is an attribute of the CCDData object, (e.g., ccd.header) and directly accessible. For the example you included, it would not seem you need to separately handle the header information at all:

for ccd, fname in image_collection.ccds(return_fname=True) :   

    subtracted = ccd.subtract(combined_image, handle_meta='first_found')

    #Add a HISTORY to the header:
    subtracted.header['HISTORY'] = 'Subtracted combined_image'
    
    newname=sub('_cbcd.fits', '_bcbcd.fits', fname)

    subtracted.write(outdir + newname, overwrite=True) 

where we explicitly add a header field HISTORY to the new CCDData object.

Please correct me if I have misunderstood your application.

tbowers7 avatar May 20 '21 01:05 tbowers7