41 #include "hawki_utils.h"
42 #include "hawki_calib.h"
43 #include "hawki_pfits.h"
44 #include "hawki_load.h"
73 (cpl_imagelist * ilist,
81 if (ilist == NULL)
return -1 ;
86 cpl_msg_info(cpl_func,
"Subtracting the dark to each chip image") ;
88 for(idet = 0; idet < HAWKI_NB_DETECTORS ; ++idet)
90 if (cpl_image_subtract(cpl_imagelist_get(ilist, idet),
91 cpl_imagelist_get(dark, idet))!=CPL_ERROR_NONE)
93 cpl_msg_error(cpl_func,
"Cannot apply the dark to chip %d",
103 cpl_msg_info(cpl_func,
"Dividing the flat to each chip image") ;
105 for(idet = 0; idet < HAWKI_NB_DETECTORS ; ++idet)
107 if (cpl_image_divide(cpl_imagelist_get(ilist, idet),
108 cpl_imagelist_get(flat, idet))!=CPL_ERROR_NONE)
110 cpl_msg_error(__func__,
"Cannot apply the flatfield to chip %d",
120 cpl_msg_info(cpl_func,
"Correct the bad pixels to each chip image");
122 for(idet = 0; idet < HAWKI_NB_DETECTORS ; ++idet)
124 cpl_mask * bpm_im_bin ;
126 bpm_im_bin = cpl_mask_threshold_image_create
127 (cpl_imagelist_get(bpm, idet), -0.5, 0.5) ;
128 cpl_mask_not(bpm_im_bin) ;
129 cpl_image_reject_from_mask(cpl_imagelist_get(ilist, idet), bpm_im_bin);
130 if (cpl_detector_interpolate_rejected
131 (cpl_imagelist_get(ilist, idet)) != CPL_ERROR_NONE)
134 (cpl_func,
"Cannot clean the bad pixels in chip %d",
136 cpl_mask_delete(bpm_im_bin) ;
139 cpl_mask_delete(bpm_im_bin) ;
162 cpl_imagelist * ilist,
163 cpl_imagelist * flat,
169 if (ilist == NULL)
return -1 ;
174 cpl_msg_info(cpl_func,
"Divide the images by the flatfield") ;
176 for(idet = 0; idet < HAWKI_NB_DETECTORS ; ++idet)
178 if (cpl_image_divide(cpl_imagelist_get(ilist, idet),
179 cpl_imagelist_get(flat, idet))!=CPL_ERROR_NONE)
181 cpl_msg_error(cpl_func,
"Cannot apply the flatfield to the images");
190 cpl_msg_info(cpl_func,
"Correct the bad pixels in the images") ;
192 for(idet = 0; idet < HAWKI_NB_DETECTORS ; ++idet)
194 cpl_mask * bpm_im_bin ;
196 bpm_im_bin = cpl_mask_threshold_image_create
197 (cpl_imagelist_get(bpm, idet), -0.5, 0.5) ;
198 cpl_mask_not(bpm_im_bin) ;
199 cpl_image_reject_from_mask(cpl_imagelist_get(ilist, idet), bpm_im_bin);
200 if (cpl_detector_interpolate_rejected
201 (cpl_imagelist_get(ilist, idet)) != CPL_ERROR_NONE)
204 (cpl_func,
"Cannot clean the bad pixels in detector %d",
206 cpl_mask_delete(bpm_im_bin) ;
209 cpl_mask_delete(bpm_im_bin) ;
226 (cpl_imagelist * ilist,
232 if (ilist == NULL)
return -1 ;
237 cpl_msg_info(cpl_func,
"Subtract the images by the bkg") ;
239 for(idet = 0; idet < HAWKI_NB_DETECTORS ; ++idet)
241 if (cpl_image_subtract(cpl_imagelist_get(ilist, idet),
242 cpl_imagelist_get(bkg, idet))!=CPL_ERROR_NONE)
244 cpl_msg_error(cpl_func,
"Cannot apply the bkg to the images");
277 cpl_imagelist * ilist,
282 cpl_mask * bpm_im_bin ;
286 if (ilist == NULL)
return -1 ;
291 cpl_msg_info(cpl_func,
"Subtract the images by the dark") ;
292 if (cpl_imagelist_subtract_image(ilist, dark)!=CPL_ERROR_NONE)
294 cpl_msg_error(cpl_func,
"Cannot apply the dark to the images");
301 cpl_msg_info(cpl_func,
"Divide the images by the flatfield") ;
304 if (cpl_imagelist_divide_image(ilist, flat)!=CPL_ERROR_NONE) {
305 cpl_msg_error(cpl_func,
"Cannot apply the flatfield to the images");
312 cpl_msg_info(cpl_func,
"Correct the bad pixels in the images") ;
315 bpm_im_bin = cpl_mask_threshold_image_create(bpm, -0.5, 0.5) ;
316 cpl_mask_not(bpm_im_bin) ;
318 for (i=0 ; i<cpl_imagelist_get_size(ilist) ; i++) {
319 cpl_image_reject_from_mask(cpl_imagelist_get(ilist, i), bpm_im_bin);
320 if (cpl_detector_interpolate_rejected(
321 cpl_imagelist_get(ilist, i)) != CPL_ERROR_NONE) {
322 cpl_msg_error(cpl_func,
"Cannot clean the bad pixels in obj %d",
324 cpl_mask_delete(bpm_im_bin) ;
328 cpl_mask_delete(bpm_im_bin) ;
355 cpl_imagelist * ilist,
359 cpl_mask * bpm_im_bin ;
363 if (ilist == NULL)
return -1 ;
367 cpl_msg_info(cpl_func,
"Divide the images by the flatfield") ;
370 if (cpl_imagelist_divide_image(ilist, flat)!=CPL_ERROR_NONE) {
371 cpl_msg_error(cpl_func,
"Cannot apply the flatfield to the images");
378 cpl_msg_info(cpl_func,
"Correct the bad pixels in the images") ;
381 bpm_im_bin = cpl_mask_threshold_image_create(bpm, -0.5, 0.5) ;
382 cpl_mask_not(bpm_im_bin) ;
384 for (i=0 ; i<cpl_imagelist_get_size(ilist) ; i++) {
385 cpl_image_reject_from_mask(cpl_imagelist_get(ilist, i), bpm_im_bin);
386 if (cpl_detector_interpolate_rejected(
387 cpl_imagelist_get(ilist, i)) != CPL_ERROR_NONE) {
388 cpl_msg_error(cpl_func,
"Cannot clean the bad pixels in obj %d",
390 cpl_mask_delete(bpm_im_bin) ;
394 cpl_mask_delete(bpm_im_bin) ;
413 (cpl_imagelist * imalist,
418 cpl_imagelist * trimmed_images = cpl_imagelist_new();
419 while(cpl_imagelist_get_size(imalist) > 0)
421 cpl_image * non_trimmed;
426 non_trimmed = cpl_imagelist_unset(imalist, 0);
427 nx = cpl_image_get_size_x(non_trimmed);
428 ny = cpl_image_get_size_y(non_trimmed);
429 trimmed = cpl_image_extract(non_trimmed,
430 nborder+1, nborder+1,
431 nx-nborder, ny-nborder);
432 cpl_imagelist_set(trimmed_images, trimmed, i);
434 cpl_image_delete(non_trimmed);
437 return trimmed_images;
455 cpl_mask * bpm_im_bin ;
456 cpl_image * bpm_im_int ;
460 if (ima == NULL)
return -1 ;
461 if (idet < 1 || idet > HAWKI_NB_DETECTORS)
return -1 ;
462 if (bpm == NULL)
return -1 ;
466 cpl_msg_error(__func__,
"Cannot get the extension with detector %d", idet) ;
470 if ((bpm_im_int = cpl_image_load(bpm, CPL_TYPE_INT, 0, ext_nb)) == NULL) {
471 cpl_msg_error(cpl_func,
"Cannot load the bad pixel map %s", bpm) ;
475 bpm_im_bin = cpl_mask_threshold_image_create(bpm_im_int, -0.5, 0.5) ;
476 cpl_mask_not(bpm_im_bin) ;
477 cpl_image_delete(bpm_im_int) ;
479 cpl_image_reject_from_mask(ima, bpm_im_bin);
480 if (cpl_detector_interpolate_rejected(ima) != CPL_ERROR_NONE) {
481 cpl_msg_error(cpl_func,
"Cannot clean the bad pixels");
482 cpl_mask_delete(bpm_im_bin) ;
485 cpl_mask_delete(bpm_im_bin) ;