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 #include <xsh_error.h>
00050
00051 #include <xsh_utils.h>
00052 #include <xsh_msg.h>
00053
00054 #include <xsh_dfs.h>
00055 #include <xsh_pfits.h>
00056 #include <xsh_data_spectrum1D.h>
00057 #include <xsh_utils_image.h>
00058 #include <xsh_model_io.h>
00059 #include <xsh_model_utils.h>
00060 #include <xsh_utils_ifu.h>
00061 #include <xsh_model_arm_constants.h>
00062
00063 #include <xsh_drl.h>
00064 #include <xsh_drl_check.h>
00065
00066 #include <cpl.h>
00067
00068
00069
00070
00071
00072 #define RECIPE_ID "xsh_scired_ifu_offset"
00073 #define RECIPE_AUTHOR "A.Modigliani, J.Vernet, P. Bristow"
00074 #define RECIPE_CONTACT "Andrea.Modigliani@eso.org"
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 static int xsh_scired_ifu_offset_create( cpl_plugin *);
00085 static int xsh_scired_ifu_offset_exec( cpl_plugin *);
00086 static int xsh_scired_ifu_offset_destroy( cpl_plugin *);
00087
00088
00089 static void xsh_scired_ifu_offset( cpl_parameterlist *, cpl_frameset *);
00090
00091
00092
00093
00094 static char xsh_scired_ifu_offset_description_short[] =
00095 "Reduce science IFU on-off exposures and build a 3D cube";
00096
00097 static char xsh_scired_ifu_offset_description[] =
00098 "This recipe Reduce science IFU on-off exposures and build a 3D cube\n\
00099 Input Frames : \n\
00100 - A set of 2xn Science frames, \
00101 Tag = OBJECT_IFU_OFFSET_arm, SKY_IFU_arm\n\
00102 - A spectral format table (Tag = SPECTRAL_FORMAT_TAB_arm)\n\
00103 - A master flat frame (Tag = MASTER_FLAT_IFU_arm)\n\
00104 - An order table frame(Tag = ORDER_TABLE_EDGES_IFU_arm)\n\
00105 - 3 wave solution frames, one per slitlet (Tag = WAVE_TAB_ARC_IFU_slitlet_arm)\n\
00106 where 'slitlet' is DOWN, CEN or UP\n\
00107 - [OPTIONAL] A dispersion table (Tag = DISP_TAB_IFU_arm)\n\
00108 - [OPTIONAL] A non-linear badpixel map (Tag = BP_MAP_NL_arm)\n\
00109 - [OPTIONAL] A reference badpixel map (Tag = BP_MAP_RP_arm)\n\
00110 Products : \n\
00111 - Merged 3D data cube (PREFIX_MERGE3D_DATA_OBJ_arm)\n\
00112 - QC Traces of 3D data cube (PREFIX_MERGE3D_TRACE_OBJ_arm)\n\
00113 - Order by order 3D data cube (PREFIX_ORDER3D_DATA_OBJ_arm)\n\
00114 - Order by order 3D qual cube (IFU_CFG_COR_arm)\n\
00115 - Order by order 3D qual cube (PREFIX_MERGE3D_DATA_SKY_arm)\n\
00116 - where PREFIX is SCI, FLUX, TELL if input raw DPR.TYPE contains OBJECT or FLUX or TELLURIC\n\
00117 - 1 Spectrum merge 3D, PRO.CATG=MERGE3D_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_offset_description_short,
00150 xsh_scired_ifu_offset_description,
00151 RECIPE_AUTHOR,
00152 RECIPE_CONTACT,
00153 xsh_get_license(),
00154 xsh_scired_ifu_offset_create,
00155 xsh_scired_ifu_offset_exec,
00156 xsh_scired_ifu_offset_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_offset_create(cpl_plugin *plugin){
00176 cpl_recipe *recipe = NULL;
00177
00178 xsh_clipping_param crh_clip_param = {5.0, 5, 0.7, 0,0.3};
00179
00180 xsh_remove_crh_single_param crh_single = { 0.1, 5, 2.0, 4} ;
00181 xsh_rectify_param rectify = { "tanh",
00182 CPL_KERNEL_DEFAULT,
00183 2,
00184 -1.0,
00185 -1.0,
00186 1,0,0.};
00187
00188 xsh_localize_obj_param loc_obj =
00189 {10, 0.1, 0, 0, LOC_MANUAL_METHOD, 0, 2.0,3,3,FALSE};
00190 xsh_stack_param stack_param = {"median",5.,5.};
00191
00192
00193
00194
00195
00196 xsh_init();
00197
00198
00199 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
00200
00201 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00202 CPL_ERROR_TYPE_MISMATCH,
00203 "Plugin is not a recipe");
00204
00205 recipe = (cpl_recipe *)plugin;
00206
00207
00208 recipe->parameters = cpl_parameterlist_new();
00209 assure( recipe->parameters != NULL,
00210 CPL_ERROR_ILLEGAL_OUTPUT,
00211 "Memory allocation failed!");
00212
00213
00214 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
00215 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
00216 check( xsh_parameters_pre_overscan( RECIPE_ID, recipe->parameters ) ) ;
00217 check(xsh_parameters_stack_create(RECIPE_ID,recipe->parameters,stack_param));
00218
00219 check(xsh_parameters_clipping_crh_create(RECIPE_ID,recipe->parameters,
00220 crh_clip_param));
00221
00222
00223 check(xsh_parameters_background_create(RECIPE_ID,recipe->parameters));
00224
00225
00226 check(xsh_parameters_remove_crh_single_create(RECIPE_ID,recipe->parameters,
00227 crh_single )) ;
00228
00229 check(xsh_parameters_rectify_create(RECIPE_ID,recipe->parameters,
00230 rectify )) ;
00231
00232 check(xsh_parameters_localize_obj_create(RECIPE_ID,recipe->parameters,
00233 loc_obj )) ;
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00247 "compute-map", FALSE,
00248 "if TRUE recompute (wave and slit) maps from the dispersion solution. If sky-subtract is set to TRUE this must be set to TRUE."));
00249
00250 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00251 "trace-obj", FALSE,
00252 "if TRUE trace object position on each IFU slice. In this case order TAB edges is required"));
00253
00254
00255 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00256 "check-afc", TRUE,
00257 "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."));
00258
00259
00260 cleanup:
00261 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
00262 xsh_error_dump(CPL_MSG_ERROR);
00263 return 1;
00264 }
00265 else {
00266 return 0;
00267 }
00268 }
00269
00270
00276
00277
00278 static int xsh_scired_ifu_offset_exec(cpl_plugin *plugin) {
00279 cpl_recipe *recipe = NULL;
00280
00281
00282
00283 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
00284
00285
00286 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00287 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00288
00289 recipe = (cpl_recipe *)plugin;
00290
00291
00292 xsh_scired_ifu_offset(recipe->parameters, recipe->frames);
00293
00294 cleanup:
00295 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
00296 xsh_error_dump(CPL_MSG_ERROR);
00297 xsh_error_reset();
00298 return 1;
00299 }
00300 else {
00301 return 0;
00302 }
00303 }
00304
00311 static cpl_error_code
00312 xsh_params_monitor(xsh_background_param* backg,
00313 xsh_rectify_param * rectify_par)
00314 {
00315
00316
00317 xsh_msg_dbg_low("bkg params: sampley=%d radius_y=%d",
00318 backg->sampley,backg->radius_y);
00319
00320 xsh_msg_dbg_low("bkg params: radius_x=%d",
00321 backg->radius_x);
00322
00323 xsh_msg_dbg_low("rectify params: radius=%g bin_lambda=%g bin_space=%g",
00324 rectify_par->rectif_radius,rectify_par->rectif_bin_lambda,
00325 rectify_par->rectif_bin_space);
00326
00327 return cpl_error_get_code();
00328
00329 }
00330
00338
00339
00340 static cpl_error_code
00341 xsh_params_bin_scale(cpl_frameset* raws,
00342 xsh_background_param* backg)
00343 {
00344
00345 cpl_frame* frame=NULL;
00346 const char* name=NULL;
00347 cpl_propertylist* plist=NULL;
00348 int binx=0;
00349 int biny=0;
00350
00351 check(frame=cpl_frameset_get_first(raws));
00352 check(name=cpl_frame_get_filename(frame));
00353 check(plist=cpl_propertylist_load(name,0));
00354 check(binx=xsh_pfits_get_binx(plist));
00355 check(biny=xsh_pfits_get_biny(plist));
00356 xsh_free_propertylist(&plist);
00357
00358 if(biny>1) {
00359
00360
00361
00362
00363
00364
00365 backg->radius_y=backg->radius_y/biny;
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386 }
00387
00388
00389 if(binx>1) {
00390
00391 backg->radius_x=backg->radius_x/binx;
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406 }
00407
00408 cleanup:
00409 xsh_free_propertylist(&plist);
00410 return cpl_error_get_code();
00411
00412 }
00413
00414
00415
00421
00422 static int xsh_scired_ifu_offset_destroy(cpl_plugin *plugin)
00423 {
00424 cpl_recipe *recipe = NULL;
00425
00426
00427 xsh_error_reset();
00428
00429 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00430
00431
00432 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00433 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00434
00435 recipe = (cpl_recipe *)plugin;
00436
00437 xsh_free_parameterlist(&recipe->parameters);
00438
00439 cleanup:
00440 if (cpl_error_get_code() != CPL_ERROR_NONE)
00441 {
00442 return 1;
00443 }
00444 else
00445 {
00446 return 0;
00447 }
00448 }
00449
00450
00451
00459
00460 static void xsh_scired_ifu_offset( cpl_parameterlist* parameters,
00461 cpl_frameset* frameset)
00462 {
00463 const char* recipe_tags[4] = {XSH_OBJECT_IFU_OFFSET, XSH_STD_TELL_IFU_OFFSET, XSH_STD_FLUX_IFU_OFFSET, XSH_SKY_IFU};
00464 int recipe_tags_size = 4;
00465
00466
00467
00468 cpl_frame *spectral_format_frame = NULL;
00469 cpl_frame *ifu_cfg_tab_frame = NULL ;
00470 cpl_frame *ifu_cfg_cor_frame = NULL ;
00471
00472
00473 cpl_frameset* raws = NULL;
00474 cpl_frameset* calib = NULL;
00475
00476
00477 cpl_frame* bpmap = NULL;
00478 cpl_frame * master_bias = NULL ;
00479 cpl_frame * master_dark = NULL ;
00480 cpl_frame* master_flat = NULL;
00481 cpl_frame* order_tab_edges = NULL;
00482 cpl_frame * wavesol_frame = NULL ;
00483 cpl_frame * model_config_frame = NULL ;
00484
00485
00486 cpl_frame * slice_offset_frame = NULL ;
00487 cpl_frameset * object_frameset = NULL, * sky_frameset = NULL ;
00488 xsh_stack_param* stack_par=NULL;
00489
00490 xsh_background_param* backg_par = NULL;
00491 xsh_remove_crh_single_param * crh_single_par = NULL ;
00492 xsh_rectify_param * rectify_par = NULL ;
00493
00494
00495 xsh_instrument* instrument = NULL;
00496 int nb_sub_frames ;
00497 int nb_raw_frames ;
00498
00499
00500
00501 cpl_frameset * sub_frameset = NULL ;
00502 cpl_frameset * rmbkg_frameset = NULL ;
00504 cpl_frameset * clean_frameset = NULL ;
00506 cpl_frame * comb_obj_frame = NULL ;
00507 cpl_frameset * rect2_frameset = NULL ;
00508
00509
00510
00511 cpl_frameset * res_1D_frameset = NULL ;
00512 cpl_frameset * res_2D_frameset = NULL ;
00513 cpl_frame * data_cube = NULL ;
00514 cpl_frameset * ext_frameset = NULL ;
00515 cpl_frameset * ext_frameset_tables = NULL ;
00516 char* prefix=NULL;
00517 int i ;
00518 char file_name[256], arm_str[16] ;
00519 char * file_tag = NULL;
00520 cpl_frame* grid_backg=NULL;
00521 cpl_frame* frame_backg=NULL;
00522 cpl_frameset * ext_frameset_images = NULL ;
00523 cpl_frameset * rect2_frameset_tables = NULL ;
00524
00525
00526 char rec_prefix[256];
00527 cpl_frame* object_frame=NULL;
00528
00529 int do_compute_map = TRUE;
00530 int recipe_use_model = FALSE;
00531 char wave_map_tag[256];
00532 char slit_map_tag[256];
00533 cpl_frame *wavemap_frame = NULL ;
00534 cpl_frame *slitmap_frame = NULL ;
00535 cpl_frame *disp_tab_frame = NULL;
00536 cpl_frame* comb_sky_frame=NULL;
00537 int pre_overscan_corr=0;
00538 cpl_frame* ifu_sky_map=NULL;
00539
00540
00541
00542 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
00543 recipe_tags, recipe_tags_size,
00544 RECIPE_ID, XSH_BINARY_VERSION,
00545 xsh_scired_ifu_offset_description_short));
00546
00547 assure( instrument->mode == XSH_MODE_IFU, CPL_ERROR_ILLEGAL_INPUT,
00548 "Instrument NOT in Ifu Mode" ) ;
00549
00550 check(xsh_recipe_params_check(parameters,instrument,RECIPE_ID));
00551
00552 check(xsh_ensure_raws_input_offset_recipe_is_proper(&raws,instrument));
00553
00554 check( nb_raw_frames = cpl_frameset_get_size( raws ) ) ;
00555 xsh_msg( "Nb of Raw frames: %d", nb_raw_frames ) ;
00556
00557 XSH_ASSURE_NOT_ILLEGAL( nb_raw_frames > 1 ) ;
00558 {
00559
00560 int even_nb = nb_raw_frames % 2 ;
00561 XSH_ASSURE_NOT_ILLEGAL( even_nb == 0 ) ;
00562
00563 }
00564 prefix=xsh_set_recipe_file_prefix(raws,"xsh_scired_ifu_offset");
00565 check(strcpy(rec_prefix,(const char*)prefix));
00566 XSH_FREE(prefix);
00567
00568
00569
00570
00571
00572
00573
00574
00575 check(ifu_cfg_tab_frame=xsh_find_frame_with_tag(calib,XSH_IFU_CFG_TAB,instrument));
00576 check(ifu_cfg_cor_frame=xsh_find_frame_with_tag(calib,XSH_IFU_CFG_COR,instrument));
00577 check(spectral_format_frame=xsh_find_spectral_format( calib, instrument ) ) ;
00578
00579
00580 check(bpmap=xsh_check_load_master_bpmap(calib,instrument,RECIPE_ID));
00581
00582 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR){
00583
00584 check( master_bias = xsh_find_frame_with_tag(calib,XSH_MASTER_BIAS,
00585 instrument));
00586 }
00587
00588 else {
00589
00590
00591
00592
00593 }
00594 check(order_tab_edges = xsh_find_order_tab_edges(calib,instrument));
00595
00596
00597 check(model_config_frame=xsh_find_frame_with_tag(calib,XSH_MOD_CFG_OPT_AFC,
00598 instrument));
00599
00600 if(model_config_frame==NULL) {
00601 check(wavesol_frame=xsh_find_frame_with_tag(calib,XSH_WAVE_TAB_AFC,
00602 instrument));
00603 }
00604
00605
00606
00607
00608
00609 check( do_compute_map = xsh_parameters_get_boolean( parameters, RECIPE_ID,
00610 "compute-map"));
00611
00612
00613
00614
00615 XSH_ASSURE_NOT_ILLEGAL( (model_config_frame != NULL && wavesol_frame == NULL ) ||
00616
00617 (model_config_frame == NULL && wavesol_frame != NULL ) );
00618
00619 check( master_flat = xsh_find_master_flat( calib, instrument ) ) ;
00620
00621 if((master_dark = xsh_find_frame_with_tag(calib,XSH_MASTER_DARK,
00622 instrument)) == NULL){
00623 xsh_msg_warning("Frame %s not provided",XSH_MASTER_DARK);
00624 xsh_error_reset();
00625 }
00626
00627
00628
00629
00630 if ((slice_offset_frame = xsh_find_frame_with_tag( calib, XSH_SLICE_OFFSET,
00631 instrument) ) == NULL ) {
00632 xsh_msg_warning("Frame %s not provided", XSH_SLICE_OFFSET );
00633 xsh_error_reset() ;
00634 }
00635
00636
00637
00638
00639
00640 check( stack_par = xsh_stack_frames_get( RECIPE_ID, parameters));
00641
00642 check( backg_par = xsh_parameters_background_get(RECIPE_ID,
00643 parameters));
00644
00645 check( rectify_par = xsh_parameters_rectify_get(RECIPE_ID,
00646 parameters));
00647 rectify_par->conserve_flux=FALSE;
00648 check( crh_single_par = xsh_parameters_remove_crh_single_get(RECIPE_ID,
00649 parameters));
00650 if ( rectify_par->rectify_full_slit == 1 ) {
00651 xsh_msg( "Use Full Slit" ) ;
00652 }
00653 else {
00654 xsh_msg( "Use Max Possible Slit" ) ;
00655 }
00656 check(xsh_rectify_params_set_defaults(parameters,RECIPE_ID,instrument,rectify_par));
00657
00658
00659 if ( xsh_instrument_get_arm( instrument ) != XSH_ARM_NIR ) {
00660 check(xsh_params_bin_scale(raws,backg_par));
00661 }
00662 check(xsh_params_monitor(backg_par,rectify_par));
00663
00664
00665
00666
00667
00668
00669
00670 check(xsh_prepare(raws, bpmap, master_bias, XSH_OBJECT_IFU_OFFSET,
00671 instrument,pre_overscan_corr,CPL_TRUE));
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684 check( nb_sub_frames = xsh_dfs_split_offset( raws, "IFU_OFFSET",
00685 XSH_SKY_IFU, &object_frameset,
00686 &sky_frameset ) ) ;
00687
00688
00689 check( sub_frameset = xsh_subtract_sky_offset( object_frameset, sky_frameset,
00690 nb_sub_frames, instrument)) ;
00691
00692
00693
00694 check(object_frame=cpl_frameset_get_frame(object_frameset,0));
00695 if ( model_config_frame == NULL){
00696 xsh_msg("RECIPE USE WAVE SOLUTION");
00697 recipe_use_model = FALSE;
00698 }
00699 else{
00700 xsh_msg("RECIPE USE MODEL");
00701 recipe_use_model = TRUE;
00702 }
00703
00704 if ( do_compute_map && recipe_use_model==FALSE){
00705 check( disp_tab_frame = xsh_find_disp_tab( calib, instrument));
00706 }
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727 if (recipe_use_model){
00728 int found_temp=true;
00729 xsh_msg("correct for temperature");
00730 check(xsh_model_temperature_update_frame(&model_config_frame,
00731 object_frame,
00732 instrument,&found_temp));
00733 }
00734 if ( do_compute_map){
00735 check(xsh_mode_set(instrument,XSH_MODE_IFU));
00736
00737 if (recipe_use_model){
00738
00739
00740 sprintf(wave_map_tag,"%s_%s",rec_prefix,XSH_WAVE_MAP_MODEL);
00741 sprintf(slit_map_tag,"%s_%s",rec_prefix,XSH_SLIT_MAP_MODEL);
00742 check( xsh_create_model_map( model_config_frame, instrument,
00743 wave_map_tag,slit_map_tag,
00744 &wavemap_frame, &slitmap_frame,1));
00745
00746 }
00747 else{
00748 xsh_msg( "Compute the wave map and the slit map");
00749 check( xsh_create_map( disp_tab_frame, order_tab_edges,
00750 object_frame, instrument,
00751 &wavemap_frame, &slitmap_frame,rec_prefix));
00752 }
00753 cpl_frameset_insert( calib, wavemap_frame);
00754 cpl_frameset_insert( calib, slitmap_frame);
00755 }
00756 else{
00757 check( wavemap_frame = xsh_find_wavemap( calib, instrument));
00758 slitmap_frame = xsh_find_slitmap(calib, instrument);
00759 }
00760
00761
00762 check( rmbkg_frameset = cpl_frameset_new() ) ;
00763 check( clean_frameset = cpl_frameset_new() ) ;
00764
00765 sprintf( arm_str, "%s_", xsh_instrument_arm_tostring(instrument) ) ;
00766
00767
00768
00769 for( i = 0 ; i<nb_sub_frames ; i++ ) {
00770 cpl_frame * a_b = NULL ;
00771 cpl_frame * rm_bkg = NULL ;
00772 char str[16] ;
00773
00774 sprintf( str, "%d", i ) ;
00775 a_b = cpl_frameset_get_frame( sub_frameset, i ) ;
00776
00777
00778 xsh_msg("Subtract inter-order background %d", i );
00779 sprintf(file_name,"%s%s",rec_prefix, str) ;
00780
00781 check(rm_bkg = xsh_subtract_background( a_b,
00782 order_tab_edges,
00783 backg_par, instrument,
00784 file_name,&grid_backg,
00785 &frame_backg,0,0,0));
00786 check( cpl_frameset_insert( rmbkg_frameset, rm_bkg ) ) ;
00787 }
00788
00789
00790 if ( nb_sub_frames < 3 && crh_single_par->nb_iter > 0 ) {
00791 xsh_msg( "Less than 3 frames AND crh_single_niter > 0" ) ;
00792 for ( i = 0 ; i < nb_sub_frames ; i++ ) {
00793 cpl_frame * divided = NULL ;
00794 cpl_frame * rm_crh = NULL ;
00795 cpl_frame * a_b = NULL ;
00796 char str[16] ;
00797
00798 check( a_b = cpl_frameset_get_frame( rmbkg_frameset, i ) ) ;
00799 sprintf( str, "%d", i ) ;
00800
00801 file_tag = xsh_stringcat_any( "NO_CRH_IFU_OFFSET_", arm_str,str, NULL ) ;
00802 xsh_msg( "Remove crh (single frame)" ) ;
00803
00804 check( rm_crh = xsh_remove_crh_single( a_b,instrument,
00805 crh_single_par,
00806 file_tag ) ) ;
00807
00808
00809 XSH_FREE( file_tag ) ;
00810 xsh_add_temporary_file(cpl_frame_get_filename(rm_crh));
00811 xsh_msg( "Divide by flat" ) ;
00812 file_tag = xsh_stringcat_any( "FF_IFU_OFFSET_", arm_str,
00813 str, NULL ) ;
00814 check( divided = xsh_divide_flat( rm_crh,
00815 master_flat, file_tag,
00816 instrument ) ) ;
00817 XSH_FREE( file_tag ) ;
00818 check( cpl_frameset_insert( clean_frameset, divided ) ) ;
00819 xsh_add_temporary_file(cpl_frame_get_filename(divided));
00820 xsh_free_frame(&rm_crh);
00821
00822 }
00823 }
00824 else for( i = 0 ; i < nb_sub_frames ; i++ ) {
00825 cpl_frame * divided = NULL ;
00826 cpl_frame * a_b = NULL ;
00827 char str[16] ;
00828
00829
00830 a_b = cpl_frameset_get_frame( rmbkg_frameset, i ) ;
00831 sprintf( str, "%d", i ) ;
00832
00833
00834 xsh_msg( "Divide by flat" ) ;
00835 file_tag = xsh_stringcat_any( "FF_IFU_OFFSET_", arm_str,
00836 str, NULL ) ;
00837 check( divided = xsh_divide_flat( a_b,
00838 master_flat, file_tag,
00839 instrument ) ) ;
00840 XSH_FREE( file_tag ) ;
00841 check( cpl_frameset_insert( clean_frameset, divided ) ) ;
00842 xsh_add_temporary_file(cpl_frame_get_filename(divided));
00843 }
00844
00845
00846
00847 xsh_msg( "Combining all frames" ) ;
00848 file_tag = xsh_stringcat_any( "COMBINED_IFU_OFFSET_", arm_str,
00849 "ALL", NULL ) ;
00850
00851 check( comb_obj_frame = xsh_combine_offset( clean_frameset,
00852 file_tag, stack_par,
00853 instrument, NULL, NULL,1 ) ) ;
00854 XSH_FREE( file_tag ) ;
00855
00856 check(comb_sky_frame=xsh_util_frameset_collapse_mean(sky_frameset,instrument));
00857
00858
00859
00860
00861 check(xsh_build_ifu_cube(comb_obj_frame,ifu_cfg_tab_frame,ifu_cfg_cor_frame,
00862 spectral_format_frame,
00863 model_config_frame,wavesol_frame,
00864 instrument,
00865 frameset,
00866 parameters,rectify_par,RECIPE_ID,rec_prefix,1));
00867
00868
00869
00870
00871 check(xsh_build_ifu_cube(comb_sky_frame,ifu_cfg_tab_frame,ifu_cfg_cor_frame,
00872 spectral_format_frame,
00873 model_config_frame,wavesol_frame,
00874 instrument,
00875 frameset,
00876 parameters,rectify_par,RECIPE_ID,rec_prefix,0));
00877
00878 if(do_compute_map) {
00879 check(ifu_sky_map=xsh_build_ifu_map(comb_obj_frame,wavemap_frame,slitmap_frame,model_config_frame,instrument));
00880 check( xsh_add_product_image( ifu_sky_map, frameset,parameters, RECIPE_ID, instrument,NULL));
00881 }
00882 cleanup:
00883
00884 xsh_end( RECIPE_ID, frameset, parameters );
00885 XSH_FREE( backg_par ) ;
00886 XSH_FREE( crh_single_par ) ;
00887 XSH_FREE( rectify_par ) ;
00888 XSH_FREE(stack_par);
00889 xsh_instrument_free(&instrument );
00890 xsh_free_frameset(&ext_frameset_images);
00891 xsh_free_frameset(&rect2_frameset_tables);
00892 xsh_free_frameset(&ext_frameset_tables);
00893
00894 xsh_free_frameset(&object_frameset);
00895 xsh_free_frameset(&sky_frameset);
00896 xsh_free_frameset(&raws);
00897 xsh_free_frameset(&calib);
00898 xsh_free_frameset( &sub_frameset ) ;
00899 xsh_free_frameset( &clean_frameset ) ;
00900 xsh_free_frameset( &rmbkg_frameset ) ;
00901 xsh_free_frameset(&res_1D_frameset) ;
00902 xsh_free_frameset(&res_2D_frameset) ;
00903 xsh_free_frameset(&rect2_frameset) ;
00904 xsh_free_frameset(&ext_frameset) ;
00905
00906
00907 xsh_free_frame( &comb_sky_frame);
00908 xsh_free_frame( &comb_obj_frame);
00909 xsh_free_frame( &grid_backg);
00910 xsh_free_frame( &frame_backg);
00911
00912 xsh_free_frame( &data_cube ) ;
00913
00914 return;
00915 }
00916