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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 #ifdef HAVE_CONFIG_H
00144 # include <config.h>
00145 #endif
00146
00147
00154
00155
00156
00157
00158
00159 #include <uves_mdark_impl.h>
00160
00161 #include <uves_parameters.h>
00162 #include <uves_utils.h>
00163 #include <uves.h>
00164 #include <uves_dfs.h>
00165 #include <uves_pfits.h>
00166 #include <uves_qclog.h>
00167 #include <uves_recipe.h>
00168 #include <uves_utils_wrappers.h>
00169 #include <uves_error.h>
00170 #include <uves_globals.h>
00171
00172 #include <cpl.h>
00173 #include <float.h>
00174
00175
00176
00177
00178 static int
00179 uves_qcdark_define_parameters_body(cpl_parameterlist *parameters,
00180 const char *recipe_id);
00181 static int
00182 uves_mdark_define_parameters(cpl_parameterlist *parameters);
00183
00184 static void uves_mdark_region_qc(cpl_image* img,
00185 const cpl_parameterlist* p,
00186 const cpl_imagelist* raw_images,
00187 cpl_table* qclog);
00188 static cpl_image *
00189 uves_mdark_process_chip(const cpl_imagelist *raw_images,
00190 uves_propertylist **raw_headers,
00191 const cpl_image *master_bias,
00192 uves_propertylist *mdark_header,
00193 const cpl_parameterlist *parameters,
00194 cpl_table* qclog, const int do_qc);
00195
00196
00197
00198
00199
00200 #define cpl_plugin_get_info uves_mdark_get_info
00201 UVES_RECIPE_DEFINE(
00202 UVES_MDARK_ID, UVES_MDARK_DOM,
00203
00204
00205 uves_mdark_define_parameters,
00206 "Jonas M. Larsen", "cpl@eso.org",
00207 "Creates the master dark frame",
00208 "This recipe creates a master dark frame by taking the median of all\n"
00209 "input frames which should have identical exposure times. Symbolically,\n"
00210 " masterdark = median( dark_i ) - masterbias\n"
00211 "\n"
00212 "The input dark frames must have same tag and size and must be either\n"
00213 "(P)DARK_BLUE or (P)DARK_RED. Also, a master bias (MASTER_BIAS_xxxx) must\n"
00214 "be provided for each chip (xxxx = BLUE, REDL, REDU).\n"
00215 "\n"
00216 "On blue input the recipe computes one master dark frame; on red input the\n"
00217 "recipe produces a master dark frame for each chip (MASTER_(P)DARK_xxxx).\n");
00218
00220
00221
00222
00223
00229
00230 static int
00231 uves_mdark_define_parameters(cpl_parameterlist *parameters)
00232 {
00233 return uves_qcdark_define_parameters_body(parameters,
00234 make_str(UVES_MDARK_ID));
00235 }
00236
00237
00244
00245 static int
00246 uves_qcdark_define_parameters_body(cpl_parameterlist *parameters,
00247 const char *recipe_id)
00248 {
00249
00250
00251
00252 if (uves_define_global_parameters(parameters) != CPL_ERROR_NONE)
00253 {
00254 return -1;
00255 }
00256
00257
00258
00259
00260
00261
00262 if (uves_propagate_parameters_step(UVES_QCDARK_ID, parameters,
00263 recipe_id, NULL) != 0)
00264 {
00265 return -1;
00266 }
00267
00268 return (cpl_error_get_code() != CPL_ERROR_NONE);
00269 }
00270
00271
00272
00280
00281 cpl_parameterlist *
00282 uves_qcdark_define_parameters(void)
00283 {
00284
00285 const char *name = "";
00286 char *full_name = NULL;
00287 cpl_parameter *p = NULL;
00288 cpl_parameterlist *parameters = NULL;
00289
00290 parameters = cpl_parameterlist_new();
00291
00292 {
00293
00294 name = "reg.num_x";
00295 full_name = uves_sprintf("%s.%s", UVES_QCDARK_ID, name);
00296 uves_msg("parameter=%s",full_name);
00297 uves_parameter_new_value(p, full_name,
00298 CPL_TYPE_INT,
00299 "Number of regions on X direction "
00300 "(where mean/med/rms are computed). ",
00301 UVES_QCDARK_ID,
00302 4);
00303
00304 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, name );
00305 cpl_parameterlist_append(parameters, p);
00306 cpl_free(full_name);
00307
00308
00309
00310 name = "reg.num_y";
00311 full_name = uves_sprintf("%s.%s", UVES_QCDARK_ID, name);
00312 uves_parameter_new_value(p, full_name,
00313 CPL_TYPE_INT,
00314 "Number of regions on Y direction"
00315 "(where mean/med/rms are computed). ",
00316 UVES_QCDARK_ID,
00317 4);
00318
00319 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, name);
00320 cpl_parameterlist_append(parameters, p);
00321 cpl_free(full_name);
00322
00323
00324
00325 name = "reg.box_sx";
00326 full_name = uves_sprintf("%s.%s", UVES_QCDARK_ID, name);
00327 uves_parameter_new_value(p, full_name,
00328 CPL_TYPE_INT,
00329 "Region X size",
00330 UVES_QCDARK_ID,
00331 100);
00332 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, name);
00333 cpl_parameterlist_append(parameters, p);
00334 cpl_free(full_name);
00335
00336
00337 name = "reg.box_sy";
00338 full_name = uves_sprintf("%s.%s", UVES_QCDARK_ID, name);
00339 uves_parameter_new_value(p, full_name,
00340 CPL_TYPE_INT,
00341 "Region Y size",
00342 UVES_QCDARK_ID,
00343 100);
00344 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, name);
00345 cpl_parameterlist_append(parameters, p);
00346 cpl_free(full_name);
00347
00348 name = "reg.border_x";
00349 full_name = uves_sprintf("%s.%s", UVES_QCDARK_ID, name);
00350 uves_parameter_new_value(p, full_name,
00351 CPL_TYPE_INT,
00352 "X distance from the left hand side "
00353 "detector's border and the left hand side "
00354 "regin's bottom corner",
00355 UVES_QCDARK_ID,
00356 100);
00357 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, name);
00358 cpl_parameterlist_append(parameters, p);
00359 cpl_free(full_name);
00360
00361
00362 name = "reg.border_y";
00363 full_name = uves_sprintf("%s.%s", UVES_QCDARK_ID, name);
00364 uves_parameter_new_value(p, full_name,
00365 CPL_TYPE_INT,
00366 "Y distance from the left hand side "
00367 "detector's border and the left hand side "
00368 "regin's bottom corner",
00369 UVES_QCDARK_ID,
00370 100);
00371 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, name);
00372 cpl_parameterlist_append(parameters, p);
00373 cpl_free(full_name);
00374
00375
00376
00377 name = "reg.when";
00378 full_name = uves_sprintf("%s.%s", UVES_QCDARK_ID, name);
00379 uves_parameter_new_enum(p, full_name,
00380 CPL_TYPE_INT,
00381 "When QC analysis is performed. "
00382 "0: on each raw frame or "
00383 "1: on the master frame",
00384 UVES_QCDARK_ID,
00385 0,2,0,1);
00386 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, name);
00387 cpl_parameterlist_append(parameters, p);
00388 cpl_free(full_name);
00389
00390
00391 }
00392
00393 if (cpl_error_get_code() != CPL_ERROR_NONE)
00394 {
00395 cpl_msg_error(__func__, "Creation of mdark parameters failed: '%s'",
00396 cpl_error_get_where());
00397 cpl_parameterlist_delete(parameters);
00398 return NULL;
00399 }
00400 else
00401 {
00402 return parameters;
00403 }
00404 }
00405
00406
00426
00427 static cpl_image *
00428 uves_mdark_process_chip(const cpl_imagelist *raw_images,
00429 uves_propertylist **raw_headers,
00430 const cpl_image *master_bias,
00431 uves_propertylist *mdark_header,
00432 const cpl_parameterlist *parameters,
00433 cpl_table* qclog,const int do_qc)
00434 {
00435 cpl_image *master_dark = NULL;
00436 cpl_image *current_dark = NULL;
00437 cpl_imagelist *preproc_images = NULL;
00438 double min_exptime = 0;
00439 double max_exptime = 0;
00440 int i;
00441
00442
00443
00444 preproc_images = cpl_imagelist_new();
00445 for (i = 0; i < cpl_imagelist_get_size(raw_images); i++)
00446 {
00447 double exposure_time = 0.0;
00448 const uves_propertylist *current_header;
00449
00450 current_dark = cpl_image_duplicate(cpl_imagelist_get_const(raw_images, i));
00451 current_header = raw_headers[i];
00452
00453
00454 if (master_bias != NULL)
00455 {
00456 uves_msg("Subtracting master bias");
00457 check( uves_subtract_bias(current_dark, master_bias),
00458 "Error subtracting master bias");
00459
00460 if (false) {
00461 uves_msg_debug("Thresholding to non-negative values");
00462 check( cpl_image_threshold(current_dark,
00463 0, DBL_MAX,
00464 0, DBL_MAX),
00465 "Error thresholding image");
00466 }
00467 }
00468 else
00469 {
00470 uves_msg("Skipping bias subtraction");
00471 }
00472
00473 check( exposure_time = uves_pfits_get_exptime(current_header),
00474 "Error reading exposure time");
00475
00476 if(do_qc == 0) {
00477 uves_msg("Calculating QC parameters on raw dark frame %d",i);
00478 uves_mdark_region_qc(current_dark,parameters,raw_images,qclog);
00479 }
00480
00481
00482 if (i == 0 || exposure_time < min_exptime)
00483 {
00484 min_exptime = exposure_time;
00485 }
00486 if (i == 0 || exposure_time > max_exptime)
00487 {
00488 max_exptime = exposure_time;
00489 }
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499 check( cpl_imagelist_set(preproc_images,
00500 current_dark,
00501 i),
00502 "Could not insert image into image list");
00503
00504
00505
00506 current_dark = NULL;
00507 }
00508
00509
00510 uves_msg("Exposure times range from %e s to %e s (%e %% variation)",
00511 min_exptime,
00512 max_exptime,
00513 100 * (max_exptime - min_exptime) / min_exptime);
00514
00515 if ((max_exptime - min_exptime) / min_exptime > .001)
00516 {
00517 uves_msg_warning("Exposure times differ by %e %%",
00518 100 * (max_exptime - min_exptime) / min_exptime);
00519 }
00520
00521
00522 uves_msg("Calculating stack median");
00523 check( master_dark = cpl_imagelist_collapse_median_create(preproc_images),
00524 "Error computing median");
00525
00526 check( uves_pfits_set_exptime(mdark_header, (max_exptime + min_exptime)/2),
00527 "Error setting master dark exposure time");
00528
00529 cleanup:
00530 uves_free_image(¤t_dark);
00531 uves_free_imagelist(&preproc_images);
00532 if (cpl_error_get_code() != CPL_ERROR_NONE)
00533 {
00534 uves_free_image(&master_dark);
00535 }
00536
00537 return master_dark;
00538 }
00539
00540
00541
00548
00549 static void
00550 IRPLIB_CONCAT2X(UVES_MDARK_ID,exe)(cpl_frameset *frames,
00551 const cpl_parameterlist *parameters,
00552 const char *starttime)
00553 {
00554 uves_mdark_exe_body(frames, parameters, starttime, make_str(UVES_MDARK_ID));
00555 return;
00556 }
00557
00558
00570
00571 void
00572 uves_mdark_exe_body(cpl_frameset *frames,
00573 const cpl_parameterlist *parameters,
00574 const char *starttime,
00575 const char *recipe_id)
00576 {
00577
00578
00579
00580
00581
00582
00583
00584
00585 cpl_imagelist *raw_images[2] = {NULL, NULL};
00586 uves_propertylist **raw_headers[2] = {NULL, NULL};
00587
00588
00589 cpl_image *master_bias = NULL;
00590 uves_propertylist *master_bias_header = NULL;
00591
00592
00593 cpl_table* qclog[2] = {NULL, NULL};
00594 cpl_image *master_dark = NULL;
00595 uves_propertylist *product_header[2] = {NULL, NULL};
00596
00597
00598 char *product_filename = NULL;
00599 const char *product_tag[2] = {NULL, NULL};
00600 bool blue;
00601 enum uves_chip chip;
00602
00603 const char* pname=NULL;
00604
00605
00606 int pr_when=0;
00607 const char* PROCESS_CHIP=NULL;
00608
00609
00610
00611
00612 if (cpl_frameset_find(frames, UVES_DARK(true )) != NULL ||
00613 cpl_frameset_find(frames, UVES_DARK(false)) != NULL)
00614 {
00615 check( uves_load_raw_imagelist(frames,
00616 false,
00617 UVES_DARK(true), UVES_DARK(false),
00618 CPL_TYPE_DOUBLE,
00619 raw_images, raw_headers, product_header,
00620 &blue), "Error loading raw dark frames");
00621
00622 for (chip = uves_chip_get_first(blue);
00623 chip != UVES_CHIP_INVALID;
00624 chip = uves_chip_get_next(chip))
00625 {
00626 product_tag[uves_chip_get_index(chip)] = UVES_MASTER_DARK(chip);
00627 }
00628 }
00629 else if (cpl_frameset_find(frames, UVES_PDARK(true )) != NULL ||
00630 cpl_frameset_find(frames, UVES_PDARK(false)) != NULL)
00631 {
00632 check( uves_load_raw_imagelist(frames,
00633 false,
00634 UVES_PDARK(true), UVES_PDARK(false),
00635 CPL_TYPE_DOUBLE,
00636 raw_images, raw_headers, product_header,
00637 &blue), "Error loading raw dark frames");
00638
00639 for (chip = uves_chip_get_first(blue);
00640 chip != UVES_CHIP_INVALID;
00641 chip = uves_chip_get_next(chip))
00642 {
00643 product_tag[uves_chip_get_index(chip)] = UVES_MASTER_PDARK(chip);
00644 }
00645 }
00646 else
00647 {
00648 assure(false, CPL_ERROR_DATA_NOT_FOUND,
00649 "Missing input dark frame: %s, %s, %s or %s expected",
00650 UVES_DARK(true) , UVES_DARK(false),
00651 UVES_PDARK(true), UVES_PDARK(false));
00652 }
00653
00654
00655
00656 pname = uves_sprintf("%s.%s", UVES_QCDARK_ID, "reg.when");
00657 check(uves_get_parameter(parameters,NULL,recipe_id,pname,CPL_TYPE_INT,&pr_when),
00658 "Could not read parameter");
00659 check( uves_get_parameter(parameters, NULL, "uves", "process_chip", CPL_TYPE_STRING, &PROCESS_CHIP),
00660 "Could not read parameter");
00661
00662
00663 for (chip = uves_chip_get_first(blue);
00664 chip != UVES_CHIP_INVALID;
00665 chip = uves_chip_get_next(chip))
00666 {
00667
00668 if(strcmp(PROCESS_CHIP,"redu") == 0) {
00669 chip = uves_chip_get_next(chip);
00670 }
00671
00672 const char *master_bias_filename = "";
00673 const char *chip_name = "";
00674
00675 int raw_index = uves_chip_get_index(chip);
00676
00677 uves_msg("Processing %s chip",
00678 uves_chip_tostring_upper(chip));
00679
00680
00681 check_nomsg( chip_name = uves_pfits_get_chipid(raw_headers[raw_index][0], chip));
00682
00683
00684 uves_free_image(&master_bias);
00685 uves_free_propertylist(&master_bias_header);
00686 if (cpl_frameset_find(frames, UVES_MASTER_BIAS(chip)) != NULL)
00687 {
00688 check( uves_load_mbias(frames, chip_name,
00689 &master_bias_filename, &master_bias,
00690 &master_bias_header, chip),
00691 "Error loading master bias");
00692
00693 uves_msg_low("Using master bias in '%s'", master_bias_filename);
00694 }
00695 else
00696 {
00697 uves_msg_low("No master bias in SOF. Bias subtraction not done");
00698 }
00699
00700
00701
00702
00703
00704 uves_free_image(&master_dark);
00705 uves_qclog_delete(&qclog[0]);
00706 qclog[0] = uves_qclog_init(raw_headers[raw_index][0], chip);
00707 check( master_dark = uves_mdark_process_chip(raw_images[raw_index],
00708 raw_headers[raw_index],
00709 master_bias,
00710 product_header[raw_index],
00711 parameters,
00712 qclog[0],pr_when),
00713 "Error processing chip");
00714
00715
00716
00717
00718 if(pr_when==1) {
00719 uves_msg("Calculating QC parameters on master dark frame");
00720 uves_mdark_region_qc(master_dark,parameters,
00721 raw_images[raw_index],qclog[0]);
00722
00723 }
00724
00725
00726 uves_msg("Saving product");
00727
00728 cpl_free(product_filename);
00729 check( product_filename = uves_masterdark_filename(chip), "Error getting filename");
00730
00731
00732 check( uves_frameset_insert(frames,
00733 master_dark,
00734 CPL_FRAME_GROUP_PRODUCT,
00735 CPL_FRAME_TYPE_IMAGE,
00736 CPL_FRAME_LEVEL_INTERMEDIATE,
00737 product_filename,
00738 product_tag[raw_index],
00739 raw_headers[raw_index][0],
00740 product_header[raw_index],
00741 NULL,
00742 parameters,
00743 recipe_id,
00744 PACKAGE "/" PACKAGE_VERSION,qclog,
00745 starttime, true,
00746 UVES_ALL_STATS),
00747 "Could not add master dark %s to frameset", product_filename);
00748 uves_msg("Master dark %s added to frameset", product_filename);
00749 uves_qclog_delete(&qclog[0]);
00750
00751 if(strcmp(PROCESS_CHIP,"redl") == 0) {
00752 chip = uves_chip_get_next(chip);
00753 }
00754
00755
00756 }
00757
00758 cleanup:
00759
00760 if (raw_images[0] != NULL)
00761 {
00762 int i;
00763 for (i = 0; i < cpl_imagelist_get_size(raw_images[0]); i++)
00764 {
00765 if (raw_headers[0] != NULL) uves_free_propertylist(&raw_headers[0][i]);
00766 if (raw_headers[1] != NULL) uves_free_propertylist(&raw_headers[1][i]);
00767 }
00768
00769 cpl_free(raw_headers[0]); raw_headers[0] = NULL;
00770 cpl_free(raw_headers[1]); raw_headers[1] = NULL;
00771 }
00772
00773 uves_free_imagelist(&raw_images[0]);
00774 uves_free_imagelist(&raw_images[1]);
00775
00776
00777 uves_free_image(&master_bias);
00778 uves_free_propertylist(&master_bias_header);
00779
00780
00781 uves_qclog_delete(&qclog[0]);
00782 uves_free_image(&master_dark);
00783 uves_free_propertylist(&product_header[0]);
00784 uves_free_propertylist(&product_header[1]);
00785 cpl_free(product_filename);
00786
00787 return;
00788 }
00789
00790
00791 static void
00792 uves_mdark_region_qc(cpl_image* img,
00793 const cpl_parameterlist* p,
00794 const cpl_imagelist* raw_images,
00795 cpl_table* qclog)
00796 {
00797
00798 int pr_num_x=4;
00799 int pr_num_y=4;
00800 int pr_box_sx=100;
00801 int pr_box_sy=100;
00802 int pr_border_x=100;
00803 int pr_border_y=100;
00804
00805
00806 int i=0;
00807 int j=0;
00808 int llx=0;
00809 int lly=0;
00810 int urx=0;
00811 int ury=0;
00812 int space_x=0;
00813 int space_y=0;
00814 int sx=0;
00815 int sy=0;
00816 int nraw=0;
00817 int raw=0;
00818 char *name = "";
00819 char *pname = NULL;
00820 char qc_key[MAX_NAME_SIZE];
00821 char qc_com[MAX_NAME_SIZE];
00822 double qc_avg=0;
00823 double qc_med=0;
00824 double qc_rms=0;
00825 double qc_min=0;
00826 double qc_max=0;
00827 cpl_table* qc_sto=NULL;
00828 const char* recipe_id=make_str(UVES_MDARK_ID);
00829
00830
00831 name = "reg.num_x";
00832 pname = uves_sprintf("%s.%s", UVES_QCDARK_ID, name);
00833
00834 check(uves_get_parameter(p,NULL,recipe_id,pname,CPL_TYPE_INT,&pr_num_x),
00835 "Could not read parameter");
00836
00837 name = "reg.num_y";
00838 pname = uves_sprintf("%s.%s", UVES_QCDARK_ID, name);
00839 check(uves_get_parameter(p,NULL,recipe_id,pname,CPL_TYPE_INT,&pr_num_y),
00840 "Could not read parameter");
00841
00842 name = "reg.box_sx";
00843 pname = uves_sprintf("%s.%s", UVES_QCDARK_ID, name);
00844 check(uves_get_parameter(p,NULL,recipe_id,pname,CPL_TYPE_INT,&pr_box_sx),
00845 "Could not read parameter");
00846
00847 name = "reg.box_sy";
00848 pname = uves_sprintf("%s.%s", UVES_QCDARK_ID, name);
00849 check(uves_get_parameter(p,NULL,recipe_id,pname,CPL_TYPE_INT,&pr_box_sy),
00850 "Could not read parameter");
00851
00852 name = "reg.border_x";
00853 pname = uves_sprintf("%s.%s", UVES_QCDARK_ID, name);
00854 check(uves_get_parameter(p,NULL,recipe_id,pname,CPL_TYPE_INT,&pr_border_x),
00855 "Could not read parameter");
00856
00857 name = "reg.border_y";
00858 pname = uves_sprintf("%s.%s", UVES_QCDARK_ID, name);
00859 check(uves_get_parameter(p,NULL,recipe_id,pname,CPL_TYPE_INT,&pr_border_y),
00860 "Could not read parameter");
00861
00862
00863 check_nomsg(nraw=cpl_imagelist_get_size(raw_images));
00864 check_nomsg(uves_qclog_add_int(qclog,
00865 "PRO DATANCOM",
00866 nraw,
00867 "Number of frames combined",
00868 "%d"));
00869
00870 sx=cpl_image_get_size_x(img);
00871 sy=cpl_image_get_size_y(img);
00872 space_x=(int)((sx-2*pr_border_x)/pr_num_x);
00873 space_y=(int)((sy-2*pr_border_y)/pr_num_y);
00874 qc_sto=cpl_table_new(pr_num_x*pr_num_y);
00875 cpl_table_new_column(qc_sto,"MIN",CPL_TYPE_DOUBLE);
00876 cpl_table_new_column(qc_sto,"MAX",CPL_TYPE_DOUBLE);
00877 cpl_table_new_column(qc_sto,"AVG",CPL_TYPE_DOUBLE);
00878 cpl_table_new_column(qc_sto,"MED",CPL_TYPE_DOUBLE);
00879 cpl_table_new_column(qc_sto,"RMS",CPL_TYPE_DOUBLE);
00880
00881 for(i=0;i<pr_num_x;i++) {
00882 llx=pr_border_x+i*space_x;
00883 urx=llx+pr_box_sx;
00884 for(j=0;j<pr_num_y;j++) {
00885 lly=pr_border_y+j*space_y;
00886 ury=lly+pr_box_sy;
00887 raw=i*pr_num_y+j;
00888 qc_min=cpl_image_get_min_window(img,llx,lly,urx,ury);
00889 qc_max=cpl_image_get_min_window(img,llx,lly,urx,ury);
00890 qc_avg=cpl_image_get_mean_window(img,llx,lly,urx,ury);
00891 qc_med=cpl_image_get_median_window(img,llx,lly,urx,ury);
00892 qc_rms=cpl_image_get_stdev_window(img,llx,lly,urx,ury);
00893 uves_msg_debug("QC on area [%d,%d:%d,%d]. Min %g Max %g Avg %g Med %g Rms %g",
00894 llx,lly,urx,ury,qc_min,qc_max,qc_avg,qc_med,qc_rms);
00895
00896 sprintf(qc_key,"%s%d%d%s","QC REG",i,j," MIN");
00897 sprintf(qc_com,"%s%d%d","Min of region [%d,%d]",i,j);
00898 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_min,qc_com,"%g"));
00899 check_nomsg(cpl_table_set_double(qc_sto,"MIN",raw,qc_min));
00900
00901 sprintf(qc_key,"%s%d%d%s","QC REG",i,j," MAX");
00902 sprintf(qc_com,"%s%d%d","Max of region [%d,%d]",i,j);
00903 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_max,qc_com,"%g"));
00904 check_nomsg(cpl_table_set_double(qc_sto,"MAX",raw,qc_max));
00905
00906 sprintf(qc_key,"%s%d%d%s","QC REG",i,j," AVG");
00907 sprintf(qc_com,"%s%d%d","Mean of region [%d,%d]",i,j);
00908 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_avg,qc_com,"%g"));
00909 check_nomsg(cpl_table_set_double(qc_sto,"AVG",raw,qc_avg));
00910
00911 sprintf(qc_key,"%s%d%d%s","QC REG",i,j," MED");
00912 sprintf(qc_com,"%s%d%d","Median of region [%d,%d]",i,j);
00913 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_med,qc_com,"%g"));
00914 check_nomsg(cpl_table_set_double(qc_sto,"MED",raw,qc_med));
00915
00916 sprintf(qc_key,"%s%d%d%s","QC REG",i,j," RMS");
00917 sprintf(qc_com,"%s%d%d","Rms of region [%d,%d]",i,j);
00918 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_rms,qc_com,"%g"));
00919 check_nomsg(cpl_table_set_double(qc_sto,"RMS",raw,qc_rms));
00920
00921
00922 }
00923 }
00924
00925
00926 check_nomsg(qc_min=cpl_table_get_column_min(qc_sto,"MIN"));
00927 check_nomsg(qc_max=cpl_table_get_column_max(qc_sto,"MIN"));
00928 check_nomsg(qc_avg=cpl_table_get_column_mean(qc_sto,"MIN"));
00929 check_nomsg(qc_med=cpl_table_get_column_median(qc_sto,"MIN"));
00930 check_nomsg(qc_rms=cpl_table_get_column_stdev(qc_sto,"MIN"));
00931
00932 sprintf(qc_key,"%s","QC REG MIN MIN");
00933 sprintf(qc_com,"%s","Min of all Mins");
00934 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_min,qc_com,"%g"));
00935
00936 sprintf(qc_key,"%s","QC REG MIN MAX");
00937 sprintf(qc_com,"%s","Max of all Mins");
00938 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_max,qc_com,"%g"));
00939
00940 sprintf(qc_key,"%s","QC REG MIN AVG");
00941 sprintf(qc_com,"%s","Mean of all Mins");
00942 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_avg,qc_com,"%g"));
00943
00944 sprintf(qc_key,"%s","QC REG MIN MED");
00945 sprintf(qc_com,"%s","Median of all Mins");
00946 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_med,qc_com,"%g"));
00947
00948 sprintf(qc_key,"%s","QC REG MIN RMS");
00949 sprintf(qc_com,"%s","Rms of all Mins");
00950 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_rms,qc_com,"%g"));
00951
00952
00953
00954 check_nomsg(qc_min=cpl_table_get_column_min(qc_sto,"MAX"));
00955 check_nomsg(qc_max=cpl_table_get_column_max(qc_sto,"MAX"));
00956 check_nomsg(qc_avg=cpl_table_get_column_mean(qc_sto,"MAX"));
00957 check_nomsg(qc_med=cpl_table_get_column_median(qc_sto,"MAX"));
00958 check_nomsg(qc_rms=cpl_table_get_column_stdev(qc_sto,"MAX"));
00959
00960 sprintf(qc_key,"%s","QC REG MAX MIN");
00961 sprintf(qc_com,"%s","Min of all Maxs");
00962 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_min,qc_com,"%g"));
00963
00964 sprintf(qc_key,"%s","QC REG MAX MAX");
00965 sprintf(qc_com,"%s","Max of all Maxs");
00966 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_max,qc_com,"%g"));
00967
00968 sprintf(qc_key,"%s","QC REG MAX AVG");
00969 sprintf(qc_com,"%s","Mean of all Maxs");
00970 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_avg,qc_com,"%g"));
00971
00972 sprintf(qc_key,"%s","QC REG MAX MED");
00973 sprintf(qc_com,"%s","Median of all Maxs");
00974 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_med,qc_com,"%g"));
00975
00976 sprintf(qc_key,"%s","QC REG MAX RMS");
00977 sprintf(qc_com,"%s","Rms of all Maxs");
00978 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_rms,qc_com,"%g"));
00979
00980
00981 check_nomsg(qc_min=cpl_table_get_column_min(qc_sto,"AVG"));
00982 check_nomsg(qc_max=cpl_table_get_column_max(qc_sto,"AVG"));
00983 check_nomsg(qc_avg=cpl_table_get_column_mean(qc_sto,"AVG"));
00984 check_nomsg(qc_med=cpl_table_get_column_median(qc_sto,"AVG"));
00985 check_nomsg(qc_rms=cpl_table_get_column_stdev(qc_sto,"AVG"));
00986
00987 sprintf(qc_key,"%s","QC REG AVG MIN");
00988 sprintf(qc_com,"%s","Min of all Means");
00989 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_min,qc_com,"%g"));
00990
00991 sprintf(qc_key,"%s","QC REG AVG MAX");
00992 sprintf(qc_com,"%s","Max of all Means");
00993 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_max,qc_com,"%g"));
00994
00995 sprintf(qc_key,"%s","QC REG AVG AVG");
00996 sprintf(qc_com,"%s","Mean of all Means");
00997 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_avg,qc_com,"%g"));
00998
00999 sprintf(qc_key,"%s","QC REG AVG MED");
01000 sprintf(qc_com,"%s","Median of all Means");
01001 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_med,qc_com,"%g"));
01002
01003 sprintf(qc_key,"%s","QC REG AVG RMS");
01004 sprintf(qc_com,"%s","Rms of all Means");
01005 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_rms,qc_com,"%g"));
01006
01007
01008 check_nomsg(qc_min=cpl_table_get_column_min(qc_sto,"MED"));
01009 check_nomsg(qc_max=cpl_table_get_column_max(qc_sto,"MED"));
01010 check_nomsg(qc_avg=cpl_table_get_column_mean(qc_sto,"MED"));
01011 check_nomsg(qc_med=cpl_table_get_column_median(qc_sto,"MED"));
01012 check_nomsg(qc_rms=cpl_table_get_column_stdev(qc_sto,"MED"));
01013
01014 sprintf(qc_key,"%s","QC REG MED MIN");
01015 sprintf(qc_com,"%s","Min of all Medians");
01016 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_min,qc_com,"%g"));
01017
01018 sprintf(qc_key,"%s","QC REG MED MAX");
01019 sprintf(qc_com,"%s","Max of all Medians");
01020 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_max,qc_com,"%g"));
01021
01022 sprintf(qc_key,"%s","QC REG MED AVG");
01023 sprintf(qc_com,"%s","Mean of all Medians");
01024 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_avg,qc_com,"%g"));
01025
01026 sprintf(qc_key,"%s","QC REG MED MED");
01027 sprintf(qc_com,"%s","Median of all Medians");
01028 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_med,qc_com,"%g"));
01029
01030 sprintf(qc_key,"%s","QC REG MED RMS");
01031 sprintf(qc_com,"%s","Rms of all Medians");
01032 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_rms,qc_com,"%g"));
01033
01034
01035 check_nomsg(qc_min=cpl_table_get_column_min(qc_sto,"RMS"));
01036 check_nomsg(qc_max=cpl_table_get_column_max(qc_sto,"RMS"));
01037 check_nomsg(qc_avg=cpl_table_get_column_mean(qc_sto,"RMS"));
01038 check_nomsg(qc_med=cpl_table_get_column_median(qc_sto,"RMS"));
01039 check_nomsg(qc_rms=cpl_table_get_column_stdev(qc_sto,"RMS"));
01040
01041
01042 sprintf(qc_key,"%s","QC REG RMS MIN");
01043 sprintf(qc_com,"%s","Min of all Rms");
01044 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_min,qc_com,"%g"));
01045
01046 sprintf(qc_key,"%s","QC REG RMS MAX");
01047 sprintf(qc_com,"%s","Max of all Rms");
01048 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_max,qc_com,"%g"));
01049
01050 sprintf(qc_key,"%s","QC REG RMS AVG");
01051 sprintf(qc_com,"%s","Mean of all Rms");
01052 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_avg,qc_com,"%g"));
01053
01054 sprintf(qc_key,"%s","QC REG RMS MED");
01055 sprintf(qc_com,"%s","Median of all Rms");
01056 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_med,qc_com,"%g"));
01057
01058 sprintf(qc_key,"%s","QC REG RMS RMS");
01059 sprintf(qc_com,"%s","Rms of all Rms");
01060 check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_rms,qc_com,"%g"));
01061
01062
01063
01064
01065 cleanup:
01066 uves_free_table(&qc_sto);
01067
01068 return;
01069
01070 }
01071
01072