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
00038
00059
00062
00063
00064
00065
00066 static int omega_qcheck_create(cpl_plugin *) ;
00067 static int omega_qcheck_exec(cpl_plugin *) ;
00068 static int omega_qcheck_destroy(cpl_plugin *) ;
00069 static int omega_qcheck_old(cpl_frameset *,cpl_parameterlist *) ;
00070 static int omega_qcheck(cpl_frameset *,cpl_parameterlist *) ;
00071
00072
00073
00074
00075 static void omega_qcheck_init(void);
00076 static void omega_qcheck_tidy(void);
00077
00078
00079 static struct {
00080
00081 float rejt;
00082 int extnum;
00083 int niter;
00084 int oc;
00085 int paf;
00086
00087
00088 double mean;
00089 double median;
00090 double stdev;
00091
00092 }omega_qcheck_config;
00093
00094
00095 static struct {
00096 cpl_size *labels;
00097 cpl_stats *stats;
00098 cpl_frameset *domelist;
00099 omega_fits *domefits1;
00100 cpl_propertylist *eh;
00101
00102
00103 char *proname;
00104 cpl_table *result;
00105 } ps;
00106
00107
00108
00109
00110 #define RECIPE "omega_qcheck"
00111
00112
00120
00121 int cpl_plugin_get_info(cpl_pluginlist * list)
00122 {
00123 cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe)) ;
00124 cpl_plugin * plugin = &recipe->interface ;
00125
00126 cpl_plugin_init(plugin,
00127 CPL_PLUGIN_API,
00128 OMEGA_BINARY_VERSION,
00129 CPL_PLUGIN_TYPE_RECIPE,
00130 "omega_qcheck",
00131 "OMEGA - Generates a quick check on the detector responsivity for each chip.",
00132 "The recipe takes as input exactly one raw domeflat frame, and \n"
00133 "a master bias. Optionally, an overscan correction mode can be set. \n"
00134 "The default is to apply no overscan correction.",
00135 "Sandra Castro",
00136 "scastro@eso.org",
00137 omega_get_license(),
00138 omega_qcheck_create,
00139 omega_qcheck_exec,
00140 omega_qcheck_destroy) ;
00141
00142 cpl_pluginlist_append(list, plugin) ;
00143
00144 return 0;
00145 }
00146
00147
00156
00157 static int omega_qcheck_create(cpl_plugin * plugin)
00158 {
00159 cpl_recipe * recipe;
00160 cpl_parameter * p ;
00161
00162
00163 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00164 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
00165 cpl_func, __LINE__, cpl_error_get_where());
00166 return (int)cpl_error_get_code();
00167 }
00168
00169 if (plugin == NULL) {
00170 cpl_msg_error(cpl_func, "Null plugin");
00171 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00172 }
00173
00174
00175 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00176 cpl_msg_error(cpl_func, "Plugin is not a recipe");
00177 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
00178 }
00179
00180
00181 recipe = (cpl_recipe *)plugin;
00182
00183
00184 recipe->parameters = cpl_parameterlist_new() ;
00185
00186
00187 p = cpl_parameter_new_value("omega.omega_qcheck.ExtensionNumber",
00188 CPL_TYPE_INT,
00189 "FITS extension number to load (1 to 32). (-1 == all)",
00190 "omega_qcheck",
00191 -1) ;
00192
00193 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ext") ;
00194 cpl_parameterlist_append(recipe->parameters, p) ;
00195
00196
00197 p = cpl_parameter_new_range("omega.omega_qcheck.OverscanMethod",
00198 CPL_TYPE_INT,
00199 "Overscan Correction Method (0 to 6):\n"
00200 "0 = no overscan correction;\n"
00201 "1 = use median of prescan in X;\n"
00202 "2 = use median of overscan in X;\n"
00203 "3 = use median on prescan in Y;\n"
00204 "4 = use median of overscan in Y;\n"
00205 "5 = per-row subtraction of the median of row in prescan regions of X;\n"
00206 "6 = per-row subtraction of the median of row in overscan regions of X\n",
00207 "omega_qcheck",
00208 0, 0, 6);
00209
00210 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"oc-meth") ;
00211 cpl_parameterlist_append(recipe->parameters, p) ;
00212
00213 p = cpl_parameter_new_value("omega.omega_qcheck.PAF",
00214 CPL_TYPE_BOOL,
00215 "Boolean value to create PAF files. 1(Yes), 0(No)",
00216 "omega_qcheck",
00217 1) ;
00218
00219 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "paf") ;
00220 cpl_parameterlist_append(recipe->parameters, p) ;
00221
00222 p = cpl_parameter_new_value("omega.omega_qcheck.rej_threshold",
00223 CPL_TYPE_DOUBLE,
00224 "The rejection threshold for outlying pixels",
00225 "omega_qcheck",
00226 5.0) ;
00227
00228 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"rej-thre") ;
00229 cpl_parameterlist_append(recipe->parameters, p) ;
00230
00231 p = cpl_parameter_new_value("omega.omega_qcheck.NumberIter",
00232 CPL_TYPE_INT,
00233 "The maximum number of iterations",
00234 "omega_qcheck",
00235 5) ;
00236
00237 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"niter") ;
00238 cpl_parameterlist_append(recipe->parameters, p) ;
00239
00240
00241
00242 return 0;
00243 }
00244
00245
00251
00252 static int omega_qcheck_exec(cpl_plugin * plugin)
00253 {
00254 cpl_recipe * recipe;
00255 int recipe_status;
00256
00257
00258 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00259 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
00260 cpl_func, __LINE__, cpl_error_get_where());
00261 return (int)cpl_error_get_code();
00262 }
00263
00264 if (plugin == NULL) {
00265 cpl_msg_error(cpl_func, "Null plugin");
00266 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00267 }
00268
00269
00270 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00271 cpl_msg_error(cpl_func, "Plugin is not a recipe");
00272 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
00273 }
00274
00275
00276 recipe = (cpl_recipe *)plugin;
00277
00278
00279 if (recipe->parameters == NULL) {
00280 cpl_msg_error(cpl_func, "Recipe invoked with NULL parameter list");
00281 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00282 }
00283 if (recipe->frames == NULL) {
00284 cpl_msg_error(cpl_func, "Recipe invoked with NULL frame set");
00285 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00286 }
00287
00288
00289 recipe_status = omega_qcheck(recipe->frames, recipe->parameters);
00290
00291
00292 if (cpl_dfs_update_product_header(recipe->frames)) {
00293 if (!recipe_status) recipe_status = (int)cpl_error_get_code();
00294 }
00295
00296
00297 return recipe_status;
00298 }
00299
00300
00306
00307 static int omega_qcheck_destroy(cpl_plugin * plugin)
00308 {
00309 cpl_recipe * recipe = (cpl_recipe *)plugin ;
00310
00311 if (plugin == NULL) {
00312 cpl_msg_error(cpl_func, "Null plugin");
00313 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00314 }
00315
00316
00317 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00318 cpl_msg_error(cpl_func, "Plugin is not a recipe");
00319 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
00320 }
00321
00322
00323 recipe = (cpl_recipe *)plugin;
00324
00325 cpl_parameterlist_delete(recipe->parameters);
00326
00327 return 0 ;
00328 }
00329
00330
00338
00339 static int omega_qcheck_old(cpl_frameset *set, cpl_parameterlist *pars)
00340 {
00341
00342 int j,jst,jfn,live,oscan1,isfirst;
00343 cpl_size nlab;
00344 const char *_id = "omega_qcheck";
00345 char *outfile = NULL;
00346
00347 cpl_frame *mbias_frame;
00348 const cpl_frame *frame1;
00349 const cpl_frame *frame2;
00350 cpl_frame *product_frame;
00351 cpl_image *mbias_image;
00352 cpl_image *trim_raw1;
00353 cpl_image *trim_raw2;
00354 cpl_parameter *par;
00355 cpl_propertylist *plist,*qclist;
00356
00357
00358
00359
00360 if (!pars) {
00361 cpl_msg_error (_id, "Parameters list not found");
00362 return -1;
00363 }
00364
00365 if (cpl_frameset_is_empty(set) == 1) {
00366 cpl_msg_error (_id, "Frameset not found");
00367 return -1;
00368 }
00369
00370
00371 omega_qcheck_init();
00372
00373
00374 par = cpl_parameterlist_find(pars, "omega.omega_qcheck.ExtensionNumber") ;
00375 omega_qcheck_config.extnum = cpl_parameter_get_int(par) ;
00376
00377 par = cpl_parameterlist_find(pars, "omega.omega_qcheck.OverscanMethod") ;
00378 omega_qcheck_config.oc = cpl_parameter_get_int(par) ;
00379
00380 par = cpl_parameterlist_find(pars, "omega.omega_qcheck.NumberIter") ;
00381 omega_qcheck_config.niter = cpl_parameter_get_int(par) ;
00382
00383 par = cpl_parameterlist_find(pars, "omega.omega_qcheck.rej_threshold") ;
00384 omega_qcheck_config.rejt = cpl_parameter_get_double(par) ;
00385
00386 par = cpl_parameterlist_find(pars, "omega.omega_qcheck.PAF") ;
00387 omega_qcheck_config.paf = cpl_parameter_get_bool(par) ;
00388
00389
00390 if (oc_dfs_set_groups(set)) {
00391 cpl_msg_error(_id, "Cannot identify RAW and CALIB frames") ;
00392 omega_qcheck_tidy();
00393 return -1 ;
00394 }
00395
00396
00397
00398
00399 if ((ps.labels = cpl_frameset_labelise(set,omega_compare_tags,
00400 &nlab)) == NULL) {
00401 cpl_msg_error(_id,"Cannot labelise the input frameset");
00402 omega_qcheck_tidy();
00403 return -1;
00404 }
00405 if ((ps.domelist = omega_frameset_subgroup(set,ps.labels,nlab,
00406 LIFETEST_RAW)) == NULL) {
00407 cpl_msg_error(_id,"Cannot find dome frames in input frameset");
00408 omega_qcheck_tidy();
00409 return -1;
00410 }
00411 if (cpl_frameset_get_size(ps.domelist) < 2) {
00412 cpl_msg_error(_id,"Need exactly 2 (%s) frames to run this recipe",LIFETEST_RAW);
00413 omega_qcheck_tidy();
00414 return -1;
00415 }
00416
00417
00418 frame1 = cpl_frameset_get_frame_const(ps.domelist,0);
00419 frame2 = cpl_frameset_get_frame_const(ps.domelist,1);
00420 cpl_msg_info (_id,"Using %s frames: %s and %s",LIFETEST_RAW,cpl_frame_get_filename(frame1),
00421 cpl_frame_get_filename(frame2));
00422
00423 mbias_frame = cpl_frameset_find(set, OMEGA_CALIB_BIAS);
00424 if (mbias_frame == NULL) {
00425 cpl_msg_error (_id,"No Master Bias is present in frame set");
00426 omega_qcheck_tidy();
00427 return -1;
00428 }
00429
00430 cpl_msg_info(_id,"Using %s %s",OMEGA_CALIB_BIAS, cpl_frame_get_filename(mbias_frame));
00431
00432
00433 omega_exten_range(omega_qcheck_config.extnum,&jst,&jfn);
00434 if(omega_qcheck_config.extnum == 0){
00435 cpl_msg_error(cpl_func,"Unsupported extension request, %d",omega_qcheck_config.extnum);
00436 omega_qcheck_tidy();
00437 return -1;
00438 }
00439
00440
00441 if(omega_pfits_check_instrume(cpl_frameset_get_first_const(set)) == 1 &&
00442 omega_qcheck_config.extnum == 0 && jfn == 32)
00443 jfn = 8;
00444
00445 for (j = jst; j <= jfn; j++) {
00446 cpl_msg_info(_id,"Beginning work on extension %d",j);
00447 isfirst = (j == jst);
00448 omega_qcheck_config.mean = 0.0;
00449 omega_qcheck_config.median = 0.0;
00450 omega_qcheck_config.stdev = 0.0;
00451
00452
00453
00454 plist = cpl_propertylist_load(cpl_frame_get_filename(frame1),j);
00455 omega_pfits_get_detlive(plist,&live);
00456 if (! live) {
00457 cpl_msg_warning(_id,"First dome image detector not live");
00458
00459 freeplist(plist);
00460 continue;
00461 }
00462 freeplist(plist);
00463
00464 plist = cpl_propertylist_load(cpl_frame_get_filename(frame2),j);
00465 omega_pfits_get_detlive(plist,&live);
00466 if (! live) {
00467 cpl_msg_warning(_id,"Second dome image detector not live");
00468
00469 freeplist(plist);
00470 continue;
00471 }
00472 freeplist(plist);
00473
00474
00475 oscan1 = omega_pfits_get_overscan(mbias_frame, j);
00476 if(oscan1 != omega_qcheck_config.oc) {
00477 cpl_msg_warning (_id, "Overscan correction mode for Master Bias (oc = %d) differs from "
00478 "the one used here (oc = %d)", oscan1, omega_qcheck_config.oc);
00479 }
00480
00481
00482 mbias_image = cpl_image_load(cpl_frame_get_filename(mbias_frame), CPL_TYPE_FLOAT, 0, j);
00483 if (mbias_image == NULL) {
00484 cpl_msg_error(_id,"Cannot load MASTER BIAS");
00485 omega_qcheck_tidy();
00486 return -1;
00487 }
00488
00489 cpl_msg_info (_id,"Doing trim and overscan correction on images");
00490
00491 trim_raw1 = TrimOscanCorrect(frame1, omega_qcheck_config.oc, j);
00492 if(trim_raw1 == NULL){
00493 cpl_msg_error(_id,"Cannot trim first image");
00494 freeimage(mbias_image);
00495 omega_qcheck_tidy();
00496 return -1;
00497 }
00498
00499 cpl_image_subtract(trim_raw1, mbias_image);
00500
00501 trim_raw2 = TrimOscanCorrect(frame2, omega_qcheck_config.oc, j);
00502 if(trim_raw2 == NULL){
00503 cpl_msg_error(_id,"Cannot trim second image");
00504 freeimage(mbias_image);
00505 omega_qcheck_tidy();
00506 return -1;
00507 }
00508
00509 cpl_image_subtract(trim_raw2, mbias_image);
00510 freeimage(mbias_image);
00511
00512 cpl_image_divide(trim_raw1, trim_raw2);
00513 if(trim_raw1 == NULL){
00514 cpl_msg_error(_id,"Error in image division");
00515 omega_qcheck_tidy();
00516 return -1;
00517 }
00518
00519 freeimage(trim_raw2);
00520
00521
00522 ps.stats = omega_iter_stat_opts(trim_raw1,NULL,omega_qcheck_config.rejt,omega_qcheck_config.niter);
00523 if(ps.stats != NULL){
00524 omega_qcheck_config.mean = cpl_stats_get_mean(ps.stats);
00525 omega_qcheck_config.median = cpl_stats_get_median(ps.stats);
00526 omega_qcheck_config.stdev = cpl_stats_get_stdev(ps.stats);
00527 }
00528 else{
00529 cpl_msg_warning(_id,"Cannot calculate statistics iteratively");
00530 }
00531
00532 freestats(ps.stats);
00533 freeimage(trim_raw1);
00534
00535
00536 ps.result = cpl_table_new(1);
00537 cpl_table_new_column(ps.result, "MEAN", CPL_TYPE_DOUBLE);
00538 cpl_table_new_column(ps.result, "MEDIAN", CPL_TYPE_DOUBLE);
00539 cpl_table_new_column(ps.result, "STDEV", CPL_TYPE_DOUBLE);
00540 cpl_table_set_double(ps.result, "MEAN", 0, omega_qcheck_config.mean);
00541 cpl_table_set_double(ps.result, "MEDIAN", 0, omega_qcheck_config.median);
00542 cpl_table_set_double(ps.result, "STDEV", 0, omega_qcheck_config.stdev);
00543
00544
00545
00546
00547
00548
00549
00550 qclist = cpl_propertylist_new();
00551 cpl_propertylist_append_double(qclist, "ESO QC QUICK CHECK MEAN",
00552 omega_qcheck_config.mean) ;
00553 cpl_propertylist_set_comment(qclist,"ESO QC QUICK CHECK MEAN","Mean of difference");
00554
00555 cpl_propertylist_append_double(qclist, "ESO QC QUICK CHECK MEDIAN",
00556 omega_qcheck_config.median) ;
00557 cpl_propertylist_set_comment(qclist,"ESO QC QUICK CHECK MEDIAN","Median of difference");
00558
00559 cpl_propertylist_append_double(qclist, "ESO QC QUICK CHECK STDEV",
00560 omega_qcheck_config.stdev) ;
00561 cpl_propertylist_set_comment(qclist,"ESO QC QUICK CHECK STDEV","Standard deviation of difference");
00562
00563 if(isfirst){
00564 ps.proname = cpl_sprintf("%s_%s.fits", INSTRUME,LTEST_PROCATG);
00565 product_frame = omega_product_frame(ps.proname, LTEST_PROCATG, CPL_FRAME_TYPE_TABLE);
00566 }
00567
00568 if(omega_save_table(ps.result,set,pars,NULL,qclist,ps.proname,RECIPE,product_frame,
00569 NULL,isfirst) == -1){
00570 cpl_msg_error(cpl_func, "Cannot save the product");
00571 freeplist(qclist);
00572 omega_qcheck_tidy();
00573 return -1 ;
00574 }
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584 freetable(ps.result);
00585 freeplist(qclist);
00586
00587
00588
00589 }
00590
00591
00592
00593 omega_qcheck_tidy();
00594
00595 return 0;
00596
00597 }
00598
00599
00612
00613
00614 static int omega_qcheck(cpl_frameset *set, cpl_parameterlist *pars)
00615 {
00616
00617 int j,jst,jfn,oscan1,isfirst;
00618 cpl_size nlab;
00619 cpl_frame *mbias_frame;
00620 const cpl_frame *frame1;
00621 cpl_image *mbias_image;
00622 cpl_image *trim_raw1;
00623 cpl_frame *product_frame;
00624 cpl_parameter *par;
00625 cpl_propertylist *qclist,*alist;
00626
00627
00628
00629
00630 if (!pars) {
00631 cpl_msg_error (cpl_func, "Parameters list not found");
00632 return -1;
00633 }
00634
00635 if (cpl_frameset_is_empty(set) == 1) {
00636 cpl_msg_error (cpl_func, "Frameset not found");
00637 return -1;
00638 }
00639
00640
00641 omega_qcheck_init();
00642
00643
00644 par = cpl_parameterlist_find(pars, "omega.omega_qcheck.ExtensionNumber") ;
00645 omega_qcheck_config.extnum = cpl_parameter_get_int(par) ;
00646
00647 par = cpl_parameterlist_find(pars, "omega.omega_qcheck.OverscanMethod") ;
00648 omega_qcheck_config.oc = cpl_parameter_get_int(par) ;
00649
00650 par = cpl_parameterlist_find(pars, "omega.omega_qcheck.NumberIter") ;
00651 omega_qcheck_config.niter = cpl_parameter_get_int(par) ;
00652
00653 par = cpl_parameterlist_find(pars, "omega.omega_qcheck.rej_threshold") ;
00654 omega_qcheck_config.rejt = cpl_parameter_get_double(par) ;
00655
00656 par = cpl_parameterlist_find(pars, "omega.omega_qcheck.PAF") ;
00657 omega_qcheck_config.paf = cpl_parameter_get_bool(par) ;
00658
00659
00660 if (oc_dfs_set_groups(set)) {
00661 cpl_msg_error(cpl_func, "Cannot identify RAW and CALIB frames") ;
00662 omega_qcheck_tidy();
00663 return -1 ;
00664 }
00665
00666
00667
00668
00669 if ((ps.labels = cpl_frameset_labelise(set,omega_compare_tags,
00670 &nlab)) == NULL) {
00671 cpl_msg_error(cpl_func,"Cannot labelise the input frameset");
00672 omega_qcheck_tidy();
00673 return -1;
00674 }
00675 if ((ps.domelist = omega_frameset_subgroup(set,ps.labels,nlab,
00676 LIFETEST_RAW)) == NULL) {
00677 cpl_msg_error(cpl_func,"Cannot find dome frame in input frameset");
00678 omega_qcheck_tidy();
00679 return -1;
00680 }
00681 if (cpl_frameset_get_size(ps.domelist) < 1) {
00682 cpl_msg_error(cpl_func,"Need exactly 1 (%s) frame to run this recipe",LIFETEST_RAW);
00683 omega_qcheck_tidy();
00684 return -1;
00685 }
00686
00687
00688 frame1 = cpl_frameset_get_frame_const(ps.domelist,0);
00689 cpl_msg_info (cpl_func,"Using %s frame: %s",LIFETEST_RAW,cpl_frame_get_filename(frame1));
00690
00691 mbias_frame = cpl_frameset_find(set, OMEGA_CALIB_BIAS);
00692 if (mbias_frame == NULL) {
00693 cpl_msg_error (cpl_func,"No Master Bias is present in frame set");
00694 omega_qcheck_tidy();
00695 return -1;
00696 }
00697
00698 cpl_msg_info(cpl_func,"Using %s %s",OMEGA_CALIB_BIAS, cpl_frame_get_filename(mbias_frame));
00699
00700
00701 omega_extensions(frame1,omega_qcheck_config.extnum,&jst,&jfn);
00702 if(omega_qcheck_config.extnum == 0){
00703 cpl_msg_error(cpl_func,"Unsupported extension request, %d",omega_qcheck_config.extnum);
00704 omega_qcheck_tidy();
00705 return -1;
00706 }
00707
00708 for (j = jst; j <= jfn; j++) {
00709 cpl_msg_info(cpl_func,"Working on extension %d",j);
00710 isfirst = (j == jst);
00711 omega_qcheck_config.mean = 0.0;
00712 omega_qcheck_config.median = 0.0;
00713 omega_qcheck_config.stdev = 0.0;
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730 oscan1 = omega_pfits_get_overscan(mbias_frame, j);
00731 if(oscan1 != omega_qcheck_config.oc) {
00732 cpl_msg_warning (cpl_func, "Overscan correction mode for Master Bias (oc = %d) differs from "
00733 "the one used here (oc = %d)", oscan1, omega_qcheck_config.oc);
00734 }
00735
00736
00737 mbias_image = cpl_image_load(cpl_frame_get_filename(mbias_frame), CPL_TYPE_FLOAT, 0, j);
00738 if (mbias_image == NULL) {
00739 cpl_msg_error(cpl_func,"Cannot load MASTER BIAS");
00740 omega_qcheck_tidy();
00741 return -1;
00742 }
00743
00744 ps.domefits1 = omega_fits_load(frame1,CPL_TYPE_FLOAT,j);
00745
00746 trim_raw1 = omega_trim_oscan_correct(ps.domefits1, omega_qcheck_config.oc);
00747 if(trim_raw1 == NULL){
00748 cpl_msg_error(cpl_func,"Cannot trim input image");
00749 freeimage(mbias_image);
00750 omega_qcheck_tidy();
00751 return -1;
00752 }
00753
00754 cpl_image_subtract(trim_raw1, mbias_image);
00755 freeimage(mbias_image);
00756
00757
00758 ps.stats = omega_iter_stat_opts(trim_raw1,NULL,omega_qcheck_config.rejt,omega_qcheck_config.niter);
00759 if(ps.stats != NULL){
00760 omega_qcheck_config.mean = cpl_stats_get_mean(ps.stats);
00761 omega_qcheck_config.median = cpl_stats_get_median(ps.stats);
00762 omega_qcheck_config.stdev = cpl_stats_get_stdev(ps.stats);
00763 }
00764 else{
00765 cpl_msg_warning(cpl_func,"Cannot calculate statistics iteratively");
00766 }
00767
00768 freestats(ps.stats);
00769 freeimage(trim_raw1);
00770
00771
00772
00773 ps.result = cpl_table_new(1);
00774 cpl_table_new_column(ps.result, "MEAN", CPL_TYPE_DOUBLE);
00775 cpl_table_new_column(ps.result, "MEDIAN", CPL_TYPE_DOUBLE);
00776 cpl_table_new_column(ps.result, "STDEV", CPL_TYPE_DOUBLE);
00777 cpl_table_set_double(ps.result, "MEAN", 0, omega_qcheck_config.mean);
00778 cpl_table_set_double(ps.result, "MEDIAN", 0, omega_qcheck_config.median);
00779 cpl_table_set_double(ps.result, "STDEV", 0, omega_qcheck_config.stdev);
00780
00781
00782 qclist = cpl_propertylist_new();
00783 cpl_propertylist_append_double(qclist, "ESO QC QUICK CHECK MEAN",
00784 omega_qcheck_config.mean) ;
00785 cpl_propertylist_set_comment(qclist,"ESO QC QUICK CHECK MEAN","Mean of difference");
00786
00787 cpl_propertylist_append_double(qclist, "ESO QC QUICK CHECK MEDIAN",
00788 omega_qcheck_config.median) ;
00789 cpl_propertylist_set_comment(qclist,"ESO QC QUICK CHECK MEDIAN","Median of difference");
00790
00791 cpl_propertylist_append_double(qclist, "ESO QC QUICK CHECK STDEV",
00792 omega_qcheck_config.stdev) ;
00793 cpl_propertylist_set_comment(qclist,"ESO QC QUICK CHECK STDEV","Standard deviation of difference");
00794
00795 if(isfirst){
00796 ps.proname = cpl_sprintf("%s_%s.fits", INSTRUME,LTEST_PROCATG);
00797 product_frame = omega_product_frame(ps.proname, LTEST_PROCATG, CPL_FRAME_TYPE_TABLE);
00798 }
00799
00800
00801 alist=cpl_propertylist_load_regexp(cpl_frame_get_filename(frame1),j,"EXTNAME",0);
00802 if(omega_save_table(ps.result,set,pars,alist,qclist,ps.proname,RECIPE,product_frame,
00803 NULL,isfirst) == -1){
00804 cpl_msg_error(cpl_func, "Cannot save the product");
00805 cpl_propertylist_delete(alist);
00806 freeplist(qclist);
00807 omega_qcheck_tidy();
00808 return -1 ;
00809 }
00810 cpl_propertylist_delete(alist);
00811
00812
00813
00814
00815
00816
00817
00818
00819 freetable(ps.result);
00820 freeplist(qclist);
00821 freefits(ps.domefits1);
00822 ps.domefits1 = NULL;
00823 }
00824
00825
00826
00827 omega_qcheck_tidy();
00828
00829 return 0;
00830
00831 }
00832
00833
00834
00835 static void omega_qcheck_init(void) {
00836 ps.labels = NULL;
00837 ps.domelist = NULL;
00838 ps.domefits1 = NULL;
00839 ps.stats = NULL;
00840 ps.eh = NULL;
00841 ps.proname = NULL;
00842 ps.result = NULL;
00843 }
00844
00845
00846 static void omega_qcheck_tidy(void) {
00847 freespace(ps.labels);
00848 freeframeset(ps.domelist);
00849 freefits(ps.domefits1);
00850 freestats(ps.stats);
00851 freespace(ps.proname);
00852 freetable(ps.result);
00853 }
00854