00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include "omega_recipe.h"
00037
00059
00060
00061
00062
00063 static int omega_mbias_create(cpl_plugin *) ;
00064 static int omega_mbias_exec(cpl_plugin *) ;
00065 static int omega_mbias_destroy(cpl_plugin *) ;
00066 static int omega_mbias(cpl_frameset *,cpl_parameterlist *) ;
00067
00068
00069
00070
00071 int omega_mbias_combine(int xn);
00072 static void omega_mbias_init(void);
00073 static void omega_mbias_tidy(void);
00074
00075
00076
00077
00078
00079 static struct {
00080
00081 float rejsig;
00082 double sigma;
00083 int extnum;
00084 int oc;
00085 int paf;
00086
00087
00088 int CountHotPixels;
00089 double Mean;
00090 double Median;
00091 double Stdev;
00092
00093 }omega_mbias_config;
00094
00095
00096
00097 static struct {
00098 cpl_size *labels;
00099 const cpl_frame *rnframe;
00100 cpl_frameset *biaslist;
00101 cpl_stats *stats;
00102 omega_fits *firstbias;
00103 cpl_propertylist *ph;
00104 cpl_propertylist *eh;
00105
00106
00107 cpl_image *mbias;
00108 cpl_image *hpixels;
00109
00110 } ps;
00111
00112
00113
00114
00115
00116
00117 #define RECIPE "omega_mbias"
00118
00119 static int isfirst;
00120 static int dummy;
00121
00122
00123
00134 int cpl_plugin_get_info(cpl_pluginlist * list)
00135 {
00136 cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe)) ;
00137 cpl_plugin * plugin = &recipe->interface ;
00138
00139 cpl_plugin_init(plugin,
00140 CPL_PLUGIN_API,
00141 OMEGA_BINARY_VERSION,
00142 CPL_PLUGIN_TYPE_RECIPE,
00143 "omega_mbias",
00144 "OMEGA - Create Master Bias for each chip.",
00145 "Trims and applies overscan correction to the raw input bias \n"
00146 "frames. Averages these frames to derive the master bias frame. \n"
00147 "Calculates the image statistics on the resulting frame. Creates \n"
00148 "the FITS header and saves it together with the FITS image.",
00149 "Sandra Castro",
00150 "scastro@eso.org",
00151 omega_get_license(),
00152 omega_mbias_create,
00153 omega_mbias_exec,
00154 omega_mbias_destroy) ;
00155
00156 cpl_pluginlist_append(list, plugin) ;
00157
00158 return 0;
00159 }
00160
00161
00170
00171 static int omega_mbias_create(cpl_plugin * plugin)
00172 {
00173 cpl_recipe * recipe;
00174 cpl_parameter * p ;
00175
00176
00177 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00178 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
00179 cpl_func, __LINE__, cpl_error_get_where());
00180 return (int)cpl_error_get_code();
00181 }
00182
00183 if (plugin == NULL) {
00184 cpl_msg_error(cpl_func, "Null plugin");
00185 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00186 }
00187
00188
00189 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00190 cpl_msg_error(cpl_func, "Plugin is not a recipe");
00191 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
00192 }
00193
00194
00195 recipe = (cpl_recipe *)plugin;
00196
00197
00198 recipe->parameters = cpl_parameterlist_new() ;
00199 if (recipe->parameters == NULL) {
00200 cpl_msg_error(cpl_func, "Parameter list allocation failed");
00201 cpl_ensure_code(0, (int)CPL_ERROR_ILLEGAL_OUTPUT);
00202 }
00203
00204
00205 p = cpl_parameter_new_value("omega.omega_mbias.ExtensionNumber",
00206 CPL_TYPE_INT,
00207 "FITS extension number to load (1 to 32). (-1 = all)",
00208 "omega_mbias",
00209 -1) ;
00210
00211 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ext") ;
00212 cpl_parameterlist_append(recipe->parameters, p) ;
00213
00214
00215 p = cpl_parameter_new_range("omega.omega_mbias.OverscanMethod",
00216 CPL_TYPE_INT,
00217 "Overscan Correction Method",
00218 "omega_mbias",
00219 0, 0, 6);
00220 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"oc-meth") ;
00221 cpl_parameterlist_append(recipe->parameters, p) ;
00222
00223 p = cpl_parameter_new_value("omega.omega_mbias.PAF",
00224 CPL_TYPE_BOOL,
00225 "Boolean value to create PAF files. 1(Yes), 0(No)",
00226 "omega_mbias",
00227 1) ;
00228
00229 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "paf") ;
00230 cpl_parameterlist_append(recipe->parameters, p) ;
00231
00232 p = cpl_parameter_new_value("omega.omega_mbias.SigmaClip",
00233 CPL_TYPE_DOUBLE,
00234 "Sigma Clipping Threshold for image",
00235 "omega_mbias",
00236 3.0) ;
00237
00238 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"sig-clip") ;
00239 cpl_parameterlist_append(recipe->parameters, p) ;
00240
00241 p = cpl_parameter_new_range("omega.omega_mbias.RejSigma",
00242 CPL_TYPE_DOUBLE,
00243 "Rejection threshold for outlying pixels in Hot Pixels Map",
00244 "omega_mbias",
00245 5.0, 1.0, 10.0) ;
00246
00247 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "rej-sigma") ;
00248 cpl_parameterlist_append(recipe->parameters, p) ;
00249
00250
00251
00252 return 0;
00253 }
00254
00255
00261
00262 static int omega_mbias_exec(cpl_plugin * plugin)
00263 {
00264 cpl_recipe * recipe;
00265 int recipe_status;
00266
00267
00268
00269 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00270 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
00271 cpl_func, __LINE__, cpl_error_get_where());
00272 return (int)cpl_error_get_code();
00273 }
00274
00275 if (plugin == NULL) {
00276 cpl_msg_error(cpl_func, "Null plugin");
00277 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00278 }
00279
00280
00281 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00282 cpl_msg_error(cpl_func, "Plugin is not a recipe");
00283 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
00284 }
00285
00286
00287 recipe = (cpl_recipe *)plugin;
00288
00289
00290 if (recipe->parameters == NULL) {
00291 cpl_msg_error(cpl_func, "Recipe invoked with NULL parameter list");
00292 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00293 }
00294 if (recipe->frames == NULL) {
00295 cpl_msg_error(cpl_func, "Recipe invoked with NULL frame set");
00296 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00297 }
00298
00299
00300 recipe_status = omega_mbias(recipe->frames, recipe->parameters);
00301
00302
00303 if (cpl_dfs_update_product_header(recipe->frames)) {
00304 if (!recipe_status) recipe_status = (int)cpl_error_get_code();
00305 }
00306
00307
00308 return recipe_status;
00309 }
00310
00311
00317
00318 static int omega_mbias_destroy(cpl_plugin * plugin)
00319 {
00320 cpl_recipe * recipe;
00321
00322 if (plugin == NULL) {
00323 cpl_msg_error(cpl_func, "Null plugin");
00324 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00325 }
00326
00327
00328 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00329 cpl_msg_error(cpl_func, "Plugin is not a recipe");
00330 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
00331 }
00332
00333
00334 recipe = (cpl_recipe *)plugin;
00335
00336 cpl_parameterlist_delete(recipe->parameters);
00337
00338 return 0 ;
00339 }
00340
00341
00348
00349 static int omega_mbias(cpl_frameset *set, cpl_parameterlist *pars)
00350 {
00351
00352 int j,jst,jfn,status;
00353 cpl_size nlab;
00354 int nbias = 0;
00355 char *outhpm = NULL;
00356 char *outmbias = NULL;
00357
00358 const char *_id = "omega_mbias";
00359
00360 cpl_parameter *par;
00361 cpl_frame *firstframe;
00362 cpl_frame *prframe_mbias = NULL;
00363 cpl_frame *prframe_hpm = NULL;
00364 const cpl_frame *refframe = NULL;
00365 cpl_propertylist *qclist;
00366 cpl_propertylist *alist;
00367 cpl_stats *diffstats = NULL;
00368
00369
00370
00371
00372 if (!pars) {
00373 cpl_msg_error (_id, "Parameters list not found");
00374 return -1;
00375 }
00376
00377 if (cpl_frameset_is_empty(set) == 1) {
00378 cpl_msg_error (_id, "Frameset not found");
00379 return -1;
00380 }
00381
00382
00383
00384 par = cpl_parameterlist_find(pars, "omega.omega_mbias.ExtensionNumber") ;
00385 omega_mbias_config.extnum = cpl_parameter_get_int(par) ;
00386
00387 par = cpl_parameterlist_find(pars, "omega.omega_mbias.OverscanMethod") ;
00388 omega_mbias_config.oc = cpl_parameter_get_int(par) ;
00389
00390 par = cpl_parameterlist_find(pars, "omega.omega_mbias.SigmaClip") ;
00391 omega_mbias_config.sigma = cpl_parameter_get_double(par) ;
00392
00393 par = cpl_parameterlist_find(pars, "omega.omega_mbias.RejSigma") ;
00394 omega_mbias_config.rejsig = cpl_parameter_get_double(par) ;
00395
00396 par = cpl_parameterlist_find(pars, "omega.omega_mbias.PAF");
00397 omega_mbias_config.paf = cpl_parameter_get_bool(par);
00398
00399
00400
00401
00402 if (oc_dfs_set_groups(set)) {
00403 cpl_msg_error(_id, "Cannot identify RAW and CALIB frames") ;
00404 return -1 ;
00405 }
00406
00407
00408
00409 omega_mbias_init();
00410
00411
00412
00413 if ((ps.labels = cpl_frameset_labelise(set,omega_compare_tags,
00414 &nlab)) == NULL) {
00415 cpl_msg_error(_id,"Cannot labelise the input frameset");
00416 omega_mbias_tidy();
00417 return -1;
00418 }
00419 if ((ps.biaslist = omega_frameset_subgroup(set,ps.labels,nlab,
00420 MBIAS_RAW)) == NULL) {
00421 cpl_msg_error(_id,"Cannot find bias frames in input frameset");
00422 omega_mbias_tidy();
00423 return -1;
00424 }
00425
00426 nbias = cpl_frameset_get_size(ps.biaslist);
00427 if (nbias < 2) {
00428 cpl_msg_error(_id,"Need at least 2 (%s) frames to run this recipe",MBIAS_RAW);
00429 omega_mbias_tidy();
00430 return -1;
00431 }
00432
00433 cpl_msg_info (_id,"There are %d %s in frame set",nbias, MBIAS_RAW);
00434
00435
00436
00437 ps.rnframe = cpl_frameset_find_const(set, OMEGA_CALIB_RDNOISE);
00438 if (ps.rnframe == NULL) {
00439 cpl_msg_info(_id,"A Readnoise table is not present in frame set. Using header values");
00440 }
00441 else{
00442 cpl_msg_info(_id,"Using %s %s",OMEGA_CALIB_RDNOISE, cpl_frame_get_filename(ps.rnframe));
00443 }
00444
00445
00446 firstframe = cpl_frameset_get_first(ps.biaslist);
00447
00448
00449 refframe = cpl_frameset_find_const(set, REFBIAS);
00450 if (refframe != NULL)
00451 cpl_msg_info(cpl_func,"Using %s for comparison",cpl_frame_get_filename(refframe));
00452
00453
00454 omega_extensions(firstframe,omega_mbias_config.extnum,&jst,&jfn);
00455
00456 if(omega_mbias_config.extnum == 0){
00457 cpl_msg_error(cpl_func,"Unsupported extension request, %d",omega_mbias_config.extnum);
00458 omega_mbias_tidy();
00459 return -1;
00460 }
00461
00462
00463
00464 if (omega_pfits_check_instrume(firstframe) == 1)
00465 sprintf(INSTRUME,"wfi");
00466
00467 if(omega_pfits_check_instrume(firstframe) == 1 &&
00468 omega_mbias_config.extnum == 0 && jfn == 32){
00469 jfn = 8;
00470 }
00471
00472 for (j = jst; j <= jfn; j++) {
00473
00474 isfirst = (j == jst);
00475 cpl_msg_info(_id,"Beginning work on extension %d",j);
00476 omega_mbias_config.CountHotPixels = 0;
00477 omega_mbias_config.Mean = 0.0;
00478 omega_mbias_config.Median = 0.0;
00479 omega_mbias_config.Stdev = 0.0;
00480
00481 ps.firstbias = omega_fits_load(firstframe,CPL_TYPE_FLOAT,j);
00482 ps.eh = omega_fits_get_ehu(ps.firstbias);
00483
00484
00485 status = omega_mbias_combine(j);
00486 if(status == 1){
00487 cpl_msg_warning(_id, "Image detector is not live");
00488
00489 freefits(ps.firstbias);
00490 ps.eh = NULL;
00491 continue;
00492 }
00493 else if(status == -1){
00494 cpl_msg_error(_id,"Cannot combine images");
00495 freespace(outhpm);
00496 freespace(outmbias);
00497 omega_mbias_tidy();
00498 return -1;
00499 }
00500
00501 status = 0;
00502
00503 qclist = cpl_propertylist_new();
00504
00505
00506 if(refframe != NULL){
00507 if(omega_compare_reference(ps.mbias,refframe,j,&diffstats) == -1){
00508 cpl_msg_warning(cpl_func,"Cannot compare with reference frame");
00509 }
00510 else{
00511 cpl_propertylist_append_double(qclist,"ESO QC DIFF REFBIAS MEAN",
00512 cpl_stats_get_mean(diffstats));
00513 cpl_propertylist_set_comment(qclist,"ESO QC DIFF REFBIAS MEAN",
00514 "Mean of difference with reference");
00515 cpl_propertylist_append_double(qclist,"ESO QC DIFF REFBIAS MEDIAN",
00516 cpl_stats_get_median(diffstats));
00517 cpl_propertylist_set_comment(qclist,"ESO QC DIFF REFBIAS MEDIAN",
00518 "Median of difference with reference");
00519 cpl_propertylist_append_double(qclist,"ESO QC DIFF REFBIAS STDEV",
00520 cpl_stats_get_stdev(diffstats));
00521 cpl_propertylist_set_comment(qclist,"ESO QC DIFF REFBIAS STDEV",
00522 "Stdev of difference with reference");
00523
00524 freestats(diffstats);
00525 }
00526 }
00527
00528
00529
00530 cpl_propertylist_append_double(qclist, "ESO QC MASTER BIAS MEAN",
00531 omega_mbias_config.Mean) ;
00532 cpl_propertylist_set_comment (qclist, "ESO QC MASTER BIAS MEAN",
00533 "Mean value of master bias");
00534
00535 cpl_propertylist_append_double(qclist, "ESO QC MASTER BIAS MEDIAN",
00536 omega_mbias_config.Median) ;
00537 cpl_propertylist_set_comment (qclist, "ESO QC MASTER BIAS MEDIAN",
00538 "Median value of master bias");
00539
00540 cpl_propertylist_append_double(qclist, "ESO QC MASTER BIAS STDEV",
00541 omega_mbias_config.Stdev) ;
00542 cpl_propertylist_set_comment (qclist, "ESO QC MASTER BIAS STDEV",
00543 "Standard Deviation of master bias");
00544
00545 if(isfirst){
00546 outmbias = cpl_sprintf("%s_%s.fits", INSTRUME,MBIAS_PROCATG);
00547 prframe_mbias = omega_product_frame(outmbias, MBIAS_PROCATG, CPL_FRAME_TYPE_IMAGE);
00548 }
00549
00550 alist = cpl_propertylist_new();
00551 cpl_propertylist_append_string(alist, "EXTNAME",
00552 cpl_propertylist_get_string(ps.eh, "EXTNAME"));
00553 cpl_propertylist_set_comment(alist,"EXTNAME", "Extension name");
00554
00555
00556 cpl_propertylist_update_int(alist, "ESO DRS OVERSCAN METHOD", omega_mbias_config.oc);
00557 cpl_propertylist_set_comment(alist, "ESO DRS OVERSCAN METHOD", "overscan correction method");
00558
00559 cpl_propertylist_copy_property_regexp(alist, ps.eh, WCS_KEYS, 0);
00560
00561
00562 if(omega_save_image(ps.mbias,set,pars,alist,qclist,CPL_BPP_IEEE_FLOAT,outmbias,
00563 RECIPE,prframe_mbias,NULL,isfirst) == -1){
00564 cpl_msg_error(_id,"Cannot save product %s", MBIAS_PROCATG);
00565 freeplist(qclist);
00566 freeplist(alist);
00567 freespace(outhpm);
00568 freespace(outmbias);
00569 omega_mbias_tidy();
00570 return -1;;
00571 }
00572
00573 freeplist(qclist);
00574 freeimage(ps.mbias);
00575
00576
00577 qclist = cpl_propertylist_new();
00578 cpl_propertylist_append_int(qclist,"ESO QC NUMBER HOT PIXELS",
00579 omega_mbias_config.CountHotPixels);
00580 cpl_propertylist_set_comment(qclist,"ESO QC NUMBER HOT PIXELS",
00581 "Number of hot pixels");
00582 if(isfirst){
00583 outhpm = cpl_sprintf("%s_%s.fits", INSTRUME,HPM_PROCATG);
00584 prframe_hpm = omega_product_frame(outhpm, HPM_PROCATG, CPL_FRAME_TYPE_IMAGE);
00585 }
00586
00587 if(omega_save_image(ps.hpixels,set,pars,alist,qclist,CPL_BPP_16_SIGNED,outhpm,
00588 RECIPE,prframe_hpm,NULL,isfirst) == -1){
00589 cpl_msg_error(_id,"Cannot save product %s", HPM_PROCATG);
00590 freeplist(qclist);
00591 freeplist(alist);
00592 freespace(outhpm);
00593 freespace(outmbias);
00594 omega_mbias_tidy();
00595 return -1;;
00596 }
00597
00598 freeplist(qclist);
00599 freeplist(alist);
00600 freeimage(ps.hpixels);
00601 status = 0;
00602
00603 freefits(ps.firstbias);
00604 ps.firstbias = NULL;
00605 ps.eh = NULL;
00606
00607
00608 }
00609
00610 freespace(outhpm);
00611 freespace(outmbias);
00612 omega_mbias_tidy();
00613
00614 return 0;
00615 }
00616
00625 int omega_mbias_combine(int xn)
00626 {
00627
00628 int i, nbias, live, naxis1, naxis2;
00629 double read_noise, threshold;
00630 double cutoff = 200.0;
00631 const char *_id = "omega_mbias_combine";
00632
00633 const cpl_frame *biasfr;
00634 cpl_image *trim_raw,*median_all,*dev,*good_int,*good_float;
00635 cpl_image *sum_data,*sum_good,*image;
00636 cpl_imagelist *ilist;
00637 cpl_mask *good,*pixelmap;
00638 cpl_table *rntable;
00639
00640
00641 nbias = cpl_frameset_get_size(ps.biaslist);
00642 biasfr = cpl_frameset_get_first_const(ps.biaslist);
00643
00644
00645
00646 omega_pfits_get_detlive(ps.eh,&live);
00647 if (! live) {
00648 return 1;
00649 }
00650
00651 cpl_msg_info (_id,"Doing trim and overscan correction on images");
00652
00653 for (i=0; i< nbias; i++){
00654
00655 trim_raw = TrimOscanCorrect(biasfr, omega_mbias_config.oc, xn);
00656 if(trim_raw == NULL){
00657 return -1;
00658 }
00659
00660 if (i == 0) {
00661 naxis1 = cpl_image_get_size_x (trim_raw);
00662 naxis2 = cpl_image_get_size_y (trim_raw);
00663 ilist = cpl_imagelist_new ();
00664 }
00665
00666 cpl_imagelist_set (ilist, trim_raw, i);
00667
00668 biasfr = cpl_frameset_get_next_const(ps.biaslist);
00669 if (biasfr == NULL)
00670 break;
00671
00672 }
00673
00674 if (ilist == NULL) {
00675 cpl_msg_error(_id,"Error in imagelist <%s>",cpl_error_get_message());
00676 freeimage(trim_raw);
00677 return -1;
00678
00679 }
00680
00681
00682
00683
00684
00685 if(ps.rnframe != NULL){
00686 rntable = cpl_table_load(cpl_frame_get_filename(ps.rnframe), xn, 0);
00687 if(rntable != NULL){
00688 read_noise = cpl_table_get_double(rntable, "READNOISE",0, NULL);
00689 freetable(rntable);
00690 }
00691 else{
00692 omega_pfits_get_readnoise(ps.eh, &read_noise);
00693 cpl_msg_warning(cpl_func,"Cannot load READNOISE_ADU table. %s",cpl_error_get_message());
00694 }
00695 }
00696 else {
00697 omega_pfits_get_readnoise(ps.eh, &read_noise);
00698 }
00699
00700 if (read_noise == 0.0){
00701 cpl_msg_info(_id,"Using default value for read noise");
00702 read_noise = 2.5;
00703 }
00704 else {
00705 cpl_msg_info(_id,"Using read noise = %g", read_noise);
00706 }
00707
00708
00709 threshold = read_noise * omega_mbias_config.sigma;
00710 cpl_msg_info (_id,"Discarding outliers using threshold %g", threshold);
00711
00712
00713
00714 cpl_msg_info (_id,"Computing the median of all images...");
00715 median_all = cpl_imagelist_collapse_median_create (ilist);
00716
00717 if (median_all == NULL) {
00718 cpl_msg_error (_id,"Cannot take median of imagelist <%s>",cpl_error_get_message());
00719 freeilist(ilist);
00720 return -1;
00721 }
00722
00723
00724 trim_raw = cpl_imagelist_get (ilist, 0);
00725 dev = cpl_image_subtract_create(median_all, trim_raw);
00726
00727 good = cpl_mask_threshold_image_create(dev, -threshold, threshold);
00728 freeimage(dev);
00729
00730 good_int = cpl_image_new_from_mask(good) ;
00731 freemask(good) ;
00732 good_float = cpl_image_cast(good_int, CPL_TYPE_FLOAT);
00733 freeimage(good_int);
00734
00735 sum_data = cpl_image_multiply_create(trim_raw, good_float);
00736 sum_good = cpl_image_duplicate(good_float);
00737
00738 freeimage(good_float);
00739
00740
00741 for (i=1; i< nbias; i++){
00742
00743 trim_raw = cpl_imagelist_get(ilist, i);
00744
00745
00746
00747 dev = cpl_image_subtract_create(median_all, trim_raw);
00748
00749 if (dev == NULL) {
00750 cpl_msg_error(_id,"Error in subtraction <%s>",cpl_error_get_function());
00751 freeilist(ilist);
00752 freeimage(median_all);
00753 freeimage(sum_data);
00754 freeimage(sum_good);
00755 return -1;
00756 }
00757
00758 good = cpl_mask_threshold_image_create (dev, -threshold, threshold);
00759
00760 freeimage(dev);
00761
00762 good_int = cpl_image_new_from_mask(good) ;
00763 freemask(good) ;
00764 good_float = cpl_image_cast(good_int, CPL_TYPE_FLOAT);
00765 freeimage(good_int);
00766
00767 image = cpl_image_multiply_create(trim_raw, good_float);
00768 cpl_image_add(sum_data, image);
00769
00770 cpl_image_add(sum_good, good_float);
00771
00772 freeimage(image);
00773 freeimage(good_float);
00774 }
00775
00776 freeimage(median_all);
00777 freeilist(ilist);
00778
00779 ps.mbias = cpl_image_divide_create(sum_data, sum_good);
00780
00781 if (ps.mbias == NULL) {
00782 cpl_msg_error(_id,"Cannot create product. Error in division");
00783 freeimage(sum_data);
00784 freeimage(sum_good);
00785 return -1;
00786 }
00787
00788 freeimage(sum_data);
00789 freeimage(sum_good);
00790
00791
00792 ps.stats = cpl_stats_new_from_image(ps.mbias, CPL_STATS_ALL);
00793 if(ps.stats != NULL) {
00794 omega_mbias_config.Mean = cpl_stats_get_mean(ps.stats);
00795 omega_mbias_config.Median = cpl_stats_get_median(ps.stats);
00796 omega_mbias_config.Stdev = cpl_stats_get_stdev(ps.stats);
00797 cutoff = omega_mbias_config.Mean + omega_mbias_config.rejsig * omega_mbias_config.Stdev;
00798 cpl_msg_info(_id,"Using cutoff %g for Hot Pixels Map creation", cutoff);
00799 }
00800
00801 freestats(ps.stats);
00802
00803
00804 pixelmap = cpl_mask_threshold_image_create(ps.mbias, -1e20, cutoff);
00805
00806
00807 cpl_mask_not(pixelmap);
00808 omega_mbias_config.CountHotPixels = cpl_mask_count(pixelmap);
00809
00810
00811
00812
00813
00814
00815 ps.hpixels = cpl_image_new_from_mask(pixelmap);
00816 freemask(pixelmap);
00817
00818 return 0;
00819 }
00820
00821
00822 static void omega_mbias_init(void) {
00823 ps.labels = NULL;
00824 ps.rnframe = NULL;
00825 ps.biaslist = NULL;
00826 ps.mbias = NULL;
00827 ps.hpixels = NULL;
00828 ps.ph = NULL;
00829 ps.eh = NULL;
00830 ps.stats = NULL;
00831 ps.firstbias = NULL;
00832 }
00833
00834
00835 static void omega_mbias_tidy(void) {
00836 freespace(ps.labels);
00837 freeframeset(ps.biaslist);
00838 freeimage(ps.mbias);
00839 freeimage(ps.hpixels);
00840 freestats(ps.stats);
00841 freefits(ps.firstbias);
00842 }
00843