astropy / ccdproc

Astropy affiliated package for reducing optical/IR CCD data
https://ccdproc.readthedocs.io
BSD 3-Clause "New" or "Revised" License
89 stars 87 forks source link

Possible to write out a header with CCDData.write()? #386

Closed jmccormac01 closed 8 years ago

jmccormac01 commented 8 years ago

Hi guys, Today after reducing some images with ccdproc I noticed that the CCDData.write method has no specific option for writing a header with the CCDData array. Is this correct, or am I missing something?

I tried specifying a kwarg combo but it did not like header=hdr where hdr is my modified header (light_travel_time update etc).

I know I can write out the image with fits.writeto, which is what CCDData.write seems to use under the hood. I had a quick look at the code but realised quickly that I need to read more on HDU objects :)

Cheers James

MSeifert04 commented 8 years ago

@jmccormac01 If you use CCDData.write the CCDData.meta (alias for CCDData.header) is written to the same PrimaryHDU as the CCDData.data (relevant code section). So you could just set the header :ccd.meta = hdr; ccd.write(...) before writing.

Or am I misunderstanding your intentions?

Edit:

However there might be one problem: The bunit and wcs-related keywords will be updated with the values saved in .unit and .wcs. For .wcs you can work around it by setting ccd.wcs = None before writing.

jmccormac01 commented 8 years ago

Ok I see. Thanks for the clarification. This is what I was looking for. The WCS info in this case is not likely to be accurate (spectroscopy, so no astrometric fit), I can try setting it to None as you suggested. I hadn't noticed the unit keywords before, I assume they are to say whether the data has been corrected by the gain factor or not?

MSeifert04 commented 8 years ago

I don't know what the rationale for unit was with regard to CCDData but generally astropy has a very powerful framework for correct unit "propagation" so it was obvious to include it (optionally) in NDData.

With regard to your issue: it would be good to know what you changed, based on which functions and what was written to the file. It may be a good idea to wrap that function within ccdproc so the next user doesn't have to manually set the attributes.

crawfordsm commented 8 years ago

@jmccormac01 Yes, the unit is for tracking gain corrections through the reductions.

If you create the CCDData object from read, it should have the header or if you set the header initially, it should propagate through and be written out when using ccd.write