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