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, NULL);
203 cpl_ensure(aIdx < aList->size, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
210 for (k = aIdx; k < aList->
size - 1; k++) {
211 aList->
list[k] = aList->
list[k + 1];
214 aList->
list[aList->
size - 1] = NULL;
242 cpl_ensure(aList, CPL_ERROR_NULL_INPUT, -1);
251 for (k = 1; k < aList->
size; k++) {
275 cpl_msg_info(__func__,
" index median mean stdev scale");
277 for (k = 0; k < aList->
size; k++) {
280 const char *empty =
"----------";
281 cpl_msg_info(__func__,
"%5d %10s %10s %10s %10s" , k,
282 empty, empty, empty, empty);
287 cpl_msg_info(__func__,
"%5d %10.2f %10.2f %10.2f %10.2f", k,
288 cpl_image_get_median(image->
data),
289 cpl_image_get_mean(image->
data),
290 cpl_image_get_stdev(image->
data), scale);
310 cpl_ensure_code(aList, CPL_ERROR_NULL_INPUT);
312 cpl_msg_info(__func__,
"Scale all images to %7.2fs exposure time",
314 cpl_msg_debug(__func__,
"Image EXPTIME scale");
315 cpl_msg_debug(__func__,
" 1 %7.2fs 1.000", t0);
317 for (k = 1; k < aList->
size; k++) {
321 cpl_msg_debug(__func__,
"%4d %7.2fs %6.3f", k+1, t, scale);
323 cpl_propertylist_update_double(image->
header,
"EXPTIME", t0);
325 return CPL_ERROR_NONE;
366 cpl_ensure(aList, CPL_ERROR_NULL_INPUT, NULL);
367 unsigned int nvalues = aList->
size;
368 cpl_ensure(nvalues > 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
374 cpl_image *ronimage = cpl_image_new(4 * 2, nvalues, CPL_TYPE_DOUBLE);
379 for (k = 0; k < nvalues; k++) {
381 cpl_image *diff = cpl_image_subtract_create(aList->
list[k]->
data,
383 for (n = 1; n <= 4; n++) {
388 cpl_stats *s = cpl_stats_new_from_image_window(diff, CPL_STATS_ALL,
389 window[0], window[2],
390 window[1], window[3]);
391 cpl_msg_debug(__func__,
"Quadrant %hhu stats: %f+/-%f %f %f..%f\n", n,
392 cpl_stats_get_mean(s), cpl_stats_get_stdev(s),
393 cpl_stats_get_median(s),
394 cpl_stats_get_min(s), cpl_stats_get_max(s));
397 double ron = 100., ronerr = 1000.;
398 unsigned int niter = 0;
399 #pragma omp critical (cpl_flux_get_noise) 401 srand(niter++ * 100 + 1);
402 cpl_flux_get_noise_window(diff, window, aHalfsize, aNSamples,
404 }
while (ronerr > 0.1 * ron && niter < 5);
406 cpl_msg_debug(__func__,
"--> intermediate RON=%f+/-%f (GAIN=%f)",
410 ron *= gain / sqrt(2);
411 ronerr *= gain / sqrt(2);
412 cpl_image_set(ronimage, n, k+1, ron);
413 cpl_image_set(ronimage, n+4, k+1, ronerr);
416 cpl_image_delete(diff);
420 cpl_vector *ron = cpl_vector_new(4),
421 *ronerr = cpl_vector_new(4);
422 for (n = 1; n <= 4; n++) {
424 cpl_stats *ronstats, *ronerrstats;
425 ronstats = cpl_stats_new_from_image_window(ronimage, CPL_STATS_ALL,
427 ronerrstats = cpl_stats_new_from_image_window(ronimage, CPL_STATS_ALL,
428 n+4, 1, n+4, nvalues);
429 cpl_msg_debug(__func__,
"IFU %hhu, quadrant %hhu RON: %f+/-%f %f %f..%f\n",
430 ifu, n, cpl_stats_get_mean(ronstats),
431 cpl_stats_get_stdev(ronstats),
432 cpl_stats_get_median(ronstats),
433 cpl_stats_get_min(ronstats),
434 cpl_stats_get_max(ronstats));
435 cpl_msg_debug(__func__,
"IFU %hhu, quadrant %hhu RONERR: %f+/-%f %f %f..%f\n",
436 ifu, n, cpl_stats_get_mean(ronerrstats),
437 cpl_stats_get_stdev(ronerrstats),
438 cpl_stats_get_median(ronerrstats),
439 cpl_stats_get_min(ronerrstats),
440 cpl_stats_get_max(ronerrstats));
441 cpl_stats_delete(ronstats);
442 cpl_stats_delete(ronerrstats);
445 double ronmean = cpl_image_get_mean_window(ronimage, n, 1, n, nvalues),
446 ronmeanerr = cpl_image_get_mean_window(ronimage, n+4, 1, n+4, nvalues);
447 cpl_vector_set(ron, n - 1, ronmean);
448 cpl_vector_set(ronerr, n - 1, ronmeanerr);
452 if (ronmean < 1. || ronmean > 5.) {
453 cpl_msg_warning(__func__,
"The RON value computed for quadrant %hhu in " 454 "IFU %hhu is likely wrong (outside the range 1..5 count: " 455 "%.2f +/- %.2f count; the raw header says %.2f count)", n,
456 ifu, ronmean, ronmeanerr, ronheader);
459 cpl_image_delete(ronimage);
463 for (k = 0; k < nvalues; k++) {
464 for (n = 1; n <= 4; n++) {
470 double variance = (1. + 1. / (pow(2 * aHalfsize + 1, 2) * aNSamples))
471 * pow(cpl_vector_get(ron, n-1)/gain, 2);
473 cpl_msg_info(__func__,
"IFU %hhu, quadrant %hhu: RON = %.3f +/- %.3f " 474 "count ==> variance = %.4f adu**2 (1st value of image " 475 "series)", ifu, n, cpl_vector_get(ron, n-1),
476 cpl_vector_get(ronerr, n-1), variance);
481 cpl_image_fill_window(aList->
list[k]->
stat, window[0], window[2],
482 window[1], window[3], variance);
487 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.
muse_image * muse_imagelist_unset(muse_imagelist *aList, unsigned int aIdx)
Unset the muse_image at given list index from the list.