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