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