26 #include <cxmessages.h>
30 #include <cpl_recipe.h>
31 #include <cpl_plugininfo.h>
32 #include <cpl_parameterlist.h>
33 #include <cpl_frameset.h>
34 #include <cpl_propertylist.h>
35 #include <cpl_vector.h>
46 #include "gistacking.h"
51 static cxint gimasterdark(cpl_parameterlist*, cpl_frameset*);
52 static cxint giqcmasterdark(cpl_frameset*);
56 _giraffe_clean_badpixels(GiImage* image, GiImage* bpixel)
65 cxint* _bpixel = NULL;
67 cxdouble* _image = NULL;
69 cpl_propertylist* properties = NULL;
72 cx_assert(image != NULL);
73 cx_assert(bpixel != NULL);
81 shift = cpl_propertylist_get_int(properties, GIALIAS_PRSCX);
86 for (i = 0; i < nx_image; i++) {
90 for (j = 0; j < ny_image; j++) {
92 if (_bpixel[i * ny_mask + j + shift] != 0) {
93 _image[i * ny_image + j] = 0.;
111 gimasterdark_create(cpl_plugin* plugin)
114 cpl_parameter* p = NULL;
116 cpl_recipe* recipe = (cpl_recipe*)plugin;
119 giraffe_error_init();
128 recipe->parameters = cpl_parameterlist_new();
129 cx_assert(recipe->parameters != NULL);
138 p = cpl_parameterlist_find(recipe->parameters,
"giraffe.stacking.method");
141 cpl_parameter_set_default_string(p,
"median");
157 gimasterdark_exec(cpl_plugin* plugin)
160 cpl_recipe* recipe = (cpl_recipe*)plugin;
165 if (recipe->parameters == NULL || recipe->frames == NULL) {
169 status = gimasterdark(recipe->parameters, recipe->frames);
175 status = giqcmasterdark(recipe->frames);
187 gimasterdark_destroy(cpl_plugin* plugin)
190 cpl_recipe* recipe = (cpl_recipe*)plugin;
199 cpl_parameterlist_delete(recipe->parameters);
201 giraffe_error_clear();
213 gimasterdark(cpl_parameterlist* config, cpl_frameset* set)
216 const cxchar*
const _id =
"gimasterdark";
222 cxdouble exptotal = 0.;
224 cx_list* darks = NULL;
226 cx_list_const_iterator position = NULL;
228 cpl_matrix* bias_areas = NULL;
230 cpl_frame* dark_frame = NULL;
231 cpl_frame* mbias_frame = NULL;
232 cpl_frame* bpixel_frame = NULL;
233 cpl_frame* mdark_frame = NULL;
235 cpl_image* _dark = NULL;
237 cpl_propertylist* properties = NULL;
240 GiImage* result = NULL;
241 GiImage* mbias = NULL;
242 GiImage* bpixel = NULL;
243 GiImage** stack = NULL;
245 GiBiasConfig* bias_config = NULL;
247 GiStackingConfig* stack_config = NULL;
249 GiRecipeInfo info = {(cxchar*)_id, 1, NULL, config};
251 GiGroupInfo groups[] = {
252 {GIFRAME_DARK, CPL_FRAME_GROUP_RAW},
253 {GIFRAME_BIAS_MASTER, CPL_FRAME_GROUP_CALIB},
254 {GIFRAME_BADPIXEL_MAP, CPL_FRAME_GROUP_CALIB},
255 {NULL, CPL_FRAME_GROUP_NONE}
264 status = giraffe_frameset_set_groups(set, groups);
267 cpl_msg_error(_id,
"Setting frame group information failed!");
276 count = cpl_frameset_count_tags(set, GIFRAME_DARK);
279 cpl_msg_error(_id,
"No raw dark frames found in frameset! "
289 mbias_frame = cpl_frameset_find(set, GIFRAME_BIAS_MASTER);
292 cpl_msg_error(_id,
"No master bias present in frame set. "
297 bpixel_frame = cpl_frameset_find(set, GIFRAME_BADPIXEL_MAP);
300 cpl_msg_info(_id,
"No bad pixel map present in frame set.");
308 cpl_msg_info(_id,
"Loading dark frames ...");
310 darks = cx_list_new();
311 dark_frame = cpl_frameset_find(set, GIFRAME_DARK);
315 while ((dark_frame != NULL ) && (i < count)) {
317 const cxchar*
const filename = cpl_frame_get_filename(dark_frame);
325 cpl_msg_error(_id,
"Cannot load dark from '%s'. Aborting ...",
334 cx_list_push_back(darks, dark);
336 dark_frame = cpl_frameset_find(set, NULL);
341 cx_assert(i == count);
354 if (bias_config->method == GIBIAS_METHOD_MASTER ||
355 bias_config->method == GIBIAS_METHOD_ZMASTER) {
357 if (mbias_frame == NULL) {
358 cpl_msg_error(_id,
"Missing master bias frame! Selected bias "
359 "removal method requires a master bias frame!");
371 const cxchar* filename = cpl_frame_get_filename(mbias_frame);
378 cpl_msg_error(_id,
"Cannot load master bias from '%s'. "
379 "Aborting ...", filename);
403 const cxchar* filename = cpl_frame_get_filename(bpixel_frame);
410 cpl_msg_error(_id,
"Cannot load bad pixel map from '%s'. "
411 "Aborting ...", filename);
434 for (i = 0; i < count; i++) {
436 GiImage* dark = cx_list_pop_front(darks);
445 cx_list_push_front(darks, dark);
468 cx_list_push_back(darks, rdark);
486 position = cx_list_begin(darks);
488 while (position != cx_list_end(darks)) {
490 cxdouble exptime = 0.;
492 GiImage* dark = cx_list_get(darks, position);
495 exptime = cpl_propertylist_get_double(properties, GIALIAS_EXPTIME);
500 cpl_propertylist_update_double(properties, GIALIAS_EXPTIME, 1.);
502 position = cx_list_next(darks, position);
514 count = cx_list_size(darks);
516 if (count < stack_config->min_nr_frames) {
518 cpl_msg_error(_id,
"Not enough frames (%d). Stacking method '%d' "
519 "requires at least %d frames! Aborting...", count,
520 stack_config->stackmethod, stack_config->min_nr_frames);
534 cpl_msg_info(_id,
"Combining %d of %d dark frames.", i, count);
536 stack = cx_calloc(count + 1,
sizeof(GiImage*));
539 position = cx_list_begin(darks);
541 while (position != cx_list_end(darks)) {
542 stack[i] = cx_list_get(darks, position);
543 position = cx_list_next(darks, position);
549 if (result == NULL) {
551 cpl_msg_error(_id,
"Frame combination failed! Aborting ...");
586 status = _giraffe_clean_badpixels(result, bpixel);
590 cpl_msg_error(_id,
"Bad pixel cleaning on master dark frame "
613 cpl_msg_info(_id,
"Writing master dark image ...");
616 cx_assert(properties != NULL);
618 cpl_propertylist_update_double(properties, GIALIAS_CRPIX1, 1.);
620 cpl_propertylist_update_double(properties, GIALIAS_EXPTTOT, exptotal);
621 cpl_propertylist_update_int(properties, GIALIAS_DATANCOM, count);
625 cpl_propertylist_update_double(properties, GIALIAS_DARKVALUE,
626 cpl_image_get_mean(_dark));
627 cpl_propertylist_set_comment(properties, GIALIAS_DARKVALUE,
628 "Dark current in ADU/s");
630 cpl_propertylist_erase(properties, GIALIAS_TPLEXPNO);
637 CPL_FRAME_LEVEL_FINAL,
640 if (mdark_frame == NULL) {
642 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
644 if (result != NULL) {
652 cpl_frameset_insert(set, mdark_frame);
655 if (result != NULL) {
669 giqcmasterdark(cpl_frameset* set)
672 const cxchar*
const fctid =
"giqcmasterdark";
677 cxdouble exptime = 1.;
683 cpl_propertylist* properties = NULL;
684 cpl_propertylist* qclog = NULL;
687 cpl_image* _mdark = NULL;
689 cpl_frame* rframe = NULL;
690 cpl_frame* pframe = NULL;
694 GiImage* mdark = NULL;
695 GiImage* dark = NULL;
697 GiWindow w = {10, 200, 2038, 3000};
700 cpl_msg_info(fctid,
"Computing QC1 parameters ...");
702 qc = giraffe_qclog_open(0);
705 cpl_msg_error(fctid,
"Cannot create QC1 log!");
709 qclog = giraffe_paf_get_properties(qc);
710 cx_assert(qclog != NULL);
718 CPL_FRAME_GROUP_PRODUCT);
720 if (pframe == NULL) {
721 cpl_msg_error(fctid,
"Missing product frame (%s)",
722 GIFRAME_DARK_MASTER);
724 giraffe_paf_delete(qc);
730 cpl_msg_info(fctid,
"Processing product frame '%s' (%s)",
731 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
737 cpl_msg_error(fctid,
"Could not load master dark '%s'! Aborting ...",
738 cpl_frame_get_filename(pframe));
743 giraffe_paf_delete(qc);
754 rframe = cpl_frameset_find(set, GIFRAME_DARK);
756 if (rframe == NULL) {
757 cpl_msg_error(fctid,
"Missing raw frame (%s)", GIFRAME_DARK);
762 giraffe_paf_delete(qc);
772 cpl_msg_error(fctid,
"Could not load dark '%s'!",
773 cpl_frame_get_filename(rframe));
781 giraffe_paf_delete(qc);
789 cx_assert(properties != NULL);
794 cpl_propertylist_update_string(qclog,
"PRO.CATG",
795 cpl_frame_get_tag(pframe));
796 cpl_propertylist_set_comment(qclog,
"PRO.CATG",
797 "Pipeline product category");
800 cx_assert(properties != NULL);
816 if (cpl_propertylist_has(properties, GIALIAS_EXPTIME) == TRUE) {
818 exptime = cpl_propertylist_get_double(properties, GIALIAS_EXPTIME);
822 exptime = 3600. / exptime;
833 mean = cpl_image_get_mean_window(_mdark, w.x0, w.y0, w.x1, w.y1);
836 cpl_propertylist_update_double(properties, GIALIAS_QCMDARKAVG,
838 cpl_propertylist_set_comment(properties, GIALIAS_QCMDARKAVG,
839 "Mean master dark current (ADU/hr)");
853 gflux = cpl_image_get_flux_window(_mdark, w.x0, w.y0, w.x1, w.y1);
855 cpl_image_get_maxpos_window(_mdark, w.x0, w.y0, w.x1, w.y1, &gpx, &gpy);
858 cpl_propertylist_update_double(properties, GIALIAS_QCGLOWFLX, gflux);
859 cpl_propertylist_set_comment(properties, GIALIAS_QCGLOWFLX,
860 "Total flux of glow feature (ADU/s)");
862 cpl_propertylist_update_int(properties, GIALIAS_QCGLOWX, (cxint)gpx);
863 cpl_propertylist_set_comment(properties, GIALIAS_QCGLOWX,
864 "X position of glow feature (pxl)");
866 cpl_propertylist_update_int(properties, GIALIAS_QCGLOWY, (cxint)gpy);
867 cpl_propertylist_set_comment(properties, GIALIAS_QCGLOWY,
868 "X position of glow feature (pxl)");
886 giraffe_qclog_close(qc);
900 cpl_plugin_get_info(cpl_pluginlist* list)
903 cpl_recipe* recipe = cx_calloc(1,
sizeof *recipe);
904 cpl_plugin* plugin = &recipe->interface;
907 cpl_plugin_init(plugin,
909 GIRAFFE_BINARY_VERSION,
910 CPL_PLUGIN_TYPE_RECIPE,
912 "Creates a master dark image from a set of raw dark "
914 "For detailed information please refer to the "
915 "GIRAFFE pipeline user manual.\nIt is available at "
916 "http://www.eso.org/pipelines.",
922 gimasterdark_destroy);
924 cpl_pluginlist_append(list, plugin);
GiBiasConfig * giraffe_bias_config_create(cpl_parameterlist *list)
Creates a setup structure for a bias removal task.
void giraffe_bias_config_add(cpl_parameterlist *list)
Adds parameters for the bias removal.
cxint giraffe_bias_remove(GiImage *result, const GiImage *raw, const GiImage *master_bias, const GiImage *bad_pixels, const cpl_matrix *biaslimits, const GiBiasConfig *config)
Removes the bias from an image.
void giraffe_bias_config_destroy(GiBiasConfig *config)
Destroys a bias removal setup structure.
cpl_frame * giraffe_frame_create_image(GiImage *image, const cxchar *tag, cpl_frame_level level, cxbool save, cxbool update)
Create an image product frame.
cpl_frame * giraffe_get_frame(const cpl_frameset *set, const cxchar *tag, cpl_frame_group group)
Get a frame from a frame set.
void giraffe_image_delete(GiImage *self)
Destroys an image.
cpl_propertylist * giraffe_image_get_properties(const GiImage *self)
Get the properties of an image.
cxint giraffe_image_add_info(GiImage *image, const GiRecipeInfo *info, const cpl_frameset *set)
Add additional frame information to an image.
cxint giraffe_image_save(GiImage *self, const cxchar *filename)
Write a Giraffe image to a file.
cpl_image * giraffe_image_get(const GiImage *self)
Gets the image data.
GiImage * giraffe_image_new(cpl_type type)
Creates an empty image container.
cxint giraffe_image_set_properties(GiImage *self, cpl_propertylist *properties)
Attaches a property list to an image.
cxint giraffe_image_load(GiImage *self, const cxchar *filename, cxint position)
Gets image data and properties from a file.
void giraffe_stacking_config_add(cpl_parameterlist *list)
Adds parameters for the stacking of images.
void giraffe_stacking_config_destroy(GiStackingConfig *config)
Destroys a setup structure for the stacking of images.
GiStackingConfig * giraffe_stacking_config_create(cpl_parameterlist *list)
Creates a setup structure for the stacking of images.
GiImage * giraffe_stacking_stack_images(GiImage **img_array, const GiStackingConfig *config)
Stack a list of images using one of four different kinds of stacking and return the resulting image.
cxint giraffe_propertylist_copy(cpl_propertylist *self, const cxchar *name, const cpl_propertylist *other, const cxchar *othername)
Copy a property from one list to another.
const cxchar * giraffe_get_license(void)
Get the pipeline copyright and license.