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_position(ps.domelist, 0) ;
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);
832 if(ps.mbframe != NULL){
833 mbias = cpl_image_load(cpl_frame_get_filename(ps.mbframe), CPL_TYPE_FLOAT,0,xn);
835 cpl_msg_warning(_id,
"Cannot load image %s", OMEGA_CALIB_BIAS);
840 bpm_map =
makebpm(ps.hframe, ps.cframe, xn);
843 scales = cpl_vector_new (nflats);
844 median_vector = cpl_vector_new (nflats);
845 cpl_vector_fill(median_vector,0.0);
847 data_scales = cpl_vector_get_data(scales);
849 ilist = cpl_imagelist_new();
850 cpl_msg_info (_id,
"Doing trim and overscan correction on images");
855 for (i=0; i< nflats; i++){
856 domefr = cpl_frameset_get_position(ps.domelist, i) ;
861 if(trim_raw == NULL){
863 freevector(median_vector);
869 cpl_image_subtract(trim_raw, mbias);
871 cpl_image_subtract_scalar(trim_raw, bias);
873 if (bpm_map == NULL) {
874 ps.stats = cpl_stats_new_from_image(trim_raw, CPL_STATS_ALL);
875 median = cpl_stats_get_median(ps.stats);
878 cpl_image_reject_from_mask(trim_raw, bpm_map);
879 ps.stats = cpl_stats_new_from_image(trim_raw, CPL_STATS_ALL);
880 median = cpl_stats_get_median(ps.stats);
883 cpl_vector_set(median_vector, i, median);
885 data_scales[i] = (double)1.0/median;
887 cpl_image_divide_scalar(trim_raw, median);
889 cpl_imagelist_set(ilist, trim_raw, i);
897 omega_mdome_config.RawMin = cpl_vector_get_min(median_vector);
898 omega_mdome_config.RawMax = cpl_vector_get_max(median_vector);
899 omega_mdome_config.RawMean = cpl_vector_get_mean(median_vector);
900 omega_mdome_config.RawMedian = cpl_vector_get_median(median_vector);
901 omega_mdome_config.RawStdev = cpl_vector_get_stdev(median_vector);
903 freevector(median_vector);
910 cpl_msg_error(_id,
"Error in image list <%s>",cpl_error_get_message());
932 cpl_msg_info(_id,
"Using default value of gain");
937 cpl_msg_info(_id,
"Gain value from image is %g", gain);
940 cpl_msg_info (_id,
"Computing the median of all images...");
941 median_all = cpl_imagelist_collapse_median_create(ilist);
943 if (median_all == NULL) {
944 cpl_msg_error (_id,
"Cannot take median of list <%s>",cpl_error_get_message());
950 naxis1 = cpl_image_get_size_x(median_all);
951 naxis2 = cpl_image_get_size_y(median_all);
953 sum_data = cpl_image_new(naxis1,naxis2,CPL_TYPE_FLOAT);
954 sum_good = cpl_image_new(naxis1,naxis2,CPL_TYPE_FLOAT);
957 for (i=0; i< nflats; i++){
959 trim_raw = cpl_imagelist_get(ilist, i);
960 new_image = cpl_image_duplicate(trim_raw);
966 cpl_image_threshold(trim_raw, 0, FLT_MAX, 0, 2e20);
968 dev = cpl_image_subtract_create(median_all, trim_raw);
970 code = cpl_image_power(trim_raw, 0.5);
971 if(code != CPL_ERROR_NONE) {
972 cpl_msg_error(_id,
"Error in SQRT operation <%s>",cpl_error_get_message());
975 freeimage(median_all);
978 freeimage(new_image);
983 cpl_image_divide(dev, trim_raw);
985 threshold = omega_mdome_config.sigma * (sqrt(gain * data_scales[i]));
987 good = cpl_mask_threshold_image_create(dev, -threshold, threshold);
990 good_int = cpl_image_new_from_mask(good) ;
993 good_float = cpl_image_cast(good_int, CPL_TYPE_FLOAT);
996 cpl_image_multiply(new_image, good_float);
997 cpl_image_add(sum_data, new_image);
999 cpl_image_add(sum_good, good_float);
1001 freeimage(new_image);
1002 freeimage(good_float);
1006 freeimage(median_all);
1010 cpl_image_threshold(sum_good, FLT_EPSILON, FLT_MAX, FLT_EPSILON, FLT_MAX);
1011 ps.mdome = cpl_image_divide_create(sum_data, sum_good);
1012 if (ps.mdome == NULL) {
1013 cpl_msg_error(_id,
"Error in division %s <%s>",MDOME_PROCATG, cpl_error_get_message());
1015 freeimage(sum_data);
1016 freeimage(sum_good);
1020 freeimage(sum_data);
1021 freeimage(sum_good);
1025 cpl_image_save(ps.mdome, mdome_name, BITPIX, NULL, CPL_IO_DEFAULT);
1031 cpl_msg_warning(_id,
"Error in creating background image");
1035 back_image = cpl_image_load(backname, CPL_TYPE_FLOAT, 0, 0);
1036 if (back_image != NULL){
1037 norm_image = cpl_image_divide_create(ps.mdome, back_image);
1038 freeimage(back_image);
1041 cpl_msg_warning(_id,
"Could not create normalised image. Cannot load background image.");
1056 pixelmap = cpl_mask_threshold_image_create(norm_image, omega_mdome_config.lthre,
1057 omega_mdome_config.hthre);
1058 cpl_mask_not(pixelmap);
1060 cpl_msg_info(_id,
"Creating pixel map with thresholds: %g,%g",omega_mdome_config.lthre,
1061 omega_mdome_config.hthre);
1063 omega_mdome_config.CountColdPixels = cpl_mask_count(pixelmap);
1064 if (omega_mdome_config.CountColdPixels == -1) {
1065 cpl_msg_warning(_id,
"Pixelmap is NULL. <%s>", cpl_error_get_message());
1068 cpl_msg_info(_id,
"Detected %d cold pixels", omega_mdome_config.CountColdPixels);
1070 freeimage(norm_image);
1073 ps.cpixels = cpl_image_new_from_mask(pixelmap);
1077 ps.stats = cpl_stats_new_from_image(ps.mdome, CPL_STATS_ALL);
1078 if(ps.stats == NULL && (cpl_error_get_code() == CPL_ERROR_DATA_NOT_FOUND)){
1079 cpl_msg_warning(_id,
" There are no good pixels in image for doing statistics");
1083 omega_mdome_config.Mean = cpl_stats_get_mean(ps.stats);
1084 omega_mdome_config.Median = cpl_stats_get_median(ps.stats);
1085 omega_mdome_config.Stdev = cpl_stats_get_stdev(ps.stats);
1088 freestats(ps.stats);
1096 static void omega_mdome_init(
void) {
1107 ps.firstdome = NULL;
1111 static void omega_mdome_tidy(
void) {
1112 freespace(ps.labels);
1113 freeframeset(ps.domelist);
1114 freestats(ps.stats);
1115 freeimage(ps.mdome);
1116 freeimage(ps.cpixels);
1117 freefits(ps.firstdome);
int omega_pfits_get_overscan(const cpl_frame *frame, int xn)
Get the DRS keyword of the overscan method used to reduce the image.
int omega_pfits_get_detlive(const cpl_propertylist *plist, int *detlive)
Get the value of DET_LIVE.
void omega_pfits_get_conad(cpl_propertylist *plist, double *conad)
Get the value of the keyword CONAD.
cpl_image * TrimOscanCorrect(const cpl_frame *frame, int oscan, int extn)
This method loads a raw image, trims it and (optionally) performs an overscan correction, using the statistics of the pre and overscan regions. This can be done with a single value for the whole image or on a per-row basis.
int omega_compare_tags(const cpl_frame *frame1, const cpl_frame *frame2)
cpl_mask * makebpm(const cpl_frame *hot, const cpl_frame *cold, int cxn)
Create a bad pixels map.
int omega_pfits_check_instrume(const cpl_frame *fr)
Check if INSTRUME is WFI or OMEGA.
omega_fits * omega_fits_load(const cpl_frame *inframe, cpl_type type, int extnum)
const char * omega_get_license(void)
Get the pipeline copyright and license.
void omega_exten_range(int inexten, int *out1, int *out2)
cpl_frame * omega_product_frame(const char *filename, const char *tag, cpl_frame_type type)
Setup a frame to save a product.
int omega_compare_reference(const cpl_image *master, const cpl_frame *refframe, int ext, cpl_stats **diffstats)
cpl_propertylist * omega_fits_get_ehu(omega_fits *p)
cpl_frameset * omega_frameset_subgroup(cpl_frameset *frameset, cpl_size *labels, cpl_size nlab, const char *tag)
int omega_mdome_combine(cpl_parameterlist *pars, int xn)
Trim and combine input images.
int omega_create_background(cpl_parameterlist *parlist, const char *in_name, const char *out_name)
Creates a background image using Sextractor.
int omega_save_image(const cpl_image *img, cpl_frameset *set, const cpl_parameterlist *pars, cpl_propertylist *alist, const cpl_propertylist *qclist, cpl_type_bpp bpp, const char *name, const char *recipe, cpl_frame *frame, const cpl_frame *inherit, int isfirst)
Save an image as a DFS compliant product.
void omega_pfits_get_gain(cpl_propertylist *plist, double *gain)
Read the gain value from an image.
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.