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 #ifdef HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030
00031
00039
00042
00043
00044
00045
00046
00047
00048
00049
00050 #include <xsh_error.h>
00051
00052 #include <xsh_utils.h>
00053 #include <xsh_utils_ifu.h>
00054 #include <xsh_utils_image.h>
00055 #include <xsh_model_utils.h>
00056 #include <xsh_model_io.h>
00057 #include <xsh_msg.h>
00058
00059 #include <xsh_dfs.h>
00060 #include <xsh_pfits.h>
00061
00062 #include <xsh_drl.h>
00063 #include <xsh_drl_check.h>
00064 #include <xsh_model_arm_constants.h>
00065
00066 #include <cpl.h>
00067
00068
00069
00070
00071
00072
00073 #define RECIPE_ID "xsh_scired_ifu_stare"
00074 #define RECIPE_AUTHOR "A.Modigliani, J.Vernet, P. Bristow"
00075 #define RECIPE_CONTACT "Andrea.Modigliani@eso.org"
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 static int xsh_scired_ifu_stare_create(cpl_plugin *);
00086 static int xsh_scired_ifu_stare_exec(cpl_plugin *);
00087 static int xsh_scired_ifu_stare_destroy(cpl_plugin *);
00088
00089
00090 static void xsh_scired_ifu_stare(cpl_parameterlist *, cpl_frameset *);
00091
00092
00093
00094
00095 static char xsh_scired_ifu_stare_description_short[] =
00096 "Reduce science IFU stare exposures and build a 3D cube";
00097
00098 static char xsh_scired_ifu_stare_description[] =
00099 "This recipe reduce science IFU stare exposures with 3D cube generation\n\
00100 Input Frames : \n\
00101 - A set of n Science frames ( n == 1 or >=3, \
00102 Tag = OBJECT_IFU_STARE_UVB)\n\
00103 - A spectral format table frame (Tag = SPECTRAL_FORMAT_TAB_arm)\n\
00104 - [UVB,VIS] A master bias frame (Tag = MASTER_BIAS_arm)\n\
00105 - A master dark frame (Tag = MASTER_DARK_arm)\n\
00106 - A master flat frame (Tag = MASTER_FLAT_IFU_arm)\n\
00107 - An order edges table frame(Tag = ORDER_TAB_EDGES_IFU_arm)\n\
00108 - [physmod] An AFC corrected model cfg frame (Tag = XSH_MOD_CFG_OPT_AFC_arm)\n\
00109 - [poly] An AFC corrected model wavesol frame (Tag = WAVE_TAB_AFC_arm)\n\
00110 - [OPTIONAL] A non-linear badpixel map (Tag = BP_MAP_NL_arm)\n\
00111 - [OPTIONAL] A reference badpixel map (Tag = BP_MAP_RP_arm)\n\
00112 Products : \n\
00113 Merged 3D data cube (MERGE3D_DATA_IFU_arm)\n\
00114 QC Traces of 3D data cube (MERGE3D_TRACE_IFU_arm)\n\
00115 Order by order 3D data cube (ORDER3D_DATA_IFU_arm)\n\
00116 Order by order 3D errs cube (ORDER3D_ERRS_IFU_arm)\n\
00117 Order by order 3D qual cube (ORDER3D_QUAL_IFU_arm)\n" ;
00118
00119
00120
00121
00122
00131
00132
00133 int cpl_plugin_get_info(cpl_pluginlist *list) {
00134 cpl_recipe *recipe = NULL;
00135 cpl_plugin *plugin = NULL;
00136
00137 recipe = cpl_calloc(1, sizeof(*recipe));
00138 if ( recipe == NULL ){
00139 return -1;
00140 }
00141
00142 plugin = &recipe->interface ;
00143
00144 cpl_plugin_init(plugin,
00145 CPL_PLUGIN_API,
00146 XSH_BINARY_VERSION,
00147 CPL_PLUGIN_TYPE_RECIPE,
00148 RECIPE_ID,
00149 xsh_scired_ifu_stare_description_short,
00150 xsh_scired_ifu_stare_description,
00151 RECIPE_AUTHOR,
00152 RECIPE_CONTACT,
00153 xsh_get_license(),
00154 xsh_scired_ifu_stare_create,
00155 xsh_scired_ifu_stare_exec,
00156 xsh_scired_ifu_stare_destroy);
00157
00158 cpl_pluginlist_append(list, plugin);
00159
00160 return (cpl_error_get_code() != CPL_ERROR_NONE);
00161 }
00162
00163
00173
00174
00175 static int xsh_scired_ifu_stare_create(cpl_plugin *plugin){
00176 cpl_recipe *recipe = NULL;
00177 xsh_clipping_param crh_clip_param = {5.0, 5, 0.7, 0,0.3};
00178
00179 xsh_rectify_param rectify = { "default",
00180 CPL_KERNEL_DEFAULT, 4,
00181 -1.,
00182 -1.,
00183 1, 0, 0 };
00184 xsh_stack_param stack_param = {"median",5.,5.,5};
00185
00186
00187
00188
00189
00190
00191 xsh_init();
00192
00193
00194 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
00195
00196
00197 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00198 CPL_ERROR_TYPE_MISMATCH,
00199 "Plugin is not a recipe");
00200
00201 recipe = (cpl_recipe *)plugin;
00202
00203
00204 recipe->parameters = cpl_parameterlist_new();
00205 assure( recipe->parameters != NULL,
00206 CPL_ERROR_ILLEGAL_OUTPUT,
00207 "Memory allocation failed!");
00208
00209
00210 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
00211
00212 check( xsh_parameters_pre_overscan( RECIPE_ID, recipe->parameters ) ) ;
00213 check(xsh_parameters_stack_create(RECIPE_ID,recipe->parameters,stack_param));
00214
00215 check(xsh_parameters_clipping_crh_create(RECIPE_ID,recipe->parameters,
00216 crh_clip_param));
00217
00218
00219 check(xsh_parameters_background_create(RECIPE_ID,recipe->parameters));
00220
00221
00222 check(xsh_parameters_rectify_create(RECIPE_ID,recipe->parameters,
00223 rectify )) ;
00224
00225
00226
00227
00228
00229
00230 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00231 "compute-map", FALSE,
00232 "if TRUE recompute (wave and slit) maps from the dispersion solution. If sky-subtract is set to TRUE this must be set to TRUE."));
00233
00234 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00235 "trace-obj", FALSE,
00236 "if TRUE trace object position on each IFU slice. In this case order TAB edges is required"));
00237
00238
00239 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00240 "check-afc", TRUE,
00241 "Input AFC corrected model/wave solution and science frame check. If TRUE the recipe verify that the input mode/wave solution is AFC corrected, its INS.OPTIi.NAME is 'Pin_0.5 ', and its OBS.ID and OBS.TARG.NAME values matches with the corresponding values of the science frame."));
00242
00243
00244 cleanup:
00245 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
00246 xsh_error_dump(CPL_MSG_ERROR);
00247 return 1;
00248 }
00249 else {
00250 return 0;
00251 }
00252 }
00253
00261
00262
00263 static cpl_error_code
00264 xsh_params_bin_scale(cpl_frameset* raws,
00265 xsh_background_param* backg)
00266 {
00267
00268 cpl_frame* frame=NULL;
00269 const char* name=NULL;
00270 cpl_propertylist* plist=NULL;
00271 int binx=0;
00272 int biny=0;
00273
00274 check(frame=cpl_frameset_get_first(raws));
00275 check(name=cpl_frame_get_filename(frame));
00276 check(plist=cpl_propertylist_load(name,0));
00277 check(binx=xsh_pfits_get_binx(plist));
00278 check(biny=xsh_pfits_get_biny(plist));
00279 xsh_free_propertylist(&plist);
00280
00281 if(biny>1) {
00282
00283
00284
00285
00286
00287
00288 backg->radius_y=backg->radius_y/biny;
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 }
00315
00316
00317 if(binx>1) {
00318
00319 backg->radius_x=backg->radius_x/binx;
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339 }
00340
00341 cleanup:
00342 xsh_free_propertylist(&plist);
00343 return cpl_error_get_code();
00344
00345 }
00346
00347
00353
00354
00355 static int xsh_scired_ifu_stare_exec(cpl_plugin *plugin) {
00356 cpl_recipe *recipe = NULL;
00357
00358
00359
00360 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00361
00362
00363 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00364 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00365
00366 recipe = (cpl_recipe *)plugin;
00367
00368
00369 xsh_scired_ifu_stare(recipe->parameters, recipe->frames);
00370
00371 cleanup:
00372 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
00373 xsh_error_dump(CPL_MSG_ERROR);
00374 xsh_error_reset();
00375 return 1;
00376 }
00377 else {
00378 return 0;
00379 }
00380 }
00381
00382
00388
00389 static int xsh_scired_ifu_stare_destroy(cpl_plugin *plugin)
00390 {
00391 cpl_recipe *recipe = NULL;
00392
00393
00394 xsh_error_reset();
00395
00396 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00397
00398 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00399 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00400
00401 recipe = (cpl_recipe *)plugin;
00402
00403 xsh_free_parameterlist(&recipe->parameters);
00404
00405 cleanup:
00406 if (cpl_error_get_code() != CPL_ERROR_NONE)
00407 {
00408 return 1;
00409 }
00410 else
00411 {
00412 return 0;
00413 }
00414 }
00415 static cpl_error_code
00416 xsh_params_monitor(xsh_background_param* backg,
00417 xsh_rectify_param * rectify_par)
00418 {
00419
00420
00421 xsh_msg_dbg_low("bkg params: sampley=%d radius_y=%d smooth_y=%d",
00422 backg->sampley,backg->radius_y,backg->smooth_y);
00423
00424 xsh_msg_dbg_low("bkg params: radius_x=%d smooth_x=%d",
00425 backg->radius_x,backg->smooth_x);
00426
00427 xsh_msg_dbg_low("rectify params: radius=%g bin_lambda=%g bin_space=%g",
00428 rectify_par->rectif_radius,rectify_par->rectif_bin_lambda,
00429 rectify_par->rectif_bin_space);
00430
00431 return cpl_error_get_code();
00432
00433 }
00434
00435
00436
00437
00438 static cpl_error_code
00439 xsh_params_set_defaults(cpl_parameterlist* pars,
00440 const char* rec_id,
00441 xsh_instrument* inst,
00442 xsh_rectify_param * rectify_par,
00443 xsh_background_param* backg)
00444 {
00445 cpl_parameter* p=NULL;
00446 check(p=xsh_parameters_find(pars,RECIPE_ID,"background-radius-x"));
00447 if(cpl_parameter_get_int(p) <= 0) {
00448 if (xsh_instrument_get_arm(inst) == XSH_ARM_NIR){
00449 backg->radius_x=1;
00450 } else {
00451 backg->radius_x=2;
00452 }
00453 }
00454 check(xsh_rectify_params_set_defaults(pars,rec_id,inst,rectify_par));
00455 cleanup:
00456
00457 return cpl_error_get_code();
00458 }
00459
00460
00461
00469
00470 static void xsh_scired_ifu_stare(cpl_parameterlist* parameters,
00471 cpl_frameset* frameset)
00472 {
00473
00474 const char* recipe_tags[3] = {XSH_OBJECT_IFU_STARE,
00475 XSH_STD_TELL_IFU_STARE,
00476 XSH_STD_FLUX_IFU_STARE};
00477
00478 int recipe_tags_size = 3;
00479
00480
00481 cpl_frameset *raws = NULL;
00482 cpl_frameset *calib = NULL;
00483
00484
00485
00486 cpl_frame *spectral_format_frame = NULL;
00487 cpl_frame *ifu_cfg_tab_frame = NULL ;
00488 cpl_frame *ifu_cfg_cor_frame = NULL ;
00489
00490
00491
00492
00493 cpl_frame *bpmap = NULL;
00494 cpl_frame *master_bias = NULL;
00495 cpl_frame *master_dark = NULL;
00496 cpl_frame *masterflat_frame = NULL;
00497 cpl_frame *order_tab_edges = NULL;
00498 cpl_frame *model_config_frame = NULL ;
00499 cpl_frame *wavemap_frame = NULL ;
00500 cpl_frame *slitmap_frame = NULL ;
00501 cpl_frame *disp_tab_frame = NULL;
00502
00503
00504 xsh_clipping_param *crh_clipping_par = NULL;
00505 xsh_background_param *backg_par = NULL;
00506 xsh_rectify_param *rectify_par = NULL ;
00507 xsh_stack_param* stack_par=NULL;
00508
00509
00510 int do_compute_map = 0;
00511 int do_trace_obj = 0;
00512
00513 int recipe_use_model = FALSE;
00514 int check_afc = TRUE;
00515
00516 xsh_instrument* instrument = NULL;
00517 int nb_raw_frames;
00518
00519
00520 #if 0
00521 cpl_frameset * on = NULL, * off = NULL ;
00522 #endif
00523 cpl_frame * crhm_frame = NULL ;
00524 cpl_frame * rmbias = NULL;
00525 cpl_frame * rmdark = NULL;
00526 cpl_frame * rmbkg = NULL ;
00527 cpl_frame *div_frame = NULL ;
00529
00530 cpl_frame* grid_backg=NULL;
00531 cpl_frame* frame_backg=NULL;
00532
00533 const char* ftag=NULL;
00534 char rec_prefix[80];
00535
00536
00537 char tag[256];
00538 char name[256];
00539 cpl_frame* wavesol_frame=NULL;
00540 cpl_frame* order_tab_edges_frame=NULL;
00541
00542 char wave_map_tag[80];
00543 char slit_map_tag[80];
00544 char* prefix=NULL;
00545 int pre_overscan_corr=0;
00546 cpl_frame* ifu_sky_map=NULL;
00547
00548
00549
00550 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
00551 recipe_tags, recipe_tags_size,RECIPE_ID, XSH_BINARY_VERSION,
00552 xsh_scired_ifu_stare_description_short));
00553
00554 assure( instrument->mode == XSH_MODE_IFU, CPL_ERROR_ILLEGAL_INPUT,
00555 "Instrument NOT in IFU Mode");
00556
00557 xsh_recipe_params_check(parameters,instrument,RECIPE_ID);
00558
00559
00560 check( nb_raw_frames = cpl_frameset_get_size( raws ) ) ;
00561 XSH_ASSURE_NOT_ILLEGAL( nb_raw_frames == 1 || nb_raw_frames >= 3 ) ;
00562 prefix=xsh_set_recipe_file_prefix(raws,"xsh_scired_ifu_stare");
00563 check(strcpy(rec_prefix,(const char*)prefix));
00564 XSH_FREE(prefix);
00565
00566
00567
00568 check(bpmap=xsh_check_load_master_bpmap(calib,instrument,RECIPE_ID));
00569
00570 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR){
00571
00572 check( master_bias = xsh_find_master_bias(calib,instrument));
00573 }
00574 #if 0
00575
00576
00577 else {
00578
00579 xsh_msg( "Calling xsh_dfs_split_nir" ) ;
00580 check(xsh_dfs_split_nir(raws, &on, &off));
00581 xsh_msg( " Nb ON: %d, OFF: %d", cpl_frameset_get_size(on),
00582 cpl_frameset_get_size(off) ) ;
00583 XSH_ASSURE_NOT_ILLEGAL(cpl_frameset_get_size(on) >= 3);
00584 XSH_ASSURE_NOT_ILLEGAL(cpl_frameset_get_size(off) >= 3);
00585 }
00586 #endif
00587
00588
00589
00590
00591 check(ifu_cfg_tab_frame=xsh_find_frame_with_tag(calib,XSH_IFU_CFG_TAB,instrument));
00592 check(ifu_cfg_cor_frame=xsh_find_frame_with_tag(calib,XSH_IFU_CFG_COR,instrument));
00593 check(spectral_format_frame=xsh_find_spectral_format( calib, instrument ) ) ;
00594
00595
00596
00597
00598 check( order_tab_edges = xsh_find_order_tab_edges( calib, instrument));
00599
00600
00601 check(model_config_frame=xsh_find_frame_with_tag(calib,XSH_MOD_CFG_OPT_AFC,
00602 instrument));
00603
00604
00605 if(model_config_frame==NULL) {
00606 check(wavesol_frame=xsh_find_frame_with_tag(calib,XSH_WAVE_TAB_AFC,
00607 instrument));
00608 }
00609
00610
00611
00612
00613
00614
00615
00616 if ( model_config_frame == NULL){
00617 xsh_msg("RECIPE USE WAVE SOLUTION");
00618 recipe_use_model = FALSE;
00619 }
00620 else{
00621 xsh_msg("RECIPE USE MODEL");
00622 recipe_use_model = TRUE;
00623 }
00624
00625 if( (model_config_frame!=NULL) && (wavesol_frame != NULL) ) {
00626
00627 xsh_msg_error("You cannot provide both a %s and a %s frame. Decide if you are in poly or physical model mode. We exit",
00628 XSH_WAVE_TAB_2D , XSH_MOD_CFG_TAB);
00629 goto cleanup;
00630 }
00631
00632 if((model_config_frame==NULL) && ( wavesol_frame == NULL) ) {
00633 xsh_msg_error("You must provide either a %s or a %s frame",
00634 XSH_WAVE_TAB_AFC, XSH_MOD_CFG_TAB);
00635 goto cleanup;
00636 }
00637
00638 if ( (master_dark = xsh_find_master_dark( calib, instrument ) ) == NULL ){
00639 xsh_msg_warning("Frame %s not provided",XSH_MASTER_DARK);
00640 xsh_error_reset();
00641 }
00642
00643 check( masterflat_frame = xsh_find_master_flat( calib, instrument));
00644
00645
00646
00647
00648
00649 recipe_use_model = ( model_config_frame != NULL);
00650 check( stack_par = xsh_stack_frames_get( RECIPE_ID, parameters));
00651 check( crh_clipping_par = xsh_parameters_clipping_crh_get(RECIPE_ID,
00652 parameters));
00653 check( backg_par = xsh_parameters_background_get(RECIPE_ID,
00654 parameters));
00655
00656
00657
00658
00659
00660 check( rectify_par = xsh_parameters_rectify_get(RECIPE_ID,
00661 parameters));
00662
00663 check( do_compute_map = xsh_parameters_get_boolean( parameters, RECIPE_ID,
00664 "compute-map"));
00665
00666 check( check_afc = xsh_parameters_get_boolean( parameters, RECIPE_ID,
00667 "check-afc"));
00668
00669 check( do_trace_obj = xsh_parameters_get_boolean( parameters, RECIPE_ID,
00670 "trace-obj"));
00671
00672 if ( do_compute_map && recipe_use_model==FALSE){
00673 check( disp_tab_frame = xsh_find_disp_tab( calib, instrument));
00674 }
00675
00676 check(xsh_params_set_defaults(parameters,RECIPE_ID,instrument,rectify_par,
00677 backg_par));
00678
00679 if ( xsh_instrument_get_arm( instrument ) != XSH_ARM_NIR ) {
00680 check(xsh_params_bin_scale(raws,backg_par));
00681 }
00682 check(xsh_params_monitor(backg_par,rectify_par));
00683
00684
00685
00686
00687
00688
00689
00690
00691 xsh_msg( "---Prepare raws frames");
00692 check( xsh_prepare( raws, bpmap, master_bias, XSH_OBJECT_IFU_STARE,
00693 instrument,pre_overscan_corr));
00694
00695
00696
00697 if ( nb_raw_frames >= 3 ) {
00698 xsh_msg( "---Remove cosmics");
00699
00700 ftag=XSH_GET_TAG_FROM_ARM(XSH_SLIT_STARE_REMOVE_CRH,instrument);
00701 check_msg( crhm_frame = xsh_remove_crh_multiple( raws,
00702 ftag,stack_par,
00703 crh_clipping_par,
00704 instrument, NULL,NULL,0 ),
00705 "Error in xsh_remove_crh" ) ;
00706 }
00707 else {
00708
00709 check( crhm_frame = cpl_frame_duplicate(cpl_frameset_get_first( raws )));
00710 }
00711 xsh_msg( "created %s", cpl_frame_get_filename( crhm_frame));
00712
00713
00714 if (recipe_use_model){
00715 int found_temp=true;
00716 xsh_msg("correct for temperature");
00717 check(xsh_model_temperature_update_frame(&model_config_frame,crhm_frame,
00718 instrument,&found_temp));
00719 }
00720 if ( do_compute_map){
00721 check(xsh_mode_set(instrument,XSH_MODE_IFU));
00722
00723 if (recipe_use_model){
00724
00725
00726 sprintf(wave_map_tag,"%s_%s",rec_prefix,XSH_WAVE_MAP_MODEL);
00727 sprintf(slit_map_tag,"%s_%s",rec_prefix,XSH_SLIT_MAP_MODEL);
00728 check( xsh_create_model_map( model_config_frame, instrument,
00729 wave_map_tag,slit_map_tag,
00730 &wavemap_frame, &slitmap_frame,0));
00731
00732 }
00733 else{
00734 xsh_msg( "Compute the wave map and the slit map");
00735 check( xsh_create_map( disp_tab_frame, order_tab_edges,
00736 crhm_frame, instrument,
00737 &wavemap_frame, &slitmap_frame,rec_prefix));
00738 }
00739 cpl_frameset_insert( calib, wavemap_frame);
00740 cpl_frameset_insert( calib, slitmap_frame);
00741 }
00742 else{
00743 check( wavemap_frame = xsh_find_wavemap( calib, instrument));
00744 slitmap_frame = xsh_find_slitmap(calib, instrument);
00745 }
00746
00747
00748 check( rmbias = xsh_check_subtract_bias( crhm_frame, master_bias,
00749 instrument, rec_prefix,
00750 pre_overscan_corr,0));
00751
00752
00753
00754
00755
00756 if(check_afc) {
00757 if(model_config_frame!=NULL) {
00758 check(xsh_frame_check_model_cfg_is_afc_corrected(model_config_frame));
00759 check(xsh_frame_check_model_cfg_is_proper_for_sci(model_config_frame,
00760 rmbias,instrument));
00761 } else {
00762 check(xsh_frame_check_model_cfg_is_afc_corrected(wavesol_frame));
00763 check(xsh_frame_check_model_cfg_is_proper_for_sci(wavesol_frame,
00764 rmbias,instrument));
00765 }
00766 }
00767
00768
00769 if ( master_dark != NULL ) {
00770 xsh_msg( "---Subtract_dark");
00771 sprintf(name, "%s_DARK_%s.fits",
00772 rec_prefix,xsh_instrument_arm_tostring(instrument));
00773 check( rmdark = xsh_subtract_dark(rmbias, master_dark,
00774 name,instrument));
00775 }
00776 else {
00777 xsh_msg( "No Master Dark" ) ;
00778 check( rmdark = cpl_frame_duplicate( rmbias ) ) ;
00779 }
00780 xsh_free_frame(&rmbias);
00781
00782
00783 xsh_msg("---Subtract_background");
00784 check( rmbkg = xsh_subtract_background( rmdark,
00785 order_tab_edges, backg_par, instrument, rec_prefix,&grid_backg,
00786 &frame_backg,0 ));
00787 xsh_free_frame(&rmdark);
00788
00789
00790 xsh_msg("---Do flatfielding");
00791 sprintf( tag, "%s_FF_%s",
00792 rec_prefix,xsh_instrument_arm_tostring(instrument));
00793 check( div_frame = xsh_divide_flat( rmbkg, masterflat_frame,
00794 tag, instrument));
00795 xsh_free_frame( &rmbkg);
00796
00797 if(do_trace_obj && do_compute_map) {
00798 check(xsh_mode_set(instrument,XSH_MODE_IFU));
00799 check(order_tab_edges_frame = xsh_find_order_tab_edges(calib,instrument));
00800 check(xsh_mode_set(instrument,XSH_MODE_SLIT));
00801 check(xsh_ifu_trace_object_calibrate(cpl_frame_get_filename(div_frame),
00802 cpl_frame_get_filename(order_tab_edges_frame),
00803 cpl_frame_get_filename(slitmap_frame),
00804 cpl_frame_get_filename(wavemap_frame)));
00805 }
00806
00807 check(xsh_build_ifu_cube(div_frame,ifu_cfg_tab_frame,ifu_cfg_cor_frame,
00808 spectral_format_frame,
00809 model_config_frame,
00810 wavesol_frame,
00811 instrument,
00812 frameset,
00813 parameters,rectify_par,RECIPE_ID,rec_prefix,1));
00814
00815 if(do_compute_map) {
00816 check(ifu_sky_map=xsh_build_ifu_map(div_frame,wavemap_frame,slitmap_frame,model_config_frame,instrument));
00817 check( xsh_add_product_image( ifu_sky_map, frameset,parameters, RECIPE_ID, instrument,NULL));
00818 }
00819 cleanup:
00820
00821 xsh_end( RECIPE_ID, frameset, parameters );
00822 xsh_instrument_free( &instrument);
00823 xsh_free_frameset( &raws);
00824 xsh_free_frameset( &calib);
00825
00826 xsh_free_frame( &crhm_frame);
00827 xsh_free_frame(&rmbias);
00828 xsh_free_frame(&div_frame);
00829 xsh_free_frame(&rmdark);
00830 xsh_free_frame( &rmbkg);
00831 xsh_free_frame( &grid_backg);
00832 xsh_free_frame( &frame_backg);
00833
00834 XSH_FREE(crh_clipping_par);
00835 XSH_FREE(backg_par);
00836 XSH_FREE(rectify_par);
00837
00838
00839 return;
00840 }
00841