33 #include "omega_recipe.h"
34 #include "omega_background.h"
71 static int omega_mdome_create(cpl_plugin *);
72 static int omega_mdome_exec(cpl_plugin *);
73 static int omega_mdome_destroy(cpl_plugin *);
74 static int omega_mdome(cpl_frameset *, cpl_parameterlist *);
81 static void omega_mdome_init(
void);
82 static void omega_mdome_tidy(
void);
114 const cpl_frame *mbframe;
115 const cpl_frame *cframe;
116 const cpl_frame *hframe;
117 cpl_frameset *domelist;
119 cpl_propertylist *ph;
120 cpl_propertylist *eh;
121 omega_fits *firstdome;
134 #define RECIPE "omega_mdome"
150 cpl_recipe * recipe = cpl_calloc(1,
sizeof(*recipe)) ;
151 cpl_plugin * plugin = &recipe->interface ;
153 cpl_plugin_init(plugin,
155 OMEGA_BINARY_VERSION,
156 CPL_PLUGIN_TYPE_RECIPE,
158 "OMEGA - Create Master Dome Flat for each chip (Calfile 542).",
159 "This recipe is used to derive a valid domeflat frame (Calfile 542) \n"
160 "for one particular chip and filter. The recipe always takes as input \n"
161 "a list of raw domeflat frames, a master bias and a measurement of the \n"
162 "gain of the chip under consideration. In addition, a hot pixel map \n"
163 "(Calfile 522) and a cold pixel map (Calfile 535) can be provided. Optionally, \n"
164 "an overscan correction mode can be set. The default is to apply no overscan \n"
166 "The raw dome flats are trimmed and overscan corrected. The data are then \n"
167 "normalized, averaged, and the result is normalized again. Image statisics \n"
168 "are computed for the resulting frame.",
174 omega_mdome_destroy) ;
176 cpl_pluginlist_append(list, plugin) ;
191 static int omega_mdome_create(cpl_plugin * plugin)
198 if (cpl_error_get_code() != CPL_ERROR_NONE) {
199 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
200 cpl_func, __LINE__, cpl_error_get_where());
201 return (
int)cpl_error_get_code();
204 if (plugin == NULL) {
205 cpl_msg_error(cpl_func,
"Null plugin");
206 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
210 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
211 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
212 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
216 recipe = (cpl_recipe *)plugin;
219 recipe->parameters = cpl_parameterlist_new() ;
221 if (recipe->parameters == NULL) {
222 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
223 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
229 p = cpl_parameter_new_value(
"omega.omega_mdome.ExtensionNumber",
231 "FITS extension number to load (1 to 32). (-1 = all)",
235 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ext") ;
236 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
237 cpl_parameterlist_append(recipe->parameters, p) ;
240 p = cpl_parameter_new_range(
"omega.omega_mdome.OverscanMethod",
242 "Overscan Correction Method",
246 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"oc-meth") ;
247 cpl_parameterlist_append(recipe->parameters, p) ;
249 p = cpl_parameter_new_value(
"omega.omega_mdome.PAF",
251 "Boolean value to create PAF files. 1(Yes), 0(No)",
255 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,
"paf") ;
256 cpl_parameterlist_append(recipe->parameters, p) ;
258 p = cpl_parameter_new_value(
"omega.omega_mdome.SigmaClip",
260 "Sigma Clipping Threshold",
264 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,
"sig-clip") ;
265 cpl_parameterlist_append(recipe->parameters, p) ;
269 p = cpl_parameter_new_range(
"omega.omega_mdome.LowThre",
271 "Low flagging threshold for cold pixels map",
275 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,
"low") ;
276 cpl_parameterlist_append(recipe->parameters, p) ;
278 p = cpl_parameter_new_range(
"omega.omega_mdome.HighThre",
280 "High flagging threshold for cold pixels map",
284 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"high") ;
285 cpl_parameterlist_append(recipe->parameters, p) ;
287 p = cpl_parameter_new_range(
"omega.omega_mdome.BackSize",
289 "Sextractor background mesh size for cold pixels map",
293 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"backsize") ;
294 cpl_parameterlist_append(recipe->parameters, p) ;
297 path = cpl_sprintf(
"%s", OMEGA_BIN_PATH);
298 p = cpl_parameter_new_value(
"omega.omega_mdome.BinPath",
300 "Path to any external executable program.",
304 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,
"bin-path");
305 cpl_parameterlist_append(recipe->parameters, p);
309 path = cpl_sprintf(
"%s/omega.sex", OMEGA_CONFIG_PATH);
310 p = cpl_parameter_new_value(
"omega.omega_mdome.SexConfig",
312 "Path to Sextractor config file.",
316 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,
"sex-config");
317 cpl_parameterlist_append(recipe->parameters, p);
320 path = cpl_sprintf(
"%s/omega.conv", OMEGA_CONFIG_PATH);
321 p = cpl_parameter_new_value(
"omega.omega_mdome.SexConv",
323 "Path to Sextractor convolution mask file.",
327 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"sex-conv");
328 cpl_parameterlist_append(recipe->parameters, p);
332 path = cpl_sprintf(
"%s/omega.param", OMEGA_CONFIG_PATH);
333 p = cpl_parameter_new_value(
"omega.omega_mdome.SexParam",
335 "Path to Sextractor parameters file.",
339 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,
"sex-param");
340 cpl_parameterlist_append(recipe->parameters, p);
343 path = cpl_sprintf(
"%s/omega.nnw", OMEGA_CONFIG_PATH);
344 p = cpl_parameter_new_value(
"omega.omega_mdome.SexNnw",
346 "Path to Sextractor neural network config file.",
350 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"sex-nnw");
351 cpl_parameterlist_append(recipe->parameters, p);
354 p = cpl_parameter_new_value(
"omega.omega_mdome.BackThreshold",
356 "Detection threshold for background in image (Sextractor DETECT_THRESH)",
360 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,
"backthre") ;
361 cpl_parameterlist_append(recipe->parameters, p) ;
375 static int omega_mdome_exec(cpl_plugin * plugin)
382 if (cpl_error_get_code() != CPL_ERROR_NONE) {
383 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
384 cpl_func, __LINE__, cpl_error_get_where());
385 return (
int)cpl_error_get_code();
388 if (plugin == NULL) {
389 cpl_msg_error(cpl_func,
"Null plugin");
390 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
394 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
395 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
396 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
400 recipe = (cpl_recipe *)plugin;
403 if (recipe->parameters == NULL) {
404 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
405 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
407 if (recipe->frames == NULL) {
408 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
409 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
413 recipe_status = omega_mdome(recipe->frames, recipe->parameters);
416 if (cpl_dfs_update_product_header(recipe->frames)) {
417 if (!recipe_status) recipe_status = (int)cpl_error_get_code();
426 return recipe_status;
437 static int omega_mdome_destroy(cpl_plugin * plugin)
441 if (plugin == NULL) {
442 cpl_msg_error(cpl_func,
"Null plugin");
443 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
447 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
448 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
449 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
453 recipe = (cpl_recipe *)plugin;
455 cpl_parameterlist_delete(recipe->parameters);
468 static int omega_mdome(cpl_frameset *
set, cpl_parameterlist *pars)
480 char *outmdome = NULL;
481 const char *_id =
"omega_mdome";
482 cpl_frame *firstframe = NULL;
483 cpl_frame *prframe_cpm = NULL;
484 cpl_frame *prframe_mdome = NULL;
485 const cpl_frame *refframe = NULL;
486 cpl_parameter *par = NULL;
487 cpl_propertylist *qclist = NULL;
488 cpl_propertylist *alist = NULL;
489 cpl_stats *diffstats = NULL;
495 cpl_msg_error (_id,
"Parameters list not found");
499 if (cpl_frameset_is_empty(
set) == 1) {
500 cpl_msg_error (_id,
"Frameset not found");
505 par = cpl_parameterlist_find(pars,
"omega.omega_mdome.ExtensionNumber") ;
506 omega_mdome_config.extnum = cpl_parameter_get_int(par) ;
508 par = cpl_parameterlist_find(pars,
"omega.omega_mdome.OverscanMethod") ;
509 omega_mdome_config.oc = cpl_parameter_get_int(par) ;
511 par = cpl_parameterlist_find(pars,
"omega.omega_mdome.SigmaClip") ;
512 omega_mdome_config.sigma = cpl_parameter_get_double(par) ;
514 par = cpl_parameterlist_find(pars,
"omega.omega_mdome.LowThre") ;
515 omega_mdome_config.lthre = cpl_parameter_get_double(par) ;
517 par = cpl_parameterlist_find(pars,
"omega.omega_mdome.HighThre") ;
518 omega_mdome_config.hthre = cpl_parameter_get_double(par) ;
520 par = cpl_parameterlist_find(pars,
"omega.omega_mdome.PAF") ;
521 omega_mdome_config.paf = cpl_parameter_get_bool(par) ;
524 if (oc_dfs_set_groups(
set)) {
525 cpl_msg_error(_id,
"Cannot identify RAW and CALIB frames") ;
535 cpl_msg_error(_id,
"Cannot labelise the input frameset");
540 MDOME_RAW)) == NULL) {
541 cpl_msg_error(_id,
"Cannot find dome frames in input frameset");
547 nflats = cpl_frameset_count_tags(ps.domelist, MDOME_RAW);
549 cpl_msg_error (_id,
"Need at least 2 (%s) frames to run "
550 "this recipe", MDOME_RAW);
555 cpl_msg_info (_id,
"There are %d %s in frame set",nflats, MDOME_RAW);
559 ps.mbframe = cpl_frameset_find_const(
set, OMEGA_CALIB_BIAS);
560 if (ps.mbframe == NULL) {
561 cpl_msg_info(_id,
"A Master Bias is not present in frame set. Using default value %f", bias);
564 cpl_msg_info(_id,
"Using %s %s",OMEGA_CALIB_BIAS, cpl_frame_get_filename(ps.mbframe));
568 ps.cframe = cpl_frameset_find_const(
set, OMEGA_CALIB_CPM);
569 if(ps.cframe != NULL){
570 cpl_msg_info(_id,
"Using %s %s",OMEGA_CALIB_CPM, cpl_frame_get_filename(ps.cframe));
574 ps.hframe = cpl_frameset_find_const(
set, OMEGA_CALIB_HPM);
575 if(ps.hframe != NULL){
576 cpl_msg_info(_id,
"Using %s %s",OMEGA_CALIB_HPM, cpl_frame_get_filename(ps.hframe));
580 refframe = cpl_frameset_find_const(
set, REFDOME);
581 if (refframe != NULL)
582 cpl_msg_info(cpl_func,
"Using %s for comparison",cpl_frame_get_filename(refframe));
585 firstframe = cpl_frameset_get_first(ps.domelist);
589 if(omega_mdome_config.extnum == 0){
590 cpl_msg_error(cpl_func,
"Unsupported extension request, %d",omega_mdome_config.extnum);
597 sprintf(INSTRUME,
"wfi");
601 omega_mdome_config.extnum == 0 && jfn == 32)
604 for (j = jst; j <= jfn; j++) {
606 isfirst = (j == jst);
607 cpl_msg_info(_id,
"Beginning work on extension %d",j);
608 omega_mdome_config.CountColdPixels = 0;
609 omega_mdome_config.Mean = 0.0;
610 omega_mdome_config.Median = 0.0;
611 omega_mdome_config.Stdev = 0.0;
612 omega_mdome_config.RawMin = 0.0;
613 omega_mdome_config.RawMax = 0.0;
614 omega_mdome_config.RawMean = 0.0;
615 omega_mdome_config.RawMedian = 0.0;
616 omega_mdome_config.RawStdev = 0.0;
619 if(ps.mbframe != NULL){
621 if(oscan1 != omega_mdome_config.oc) {
622 cpl_msg_warning (_id,
"Overscan correction mode for Master Bias (oc = %d) differs from "
623 "the one used here (oc = %d)", oscan1, omega_mdome_config.oc);
635 cpl_msg_warning(_id,
"Image detector is not live");
637 freefits(ps.firstdome);
641 else if(status == -1){
642 cpl_msg_error(_id,
"Cannot combine images");
649 qclist = cpl_propertylist_new();
652 if(refframe != NULL){
654 cpl_msg_warning(cpl_func,
"Cannot compare with reference frame");
657 cpl_propertylist_append_double(qclist,
"ESO QC DIFF REFDOME MEAN",
658 cpl_stats_get_mean(diffstats));
659 cpl_propertylist_set_comment(qclist,
"ESO QC DIFF REFDOME MEAN",
660 "Mean of difference with reference");
661 cpl_propertylist_append_double(qclist,
"ESO QC DIFF REFDOME MEDIAN",
662 cpl_stats_get_median(diffstats));
663 cpl_propertylist_set_comment(qclist,
"ESO QC DIFF REFDOME MEDIAN",
664 "Median of difference with reference");
665 cpl_propertylist_append_double(qclist,
"ESO QC DIFF REFDOME STDEV",
666 cpl_stats_get_stdev(diffstats));
667 cpl_propertylist_set_comment(qclist,
"ESO QC DIFF REFDOME STDEV",
668 "Stdev of difference with reference");
670 freestats(diffstats);
677 cpl_propertylist_append_double(qclist,
"ESO QC MASTER DOME MEAN",
678 omega_mdome_config.Mean) ;
679 cpl_propertylist_set_comment (qclist,
"ESO QC MASTER DOME MEAN",
680 "Mean of master dome flat");
682 cpl_propertylist_append_double(qclist,
"ESO QC MASTER DOME MEDIAN",
683 omega_mdome_config.Median) ;
684 cpl_propertylist_set_comment (qclist,
"ESO QC MASTER DOME MEDIAN",
685 "Median of master dome flat");
687 cpl_propertylist_append_double(qclist,
"ESO QC MASTER DOME STDEV",
688 omega_mdome_config.Stdev) ;
689 cpl_propertylist_set_comment (qclist,
"ESO QC MASTER DOME STDEV",
690 "Std Deviation of master dome flat");
692 cpl_propertylist_append_double(qclist,
"ESO QC RAW DOME MIN",
693 omega_mdome_config.RawMin);
694 cpl_propertylist_append_double(qclist,
"ESO QC RAW DOME MAX",
695 omega_mdome_config.RawMax);
696 cpl_propertylist_append_double(qclist,
"ESO QC RAW DOME MEAN",
697 omega_mdome_config.RawMean);
698 cpl_propertylist_append_double(qclist,
"ESO QC RAW DOME MEDIAN",
699 omega_mdome_config.RawMedian);
700 cpl_propertylist_append_double(qclist,
"ESO QC RAW DOME STDEV",
701 omega_mdome_config.RawStdev);
703 cpl_propertylist_set_comment(qclist,
"ESO QC RAW DOME MIN",
704 "median value of the raw dome flat having the lowest flux");
705 cpl_propertylist_set_comment(qclist,
"ESO QC RAW DOME MAX",
706 "median value of the raw dome flat having the highest flux");
707 cpl_propertylist_set_comment(qclist,
"ESO QC RAW DOME MEAN",
708 "mean value of all input raw dome flats (ADU)");
709 cpl_propertylist_set_comment(qclist,
"ESO QC RAW DOME MEDIAN",
710 "median value of all input raw dome flats (ADU)");
711 cpl_propertylist_set_comment(qclist,
"ESO QC RAW DOME STDEV",
712 "standard deviation of all input raw dome flats (ADU)");
715 outmdome = cpl_sprintf(
"%s_%s.fits", INSTRUME,MDOME_PROCATG);
719 alist = cpl_propertylist_new();
720 cpl_propertylist_append_string(alist,
"EXTNAME",
721 cpl_propertylist_get_string(ps.eh,
"EXTNAME"));
722 cpl_propertylist_set_comment(alist,
"EXTNAME",
"Extension name");
725 cpl_propertylist_update_int(alist,
"ESO DRS OVERSCAN METHOD", omega_mdome_config.oc);
726 cpl_propertylist_set_comment(alist,
"ESO DRS OVERSCAN METHOD",
"overscan correction method");
728 cpl_propertylist_copy_property_regexp(alist, ps.eh, WCS_KEYS, 0);
730 if(
omega_save_image(ps.mdome,
set,pars,alist,qclist,CPL_BPP_IEEE_FLOAT,outmdome,
731 RECIPE,prframe_mdome,NULL,isfirst) == -1){
732 cpl_msg_error(_id,
"Cannot save product %s", MDOME_PROCATG);
744 qclist = cpl_propertylist_new();
745 cpl_propertylist_append_int(qclist,
"ESO QC NUMBER COLD PIXELS",
746 omega_mdome_config.CountColdPixels);
748 cpl_propertylist_set_comment(qclist,
"ESO QC NUMBER COLD PIXELS",
749 "Number of cold pixels");
751 outcpm = cpl_sprintf(
"%s_%s.fits", INSTRUME,CPM_PROCATG);
755 if(
omega_save_image(ps.cpixels,
set,pars,alist,qclist,CPL_BPP_16_SIGNED,outcpm,
756 RECIPE,prframe_cpm,NULL,isfirst) == -1){
757 cpl_msg_error(_id,
"Cannot save product %s", CPM_PROCATG);
768 freeimage(ps.cpixels);
769 freefits(ps.firstdome);
800 int i,nflats,live, naxis1, naxis2;
804 double threshold = 0.0;
805 double *data_scales = NULL;
806 const char *_id =
"omega_mdome_combine";
807 const char *mdome_name =
"omega_mdome_temp.fits";
808 const char *backname =
"omega_mdome_background.fits";
811 const cpl_frame *domefr = NULL;
812 cpl_vector *scales = NULL;
813 cpl_vector *median_vector = NULL;
814 cpl_image *mbias = NULL;
815 cpl_image *trim_raw = NULL, *back_image = NULL, *dev = NULL;
816 cpl_image *good_float = NULL, *good_int = NULL, *median_all = NULL;
817 cpl_image *sum_data = NULL, *sum_good = NULL, *new_image = NULL;
818 cpl_image *norm_image = NULL;
819 cpl_imagelist *ilist = NULL;
820 cpl_mask *good = NULL, *bpm_map = NULL;
821 cpl_mask *pixelmap = NULL;
823 nflats = cpl_frameset_get_size(ps.domelist);
824 domefr = cpl_frameset_get_first_const(ps.domelist);
833 if(ps.mbframe != NULL){
834 mbias = cpl_image_load(cpl_frame_get_filename(ps.mbframe), CPL_TYPE_FLOAT,0,xn);
836 cpl_msg_warning(_id,
"Cannot load image %s", OMEGA_CALIB_BIAS);
841 bpm_map =
makebpm(ps.hframe, ps.cframe, xn);
844 scales = cpl_vector_new (nflats);
845 median_vector = cpl_vector_new (nflats);
846 cpl_vector_fill(median_vector,0.0);
848 data_scales = cpl_vector_get_data(scales);
850 ilist = cpl_imagelist_new();
851 cpl_msg_info (_id,
"Doing trim and overscan correction on images");
854 for (i=0; i< nflats; i++){
857 if(trim_raw == NULL){
859 freevector(median_vector);
865 cpl_image_subtract(trim_raw, mbias);
867 cpl_image_subtract_scalar(trim_raw, bias);
869 if (bpm_map == NULL) {
870 ps.stats = cpl_stats_new_from_image(trim_raw, CPL_STATS_ALL);
871 median = cpl_stats_get_median(ps.stats);
874 cpl_image_reject_from_mask(trim_raw, bpm_map);
875 ps.stats = cpl_stats_new_from_image(trim_raw, CPL_STATS_ALL);
876 median = cpl_stats_get_median(ps.stats);
879 cpl_vector_set(median_vector, i, median);
881 data_scales[i] = (double)1.0/median;
883 cpl_image_divide_scalar(trim_raw, median);
885 cpl_imagelist_set(ilist, trim_raw, i);
888 domefr = cpl_frameset_get_next_const(ps.domelist);
896 omega_mdome_config.RawMin = cpl_vector_get_min(median_vector);
897 omega_mdome_config.RawMax = cpl_vector_get_max(median_vector);
898 omega_mdome_config.RawMean = cpl_vector_get_mean(median_vector);
899 omega_mdome_config.RawMedian = cpl_vector_get_median(median_vector);
900 omega_mdome_config.RawStdev = cpl_vector_get_stdev(median_vector);
902 freevector(median_vector);
909 cpl_msg_error(_id,
"Error in image list <%s>",cpl_error_get_message());
931 cpl_msg_info(_id,
"Using default value of gain");
936 cpl_msg_info(_id,
"Gain value from image is %g", gain);
939 cpl_msg_info (_id,
"Computing the median of all images...");
940 median_all = cpl_imagelist_collapse_median_create(ilist);
942 if (median_all == NULL) {
943 cpl_msg_error (_id,
"Cannot take median of list <%s>",cpl_error_get_message());
949 naxis1 = cpl_image_get_size_x(median_all);
950 naxis2 = cpl_image_get_size_y(median_all);
952 sum_data = cpl_image_new(naxis1,naxis2,CPL_TYPE_FLOAT);
953 sum_good = cpl_image_new(naxis1,naxis2,CPL_TYPE_FLOAT);
956 for (i=0; i< nflats; i++){
958 trim_raw = cpl_imagelist_get(ilist, i);
959 new_image = cpl_image_duplicate(trim_raw);
965 cpl_image_threshold(trim_raw, 0, FLT_MAX, 0, 2e20);
967 dev = cpl_image_subtract_create(median_all, trim_raw);
969 code = cpl_image_power(trim_raw, 0.5);
970 if(code != CPL_ERROR_NONE) {
971 cpl_msg_error(_id,
"Error in SQRT operation <%s>",cpl_error_get_message());
974 freeimage(median_all);
977 freeimage(new_image);
982 cpl_image_divide(dev, trim_raw);
984 threshold = omega_mdome_config.sigma * (sqrt(gain * data_scales[i]));
986 good = cpl_mask_threshold_image_create(dev, -threshold, threshold);
989 good_int = cpl_image_new_from_mask(good) ;
992 good_float = cpl_image_cast(good_int, CPL_TYPE_FLOAT);
995 cpl_image_multiply(new_image, good_float);
996 cpl_image_add(sum_data, new_image);
998 cpl_image_add(sum_good, good_float);
1000 freeimage(new_image);
1001 freeimage(good_float);
1005 freeimage(median_all);
1009 ps.mdome = cpl_image_divide_create(sum_data, sum_good);
1010 if (ps.mdome == NULL) {
1011 cpl_msg_error(_id,
"Error in division %s <%s>",MDOME_PROCATG, cpl_error_get_message());
1013 freeimage(sum_data);
1014 freeimage(sum_good);
1018 freeimage(sum_data);
1019 freeimage(sum_good);
1023 cpl_image_save(ps.mdome, mdome_name, BITPIX, NULL, CPL_IO_DEFAULT);
1029 cpl_msg_warning(_id,
"Error in creating background image");
1033 back_image = cpl_image_load(backname, CPL_TYPE_FLOAT, 0, 0);
1034 if (back_image != NULL){
1035 norm_image = cpl_image_divide_create(ps.mdome, back_image);
1036 freeimage(back_image);
1039 cpl_msg_warning(_id,
"Could not create normalised image. Cannot load background image.");
1054 pixelmap = cpl_mask_threshold_image_create(norm_image, omega_mdome_config.lthre,
1055 omega_mdome_config.hthre);
1056 cpl_mask_not(pixelmap);
1058 cpl_msg_info(_id,
"Creating pixel map with thresholds: %g,%g",omega_mdome_config.lthre,
1059 omega_mdome_config.hthre);
1061 omega_mdome_config.CountColdPixels = cpl_mask_count(pixelmap);
1062 if (omega_mdome_config.CountColdPixels == -1) {
1063 cpl_msg_warning(_id,
"Pixelmap is NULL. <%s>", cpl_error_get_message());
1066 cpl_msg_info(_id,
"Detected %d cold pixels", omega_mdome_config.CountColdPixels);
1068 freeimage(norm_image);
1071 ps.cpixels = cpl_image_new_from_mask(pixelmap);
1075 ps.stats = cpl_stats_new_from_image(ps.mdome, CPL_STATS_ALL);
1076 if(ps.stats == NULL && (cpl_error_get_code() == CPL_ERROR_DATA_NOT_FOUND)){
1077 cpl_msg_warning(_id,
" There are no good pixels in image for doing statistics");
1081 omega_mdome_config.Mean = cpl_stats_get_mean(ps.stats);
1082 omega_mdome_config.Median = cpl_stats_get_median(ps.stats);
1083 omega_mdome_config.Stdev = cpl_stats_get_stdev(ps.stats);
1086 freestats(ps.stats);
1094 static void omega_mdome_init(
void) {
1105 ps.firstdome = NULL;
1109 static void omega_mdome_tidy(
void) {
1110 freespace(ps.labels);
1111 freeframeset(ps.domelist);
1112 freestats(ps.stats);
1113 freeimage(ps.mdome);
1114 freeimage(ps.cpixels);
1115 freefits(ps.firstdome);