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_readnoise_create(cpl_plugin *) ;
00067 static int omega_readnoise_exec(cpl_plugin *) ;
00068 static int omega_readnoise_destroy(cpl_plugin *) ;
00069 static int omega_readnoise(cpl_frameset *,cpl_parameterlist *) ;
00070
00071
00072
00073
00074 int omega_readnoise_save(cpl_frameset *set, cpl_parameterlist *parlist);
00075 static void omega_readnoise_init(void);
00076 static void omega_readnoise_tidy(void);
00077
00078 static struct {
00079
00080 float rej_sig;
00081 int niter;
00082 int extnum;
00083 int paf;
00084
00085
00086 double rnoise;
00087 double mean_diff;
00088 double median_diff;
00089 double RawBias1Min;
00090 double RawBias1Max;
00091 double RawBias1Mean;
00092 double RawBias1Median;
00093 double RawBias1Stdev;
00094
00095 double RawBias2Min;
00096 double RawBias2Max;
00097 double RawBias2Mean;
00098 double RawBias2Median;
00099 double RawBias2Stdev;
00100
00101 }omega_readnoise_config;
00102
00103 static struct {
00104 cpl_size *labels;
00105 cpl_frameset *biaslist;
00106 omega_fits *biasfits1;
00107 omega_fits *biasfits2;
00108 cpl_stats *stats;
00109
00110
00111 cpl_table *table;
00112 } ps;
00113
00114
00115
00116
00117 #define RECIPE "omega_readnoise"
00118
00119 static cpl_frame *product_frame = NULL;
00120 static int isfirst;
00121 static int dummy;
00122 static char outfile[100];
00123 static char outpaf[100];
00124 static const char *PROCATG = OMEGA_CALIB_RDNOISE;
00125
00126
00127
00135
00136 int cpl_plugin_get_info(cpl_pluginlist * list)
00137 {
00138 cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe)) ;
00139 cpl_plugin * plugin = &recipe->interface ;
00140
00141 cpl_plugin_init(plugin,
00142 CPL_PLUGIN_API,
00143 OMEGA_BINARY_VERSION,
00144 CPL_PLUGIN_TYPE_RECIPE,
00145 "omega_readnoise",
00146 "OMEGA - Calculate the read noise of the detector.",
00147 "The read_noise is computed by subtracting two raw bias images, \n"
00148 "and dividing the standard deviation by sqrt(2). The descriptor \n"
00149 "value read_noise will be set to the computed value. The statistics \n"
00150 "of the difference between the raw biases is computed iteratively. Bad \n"
00151 "pixels are rejected if they differ more than process_params.REJECTION_THRESHOLD \n"
00152 "sigma from the median. The maximum number of iteration is \n"
00153 "process_params.MAXIMUM_ITERATIONS.",
00154 "Sandra Castro",
00155 "scastro@eso.org",
00156 omega_get_license(),
00157 omega_readnoise_create,
00158 omega_readnoise_exec,
00159 omega_readnoise_destroy) ;
00160
00161 cpl_pluginlist_append(list, plugin) ;
00162
00163 return 0;
00164 }
00165
00166
00175
00176 static int omega_readnoise_create(cpl_plugin * plugin)
00177 {
00178 cpl_recipe * recipe;
00179 cpl_parameter * p ;
00180
00181
00182 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00183 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
00184 cpl_func, __LINE__, cpl_error_get_where());
00185 return (int)cpl_error_get_code();
00186 }
00187
00188 if (plugin == NULL) {
00189 cpl_msg_error(cpl_func, "Null plugin");
00190 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00191 }
00192
00193
00194 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00195 cpl_msg_error(cpl_func, "Plugin is not a recipe");
00196 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
00197 }
00198
00199
00200 recipe = (cpl_recipe *)plugin;
00201
00202
00203 recipe->parameters = cpl_parameterlist_new() ;
00204
00205 if (recipe->parameters == NULL) {
00206 cpl_msg_error(cpl_func, "Parameter list allocation failed");
00207 cpl_ensure_code(0, (int)CPL_ERROR_ILLEGAL_OUTPUT);
00208 }
00209
00210
00211 p = cpl_parameter_new_value("omega.omega_readnoise.ExtensionNumber",
00212 CPL_TYPE_INT,
00213 "FITS extension number to load (1 to 32). (-1 = all)",
00214 "omega_readnoise",
00215 -1) ;
00216
00217 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ext") ;
00218 cpl_parameterlist_append(recipe->parameters, p) ;
00219
00220 p = cpl_parameter_new_value("omega.omega_readnoise.PAF",
00221 CPL_TYPE_BOOL,
00222 "Boolean value to create PAF files. 1(Yes), 0(No)",
00223 "omega_readnoise",
00224 0) ;
00225
00226 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "paf") ;
00227 cpl_parameterlist_append(recipe->parameters, p) ;
00228
00229 p = cpl_parameter_new_range("omega.omega_readnoise.NumberIter",
00230 CPL_TYPE_INT,
00231 "Maximum number of iterations",
00232 "omega_readnoise",
00233 5, 2, 10) ;
00234
00235 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"niter") ;
00236 cpl_parameterlist_append(recipe->parameters, p) ;
00237
00238
00239 p = cpl_parameter_new_range("omega.omega_readnoise.RejSigma",
00240 CPL_TYPE_DOUBLE,
00241 "Sigma Clipping Threshold",
00242 "omega_readnoise",
00243 5.0, 1.0, 10.0) ;
00244
00245 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "sig-clip") ;
00246 cpl_parameterlist_append(recipe->parameters, p) ;
00247
00248
00249
00250 return 0;
00251 }
00252
00253
00254
00260
00261 static int omega_readnoise_exec(cpl_plugin * plugin)
00262 {
00263 cpl_recipe * recipe;
00264 int recipe_status;
00265
00266
00267 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00268 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
00269 cpl_func, __LINE__, cpl_error_get_where());
00270 return (int)cpl_error_get_code();
00271 }
00272
00273 if (plugin == NULL) {
00274 cpl_msg_error(cpl_func, "Null plugin");
00275 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00276 }
00277
00278
00279 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00280 cpl_msg_error(cpl_func, "Plugin is not a recipe");
00281 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
00282 }
00283
00284
00285 recipe = (cpl_recipe *)plugin;
00286
00287
00288 if (recipe->parameters == NULL) {
00289 cpl_msg_error(cpl_func, "Recipe invoked with NULL parameter list");
00290 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00291 }
00292 if (recipe->frames == NULL) {
00293 cpl_msg_error(cpl_func, "Recipe invoked with NULL frame set");
00294 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00295 }
00296
00297
00298 recipe_status = omega_readnoise(recipe->frames, recipe->parameters);
00299
00300
00301 if (cpl_dfs_update_product_header(recipe->frames)) {
00302 if (!recipe_status) recipe_status = (int)cpl_error_get_code();
00303 }
00304
00305 return recipe_status;
00306
00307 }
00308
00309
00315
00316 static int omega_readnoise_destroy(cpl_plugin * plugin)
00317 {
00318 cpl_recipe *recipe;
00319
00320 if (plugin == NULL) {
00321 cpl_msg_error(cpl_func, "Null plugin");
00322 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00323 }
00324
00325
00326 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00327 cpl_msg_error(cpl_func, "Plugin is not a recipe");
00328 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
00329 }
00330
00331
00332 recipe = (cpl_recipe *)plugin;
00333
00334 cpl_parameterlist_delete(recipe->parameters);
00335
00336 return 0 ;
00337 }
00338
00339
00340
00348
00349
00350 static int omega_readnoise(cpl_frameset *set,cpl_parameterlist *pars)
00351 {
00352
00353 int j,jst,jfn,live;
00354 cpl_size nlab;
00355 float stdev = 0.0;
00356
00357 const char *_id = "omega_readnoise";
00358 const char *chipid = NULL;
00359
00360 const cpl_frame *bias1, *bias2;
00361 const cpl_image *rawbiasfits1, *rawbiasfits2=NULL;
00362 cpl_image *biasim;
00363 cpl_parameter *par;
00364 cpl_propertylist *plist;
00365
00366
00367
00368
00369 if (pars == NULL) {
00370 cpl_msg_error (_id, "Parameters list not found");
00371 return -1;
00372 }
00373
00374 if (cpl_frameset_is_empty(set) == 1) {
00375 cpl_msg_error (_id, "Frameset not found");
00376 return -1;
00377 }
00378
00379
00380
00381 omega_readnoise_init();
00382
00383
00384
00385
00386 par = cpl_parameterlist_find(pars, "omega.omega_readnoise.ExtensionNumber") ;
00387 omega_readnoise_config.extnum = cpl_parameter_get_int(par) ;
00388
00389 par = cpl_parameterlist_find(pars, "omega.omega_readnoise.NumberIter") ;
00390 omega_readnoise_config.niter = cpl_parameter_get_int(par) ;
00391
00392 par = cpl_parameterlist_find(pars, "omega.omega_readnoise.RejSigma") ;
00393 omega_readnoise_config.rej_sig = cpl_parameter_get_double(par) ;
00394
00395 par = cpl_parameterlist_find(pars, "omega.omega_readnoise.PAF") ;
00396 omega_readnoise_config.paf = cpl_parameter_get_bool(par) ;
00397
00398
00399 if (oc_dfs_set_groups(set)) {
00400 cpl_msg_error(_id, "Cannot identify RAW and CALIB frames") ;
00401 omega_readnoise_tidy();
00402 return -1 ;
00403 }
00404
00405
00406
00407
00408 if ((ps.labels = cpl_frameset_labelise(set,omega_compare_tags,
00409 &nlab)) == NULL) {
00410 cpl_msg_error(_id,"Cannot labelise the input frameset");
00411 omega_readnoise_tidy();
00412 return -1;
00413 }
00414 if ((ps.biaslist = omega_frameset_subgroup(set,ps.labels,nlab,
00415 RNOISE_RAW)) == NULL) {
00416 cpl_msg_error(_id,"Cannot find bias frames in input frameset");
00417 omega_readnoise_tidy();
00418 return -1;
00419 }
00420 if (cpl_frameset_get_size(ps.biaslist) < 2) {
00421 cpl_msg_error(_id,"Need exactly 2 (%s) frames to run this recipe",RNOISE_RAW);
00422 omega_readnoise_tidy();
00423 return -1;
00424 }
00425
00426
00427 bias1 = cpl_frameset_get_frame_const(ps.biaslist,0);
00428 bias2 = cpl_frameset_get_frame_const(ps.biaslist,1);
00429
00430 cpl_msg_info (_id,"Using %s frames: %s and %s",RNOISE_RAW,cpl_frame_get_filename(bias1),
00431 cpl_frame_get_filename(bias2));
00432
00433
00434 omega_exten_range(omega_readnoise_config.extnum,&jst,&jfn);
00435 if(omega_readnoise_config.extnum == 0){
00436 cpl_msg_error(cpl_func,"Unsupported extension request, %d",omega_readnoise_config.extnum);
00437 omega_readnoise_tidy();
00438 return -1;
00439 }
00440
00441
00442 if(omega_pfits_check_instrume(cpl_frameset_get_first_const(set)) == 1 &&
00443 omega_readnoise_config.extnum == 0 && jfn == 32)
00444 jfn = 8;
00445
00446 for (j = jst; j <= jfn; j++) {
00447 cpl_msg_info(_id,"Beginning work on extension %d",j);
00448 isfirst = (j == jst);
00449 omega_readnoise_config.rnoise = 0.0;
00450 omega_readnoise_config.mean_diff = 0.0;
00451 omega_readnoise_config.median_diff = 0.0;
00452 omega_readnoise_config.RawBias1Min=0.;
00453 omega_readnoise_config.RawBias1Max=0.;
00454 omega_readnoise_config.RawBias1Mean=0.;
00455 omega_readnoise_config.RawBias1Median=0.;
00456 omega_readnoise_config.RawBias1Stdev=0.;
00457 omega_readnoise_config.RawBias2Min=0.;
00458 omega_readnoise_config.RawBias2Max=0.;
00459 omega_readnoise_config.RawBias2Mean=0.;
00460 omega_readnoise_config.RawBias2Median=0.;
00461 omega_readnoise_config.RawBias2Stdev=0.;
00462
00463 ps.biasfits1 = omega_fits_load(bias1,CPL_TYPE_FLOAT,j);
00464 ps.biasfits2 = omega_fits_load(bias2,CPL_TYPE_FLOAT,j);
00465
00466 if (ps.biasfits1 == NULL || ps.biasfits2 == NULL) {
00467 cpl_msg_error(_id,"NULL image input for extension %d",j);
00468
00469 freefits(ps.biasfits1);
00470 freefits(ps.biasfits2);
00471 continue;
00472 }
00473
00474
00475
00476 plist = cpl_propertylist_load(cpl_frame_get_filename(bias1),j);
00477 omega_pfits_get_detlive(plist,&live);
00478 if (! live) {
00479 cpl_msg_warning(_id,"First bias image detector not live");
00480
00481 freefits(ps.biasfits1);
00482 freefits(ps.biasfits2);
00483 freeplist(plist);
00484 continue;
00485 }
00486 freeplist(plist);
00487
00488 plist = cpl_propertylist_load(cpl_frame_get_filename(bias2),j);
00489 omega_pfits_get_detlive(plist,&live);
00490 if (! live) {
00491 cpl_msg_warning(_id,"Second bias image detector not live");
00492
00493 freefits(ps.biasfits1);
00494 freefits(ps.biasfits2);
00495 freeplist(plist);
00496 continue;
00497 }
00498 freeplist(plist);
00499
00500
00501
00502 rawbiasfits1=omega_fits_get_image(ps.biasfits1);
00503 rawbiasfits2=omega_fits_get_image(ps.biasfits2);
00504 omega_readnoise_config.RawBias1Min =cpl_image_get_min(rawbiasfits1);
00505 omega_readnoise_config.RawBias1Max =cpl_image_get_max(rawbiasfits1);
00506 omega_readnoise_config.RawBias1Mean =cpl_image_get_mean(rawbiasfits1);
00507 omega_readnoise_config.RawBias1Median=cpl_image_get_median(rawbiasfits1);
00508 omega_readnoise_config.RawBias1Stdev =cpl_image_get_stdev(rawbiasfits1);
00509 omega_readnoise_config.RawBias2Min =cpl_image_get_min(rawbiasfits2);
00510 omega_readnoise_config.RawBias2Max =cpl_image_get_max(rawbiasfits2);
00511 omega_readnoise_config.RawBias2Mean =cpl_image_get_mean(rawbiasfits2);
00512 omega_readnoise_config.RawBias2Median=cpl_image_get_median(rawbiasfits2);
00513 omega_readnoise_config.RawBias2Stdev =cpl_image_get_stdev(rawbiasfits2);
00514
00515
00516
00517 biasim = cpl_image_subtract_create(omega_fits_get_image(ps.biasfits1),
00518 omega_fits_get_image(ps.biasfits2));
00519
00520 freefits(ps.biasfits2);
00521
00522
00523 ps.stats = omega_iter_stat(biasim,omega_readnoise_config.rej_sig,omega_readnoise_config.niter);
00524
00525
00526 if(ps.stats != NULL){
00527 stdev = cpl_stats_get_stdev(ps.stats);
00528 omega_readnoise_config.rnoise = stdev / sqrt(2);
00529 omega_readnoise_config.mean_diff = cpl_stats_get_mean(ps.stats);
00530 omega_readnoise_config.median_diff = cpl_stats_get_median(ps.stats);
00531 }
00532 else{
00533 cpl_msg_warning(_id,"Cannot calculate statistics iteratively");
00534 }
00535
00536 plist = cpl_propertylist_load(cpl_frame_get_filename(bias1),j);
00537 chipid = omega_pfits_get_chipid(plist);
00538
00539 cpl_msg_info(_id,"The read noise of %s is: %5.3g", chipid, omega_readnoise_config.rnoise);
00540 cpl_msg_info(_id,"Difference between bias frames is: %5.3g (mean), %5.3g (median)",
00541 omega_readnoise_config.mean_diff, omega_readnoise_config.median_diff);
00542
00543 freeimage(biasim);
00544 freestats(ps.stats);
00545 freeplist(plist);
00546
00547
00548 ps.table = cpl_table_new(1);
00549 cpl_table_new_column(ps.table, "READNOISE", CPL_TYPE_DOUBLE);
00550 cpl_table_new_column(ps.table, "MEAN_DIFF", CPL_TYPE_DOUBLE);
00551 cpl_table_new_column(ps.table, "MEDIAN_DIFF", CPL_TYPE_DOUBLE);
00552 cpl_table_set_double(ps.table, "READNOISE", 0, omega_readnoise_config.rnoise);
00553 cpl_table_set_double(ps.table, "MEAN_DIFF", 0, omega_readnoise_config.mean_diff);
00554 cpl_table_set_double(ps.table, "MEDIAN_DIFF", 0, omega_readnoise_config.median_diff);
00555
00556
00557 if(omega_readnoise_save(set, pars) == -1){
00558 cpl_msg_error(_id,"Cannot save this extension product");
00559 omega_readnoise_tidy();
00560 return -1;
00561 }
00562
00563 freefits(ps.biasfits1);
00564 freetable(ps.table);
00565 }
00566
00567 omega_readnoise_tidy();
00568
00569 return 0;
00570
00571 }
00572
00573
00582
00583 int omega_readnoise_save(cpl_frameset *set,
00584 cpl_parameterlist *parlist)
00585 {
00586
00587 const char *fctid = "omega_readnoise_save";
00588 cpl_propertylist *plist;
00589 cpl_propertylist *qclist;
00590
00591
00592
00593 if (isfirst) {
00594
00595
00596 if(omega_pfits_check_instrume(cpl_frameset_get_first_const(set)) == 1)
00597 sprintf(INSTRUME,"wfi");
00598
00599
00600 sprintf(outfile, "%s_%s.fits",INSTRUME,PROCATG) ;
00601
00602
00603 product_frame = cpl_frame_new();
00604 cpl_frame_set_filename(product_frame,outfile);
00605 cpl_frame_set_tag(product_frame,PROCATG);
00606 cpl_frame_set_type(product_frame,CPL_FRAME_TYPE_TABLE);
00607 cpl_frame_set_group(product_frame,CPL_FRAME_GROUP_PRODUCT);
00608 cpl_frame_set_level(product_frame,CPL_FRAME_LEVEL_FINAL);
00609
00610 plist = cpl_propertylist_new();
00611
00612
00613 if (cpl_dfs_setup_product_header(plist, product_frame, set, parlist,
00614 RECIPE,PIPEID,DICID,NULL) != CPL_ERROR_NONE) {
00615
00616 cpl_msg_warning(fctid, "Problem in the main header of product DFS-compliance") ;
00617 }
00618
00619
00620
00621
00622 cpl_propertylist_erase_regexp(plist,REM_PRIM_KEYS,0);
00623
00624
00625 if (cpl_propertylist_save(plist,outfile,CPL_IO_DEFAULT) != CPL_ERROR_NONE){
00626 cpl_msg_error(fctid,"Cannot save product PHU");
00627 cpl_frame_delete(product_frame);
00628 freeplist(plist);
00629 return -1;
00630 }
00631
00632 freeplist(plist);
00633 cpl_frameset_insert(set,product_frame);
00634 }
00635
00636
00637 plist = cpl_propertylist_duplicate(omega_fits_get_ehu(ps.biasfits1));
00638 qclist = cpl_propertylist_new();
00639
00640
00641 if (cpl_dfs_setup_product_header(plist, product_frame, set, parlist,
00642 RECIPE,PIPEID,DICID,NULL) != CPL_ERROR_NONE) {
00643
00644 cpl_msg_warning(fctid, "Problem in the extension header of product DFS-compliance") ;
00645 }
00646
00647
00648 cpl_propertylist_erase_regexp(plist, REM_EXT_KEYS, 0);
00649
00650
00651
00652
00653 cpl_propertylist_update_float(qclist,"ESO QC READNOISE",
00654 omega_readnoise_config.rnoise);
00655 cpl_propertylist_update_float(qclist,"ESO QC READNOISE MEAN DIFF",
00656 omega_readnoise_config.mean_diff);
00657 cpl_propertylist_update_float(qclist,"ESO QC READNOISE MEDIAN DIFF",
00658 omega_readnoise_config.median_diff);
00659
00660 cpl_propertylist_update_float(qclist,"ESO QC RAW BIAS1 MIN" , omega_readnoise_config.RawBias1Min );
00661 cpl_propertylist_update_float(qclist,"ESO QC RAW BIAS1 MAX" , omega_readnoise_config.RawBias1Max );
00662 cpl_propertylist_update_float(qclist,"ESO QC RAW BIAS1 MEAN" , omega_readnoise_config.RawBias1Mean );
00663 cpl_propertylist_update_float(qclist,"ESO QC RAW BIAS1 MEDIAN", omega_readnoise_config.RawBias1Median);
00664 cpl_propertylist_update_float(qclist,"ESO QC RAW BIAS1 STDEV" , omega_readnoise_config.RawBias1Stdev );
00665 cpl_propertylist_update_float(qclist,"ESO QC RAW BIAS2 MIN" , omega_readnoise_config.RawBias2Min );
00666 cpl_propertylist_update_float(qclist,"ESO QC RAW BIAS2 MAX" , omega_readnoise_config.RawBias2Max );
00667 cpl_propertylist_update_float(qclist,"ESO QC RAW BIAS2 MEAN" , omega_readnoise_config.RawBias2Mean );
00668 cpl_propertylist_update_float(qclist,"ESO QC RAW BIAS2 MEDIAN", omega_readnoise_config.RawBias2Median);
00669 cpl_propertylist_update_float(qclist,"ESO QC RAW BIAS2 STDEV ", omega_readnoise_config.RawBias2Stdev );
00670
00671 cpl_propertylist_set_comment(qclist,"ESO QC RAW BIAS1 MIN" , "minimum value of first frame");
00672 cpl_propertylist_set_comment(qclist,"ESO QC RAW BIAS1 MAX" , "maximum value of first frame");
00673 cpl_propertylist_set_comment(qclist,"ESO QC RAW BIAS1 MEAN" , "mean value of first frame");
00674 cpl_propertylist_set_comment(qclist,"ESO QC RAW BIAS1 MEDIAN", "median value of first frame");
00675 cpl_propertylist_set_comment(qclist,"ESO QC RAW BIAS1 STDEV" , "standard deviation of first frame");
00676 cpl_propertylist_set_comment(qclist,"ESO QC RAW BIAS2 MIN" , "minimum value of second frame");
00677 cpl_propertylist_set_comment(qclist,"ESO QC RAW BIAS2 MAX" , "maximum value of second frame");
00678 cpl_propertylist_set_comment(qclist,"ESO QC RAW BIAS2 MEAN" , "mean value of second frame");
00679 cpl_propertylist_set_comment(qclist,"ESO QC RAW BIAS2 MEDIAN", "median value of second frame");
00680 cpl_propertylist_set_comment(qclist,"ESO QC RAW BIAS2 STDEV ", "standard deviation of second frame");
00681
00682
00683 cpl_propertylist_append(plist, qclist);
00684
00685
00686 cpl_propertylist_set_comment(plist,"ESO QC READNOISE",
00687 "Calculated detector readnoise");
00688 cpl_propertylist_set_comment(plist,"ESO QC READNOISE MEAN DIFF",
00689 "Calculated mean of difference");
00690 cpl_propertylist_set_comment(plist,"ESO QC READNOISE MEDIAN DIFF",
00691 "Calculated median of difference");
00692
00693
00694 if (cpl_table_save(ps.table,NULL,plist,outfile,CPL_IO_EXTEND) != CPL_ERROR_NONE) {
00695 cpl_msg_error(fctid,"Cannot save product. %s", cpl_error_get_message());
00696 freeplist(plist);
00697 freeplist(qclist);
00698 return -1;
00699 }
00700
00701
00702 if(omega_readnoise_config.paf){
00703 int xtnum = omega_fits_get_extnum(ps.biasfits1);
00704 const char pafcopy[] = "^(DATE-OBS|ARCFILE|ESO TPL ID|ESO DET WIN1 DIT1|MJD-OBS|EXTNAME|ESO PRO CATG)$";
00705 sprintf(outpaf, "%s_%s_%d.paf",INSTRUME,PROCATG,xtnum) ;
00706 cpl_frame *fframe = cpl_frameset_get_first(set);
00707 cpl_propertylist *mlist = cpl_propertylist_load_regexp(cpl_frame_get_filename(fframe),0,pafcopy, 0);
00708 cpl_propertylist_copy_property_regexp(qclist, mlist, pafcopy, 0);
00709 if(cpl_propertylist_copy_property_regexp(qclist, plist,
00710 pafcopy, 0) != CPL_ERROR_NONE){
00711 cpl_msg_warning(fctid,"Some mandatory keywords are missing in PAF file");
00712 }
00713
00714 cpl_dfs_save_paf(INSTRUME, RECIPE, qclist, outpaf);
00715 freeplist(mlist);
00716 }
00717
00718 freeplist(plist);
00719 freeplist(qclist);
00720
00721 return 0;
00722 }
00723
00724
00725
00729
00730
00731 static void omega_readnoise_init(void) {
00732 ps.labels = NULL;
00733 ps.biaslist = NULL;
00734 ps.biasfits1 = NULL;
00735 ps.biasfits2 = NULL;
00736 ps.stats = NULL;
00737 ps.table = NULL;
00738 return;
00739 }
00740
00741
00745
00746
00747 static void omega_readnoise_tidy(void) {
00748 freespace(ps.labels);
00749 freeframeset(ps.biaslist);
00750 freefits(ps.biasfits1);
00751 freefits(ps.biasfits2);
00752 freetable(ps.table);
00753 freestats(ps.stats);
00754 return;
00755 }