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 #ifdef HAVE_CONFIG_H
00027 #include <config.h>
00028 #endif
00029
00030
00038
00041
00042
00043
00044
00045
00046
00047
00048
00049 #include <xsh_error.h>
00050
00051 #include <xsh_utils.h>
00052 #include <xsh_utils_image.h>
00053 #include <xsh_msg.h>
00054
00055 #include <xsh_dfs.h>
00056
00057 #include <xsh_drl.h>
00058
00059 #include <xsh_pfits.h>
00060
00061 #include <cpl.h>
00062
00063 #include <xsh_drl_check.h>
00064 #include <xsh_model_arm_constants.h>
00065
00066
00067
00068
00069
00070 #define RECIPE_ID "xsh_mdark"
00071 #define RECIPE_AUTHOR "P.Goldoni, L.Guglielmi, R. Haigron, F. Royer, A. Modigliani"
00072 #define RECIPE_CONTACT "amodigli@eso.org"
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 static int xsh_mdark_create(cpl_plugin *);
00083 static int xsh_mdark_exec(cpl_plugin *);
00084 static int xsh_mdark_destroy(cpl_plugin *);
00085
00086
00087 static void xsh_mdark(cpl_parameterlist *, cpl_frameset *);
00088
00089
00090
00091
00092 static char xsh_mdark_description_short[] =
00093 "Create the master dark frame";
00094
00095 static char xsh_mdark_description[] =
00096 "This recipe creates a master dark frame\n\
00097 Input Frames : \n\
00098 - A set of n RAW frames (Format=RAW, n >=3, Tag = DARK_arm)\n\
00099 - [UVB,VIS] A master bias frame (Format=PRE, Tag = MASTER_BIAS_arm)\n\
00100 - [OPTIONAL] A badpixel map (Format=QUP, Tag = MASTER_BP_MAP_NLIN_arm)\n\
00101 - [OPTIONAL] A map of reference bad pixel (Format = QUP,RAW, Tag = BP_MAP_RP_arm)\n\
00102 Products : \n\
00103 - A master dark frame (Format=PRE, PRO.CATG = MASTER_DARK_arm)\n\
00104 A dark frame, (Format=PRE, PRO.CATG = DARK_arm)\n";
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00125
00126
00127 int cpl_plugin_get_info(cpl_pluginlist *list) {
00128 cpl_recipe *recipe = NULL;
00129 cpl_plugin *plugin = NULL;
00130
00131 recipe = cpl_calloc(1, sizeof(*recipe));
00132 if ( recipe == NULL ){
00133 return -1;
00134 }
00135
00136 plugin = &recipe->interface ;
00137
00138 cpl_plugin_init(plugin,
00139 CPL_PLUGIN_API,
00140 XSH_BINARY_VERSION,
00141 CPL_PLUGIN_TYPE_RECIPE,
00142 RECIPE_ID,
00143 xsh_mdark_description_short,
00144 xsh_mdark_description,
00145 RECIPE_AUTHOR,
00146 RECIPE_CONTACT,
00147 xsh_get_license(),
00148 xsh_mdark_create,
00149 xsh_mdark_exec,
00150 xsh_mdark_destroy);
00151
00152 cpl_pluginlist_append(list, plugin);
00153
00154 return (cpl_error_get_code() != CPL_ERROR_NONE);
00155 }
00156
00157
00167
00168
00169 static int xsh_mdark_create(cpl_plugin *plugin){
00170 cpl_recipe *recipe = NULL;
00171 xsh_clipping_param crh_clip_param = {-1.0, 3, 0.7, 0, 0.3};
00172 xsh_clipping_param noise_clip_param = {9.0, 5, 0.7, 0, 0.3};
00173 xsh_fpn_param fpn_param = {-1,-1,-1,-1,2,1000};
00174 xsh_ref_param ref_param = {-1,-1,-1,-1};
00175 xsh_ron_dark_param ron_param = {-1,-1,-1,-1,4,100};
00176 xsh_stack_param stack_param = {"median",5.,5.,5};
00177
00178 xsh_init();
00179
00180
00181 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
00182
00183
00184 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00185 CPL_ERROR_TYPE_MISMATCH,
00186 "Plugin is not a recipe");
00187
00188 recipe = (cpl_recipe *)plugin;
00189
00190
00191 recipe->parameters = cpl_parameterlist_new();
00192 assure( recipe->parameters != NULL,
00193 CPL_ERROR_ILLEGAL_OUTPUT,
00194 "Memory allocation failed!");
00195
00196
00197 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
00198 check( xsh_parameters_pre_overscan( RECIPE_ID, recipe->parameters ) ) ;
00199 check(xsh_parameters_stack_create(RECIPE_ID,recipe->parameters,stack_param));
00200
00201
00202 check(xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00203 "bp-output", false,
00204 "Flag indicating whether the noise bad pixel map is to be computed"));
00205
00206
00207 check(xsh_parameters_clipping_crh_create(RECIPE_ID,recipe->parameters,
00208 crh_clip_param));
00209
00210
00211 check(xsh_parameters_clipping_noise_create(RECIPE_ID,
00212 recipe->parameters,
00213 noise_clip_param));
00214
00215 check(xsh_parameters_new_double( recipe->parameters,RECIPE_ID,
00216 "noise-lower-rejection", 10.,
00217 "Lower rejection percentile to flag bad pixels via noise"));
00218
00219 check(xsh_parameters_new_double( recipe->parameters, RECIPE_ID,
00220 "noise-higher-rejection", 10.,
00221 "Upper rejection percentile to flag bad pixels via noise"));
00222
00223
00224 check(xsh_parameters_ref1_create(RECIPE_ID,recipe->parameters,
00225 ref_param));
00226
00227
00228 check(xsh_parameters_ron_dark_create(RECIPE_ID,recipe->parameters,
00229 ron_param));
00230
00231 check(xsh_parameters_fpn_create(RECIPE_ID,recipe->parameters,
00232 fpn_param));
00233
00234
00235
00236 cleanup:
00237 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
00238 xsh_error_dump(CPL_MSG_ERROR);
00239 return 1;
00240 }
00241 else {
00242 return 0;
00243 }
00244 }
00245
00246
00252
00253
00254 static int xsh_mdark_exec(cpl_plugin *plugin) {
00255 cpl_recipe *recipe = NULL;
00256
00257
00258
00259 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00260
00261
00262 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00263 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00264
00265 recipe = (cpl_recipe *)plugin;
00266
00267
00268 xsh_mdark(recipe->parameters, recipe->frames);
00269
00270 cleanup:
00271 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
00272 xsh_error_dump(CPL_MSG_ERROR);
00273 xsh_error_reset();
00274 return 1;
00275 }
00276 else {
00277 return 0;
00278 }
00279 }
00280
00281
00287
00288 static int xsh_mdark_destroy(cpl_plugin *plugin)
00289 {
00290 cpl_recipe *recipe = NULL;
00291
00292
00293 xsh_error_reset();
00294
00295 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00296
00297
00298 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00299 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00300 recipe = (cpl_recipe *)plugin;
00301
00302 xsh_free_parameterlist(&recipe->parameters);
00303
00304 cleanup:
00305 if (cpl_error_get_code() != CPL_ERROR_NONE)
00306 {
00307 return 1;
00308 }
00309 else
00310 {
00311 return 0;
00312 }
00313 }
00314
00315 static cpl_error_code
00316 xsh_params_set_defaults(cpl_parameterlist* pars,
00317 xsh_instrument* inst)
00318 {
00319 cpl_parameter* p=NULL;
00320
00321 check(p=xsh_parameters_find(pars,RECIPE_ID,"crh-clip-kappa"));
00322 if(cpl_parameter_get_double(p) <= 0) {
00323 if (xsh_instrument_get_arm(inst) == XSH_ARM_NIR){
00324 cpl_parameter_set_double(p,11.);
00325 } else {
00326 cpl_parameter_set_double(p,9.);
00327 }
00328 }
00329
00330 cleanup:
00331
00332 return cpl_error_get_code();
00333
00334 }
00335
00336
00337
00338 static cpl_frame*
00339 xsh_get_master_dark_nir_via_noise(cpl_imagelist* dataList, cpl_frame* medFrame,
00340 cpl_parameterlist* parameters, xsh_clipping_param* noise_clipping,
00341 xsh_instrument* instrument,cpl_frame** noisyFrame) {
00342 cpl_frame* nirFrame = NULL;
00343
00344 cpl_parameter* p = NULL;
00345 int llx = 0;
00346 int lly = 0;
00347 int urx = 0;
00348 int ury = 0;
00349 int iter = 0;
00350 int low_rej = 0;
00351 int high_rej = 0;
00352 cpl_image* noise_image = NULL;
00353 cpl_mask* bp_map_noise = NULL;
00354 cpl_propertylist* plist = NULL;
00355 const char* bp_map_noise_pro_catg = NULL;
00356 char bp_map_noise_name[256];
00357
00358
00359 xsh_msg_dbg_low(
00360 "Noise parameters: Sigma %lf, Niteration %d, \
00361 Fraction %lf, Diff %lf", noise_clipping->sigma, noise_clipping->niter, noise_clipping->frac, noise_clipping->diff);
00362
00363 #if defined(PICKUP_NOISE_HOT_PIXEL_MAP)
00364 nirFrame = xsh_compute_noise_map(dataList, medFrame, noise_clipping,
00365 instrument,noisyFrame);
00366
00367 #else
00368 nirFrame = xsh_compute_noise_map( dataList, medFrame,noise_clipping,instrument);
00369 #endif
00370
00371 p = cpl_parameterlist_find(parameters, "xsh.xsh_mdark.ref1_llx");
00372 llx = cpl_parameter_get_int(p);
00373 p = cpl_parameterlist_find(parameters, "xsh.xsh_mdark.ref1_lly");
00374 lly = cpl_parameter_get_int(p);
00375 p = cpl_parameterlist_find(parameters, "xsh.xsh_mdark.ref1_urx");
00376 urx = cpl_parameter_get_int(p);
00377 p = cpl_parameterlist_find(parameters, "xsh.xsh_mdark.ref1_ury");
00378 ury = cpl_parameter_get_int(p);
00379 p = cpl_parameterlist_find(parameters, "xsh.xsh_mdark.noise-clip-niter");
00380 iter = cpl_parameter_get_int(p);
00381 p = cpl_parameterlist_find(parameters, "xsh.xsh_mdark.noise-lower-rejection");
00382 low_rej = cpl_parameter_get_double(p);
00383 p = cpl_parameterlist_find(parameters, "xsh.xsh_mdark.noise-higher-rejection");
00384 high_rej = cpl_parameter_get_double(p);
00385
00386 noise_image = xsh_image_search_bad_pixels_via_noise(dataList, iter, low_rej,
00387 high_rej, llx, lly, urx, ury);
00388 bp_map_noise = cpl_mask_threshold_image_create(noise_image,
00389 QFLAG_HOT_PIXEL - 1, QFLAG_HOT_PIXEL + 1);
00390 xsh_free_image(&noise_image);
00391 noise_image = cpl_image_new_from_mask(bp_map_noise);
00392 cpl_mask_not(bp_map_noise);
00393 xsh_bpmap_mask_bad_pixel(noise_image, bp_map_noise, QFLAG_HOT_PIXEL);
00394
00395
00396
00397 cpl_image_threshold(noise_image, 1.1, DBL_MAX, 0, DBL_MAX);
00398
00399 plist = cpl_propertylist_new();
00400 bp_map_noise_pro_catg = XSH_GET_TAG_FROM_ARM(XSH_BP_MAP_NP, instrument);
00401 sprintf(bp_map_noise_name, "%s.fits", bp_map_noise_pro_catg);
00402 xsh_pfits_set_pcatg(plist, bp_map_noise_pro_catg);
00403 check(cpl_image_save(noise_image,bp_map_noise_name,CPL_BPP_IEEE_FLOAT, plist,CPL_IO_DEFAULT));
00404 xsh_add_temporary_file(bp_map_noise_name);
00405
00406
00407 cleanup:
00408 xsh_free_mask(&bp_map_noise);
00409 xsh_free_propertylist(&plist);
00410 xsh_free_image(&noise_image);
00411 return nirFrame;
00412
00413 }
00414
00415 static cpl_frame*
00416 xsh_get_master_dark_opt(cpl_frame* medFrame, cpl_frame* master_bias,
00417 cpl_parameterlist* parameters, cpl_parameterlist* drs_params,
00418 cpl_frame* crh_frm, cpl_frame* bp_map_noise_frm, xsh_instrument* instrument,
00419 const int pre_overscan_corr) {
00420 cpl_frame* resFrame = NULL;
00421 cpl_frame* rmbias = NULL;
00422 if (master_bias != NULL) {
00423 xsh_msg("Subtract bias");
00424 check(
00425 rmbias = xsh_subtract_bias(medFrame,master_bias,instrument,"DARK_",pre_overscan_corr,0));
00426
00427 xsh_msg( "Generates master dark");
00428 check_msg(
00429 resFrame=xsh_create_master_dark(rmbias, instrument,parameters, crh_frm,bp_map_noise_frm),
00430 "Error in create master dark");
00431 } else {
00432 check(resFrame=cpl_frame_duplicate(medFrame));
00433 }
00434
00435 cleanup:
00436
00437 return resFrame;
00438 }
00439
00440 static cpl_frame*
00441 xsh_coadd_bp_maps(cpl_frameset* bpmap_set, xsh_instrument* instrument) {
00442
00443 cpl_frame* map = NULL;
00444 cpl_frame* sum=0;
00445 int sz=0;
00446 int i=0;
00447 char name[256];
00448 cpl_image* ima = NULL;
00449 cpl_propertylist* head = NULL;
00450 const char* pro_catg = NULL;
00451 assure( bpmap_set != NULL, CPL_ERROR_NULL_INPUT, "Null set of maps" );
00452 sz=cpl_frameset_get_size(bpmap_set);
00453
00454 XSH_ASSURE_NOT_ILLEGAL_MSG(sz>0,"You must have at least a BP map");
00455 sum=cpl_frameset_get_frame(bpmap_set,0);
00456 sprintf(name, cpl_frame_get_filename(sum));
00457 xsh_msg("Combine mask frames via bitwise OR");
00458
00459 for(i=1;i<sz;i++) {
00460 map=cpl_frameset_get_frame(bpmap_set,i);
00461 check(xsh_badpixelmap_coadd(sum,map));
00462 }
00463
00464 check(ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
00465 check(head=cpl_propertylist_load(name,0));
00466 check(pro_catg=XSH_GET_TAG_FROM_ARM(XSH_MASTER_BP_MAP_DARK,instrument));
00467 sprintf(name, "%s.fits", pro_catg);
00468 check(cpl_image_save(ima,name,CPL_BPP_IEEE_FLOAT,head,CPL_IO_DEFAULT));
00469 xsh_free_image(&ima);
00470 xsh_free_propertylist(&head);
00471
00472 check(cpl_frame_set_tag(sum,pro_catg));
00473 xsh_add_temporary_file(name);
00474
00475 cleanup:
00476
00477 return sum;
00478 }
00479
00480 static cpl_frame*
00481 xsh_get_crh_frame(cpl_image* crh_ima, xsh_instrument* instrument) {
00482 char* crh_name = NULL;
00483 char* crh_pro_catg = NULL;
00484 cpl_frame* crh_frm = NULL;
00485 char *prefix = NULL;
00486
00487 crh_name = cpl_sprintf("%s_%s.fits", XSH_CRH_MAP,
00488 xsh_instrument_arm_tostring(instrument));
00489
00490 if (crh_ima != NULL) {
00491
00492 crh_pro_catg = XSH_GET_TAG_FROM_ARM(XSH_CRH_MAP,instrument);
00493 crh_frm = xsh_frame_product(crh_name, crh_pro_catg, CPL_FRAME_TYPE_IMAGE,
00494 CPL_FRAME_GROUP_PRODUCT, CPL_FRAME_LEVEL_FINAL);
00495
00496 XSH_PREFIX(prefix, "CRH_MAP", instrument);
00497 cpl_image_save(crh_ima, crh_name, CPL_BPP_32_SIGNED, NULL, CPL_IO_DEFAULT);
00498 xsh_add_temporary_file(crh_name);
00499
00500 }
00501 cleanup:
00502 XSH_FREE(crh_name);
00503 XSH_FREE(prefix);
00504 return crh_frm;
00505 }
00506
00507 cpl_error_code
00508 xsh_mdark_check_exptime(cpl_frameset* raws)
00509 {
00510 int i=0;
00511 int sz=0;
00512 cpl_frame* frm=NULL;
00513 cpl_propertylist* plist=NULL;
00514 const char* name=NULL;
00515 double ref_exptime=0;
00516 double tmp_exptime=0;
00517
00518 sz=cpl_frameset_get_size(raws);
00519 for(i=0;i<sz;i++){
00520 check(frm=cpl_frameset_get_frame(raws,i));
00521 name=cpl_frame_get_filename(frm);
00522 plist=cpl_propertylist_load(name,0);
00523
00524 if(i==0) {
00525 ref_exptime=xsh_pfits_get_exptime(plist);
00526 tmp_exptime=ref_exptime;
00527 } else {
00528 tmp_exptime=xsh_pfits_get_exptime(plist);
00529 if( fabs(tmp_exptime-ref_exptime) > 0.001) {
00530 xsh_msg_error("Some dark has EXPTIME different from others.");
00531 xsh_msg("EXPTIME(%d)=%g EXPTIME(0)=%g",i,tmp_exptime,ref_exptime);
00532 cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT);
00533 }
00534 }
00535 xsh_free_propertylist(&plist);
00536 }
00537
00538 cleanup:
00539 xsh_free_propertylist(&plist);
00540 return cpl_error_get_code();
00541 }
00542
00543
00551
00552 static void xsh_mdark(cpl_parameterlist* parameters, cpl_frameset* frameset) {
00553
00554 const char* recipe_tags[1] = { XSH_DARK };
00555 int recipe_tags_size = 1;
00556
00557 cpl_frameset* raws = NULL;
00558 cpl_frameset* calib = NULL;
00559 cpl_frame* bpmap = NULL;
00560 cpl_frame* master_bias = NULL;
00561 cpl_frame* rmbias = NULL;
00562 xsh_instrument* instrument = NULL;
00563 xsh_clipping_param* crh_clipping = NULL;
00564 xsh_clipping_param* noise_clipping = NULL;
00565 cpl_imagelist * dataList = NULL;
00566
00567
00568 cpl_frame * medFrame = NULL;
00569 cpl_frame * nirFrame = NULL;
00570 #if defined(PICKUP_NOISE_HOT_PIXEL_MAP)
00571 cpl_frame * noisyFrame = NULL;
00572 #endif
00573
00574 cpl_frame * resFrame = NULL;
00575 cpl_frame * bpmapFrame = NULL;
00576 cpl_image* crh_ima = NULL;
00577
00578
00579 cpl_frame* crh_frm = NULL;
00580
00581 char name[80];
00582 int binx = 0;
00583 int biny = 0;
00584 cpl_frame* dark_frm = NULL;
00585 cpl_propertylist* plist = NULL;
00586 char med_frame_tag[256];
00587
00588 int nraws = 0;
00589 cpl_frame* dark_on = NULL;
00590 cpl_frame* dark_qc = NULL;
00591
00592
00593
00594
00595
00596
00597 int pre_overscan_corr = 0;
00598 xsh_stack_param* stack_par = NULL;
00599 cpl_frame* coadd_bp_map = NULL;
00600 char pcatg[80];
00601 cpl_propertylist* qc_log = NULL;
00602 cpl_frameset* bpmap_set=NULL;
00603 int sz=0;
00604
00605
00606 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
00607 recipe_tags, recipe_tags_size,
00608 RECIPE_ID, XSH_BINARY_VERSION,
00609 xsh_mdark_description_short ) );
00610
00611 check(xsh_recipe_params_check(parameters,instrument,RECIPE_ID));
00612
00613
00614
00615
00616 XSH_ASSURE_NOT_ILLEGAL((nraws=cpl_frameset_get_size(raws)) >= 1);
00617 check(bpmap=xsh_check_load_master_bpmap(calib,instrument,RECIPE_ID));
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633 if (xsh_instrument_get_arm(instrument) != XSH_ARM_NIR) {
00634
00635 if ((master_bias = xsh_find_frame_with_tag(calib, XSH_MASTER_BIAS,
00636 instrument)) == NULL) {
00637 xsh_msg_error(
00638 "%s_%s is required input for error computation", XSH_MASTER_BIAS, xsh_instrument_arm_tostring (instrument));
00639 goto cleanup;
00640 }check(dark_frm=cpl_frameset_get_first(raws));
00641 check(plist=cpl_propertylist_load(cpl_frame_get_filename(dark_frm),0));
00642 check(binx=xsh_pfits_get_binx(plist));
00643 check(biny=xsh_pfits_get_biny(plist));
00644 xsh_free_propertylist(&plist);
00645
00646 sprintf(med_frame_tag, "DARK_REMOVE_CRH_%s",
00647 xsh_instrument_arm_tostring(instrument));
00648
00649 }
00650
00651 else {
00652 sprintf(med_frame_tag, "DARK_REMOVE_CRH_%s",
00653 xsh_instrument_arm_tostring(instrument));
00654 }
00655
00656
00657
00658
00659 check(xsh_params_set_defaults(parameters,instrument));
00660 check(
00661 pre_overscan_corr = xsh_parameters_get_int( parameters, RECIPE_ID, "pre-overscan-corr"));
00662 stack_par = xsh_stack_frames_get(RECIPE_ID, parameters);
00663
00664 crh_clipping = xsh_parameters_clipping_crh_get(RECIPE_ID, parameters);
00665 noise_clipping = xsh_parameters_clipping_noise_get(RECIPE_ID, parameters);
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682 check(xsh_prepare(raws, bpmap, master_bias, XSH_DARK, instrument,pre_overscan_corr));
00683
00684 check(xsh_mdark_check_exptime(raws));
00685 bpmap_set=cpl_frameset_new();
00686 if(bpmap!=NULL) {
00687 cpl_frameset_insert(bpmap_set,bpmap);
00688 }
00689
00690
00691 xsh_msg( "Calling xsh_remove_crh_multiple" );
00692 check_msg( medFrame = xsh_remove_crh_multiple( raws,med_frame_tag,stack_par,
00693 crh_clipping,instrument,&dataList,&crh_ima,1 ),"Error in xsh_remove_crh" );
00694
00695 check(crh_frm=xsh_get_crh_frame(crh_ima,instrument));
00696
00697
00698 if (xsh_instrument_get_arm(instrument) == XSH_ARM_NIR) {
00699 check(nirFrame=xsh_get_master_dark_nir_via_noise(dataList,medFrame,parameters,noise_clipping,instrument,&noisyFrame));
00700 check(cpl_frameset_insert(bpmap_set,noisyFrame));
00701 xsh_msg( "Create master dark");
00702
00703 check_msg(
00704 resFrame=xsh_create_master_dark(nirFrame,instrument,parameters,crh_frm,bpmap ),
00705 "Error in create master dark");
00706 } else {
00707
00708 check(
00709 resFrame=xsh_get_master_dark_opt(medFrame,master_bias,parameters,parameters,crh_frm,bpmap, instrument,pre_overscan_corr));
00710 }
00711
00712
00713
00714
00715
00716 qc_log = xsh_frame_head_extract_qc(resFrame);
00717
00718
00719
00720
00721 xsh_free_frame(&resFrame);
00722 check(resFrame=xsh_create_master_dark2(raws,stack_par,parameters,qc_log,instrument));
00723
00724 check(bpmapFrame = xsh_create_master_dark_bpmap(resFrame, instrument));
00725 cpl_frameset_insert(bpmap_set,bpmapFrame);
00726
00727 XSH_ASSURE_NOT_NULL(bpmapFrame);
00728 sz=cpl_frameset_get_size(bpmap_set);
00729 if(sz>0) {
00730 coadd_bp_map=xsh_coadd_bp_maps(bpmap_set,instrument);
00731 }
00732
00733
00734
00735
00736
00737
00738 if (xsh_instrument_get_arm(instrument) == XSH_ARM_NIR) {
00739 #if defined(PICKUP_NOISE_HOT_PIXEL_MAP)
00740
00741
00742
00743
00744
00745 #else
00746 check( xsh_add_product_pre( nirFrame, frameset, parameters,
00747 RECIPE_ID, instrument));
00748 #endif
00749
00750 }
00751 xsh_msg("coadd_bp_map=%p",coadd_bp_map);
00752 if (coadd_bp_map != NULL) {
00753 xsh_frame_qual_update(resFrame, coadd_bp_map, instrument);
00754 }
00755 xsh_msg( "Save products" );
00756 check(xsh_add_product_pre( resFrame, frameset, parameters,RECIPE_ID, instrument));
00757
00758
00759 dark_on = cpl_frameset_get_frame(raws, 0);
00760 sprintf(pcatg, "DARK_ON");
00761 sprintf(name, "%s.fits", pcatg);
00762 xsh_add_product_image(dark_on,frameset,parameters,RECIPE_ID,instrument,pcatg);
00763
00764
00765
00766 sz=cpl_frameset_get_size(raws);
00767 dark_qc = cpl_frameset_get_frame(raws, sz-1);
00768 sprintf(pcatg, "DARK_QC");
00769 sprintf(name, "%s.fits", pcatg);
00770 xsh_add_product_image(dark_qc,frameset,parameters,RECIPE_ID,instrument,pcatg);
00771
00772
00773 cleanup: xsh_end(RECIPE_ID, frameset, parameters);
00774 XSH_FREE(crh_clipping);
00775 XSH_FREE(noise_clipping);
00776 XSH_FREE(stack_par);
00777 xsh_instrument_free(&instrument);
00778 xsh_free_frameset(&raws);
00779 xsh_free_frameset(&calib);
00780 xsh_free_frameset(&bpmap_set);
00781
00782 xsh_free_imagelist(&dataList);
00783 xsh_free_frame(&medFrame);
00784 xsh_free_frame(&nirFrame);
00785 xsh_free_frame(&resFrame);
00786 xsh_free_frame(&rmbias);
00787 xsh_free_frame(&crh_frm);
00788 xsh_free_image(&crh_ima);
00789 xsh_free_propertylist(&plist);
00790 xsh_free_propertylist(&qc_log);
00791
00792
00793
00794 return;
00795 }
00796