Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
janerigby opened this issue Feb 3, 2021 · 1 comment
Open

Comments

@janerigby
Copy link

janerigby commented Feb 3, 2021

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) 
@tbowers7
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants