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 if(omega_save_image(ps.mbias,set,pars,alist,qclist,CPL_BPP_IEEE_FLOAT,outmbias,
00560 RECIPE,prframe_mbias,NULL,isfirst) == -1){
00561 cpl_msg_error(_id,"Cannot save product %s", MBIAS_PROCATG);
00562 freeplist(qclist);
00563 freeplist(alist);
00564 freespace(outhpm);
00565 freespace(outmbias);
00566 omega_mbias_tidy();
00567 return -1;;
00568 }
00569
00570 freeplist(qclist);
00571 freeimage(ps.mbias);
00572
00573
00574 qclist = cpl_propertylist_new();
00575 cpl_propertylist_append_int(qclist,"ESO QC NUMBER HOT PIXELS",
00576 omega_mbias_config.CountHotPixels);
00577 cpl_propertylist_set_comment(qclist,"ESO QC NUMBER HOT PIXELS",
00578 "Number of hot pixels");
00579 if(isfirst){
00580 outhpm = cpl_sprintf("%s_%s.fits", INSTRUME,HPM_PROCATG);
00581 prframe_hpm = omega_product_frame(outhpm, HPM_PROCATG, CPL_FRAME_TYPE_IMAGE);
00582 }
00583
00584 if(omega_save_image(ps.hpixels,set,pars,alist,qclist,CPL_BPP_16_SIGNED,outhpm,
00585 RECIPE,prframe_hpm,NULL,isfirst) == -1){
00586 cpl_msg_error(_id,"Cannot save product %s", HPM_PROCATG);
00587 freeplist(qclist);
00588 freeplist(alist);
00589 freespace(outhpm);
00590 freespace(outmbias);
00591 omega_mbias_tidy();
00592 return -1;;
00593 }
00594
00595 freeplist(qclist);
00596 freeplist(alist);
00597 freeimage(ps.hpixels);
00598 status = 0;
00599
00600 freefits(ps.firstbias);
00601 ps.firstbias = NULL;
00602 ps.eh = NULL;
00603
00604
00605 }
00606
00607 freespace(outhpm);
00608 freespace(outmbias);
00609 omega_mbias_tidy();
00610
00611 return 0;
00612 }
00613
00622 int omega_mbias_combine(int xn)
00623 {
00624
00625 int i, nbias, live, naxis1, naxis2;
00626 double read_noise, threshold;
00627 double cutoff = 200.0;
00628 const char *_id = "omega_mbias_combine";
00629
00630 const cpl_frame *biasfr;
00631 cpl_image *trim_raw,*median_all,*dev,*good_int,*good_float;
00632 cpl_image *sum_data,*sum_good,*image;
00633 cpl_imagelist *ilist;
00634 cpl_mask *good,*pixelmap;
00635 cpl_table *rntable;
00636
00637
00638 nbias = cpl_frameset_get_size(ps.biaslist);
00639 biasfr = cpl_frameset_get_first_const(ps.biaslist);
00640
00641
00642
00643 omega_pfits_get_detlive(ps.eh,&live);
00644 if (! live) {
00645 return 1;
00646 }
00647
00648 cpl_msg_info (_id,"Doing trim and overscan correction on images");
00649
00650 for (i=0; i< nbias; i++){
00651
00652 trim_raw = TrimOscanCorrect(biasfr, omega_mbias_config.oc, xn);
00653 if(trim_raw == NULL){
00654 return -1;
00655 }
00656
00657 if (i == 0) {
00658 naxis1 = cpl_image_get_size_x (trim_raw);
00659 naxis2 = cpl_image_get_size_y (trim_raw);
00660 ilist = cpl_imagelist_new ();
00661 }
00662
00663 cpl_imagelist_set (ilist, trim_raw, i);
00664
00665 biasfr = cpl_frameset_get_next_const(ps.biaslist);
00666 if (biasfr == NULL)
00667 break;
00668
00669 }
00670
00671 if (ilist == NULL) {
00672 cpl_msg_error(_id,"Error in imagelist <%s>",cpl_error_get_message());
00673 freeimage(trim_raw);
00674 return -1;
00675
00676 }
00677
00678
00679
00680
00681
00682 if(ps.rnframe != NULL){
00683 rntable = cpl_table_load(cpl_frame_get_filename(ps.rnframe), xn, 0);
00684 if(rntable != NULL){
00685 read_noise = cpl_table_get_double(rntable, "READNOISE",0, NULL);
00686 freetable(rntable);
00687 }
00688 else{
00689 omega_pfits_get_readnoise(ps.eh, &read_noise);
00690 cpl_msg_warning(cpl_func,"Cannot load READNOISE_ADU table. %s",cpl_error_get_message());
00691 }
00692 }
00693 else {
00694 omega_pfits_get_readnoise(ps.eh, &read_noise);
00695 }
00696
00697 if (read_noise == 0.0){
00698 cpl_msg_info(_id,"Using default value for read noise");
00699 read_noise = 2.5;
00700 }
00701 else {
00702 cpl_msg_info(_id,"Using read noise = %g", read_noise);
00703 }
00704
00705
00706 threshold = read_noise * omega_mbias_config.sigma;
00707 cpl_msg_info (_id,"Discarding outliers using threshold %g", threshold);
00708
00709
00710
00711 cpl_msg_info (_id,"Computing the median of all images...");
00712 median_all = cpl_imagelist_collapse_median_create (ilist);
00713
00714 if (median_all == NULL) {
00715 cpl_msg_error (_id,"Cannot take median of imagelist <%s>",cpl_error_get_message());
00716 freeilist(ilist);
00717 return -1;
00718 }
00719
00720
00721 trim_raw = cpl_imagelist_get (ilist, 0);
00722 dev = cpl_image_subtract_create(median_all, trim_raw);
00723
00724 good = cpl_mask_threshold_image_create(dev, -threshold, threshold);
00725 freeimage(dev);
00726
00727 good_int = cpl_image_new_from_mask(good) ;
00728 freemask(good) ;
00729 good_float = cpl_image_cast(good_int, CPL_TYPE_FLOAT);
00730 freeimage(good_int);
00731
00732 sum_data = cpl_image_multiply_create(trim_raw, good_float);
00733 sum_good = cpl_image_duplicate(good_float);
00734
00735 freeimage(good_float);
00736
00737
00738 for (i=1; i< nbias; i++){
00739
00740 trim_raw = cpl_imagelist_get(ilist, i);
00741
00742
00743
00744 dev = cpl_image_subtract_create(median_all, trim_raw);
00745
00746 if (dev == NULL) {
00747 cpl_msg_error(_id,"Error in subtraction <%s>",cpl_error_get_function());
00748 freeilist(ilist);
00749 freeimage(median_all);
00750 freeimage(sum_data);
00751 freeimage(sum_good);
00752 return -1;
00753 }
00754
00755 good = cpl_mask_threshold_image_create (dev, -threshold, threshold);
00756
00757 freeimage(dev);
00758
00759 good_int = cpl_image_new_from_mask(good) ;
00760 freemask(good) ;
00761 good_float = cpl_image_cast(good_int, CPL_TYPE_FLOAT);
00762 freeimage(good_int);
00763
00764 image = cpl_image_multiply_create(trim_raw, good_float);
00765 cpl_image_add(sum_data, image);
00766
00767 cpl_image_add(sum_good, good_float);
00768
00769 freeimage(image);
00770 freeimage(good_float);
00771 }
00772
00773 freeimage(median_all);
00774 freeilist(ilist);
00775
00776 ps.mbias = cpl_image_divide_create(sum_data, sum_good);
00777
00778 if (ps.mbias == NULL) {
00779 cpl_msg_error(_id,"Cannot create product. Error in division");
00780 freeimage(sum_data);
00781 freeimage(sum_good);
00782 return -1;
00783 }
00784
00785 freeimage(sum_data);
00786 freeimage(sum_good);
00787
00788
00789 ps.stats = cpl_stats_new_from_image(ps.mbias, CPL_STATS_ALL);
00790 if(ps.stats != NULL) {
00791 omega_mbias_config.Mean = cpl_stats_get_mean(ps.stats);
00792 omega_mbias_config.Median = cpl_stats_get_median(ps.stats);
00793 omega_mbias_config.Stdev = cpl_stats_get_stdev(ps.stats);
00794 cutoff = omega_mbias_config.Mean + omega_mbias_config.rejsig * omega_mbias_config.Stdev;
00795 cpl_msg_info(_id,"Using cutoff %g for Hot Pixels Map creation", cutoff);
00796 }
00797
00798 freestats(ps.stats);
00799
00800
00801 pixelmap = cpl_mask_threshold_image_create(ps.mbias, -1e20, cutoff);
00802
00803
00804 cpl_mask_not(pixelmap);
00805 omega_mbias_config.CountHotPixels = cpl_mask_count(pixelmap);
00806
00807
00808
00809
00810
00811
00812 ps.hpixels = cpl_image_new_from_mask(pixelmap);
00813 freemask(pixelmap);
00814
00815 return 0;
00816 }
00817
00818
00819 static void omega_mbias_init(void) {
00820 ps.labels = NULL;
00821 ps.rnframe = NULL;
00822 ps.biaslist = NULL;
00823 ps.mbias = NULL;
00824 ps.hpixels = NULL;
00825 ps.ph = NULL;
00826 ps.eh = NULL;
00827 ps.stats = NULL;
00828 ps.firstbias = NULL;
00829 }
00830
00831
00832 static void omega_mbias_tidy(void) {
00833 freespace(ps.labels);
00834 freeframeset(ps.biaslist);
00835 freeimage(ps.mbias);
00836 freeimage(ps.hpixels);
00837 freestats(ps.stats);
00838 freefits(ps.firstbias);
00839 }
00840