In my script, I load all files in a ccdproc collection and try to iterate on it like this:
for img, fname in collection.ccds(return_fname=True):
But then I get the following error:
ValueError: a unit for CCDData must be specified.
From what I've read
, this seems to be due to a missing BUNIT header in the FITS file. So I've wrote the following workaround:
for hdu in collection.hdus(overwrite=True):
hdu.header['bunit'] = 'adu'
hdu.header['radesys'] = 'FK5'
The problem is that it somehow resets the "created at" value of the FITS file and generally feels like bad practice.
So my question(s) is (are): Are we really missing a BUNIT header or is my code wrong? If we're missing it, is there a way to tell Ekos to write it in?
Bonus question: Say I wanted to run each newly acquired FITS file through a simple pipeline (write the BUNIT value and update the WCS with a freshly solved one), what would be the best way to do it?
I really don't know anything about how standard that header is, as I've only learned its existence when seeing that error I'm getting from my Python scripts. I solved it by creating the header with the value "adu", so that's what worked for me.
Here is the paragraph about this header in the FITS standard:
REFERENCE: FITS Standard
COMMENT: physical units of the array values
DEFINITION: The value field shall contain a character string,
describing the physical units in which the quantities in the array,
after application of BSCALE and BZERO, are expressed. The units of
all FITS header keyword values, with the exception of measurements of
angles, should conform with the recommendations in the IAU Style
Manual. For angular measurements given as floating point values and
specified with reserved keywords, degrees are the recommended units
(with the units, if specified, given as 'deg').
My understanding is that the value would pretty much always be "adu" for all uses specific to consumer-grade astronomical cameras. Maybe in some research environment a camera can be directly counting individual photons, but for what we all do here it should be "adu".
The keyword in this list are only "reserved", this meant they cannot be used with another signification.
But they are not mandatory and processing software must expect they are not present. In fact I never see any capture software that add this keyword because it make some sens only after calibration to some physical flux units.
Instead of adding a dummy value like "adu" it is better to report that to astro-pipelines so it can be fixed to work without this keyword.
I am the one who wrote astro-pipelines and I'm not sure how to fix that! As I explain on the post above, my workaround is to actually write that header down before loading any collection with ccdproc.
Maybe the right way to work it out is to have a part of my pipelines automatically running on each captured frame freshly coming out of Ekos? But then I'm not sure how to properly implement this. Would the best way to have it done through the "post-capture script" hook on Ekos? Or with a separate script that monitors new files in the folder and processes them?
Anyway the problem is with ccdproc, there is already an issue for that: github.com/astropy/astropy/issues/10977
A proposed solution is to add a default value for BUNIT, I not follow further to see if the proposed solution was merged.