35 #include "muse_imagelist.h"
38 #include "muse_pfits.h"
39 #include "muse_quadrants.h"
40 #include "muse_quality.h"
41 #include "muse_utils.h"
84 for (k = 0; k < aList->
size; k++) {
87 cpl_free(aList->
list);
105 cpl_ensure(aList, CPL_ERROR_NULL_INPUT, 0);
128 cpl_ensure(aList, CPL_ERROR_NULL_INPUT, NULL);
129 cpl_ensure(aIdx < aList->size, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
131 return aList->
list[aIdx];
158 cpl_ensure_code(aList && aImage, CPL_ERROR_NULL_INPUT);
161 for (k = 0; k < aList->
size; k++) {
163 cpl_ensure_code(aList->
list[k] != aImage, CPL_ERROR_ILLEGAL_INPUT);
166 if (aIdx >= aList->
size || aList->
list == NULL) {
170 for (k = aList->
size; k <= aIdx; k++) {
171 aList->
list[k] = NULL;
173 aList->
size = aIdx + 1;
177 aList->
list[aIdx] = aImage;
178 return CPL_ERROR_NONE;
202 cpl_ensure(aList, CPL_ERROR_NULL_INPUT, -1);
211 for (k = 1; k < aList->
size; k++) {
235 cpl_msg_info(__func__,
" index median mean stdev scale");
237 for (k = 0; k < aList->
size; k++) {
240 const char *empty =
"----------";
241 cpl_msg_info(__func__,
"%5d %10s %10s %10s %10s" , k,
242 empty, empty, empty, empty);
247 cpl_msg_info(__func__,
"%5d %10.2f %10.2f %10.2f %10.2f", k,
248 cpl_image_get_median(image->
data),
249 cpl_image_get_mean(image->
data),
250 cpl_image_get_stdev(image->
data), scale);
270 cpl_ensure_code(aList, CPL_ERROR_NULL_INPUT);
272 cpl_msg_info(__func__,
"Scale all images to %7.2fs exposure time",
274 cpl_msg_debug(__func__,
"Image EXPTIME scale");
275 cpl_msg_debug(__func__,
" 1 %7.2fs 1.000", t0);
277 for (k = 1; k < aList->
size; k++) {
281 cpl_msg_debug(__func__,
"%4d %7.2fs %6.3f", k+1, t, scale);
283 cpl_propertylist_update_double(image->
header,
"EXPTIME", t0);
285 return CPL_ERROR_NONE;
326 cpl_ensure(aList, CPL_ERROR_NULL_INPUT, NULL);
327 unsigned int nvalues = aList->
size;
328 cpl_ensure(nvalues > 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
334 cpl_image *ronimage = cpl_image_new(4 * 2, nvalues, CPL_TYPE_DOUBLE);
339 for (k = 0; k < nvalues; k++) {
341 cpl_image *diff = cpl_image_subtract_create(aList->
list[k]->
data,
343 for (n = 1; n <= 4; n++) {
348 cpl_stats *s = cpl_stats_new_from_image_window(diff, CPL_STATS_ALL,
349 window[0], window[2],
350 window[1], window[3]);
351 cpl_msg_debug(__func__,
"Quadrant %hhu stats: %f+/-%f %f %f..%f\n", n,
352 cpl_stats_get_mean(s), cpl_stats_get_stdev(s),
353 cpl_stats_get_median(s),
354 cpl_stats_get_min(s), cpl_stats_get_max(s));
357 double ron = 100., ronerr = 1000.;
358 unsigned int niter = 0;
359 #pragma omp critical (cpl_flux_get_noise)
361 srand(niter++ * 100 + 1);
362 cpl_flux_get_noise_window(diff, window, aHalfsize, aNSamples,
364 }
while (ronerr > 0.1 * ron && niter < 5);
366 cpl_msg_debug(__func__,
"--> intermediate RON=%f+/-%f (GAIN=%f)",
370 ron *= gain / sqrt(2);
371 ronerr *= gain / sqrt(2);
372 cpl_image_set(ronimage, n, k+1, ron);
373 cpl_image_set(ronimage, n+4, k+1, ronerr);
376 cpl_image_delete(diff);
380 cpl_vector *ron = cpl_vector_new(4),
381 *ronerr = cpl_vector_new(4);
382 for (n = 1; n <= 4; n++) {
384 cpl_stats *ronstats, *ronerrstats;
385 ronstats = cpl_stats_new_from_image_window(ronimage, CPL_STATS_ALL,
387 ronerrstats = cpl_stats_new_from_image_window(ronimage, CPL_STATS_ALL,
388 n+4, 1, n+4, nvalues);
389 cpl_msg_debug(__func__,
"IFU %hhu, quadrant %hhu RON: %f+/-%f %f %f..%f\n",
390 ifu, n, cpl_stats_get_mean(ronstats),
391 cpl_stats_get_stdev(ronstats),
392 cpl_stats_get_median(ronstats),
393 cpl_stats_get_min(ronstats),
394 cpl_stats_get_max(ronstats));
395 cpl_msg_debug(__func__,
"IFU %hhu, quadrant %hhu RONERR: %f+/-%f %f %f..%f\n",
396 ifu, n, cpl_stats_get_mean(ronerrstats),
397 cpl_stats_get_stdev(ronerrstats),
398 cpl_stats_get_median(ronerrstats),
399 cpl_stats_get_min(ronerrstats),
400 cpl_stats_get_max(ronerrstats));
401 cpl_stats_delete(ronstats);
402 cpl_stats_delete(ronerrstats);
405 double ronmean = cpl_image_get_mean_window(ronimage, n, 1, n, nvalues),
406 ronmeanerr = cpl_image_get_mean_window(ronimage, n+4, 1, n+4, nvalues);
407 cpl_vector_set(ron, n - 1, ronmean);
408 cpl_vector_set(ronerr, n - 1, ronmeanerr);
412 if (ronmean < 1. || ronmean > 5.) {
413 cpl_msg_warning(__func__,
"The RON value computed for quadrant %hhu in "
414 "IFU %hhu is likely wrong (outside the range 1..5 count: "
415 "%.2f +/- %.2f count; the raw header says %.2f count)", n,
416 ifu, ronmean, ronmeanerr, ronheader);
419 cpl_image_delete(ronimage);
423 for (k = 0; k < nvalues; k++) {
424 for (n = 1; n <= 4; n++) {
430 double variance = (1. + 1. / (pow(2 * aHalfsize + 1, 2) * aNSamples))
431 * pow(cpl_vector_get(ron, n-1)/gain, 2);
433 cpl_msg_info(__func__,
"IFU %hhu, quadrant %hhu: RON = %.3f +/- %.3f "
434 "count ==> variance = %.4f adu**2 (1st value of image "
435 "series)", ifu, n, cpl_vector_get(ron, n-1),
436 cpl_vector_get(ronerr, n-1), variance);
441 cpl_image_fill_window(aList->
list[k]->
stat, window[0], window[2],
442 window[1], window[3], variance);
447 return cpl_bivector_wrap_vectors(ron, ronerr);
Structure definition for a collection of muse_images.
void muse_image_delete(muse_image *aImage)
Deallocate memory associated to a muse_image object.
cpl_size * muse_quadrants_get_window(const muse_image *aImage, unsigned char aQuadrant)
Determine the data window of a given quadrant on the CCD.
int muse_image_scale(muse_image *aImage, double aScale)
Scale a muse_image with correct treatment of variance.
unsigned char muse_utils_get_ifu(const cpl_propertylist *aHeaders)
Find out the IFU/channel from which this header originated.
double muse_pfits_get_gain(const cpl_propertylist *aHeaders, unsigned char aQuadrant)
find the detector gain (in units of count/adu)
cpl_image * data
the data extension
cpl_image * stat
the statistics extension
void muse_imagelist_delete(muse_imagelist *aList)
Free the memory of the MUSE image list.
void muse_imagelist_dump_statistics(muse_imagelist *aList)
Show statistics of a muse_image list.
Structure definition of MUSE three extension FITS file.
cpl_propertylist * header
the FITS header
unsigned int muse_imagelist_get_size(muse_imagelist *aList)
Return the number of stored images.
cpl_error_code muse_imagelist_scale_exptime(muse_imagelist *aList)
Scale muse_images to a common exposure time.
muse_image * muse_imagelist_get(muse_imagelist *aList, unsigned int aIdx)
Get the muse_image of given list index.
double muse_pfits_get_ron(const cpl_propertylist *aHeaders, unsigned char aQuadrant)
find the detector read-out noise
int muse_imagelist_is_uniform(muse_imagelist *aList)
Check that all images in the muse_imagelist have the same size.
cpl_bivector * muse_imagelist_compute_ron(muse_imagelist *aList, int aHalfsize, int aNSamples)
Compute the read-out noise from bias images in an imagelist.
muse_imagelist * muse_imagelist_new(void)
Create a new (empty) MUSE image list.
double muse_pfits_get_exptime(const cpl_propertylist *aHeaders)
find out the exposure time
muse_image ** list
The list of muse_images.
cpl_error_code muse_imagelist_set(muse_imagelist *aList, muse_image *aImage, unsigned int aIdx)
Set the muse_image of given list index.