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_msg.h>
00054
00055 #include <xsh_dfs.h>
00056 #include <xsh_pfits.h>
00057
00058 #include <xsh_drl.h>
00059 #include <xsh_utils_table.h>
00060 #include <xsh_model_utils.h>
00061
00062 #include <cpl.h>
00063
00064
00065
00066
00067
00068
00069 #define RECIPE_ID "xsh_geom_ifu"
00070 #define RECIPE_AUTHOR "P.Goldoni, L.Guglielmi, R. Haigron, F. Royer"
00071 #define RECIPE_CONTACT "laurent.guglielmi@apc.univ-paris7.fr"
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 static int xsh_geom_ifu_create(cpl_plugin *);
00082 static int xsh_geom_ifu_exec(cpl_plugin *);
00083 static int xsh_geom_ifu_destroy(cpl_plugin *);
00084
00085
00086 static void xsh_geom_ifu(cpl_parameterlist *, cpl_frameset *);
00087
00088
00089
00090
00091 static char xsh_geom_ifu_description_short[] =
00092 "Produces the spatial geometry of the IFU pattern on the sky";
00093
00094 static char xsh_geom_ifu_description[] =
00095 "This recipe Produces the spatial geometry of the IFU pattern on the sky\n\
00096 Input Frames : \n\
00097 - A set of n Science frames ( n == 1 or >=3, \
00098 Tag = OBJECT_IFU_STARE_UVB)\n\
00099 - [UVB,VIS] A master bias frame (Tag = MASTER_BIAS_arm)\n\
00100 - A master dark frame (Tag = MASTER_DARK_arm)\n\
00101 - A master flat frame (Tag = MASTER_FLAT_IFU_arm)\n\
00102 - An order table frame(Tag = ORDER_TABLE_arm)\n\
00103 - 3 wave solution frames, one per slitlet(Tag = WAVE_SOLUTION_IFU_slitlet_arm)\n\
00104 where 'slitlet' is DOWN, CEN or UP\n\
00105 - [OPTIONAL] A badpixel map (Tag = BADPIXEL_MAP_arm)\n\
00106 Products : \n\
00107 - A Slice Offset Table (similar to a localization table)\n\
00108 Tag = SLICE_OFFSET_TABLE_arm\n" ;
00109
00110
00111
00112
00113
00122
00123
00124 int cpl_plugin_get_info(cpl_pluginlist *list) {
00125 cpl_recipe *recipe = NULL;
00126 cpl_plugin *plugin = NULL;
00127
00128 recipe = cpl_calloc(1, sizeof(*recipe));
00129 if ( recipe == NULL ){
00130 return -1;
00131 }
00132
00133 plugin = &recipe->interface ;
00134
00135 cpl_plugin_init(plugin,
00136 CPL_PLUGIN_API,
00137 XSH_BINARY_VERSION,
00138 CPL_PLUGIN_TYPE_RECIPE,
00139 RECIPE_ID,
00140 xsh_geom_ifu_description_short,
00141 xsh_geom_ifu_description,
00142 RECIPE_AUTHOR,
00143 RECIPE_CONTACT,
00144 xsh_get_license(),
00145 xsh_geom_ifu_create,
00146 xsh_geom_ifu_exec,
00147 xsh_geom_ifu_destroy);
00148
00149 cpl_pluginlist_append(list, plugin);
00150
00151 return (cpl_error_get_code() != CPL_ERROR_NONE);
00152 }
00153
00154
00164
00165
00166 static int xsh_geom_ifu_create(cpl_plugin *plugin){
00167 cpl_recipe *recipe = NULL;
00168 xsh_clipping_param crh_clip_param = {0., 5.0, 5, 0.7, 0};
00169
00170 xsh_remove_crh_single_param crh_single = { 0.1, 5, 2.0, 4} ;
00171 xsh_rectify_param rectify = { "default",
00172 CPL_KERNEL_DEFAULT, 4,
00173 XSH_WAVE_BIN_SIZE_PIPE_NIR,
00174 XSH_SLIT_BIN_SIZE_PIPE_NIR,
00175 1, 0, 0 };
00176
00177 xsh_localize_obj_param loc_obj =
00178 {10, 0.1, 1, 0, LOC_GAUSSIAN_METHOD, 0, 0.5, 2.0, 3};
00179
00180
00181 xsh_init();
00182
00183
00184 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
00185
00186
00187 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00188 CPL_ERROR_TYPE_MISMATCH,
00189 "Plugin is not a recipe");
00190
00191 recipe = (cpl_recipe *)plugin;
00192
00193
00194 recipe->parameters = cpl_parameterlist_new();
00195 assure( recipe->parameters != NULL,
00196 CPL_ERROR_ILLEGAL_OUTPUT,
00197 "Memory allocation failed!");
00198
00199
00200 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
00201
00202
00203 check(xsh_parameters_clipping_crh_create(RECIPE_ID,recipe->parameters,
00204 crh_clip_param));
00205
00206
00207 check(xsh_parameters_background_create(RECIPE_ID,recipe->parameters));
00208
00209
00210 check(xsh_parameters_remove_crh_single_create(RECIPE_ID,recipe->parameters,
00211 crh_single )) ;
00212
00213
00214 check(xsh_parameters_rectify_create(RECIPE_ID,recipe->parameters,
00215 rectify )) ;
00216
00217
00218 check(xsh_parameters_localize_obj_create(RECIPE_ID,recipe->parameters,
00219 loc_obj )) ;
00220
00221
00222 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00223 "compute-map", TRUE,
00224 "if TRUE recompute (wave and slit) maps from the dispersion solution. If sky-subtract is set to TRUE this must be set to TRUE."));
00225
00226
00227 check( xsh_parameters_new_double( recipe->parameters, RECIPE_ID,
00228 "slicedist-lambda", -1,
00229 "[DEBUG PARAM] If positive give the lambda in nm where we estimate the distance between slice"));
00230
00231
00232 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00233 "slicedist-global", CPL_TRUE,
00234 "If positive take the total spectal range else take 1 nm around slicedist-lambda"));
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
00253
00254
00255 static cpl_error_code
00256 xsh_params_bin_scale(cpl_frameset* raws,
00257 xsh_background_param* backg)
00258 {
00259
00260 cpl_frame* frame=NULL;
00261 const char* name=NULL;
00262 cpl_propertylist* plist=NULL;
00263 int binx=0;
00264 int biny=0;
00265
00266 check(frame=cpl_frameset_get_first(raws));
00267 check(name=cpl_frame_get_filename(frame));
00268 check(plist=cpl_propertylist_load(name,0));
00269 check(binx=xsh_pfits_get_binx(plist));
00270 check(biny=xsh_pfits_get_biny(plist));
00271 xsh_free_propertylist(&plist);
00272
00273 if(biny>1) {
00274
00275
00276
00277
00278
00279
00280 backg->radius_y=backg->radius_y/biny;
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306 }
00307
00308
00309 if(binx>1) {
00310
00311 backg->radius_x=backg->radius_x/binx;
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331 }
00332
00333 cleanup:
00334 xsh_free_propertylist(&plist);
00335 return cpl_error_get_code();
00336
00337 }
00338
00339
00345
00346
00347 static int xsh_geom_ifu_exec(cpl_plugin *plugin) {
00348 cpl_recipe *recipe = NULL;
00349
00350
00351
00352 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00353
00354
00355 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00356 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00357
00358 recipe = (cpl_recipe *)plugin;
00359
00360
00361 xsh_geom_ifu(recipe->parameters, recipe->frames);
00362
00363 cleanup:
00364 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
00365 xsh_error_dump(CPL_MSG_ERROR);
00366 xsh_error_reset();
00367 return 1;
00368 }
00369 else {
00370 return 0;
00371 }
00372 }
00373
00374
00380
00381 static int xsh_geom_ifu_destroy(cpl_plugin *plugin)
00382 {
00383 cpl_recipe *recipe = NULL;
00384
00385
00386 xsh_error_reset();
00387
00388 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00389
00390
00391 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00392 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00393
00394 recipe = (cpl_recipe *)plugin;
00395
00396 xsh_free_parameterlist(&recipe->parameters);
00397
00398 cleanup:
00399 if (cpl_error_get_code() != CPL_ERROR_NONE)
00400 {
00401 return 1;
00402 }
00403 else
00404 {
00405 return 0;
00406 }
00407 }
00408 static cpl_error_code
00409 xsh_params_monitor(xsh_background_param* backg,
00410 xsh_rectify_param * rectify_par,
00411 xsh_localize_obj_param * loc_obj_par)
00412 {
00413
00414
00415 xsh_msg_dbg_low("bkg params: sampley=%d radius_y=%d smooth_y=%d",
00416 backg->sampley,backg->radius_y,backg->smooth_y);
00417
00418 xsh_msg_dbg_low("bkg params: radius_x=%d smooth_x=%d",
00419 backg->radius_x,backg->smooth_x);
00420
00421 xsh_msg_dbg_low("rectify params: radius=%g bin_lambda=%g bin_space=%g",
00422 rectify_par->rectif_radius,rectify_par->rectif_bin_lambda,
00423 rectify_par->rectif_bin_space);
00424
00425 xsh_msg_dbg_low("localize params: chunk_nb=%d nod_step=%g",
00426 loc_obj_par->loc_chunk_nb,loc_obj_par->nod_step);
00427
00428 return cpl_error_get_code();
00429
00430 }
00431
00432 static cpl_error_code
00433 xsh_params_set_defaults(cpl_parameterlist* pars,
00434 xsh_instrument* inst,
00435 xsh_rectify_param * rectify_par)
00436 {
00437 cpl_parameter* p=NULL;
00438
00439 if (xsh_instrument_get_arm(inst) == XSH_ARM_NIR){
00440
00441 check(p=xsh_parameters_find(pars,RECIPE_ID,"rectify-bin-slit"));
00442 if(xsh_parameter_get_default_flag(p) == 0) {
00443
00444 rectify_par->rectif_bin_space=XSH_SLIT_BIN_SIZE_PIPE_NIR;
00445 cpl_parameter_set_double(p,XSH_SLIT_BIN_SIZE_PIPE_NIR);
00446 }
00447
00448 check(p=xsh_parameters_find(pars,RECIPE_ID,"rectify-bin-lambda"));
00449 if(xsh_parameter_get_default_flag(p) == 0) {
00450
00451 rectify_par->rectif_bin_lambda=XSH_WAVE_BIN_SIZE_PIPE_NIR;
00452 cpl_parameter_set_double(p,XSH_WAVE_BIN_SIZE_PIPE_NIR);
00453 }
00454
00455
00456
00457 } else {
00458
00459
00460 check(p=xsh_parameters_find(pars,RECIPE_ID,"rectify-bin-slit"));
00461 if(xsh_parameter_get_default_flag(p) == 0) {
00462
00463 rectify_par->rectif_bin_space=XSH_SLIT_BIN_SIZE_PIPE_UVB;
00464 cpl_parameter_set_double(p,XSH_SLIT_BIN_SIZE_PIPE_UVB);
00465 }
00466
00467 check(p=xsh_parameters_find(pars,RECIPE_ID,"rectify-bin-lambda"));
00468 if(xsh_parameter_get_default_flag(p) == 0) {
00469
00470 rectify_par->rectif_bin_lambda=XSH_WAVE_BIN_SIZE_PIPE_UVB;
00471 cpl_parameter_set_double(p,XSH_WAVE_BIN_SIZE_PIPE_UVB);
00472 }
00473
00474
00475 }
00476
00477 cleanup:
00478
00479 return cpl_error_get_code();
00480
00481 }
00482
00483
00491
00492 static void xsh_geom_ifu(cpl_parameterlist* parameters,
00493 cpl_frameset* frameset)
00494 {
00495 const char* recipe_tags[1] = {XSH_TRACE};
00496 int recipe_tags_size = 1;
00497
00498
00499 cpl_frameset *raws = NULL;
00500 cpl_frameset *calib = NULL;
00501
00502
00503
00504 cpl_frame *bpmap = NULL;
00505 cpl_frame *master_bias = NULL;
00506 cpl_frame *master_dark = NULL;
00507 cpl_frame *masterflat_frame = NULL;
00508 cpl_frame *order_tab_edges = NULL;
00509 cpl_frameset *wave_tabs_ifu = NULL ;
00510 cpl_frame *model_config_frame = NULL ;
00511 cpl_frame *wavemap_frame = NULL ;
00512 cpl_frame *spectralformat_frame = NULL ;
00513 cpl_frame *slitmap_frame = NULL ;
00514 cpl_frame *disp_tab_frame = NULL;
00515
00516
00517 xsh_clipping_param *crh_clipping_par = NULL;
00518 xsh_background_param *backg_par = NULL;
00519 xsh_remove_crh_single_param *crh_single_par = NULL ;
00520 xsh_rectify_param *rectify_par = NULL ;
00521 xsh_localize_obj_param *loc_obj_par = NULL ;
00522
00523 int do_computemap = 0;
00524 double slicedist_lambda = -1;
00525 int slicedist_global = CPL_TRUE;
00526 int recipe_use_model = FALSE;
00527 xsh_instrument* instrument = NULL;
00528 int nb_raw_frames;
00529
00530
00531 #if 0
00532 cpl_frameset * on = NULL, * off = NULL ;
00533 #endif
00534 cpl_frame * crhm_frame = NULL ;
00535 cpl_frame * rmbias = NULL;
00536 cpl_frame * rmdark = NULL;
00537 cpl_frame * rmbkg = NULL ;
00538 cpl_frame *div_frame = NULL ;
00539 cpl_frameset *rect_frameset = NULL ;
00540 cpl_frameset *loc_frameset = NULL ;
00541 cpl_frame * clean_frame = NULL ;
00543
00544 cpl_frame * slice_offset = NULL ;
00545 cpl_frame* grid_backg=NULL;
00546 cpl_frame* frame_backg=NULL;
00547 cpl_frameset* rect_frameset_eso=NULL;
00548 cpl_frameset* rect_frameset_tab=NULL;
00549 const char* ftag=NULL;
00550 char tag[256];
00551 char rec_prefix[80];
00552 int pre_overscan_corr=0;
00553
00554
00555
00556
00557
00558
00559
00560 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
00561 recipe_tags, recipe_tags_size,RECIPE_ID, XSH_BINARY_VERSION,
00562 xsh_geom_ifu_description_short));
00563
00564 assure( instrument->mode == XSH_MODE_IFU, CPL_ERROR_ILLEGAL_INPUT,
00565 "Instrument NOT in IFU Mode");
00566
00567
00568 check( nb_raw_frames = cpl_frameset_get_size( raws ) ) ;
00569 XSH_ASSURE_NOT_ILLEGAL( nb_raw_frames == 1 || nb_raw_frames >= 3 ) ;
00570 check(strcpy(rec_prefix,
00571 xsh_set_recipe_file_prefix(raws,"xsh_geom_ifu")));
00572
00573
00574
00575 bpmap = xsh_find_master_bpmap(calib);
00576
00577
00578 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR){
00579
00580 check( master_bias = xsh_find_master_bias(calib,instrument));
00581 }
00582 #if 0
00583
00584
00585 else {
00586
00587 xsh_msg( "Calling xsh_dfs_split_nir" ) ;
00588 check(xsh_dfs_split_nir(raws, &on, &off));
00589 xsh_msg( " Nb ON: %d, OFF: %d", cpl_frameset_get_size(on),
00590 cpl_frameset_get_size(off) ) ;
00591 XSH_ASSURE_NOT_ILLEGAL(cpl_frameset_get_size(on) >= 3);
00592 XSH_ASSURE_NOT_ILLEGAL(cpl_frameset_get_size(off) >= 3);
00593 }
00594 #endif
00595
00596 check( order_tab_edges = xsh_find_order_tab_edges( calib, instrument));
00597
00598
00599 model_config_frame = xsh_find_model_config( calib, instrument);
00600 xsh_error_reset();
00601
00602 wave_tabs_ifu = xsh_find_wave_tab_ifu( calib, instrument);
00603 xsh_error_reset();
00604
00605 if( (model_config_frame!=NULL) && (wave_tabs_ifu != NULL) ) {
00606
00607 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",
00608 XSH_WAVE_TAB_2D , XSH_MOD_CFG_TAB);
00609 goto cleanup;
00610 }
00611
00612 if((model_config_frame==NULL) && ( wave_tabs_ifu == NULL) ) {
00613 xsh_msg_error("You must provide either a %s or a %s frame",
00614 XSH_WAVE_TAB_2D, XSH_MOD_CFG_TAB);
00615 goto cleanup;
00616 }
00617
00618 if ( (master_dark = xsh_find_master_dark( calib, instrument ) ) == NULL ){
00619 xsh_msg_warning("Frame %s not provided",XSH_MASTER_DARK);
00620 xsh_error_reset();
00621 }
00622
00623 check( masterflat_frame = xsh_find_master_flat( calib, instrument));
00624 check(spectralformat_frame = xsh_find_spectral_format( calib, instrument ) ) ;
00625
00626
00627
00628
00629 recipe_use_model = ( model_config_frame != NULL);
00630
00631 check( crh_clipping_par = xsh_parameters_clipping_crh_get(RECIPE_ID,
00632 parameters));
00633 check( backg_par = xsh_parameters_background_get(RECIPE_ID,
00634 parameters));
00635
00636 check( loc_obj_par = xsh_parameters_localize_obj_get(RECIPE_ID,
00637 parameters));
00638 check( rectify_par = xsh_parameters_rectify_get(RECIPE_ID,
00639 parameters));
00640 check( crh_single_par = xsh_parameters_remove_crh_single_get(RECIPE_ID,
00641 parameters));
00642
00643 check( do_computemap = xsh_parameters_get_boolean( parameters, RECIPE_ID,
00644 "compute-map"));
00645
00646 check( slicedist_lambda = xsh_parameters_get_double( parameters, RECIPE_ID,
00647 "slicedist-lambda"));
00648
00649 check( slicedist_global = xsh_parameters_get_boolean( parameters, RECIPE_ID,
00650 "slicedist-global"));
00651
00652 if ( do_computemap && recipe_use_model==FALSE){
00653 check( disp_tab_frame = xsh_find_disp_tab( calib, instrument));
00654 }
00655
00656
00657
00658 check(xsh_params_set_defaults(parameters,instrument,rectify_par));
00659
00660 if ( xsh_instrument_get_arm( instrument ) != XSH_ARM_NIR ) {
00661 check(xsh_params_bin_scale(raws,backg_par));
00662 }
00663 check(xsh_params_monitor(backg_par,rectify_par,loc_obj_par));
00664
00665
00666
00667
00668
00669
00670
00671
00672 xsh_msg( "---Prepare raws frames");
00673 check( xsh_prepare( raws, bpmap, master_bias, XSH_OBJECT_IFU_STARE,
00674 instrument,pre_overscan_corr));
00675
00676
00677
00678 if ( nb_raw_frames >= 3 ) {
00679 xsh_msg( "---Remove cosmics");
00680
00681 ftag=XSH_GET_TAG_FROM_ARM(XSH_SLIT_STARE_REMOVE_CRH,instrument);
00682 check_msg( crhm_frame = xsh_remove_crh_multiple( raws,
00683 ftag,
00684 crh_clipping_par,
00685 instrument, NULL,NULL ),
00686 "Error in xsh_remove_crh" ) ;
00687 }
00688 else {
00689
00690 check( crhm_frame = cpl_frame_duplicate(cpl_frameset_get_first( raws )));
00691 }
00692 xsh_msg( "created %s", cpl_frame_get_filename( crhm_frame));
00693
00694 if ( do_computemap){
00695 if (recipe_use_model){
00696 char wave_map_tag[80];
00697 char slit_map_tag[80];
00698 int found_temp=true;
00699
00700 check(xsh_model_temperature_update_frame(&model_config_frame,crhm_frame,
00701 instrument,&found_temp));
00702
00703 sprintf(wave_map_tag,"%s_%s",rec_prefix,XSH_WAVE_MAP_MODEL);
00704 sprintf(slit_map_tag,"%s_%s",rec_prefix,XSH_SLIT_MAP_MODEL);
00705 check( xsh_create_model_map( model_config_frame, instrument,
00706 wave_map_tag,slit_map_tag,
00707 &wavemap_frame, &slitmap_frame));
00708 }
00709 else{
00710 xsh_msg( "Compute the wave map and the slit map");
00711 check( xsh_create_map( disp_tab_frame, order_tab_edges,
00712 crhm_frame, instrument,
00713 &wavemap_frame, &slitmap_frame,rec_prefix));
00714 }
00715 cpl_frameset_insert( calib, wavemap_frame);
00716 cpl_frameset_insert( calib, slitmap_frame);
00717 }
00718 else{
00719 check( wavemap_frame = xsh_find_wavemap( calib, instrument));
00720 slitmap_frame = xsh_find_slitmap(calib, instrument);
00721 }
00722
00723
00724 if ( xsh_instrument_get_arm(instrument) == XSH_ARM_NIR ) {
00725
00726 check( rmbias = cpl_frame_duplicate(cpl_frameset_get_first( raws )));
00727 }
00728 else {
00729
00730 xsh_msg( "---Subtract bias");
00731 check(rmbias = xsh_subtract_bias(crhm_frame,master_bias,instrument,
00732 "GEOM_IFU" ));
00733 }
00734
00735 if ( master_dark != NULL ) {
00736 xsh_msg( "---Subtract_dark");
00737 check( rmdark = xsh_subtract_dark(rmbias, master_dark,
00738 "IFU_STARE_DARK.fits",instrument));
00739 }
00740 else {
00741 xsh_msg( "No Master Dark" ) ;
00742 check( rmdark = cpl_frame_duplicate( rmbias ) ) ;
00743 }
00744
00745
00746 xsh_msg("---Subtract_background");
00747 check( rmbkg = xsh_subtract_background( rmdark,
00748 order_tab_edges, backg_par, instrument, "GEOM_IFU",&grid_backg,
00749 &frame_backg ));
00750
00751
00752 xsh_msg("---Do flatfielding");
00753 sprintf( tag, "GEOM_IFU_FF_%s",
00754 xsh_instrument_arm_tostring(instrument));
00755 check( div_frame = xsh_divide_flat( rmbkg, masterflat_frame,
00756 tag, instrument));
00757
00758
00759 xsh_msg( "---Do rectify for ifu");
00760 rect_frameset_eso=cpl_frameset_new();
00761 rect_frameset_tab=cpl_frameset_new();
00762
00763 if ( slicedist_global ){
00764 check( rect_frameset = xsh_rectify_ifu( div_frame, order_tab_edges,
00765 wave_tabs_ifu, model_config_frame, instrument, rectify_par,
00766 spectralformat_frame, NULL, slitmap_frame,
00767 &rect_frameset_eso, &rect_frameset_tab, "GEOM_IFU"));
00768 }
00769 else{
00770 double lambda_ref_min;
00771 double lambda_ref_max;
00772 const char * tablename = NULL;
00773 cpl_table *table = NULL;
00774 cpl_frame *spectralformat2_frame = NULL;
00775 xsh_spectralformat_list* list = NULL;
00776 xsh_order_list *order_list = NULL;
00777 cpl_vector* orders = NULL;
00778 int size, absorder, iorder;
00779
00780 if ( loc_obj_par->loc_chunk_nb != 1){
00781 xsh_msg("WARNING local mode force LOCALIZATION chunk number to 1");
00782 loc_obj_par->loc_chunk_nb = 1;
00783 }
00784 if ( loc_obj_par->loc_deg_poly != 0){
00785 xsh_msg("WARNING local mode force LOCALIZATION deg poly to 0");
00786 loc_obj_par->loc_deg_poly = 0;
00787 }
00788 if ( loc_obj_par->niter != 0){
00789 xsh_msg("WARNING local mode force LOCALIZATION to disable sigma clipping (niter=0)");
00790 loc_obj_par->niter = 0;
00791 }
00792
00793 check( list = xsh_spectralformat_list_load( spectralformat_frame,
00794 instrument));
00795
00796 check( order_list = xsh_order_list_load ( order_tab_edges, instrument));
00797 if ( slicedist_lambda == -1){
00798 slicedist_lambda = (list->list[0].lambda_min+
00799 list->list[list->size-1].lambda_max)/2.0;
00800 }
00801 lambda_ref_min = slicedist_lambda-0.5;
00802 lambda_ref_max = slicedist_lambda+0.5;
00803
00804 xsh_msg( "Lambda from %f to %f", lambda_ref_min, lambda_ref_max);
00805 check( list = xsh_spectralformat_list_load( spectralformat_frame,
00806 instrument));
00807 check( orders = xsh_spectralformat_list_get_orders( list, slicedist_lambda));
00808 size = cpl_vector_get_size( orders);
00809
00810 tablename = cpl_frame_get_filename( spectralformat_frame);
00811 XSH_TABLE_LOAD( table, tablename);
00812
00813 for( iorder=0; iorder < size; iorder++){
00814 absorder = cpl_vector_get( orders, iorder);
00815 cpl_table_set_int(table, XSH_SPECTRALFORMAT_TABLE_COLNAME_ORDER, iorder, absorder);
00816 cpl_table_set_float(table, XSH_SPECTRALFORMAT_TABLE_COLNAME_WLMIN, iorder, lambda_ref_min);
00817 cpl_table_set_float(table, XSH_SPECTRALFORMAT_TABLE_COLNAME_WLMAX, iorder, lambda_ref_max);
00818 }
00819 cpl_table_save( table, NULL,NULL,"LAMBDA_REF_FORMAT.fits",CPL_IO_DEFAULT);
00820 spectralformat2_frame = cpl_frame_duplicate( spectralformat_frame);
00821 cpl_frame_set_filename( spectralformat2_frame, "LAMBDA_REF_FORMAT.fits");
00822
00823 check( rect_frameset = xsh_rectify_orders_ifu( div_frame, order_list,
00824 wave_tabs_ifu, model_config_frame, instrument, rectify_par,
00825 spectralformat2_frame, NULL, slitmap_frame, &rect_frameset_eso, &rect_frameset_tab, 0,
00826 size-1, "GEOM_IFU"));
00827 }
00828
00829
00830 xsh_msg( "---Localize the objects for IFU");
00831
00832 check( loc_frameset = xsh_localize_obj_ifu( rect_frameset,
00833 NULL, instrument, loc_obj_par, NULL));
00834
00835
00836
00837 xsh_msg( "---Compute slice offset");
00838 check( slice_offset = xsh_compute_slice_dist( loc_frameset,
00839 order_tab_edges, slitmap_frame, rect_frameset, slicedist_lambda,
00840 instrument));
00841
00842
00843 xsh_msg( "---Save products");
00844 check( xsh_add_product_table( slice_offset, frameset,
00845 parameters, RECIPE_ID, instrument));
00846
00847 xsh_msg( "---End of GEOM_IFU recipe");
00848
00849 cleanup:
00850 xsh_end( RECIPE_ID, frameset, parameters );
00851 XSH_FREE( crh_clipping_par);
00852 XSH_FREE( backg_par);
00853 XSH_FREE( crh_single_par);
00854 XSH_FREE( rectify_par);
00855 XSH_FREE( loc_obj_par);
00856 xsh_instrument_free( &instrument);
00857
00858 xsh_free_frameset( &raws);
00859 xsh_free_frameset( &calib);
00860 xsh_free_frameset( &wave_tabs_ifu);
00861
00862 xsh_free_frame( &crhm_frame ) ;
00863 xsh_free_frame( &rmbias);
00864 xsh_free_frame( &rmdark);
00865 xsh_free_frame( &rmbkg);
00866 xsh_free_frame( &div_frame);
00867
00868 xsh_free_frameset( &rect_frameset);
00869 xsh_free_frameset( &rect_frameset_eso);
00870 xsh_free_frameset( &rect_frameset_tab) ;
00871 xsh_free_frameset( &loc_frameset) ;
00872
00873 xsh_free_frame( &clean_frame);
00874 xsh_free_frame( &slice_offset);
00875 xsh_free_frame( &grid_backg);
00876 xsh_free_frame( &frame_backg);
00877
00878 return;
00879 }
00880