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_image.h>
00053 #include <xsh_utils_ifu.h>
00054 #include <xsh_msg.h>
00055
00056 #include <xsh_dfs.h>
00057 #include <xsh_pfits.h>
00058
00059 #include <xsh_drl_check.h>
00060 #include <xsh_drl.h>
00061 #include <xsh_data_spectrum1D.h>
00062 #include <xsh_model_arm_constants.h>
00063 #include <xsh_blaze.h>
00064
00065 #include <cpl.h>
00066
00067
00068
00069
00070
00071
00072 #define RECIPE_ID "xsh_scired_ifu_stare_drl"
00073 #define RECIPE_AUTHOR "P.Goldoni, L.Guglielmi, R. Haigron, F. Royer"
00074 #define RECIPE_CONTACT "amodigli@eso.org"
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 static int xsh_scired_ifu_stare_create(cpl_plugin *);
00085 static int xsh_scired_ifu_stare_exec(cpl_plugin *);
00086 static int xsh_scired_ifu_stare_destroy(cpl_plugin *);
00087
00088
00089 static void xsh_scired_ifu_stare(cpl_parameterlist *, cpl_frameset *);
00090
00091
00092
00093
00094 static char xsh_scired_ifu_stare_description_short[] =
00095 "Reduce science exposure in IFU configuration and stare mode";
00096
00097 static char xsh_scired_ifu_stare_description[] =
00098 "This recipe reduces science exposure in IFU configuration and stare mode\n\
00099 Input Frames : \n\
00100 - A set of n Science frames ( n == 1 or >=3, \
00101 Tag = OBJECT_IFU_STARE_arm or STD_TELL_IFU_STARE_arm or STD_FLUX_IFU_STARE_arm)\n\
00102 - A spectral format table (Tag = SPECTRAL_FORMAT_TAB_arm)\n\
00103 - [UVB,VIS] A master bias frame (Tag = MASTER_BIAS_arm)\n\
00104 - [OPTIONAL]A master dark frame (Tag = MASTER_DARK_arm)\n\
00105 - A master flat frame (Tag = MASTER_FLAT_IFU_arm)\n\
00106 - An AFC corrected order table frame (Tag = ORDER_TAB_AFC_IFU_arm)\n\
00107 - [physmod] An AFC corrected model cfg frame (Tag = XSH_MOD_CFG_OPT_AFC_arm)\n\
00108 - [poly] An AFC corrected model wavesol frame (Tag = WAVE_TAB_AFC_arm) \n\
00109 - [OPTIONAL] An AFC corrected dispersion solution frame (Tag = DISP_TAB_AFC_arm)\n\
00110 - [OPTIONAL] A slit map (Tag = SLIT_MAP_arm)\n\
00111 - [OPTIONAL] A badpixel map (Tag = BADPIXEL_MAP_arm)\n\
00112 - [OPTIONAL] A mask of telluric lines (Tag = TELL_MASK_arm)\n\
00113 Products : \n\
00114 - 3 Spectrum order tables 2D (1 per slitlet), PRO.CATG=ORDER2D_slitlet_IFU_arm\n\
00115 - 3 Spectrum merge tables 2D (1 per slitlet), PRO.CATG=MERGE2D_slitlet_IFU_arm\n\
00116 - 1 Spectrum merge 3D, PRO.CATG=MERGE3D_IFU_arm\n" ;
00117
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 cpl_parameter* p=NULL;
00178 char paramname[256];
00179 char recipename[256];
00180 xsh_clipping_param crh_clip_param = {5.0, 5, 0.7, 0,0.3};
00181
00182 xsh_remove_crh_single_param crh_single = { 0.1, 5, 2.0, 4} ;
00183 xsh_rectify_param rectify = { "default",
00184 CPL_KERNEL_DEFAULT,
00185 4,
00186 XSH_WAVE_BIN_SIZE_PIPE_NIR,
00187 XSH_SLIT_BIN_SIZE_PIPE_NIR,
00188 1,
00189 0, 0.};
00190
00191 xsh_stack_param stack_param = {"median",5.,5.,5};
00192
00193 xsh_localize_obj_param loc_obj =
00194 {10, 0.1, 0, 0, LOC_MANUAL_METHOD, 0, 2.0,3,3,FALSE};
00195 xsh_extract_param extract_par =
00196 { LOCALIZATION_METHOD};
00197
00198
00199 xsh_init();
00200
00201
00202 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
00203
00204
00205 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00206 CPL_ERROR_TYPE_MISMATCH,
00207 "Plugin is not a recipe");
00208
00209 recipe = (cpl_recipe *)plugin;
00210
00211
00212 recipe->parameters = cpl_parameterlist_new();
00213 assure( recipe->parameters != NULL,
00214 CPL_ERROR_ILLEGAL_OUTPUT,
00215 "Memory allocation failed!");
00216
00217
00218 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
00219 check( xsh_parameters_pre_overscan( RECIPE_ID, recipe->parameters ) ) ;
00220 check(xsh_parameters_stack_create(RECIPE_ID,recipe->parameters,stack_param));
00221
00222 check(xsh_parameters_clipping_crh_create(RECIPE_ID,recipe->parameters,
00223 crh_clip_param));
00224
00225
00226 check(xsh_parameters_background_create(RECIPE_ID,recipe->parameters));
00227 check(p=xsh_parameters_find(recipe->parameters,RECIPE_ID,"background-method"));
00228 cpl_parameter_set_default_string(p,"poly");
00229
00230
00231 check(xsh_parameters_remove_crh_single_create(RECIPE_ID,recipe->parameters,
00232 crh_single )) ;
00233
00234
00235 check(xsh_parameters_rectify_create(RECIPE_ID,recipe->parameters,
00236 rectify )) ;
00237
00238
00239 check(xsh_parameters_localize_obj_create(RECIPE_ID,recipe->parameters,
00240 loc_obj )) ;
00241
00242
00243
00244 check(xsh_parameters_extract_create(RECIPE_ID,
00245 recipe->parameters,
00246 extract_par,LOCALIZATION_METHOD )) ;
00247
00248 check(xsh_parameters_merge_ord_create(RECIPE_ID,
00249 recipe->parameters,
00250 WEIGHTED_MERGE_METHOD)) ;
00251
00252
00253 check( xsh_parameters_new_double( recipe->parameters, RECIPE_ID,
00254 "shift-offsettab-low", 0.0,
00255 "Global shift of the lower slitlet slit positions, relative to the central one[arcsec]."));
00256 check( xsh_parameters_new_double( recipe->parameters, RECIPE_ID,
00257 "shift-offsettab-up", 0.0,
00258 "Global shift of the upper slitlet slit positions, relative to the central one[arcsec]."));
00259
00260 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00261 "compute-map", TRUE,
00262 "if TRUE recompute (wave and slit) maps from the dispersion solution. If sky-subtract is set to TRUE this must be set to TRUE."));
00263
00264 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00265 "check-afc", TRUE,
00266 "Input AFC corrected model/wave solution and science frame check."\
00267 "If TRUE the recipe verify that the input mode/wave solution is AFC corrected,"\
00268 " its INS.OPTIi.NAME is 'Pin_0.5 ', and its OBS.ID and OBS.TARG.NAME values"\
00269 " matches with the corresponding values of the science frame."));
00270
00271 sprintf(recipename,"xsh.%s",RECIPE_ID);
00272 sprintf(paramname,"%s.%s",recipename,"flat-method");
00273 check( p = cpl_parameter_new_enum( paramname,CPL_TYPE_STRING,
00274 "method adopted for flat:",
00275 recipename,"master",
00276 2,"master","blaze"));
00277
00278 check(cpl_parameter_set_alias( p,CPL_PARAMETER_MODE_CLI,
00279 "flat-method"));
00280 check(cpl_parameterlist_append( recipe->parameters, p));
00281
00282 cleanup:
00283 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
00284 xsh_error_dump(CPL_MSG_ERROR);
00285 return 1;
00286 }
00287 else {
00288 return 0;
00289 }
00290 }
00291
00292
00298
00299
00300 static int xsh_scired_ifu_stare_exec(cpl_plugin *plugin) {
00301 cpl_recipe *recipe = NULL;
00302
00303
00304
00305 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00306
00307
00308 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00309 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00310
00311 recipe = (cpl_recipe *)plugin;
00312
00313
00314 xsh_scired_ifu_stare(recipe->parameters, recipe->frames);
00315
00316 cleanup:
00317 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
00318 xsh_error_dump(CPL_MSG_ERROR);
00319 xsh_error_reset();
00320 return 1;
00321 }
00322 else {
00323 return 0;
00324 }
00325 }
00326
00327
00333
00334 static int xsh_scired_ifu_stare_destroy(cpl_plugin *plugin)
00335 {
00336 cpl_recipe *recipe = NULL;
00337
00338
00339 xsh_error_reset();
00340
00341 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00342
00343
00344 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00345 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00346
00347 recipe = (cpl_recipe *)plugin;
00348
00349 xsh_free_parameterlist(&recipe->parameters);
00350
00351 cleanup:
00352 if (cpl_error_get_code() != CPL_ERROR_NONE)
00353 {
00354 return 1;
00355 }
00356 else
00357 {
00358 return 0;
00359 }
00360 }
00361
00362
00363
00364
00365 static cpl_error_code
00366 xsh_params_set_defaults(cpl_parameterlist* pars,
00367 xsh_instrument* inst,
00368 xsh_rectify_param * rectify_par,
00369 xsh_background_param* backg)
00370 {
00371 cpl_parameter* p=NULL;
00372
00373 check(p=xsh_parameters_find(pars,RECIPE_ID,"background-radius-x"));
00374 if(cpl_parameter_get_int(p) <= 0) {
00375 if (xsh_instrument_get_arm(inst) == XSH_ARM_NIR){
00376 backg->radius_x=1;
00377 } else {
00378 backg->radius_x=2;
00379 }
00380 cpl_parameter_set_int(p,backg->radius_x);
00381 }
00382 check(xsh_rectify_params_set_defaults(pars,RECIPE_ID,inst,rectify_par));
00383
00384 cleanup:
00385
00386 return cpl_error_get_code();
00387
00388 }
00389
00390
00391
00392 static cpl_error_code
00393 xsh_params_monitor(xsh_background_param* backg,
00394 xsh_rectify_param * rectify_par,
00395 xsh_localize_obj_param * loc_obj_par)
00396 {
00397
00398
00399 xsh_msg_dbg_low("bkg params: sampley=%d radius_y=%d smooth_y=%d",
00400 backg->sampley,backg->radius_y,backg->smooth_y);
00401
00402 xsh_msg_dbg_low("bkg params: radius_x=%d smooth_x=%d",
00403 backg->radius_x,backg->smooth_x);
00404
00405 xsh_msg_dbg_low("rectify params: radius=%g bin_lambda=%g bin_space=%g",
00406 rectify_par->rectif_radius,rectify_par->rectif_bin_lambda,
00407 rectify_par->rectif_bin_space);
00408
00409 xsh_msg_dbg_low("localize params: chunk_nb=%d nod_step=%g",
00410 loc_obj_par->loc_chunk_nb,loc_obj_par->nod_step);
00411
00412 return cpl_error_get_code();
00413
00414 }
00415
00423
00424
00425 static cpl_error_code
00426 xsh_params_bin_scale(cpl_frameset* raws,
00427 xsh_background_param* backg)
00428 {
00429
00430 cpl_frame* frame=NULL;
00431 const char* name=NULL;
00432 cpl_propertylist* plist=NULL;
00433 int binx=0;
00434 int biny=0;
00435
00436 check(frame=cpl_frameset_get_first(raws));
00437 check(name=cpl_frame_get_filename(frame));
00438 check(plist=cpl_propertylist_load(name,0));
00439 check(binx=xsh_pfits_get_binx(plist));
00440 check(biny=xsh_pfits_get_biny(plist));
00441 xsh_free_propertylist(&plist);
00442
00443 if(biny>1) {
00444
00445
00446
00447
00448
00449
00450 backg->radius_y=backg->radius_y/biny;
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480 }
00481
00482
00483 if(binx>1) {
00484
00485 backg->radius_x=backg->radius_x/binx;
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507 }
00508
00509 cleanup:
00510 xsh_free_propertylist(&plist);
00511 return cpl_error_get_code();
00512
00513 }
00514
00515
00523
00524 static void xsh_scired_ifu_stare(cpl_parameterlist* parameters,
00525 cpl_frameset* frameset)
00526 {
00527 const char* recipe_tags[3] = {XSH_OBJECT_IFU_STARE,
00528 XSH_STD_TELL_IFU_STARE,
00529 XSH_STD_FLUX_IFU_STARE};
00530 int recipe_tags_size = 3;
00531
00532
00533 xsh_instrument *instrument = NULL;
00534 int nb_raw_frames ;
00535 cpl_frameset *raws = NULL;
00536 cpl_frameset *calib = NULL;
00537
00538
00539 cpl_frame *bpmap = NULL;
00540 cpl_frame *master_bias = NULL;
00541 cpl_frame *master_dark = NULL;
00542 cpl_frame *master_flat = NULL;
00543 cpl_frame *order_tab_edges = NULL;
00544 cpl_frame *wavetab_frame = NULL;
00545 cpl_frameset *wavetab_frameset = NULL ;
00546 cpl_frame *model_config_frame = NULL ;
00547 cpl_frame *spectral_format = NULL ;
00548 cpl_frame *disp_tab_frame = NULL;
00549 cpl_frame *shifttab_frame = NULL;
00550
00551
00552 xsh_clipping_param *crh_clipping_par = NULL;
00553 xsh_background_param *backg_par = NULL;
00554 xsh_remove_crh_single_param *crh_single_par = NULL ;
00555 xsh_rectify_param *rectify_par = NULL ;
00556 xsh_localize_obj_param *loc_obj_par = NULL ;
00557 xsh_merge_param *merge_par = NULL;
00558 xsh_extract_param *extract_par = NULL ;
00559 double offset_low =0.0;
00560 double offset_up =0.0;
00561
00562 xsh_stack_param* stack_par=NULL;
00563
00564 int recipe_use_model = FALSE;
00565 int do_computemap = 0;
00566 int check_afc = TRUE;
00567
00568
00569 cpl_frame *slitmap_frame = NULL;
00570 cpl_frame *wavemap_frame = NULL;
00571 cpl_frame *crhm_frame = NULL ;
00572 cpl_frame *rmbias = NULL;
00573 cpl_frame *rmdark = NULL;
00574 cpl_frame *rmbkg = NULL ;
00575 cpl_frame *clean_frame = NULL ;
00576 cpl_frame *div_frame = NULL ;
00577 cpl_frameset *rect_frameset = NULL ;
00578 cpl_frameset *loc_table_frameset = NULL ;
00580
00581 cpl_frameset *res_2D_frameset = NULL ;
00582 cpl_frame *data_cube = NULL ;
00583 char div_tag[80];
00584 char prefix[80];
00585 const char * ftag=NULL;
00586 cpl_frame* grid_backg=NULL;
00587 cpl_frame* frame_backg=NULL;
00588 cpl_frameset* rect_frameset_eso=NULL;
00589 cpl_frameset* rect_frameset_tab=NULL;
00590 char *rec_prefix = NULL;
00591 int pre_overscan_corr=0;
00592
00593 cpl_frameset *shiftifu_frameset = NULL;
00594 cpl_frameset *nshiftifu_frameset = NULL;
00595 int i;
00596
00597 cpl_propertylist* plist=NULL;
00598 const char* name=NULL;
00599 const char* tag="";
00600 int naxis2=0;
00601 cpl_frame* qc_trace_frame=NULL;
00602 int save_size=0;
00603 const int peack_search_hsize=5;
00604 int method=0;
00605 char* flat_method = NULL;
00606
00607 cpl_frame *tellmask_frame = NULL;
00608 cpl_frame * blaze_frame = NULL;
00609
00610
00611
00612
00613 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
00614 recipe_tags, recipe_tags_size,
00615 RECIPE_ID, XSH_BINARY_VERSION,
00616 xsh_scired_ifu_stare_description_short ) ) ;
00617
00618 assure( instrument->mode == XSH_MODE_IFU, CPL_ERROR_ILLEGAL_INPUT,
00619 "Instrument NOT in IFU Mode" ) ;
00620
00621 xsh_recipe_params_check(parameters,instrument,RECIPE_ID);
00622
00623 check( nb_raw_frames = cpl_frameset_get_size( raws));
00624
00625 XSH_ASSURE_NOT_ILLEGAL_MSG( nb_raw_frames == 1 || nb_raw_frames >= 3,
00626 "This recipe expects either one or at least 3 input raw frames" );
00627
00628
00629
00630
00631
00632 bpmap = xsh_find_master_bpmap(calib);
00633
00634
00635 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR){
00636
00637 check( master_bias = xsh_find_frame_with_tag(calib,XSH_MASTER_BIAS,
00638 instrument));
00639 }
00640
00641 if(NULL==(order_tab_edges=xsh_find_frame_with_tag(calib,XSH_ORDER_TAB_AFC_IFU,
00642 instrument))) {
00643 xsh_msg_error("Missing frame %s_%s", XSH_ORDER_TAB_AFC_IFU,
00644 xsh_instrument_arm_tostring( instrument ));
00645 goto cleanup;
00646 }
00647
00648
00649 check(model_config_frame=xsh_find_frame_with_tag(calib,XSH_MOD_CFG_OPT_AFC,
00650 instrument));
00651 if(model_config_frame==NULL) {
00652 wavetab_frame = xsh_find_wave_tab( calib, instrument);
00653 }
00654
00655
00656
00657 if ( model_config_frame == NULL){
00658 xsh_msg("RECIPE USE WAVE SOLUTION");
00659 recipe_use_model = FALSE;
00660 }
00661 else{
00662 xsh_msg("RECIPE USE MODEL");
00663 recipe_use_model = TRUE;
00664 }
00665 XSH_ASSURE_NOT_ILLEGAL( (model_config_frame != NULL && wavetab_frame == NULL ) ||
00666 (model_config_frame == NULL && wavetab_frame != NULL ) );
00667
00668 check( master_flat = xsh_find_master_flat( calib, instrument ) ) ;
00669 if((master_dark = xsh_find_frame_with_tag(calib,XSH_MASTER_DARK,
00670 instrument)) == NULL){
00671 xsh_msg_warning("Frame %s not provided",XSH_MASTER_DARK);
00672 xsh_error_reset();
00673 }
00674 check(spectral_format=xsh_find_spectral_format( calib, instrument ) ) ;
00675 check( xsh_instrument_update_from_spectralformat( instrument,
00676 spectral_format));
00677
00678
00679 shiftifu_frameset = xsh_find_offset_tab_ifu( calib,
00680 instrument);
00681 xsh_error_reset();
00682
00683 tellmask_frame = xsh_find_frame_with_tag( calib, XSH_TELL_MASK,
00684 instrument);
00685 xsh_error_reset() ;
00686
00687 shifttab_frame = xsh_find_frame_with_tag( calib, XSH_SHIFT_TAB_IFU,
00688 instrument);
00689 xsh_error_reset() ;
00690
00691 if ( recipe_use_model == FALSE){
00692 check( wavetab_frameset = xsh_ifu_wavetab_create( wavetab_frame,
00693 shifttab_frame, instrument));
00694 }
00695
00696
00697
00698
00699 check( stack_par = xsh_stack_frames_get( RECIPE_ID, parameters));
00700 check( crh_clipping_par = xsh_parameters_clipping_crh_get(RECIPE_ID,
00701 parameters));
00702 check( backg_par = xsh_parameters_background_get(RECIPE_ID,
00703 parameters));
00704
00705 check( loc_obj_par = xsh_parameters_localize_obj_get(RECIPE_ID,
00706 parameters));
00707 check( rectify_par = xsh_parameters_rectify_get(RECIPE_ID,
00708 parameters));
00709 check( crh_single_par = xsh_parameters_remove_crh_single_get(RECIPE_ID,
00710 parameters));
00711 check( merge_par = xsh_parameters_merge_ord_get(RECIPE_ID,
00712 parameters));
00713 check( extract_par = xsh_parameters_extract_get( RECIPE_ID, parameters));
00714
00715 check( do_computemap = xsh_parameters_get_boolean( parameters, RECIPE_ID,
00716 "compute-map"));
00717
00718 check( check_afc = xsh_parameters_get_boolean( parameters, RECIPE_ID,
00719 "check-afc"));
00720
00721 if ( do_computemap && recipe_use_model==FALSE){
00722 check( disp_tab_frame = xsh_find_disp_tab( calib, instrument));
00723 }
00724
00725 check(xsh_params_set_defaults(parameters,instrument,rectify_par,backg_par));
00726
00727 if ( xsh_instrument_get_arm( instrument ) != XSH_ARM_NIR ) {
00728 check(xsh_params_bin_scale(raws,backg_par));
00729 }
00730 check(xsh_params_monitor(backg_par,rectify_par,loc_obj_par));
00731
00732 check( offset_low = xsh_parameters_get_double( parameters, RECIPE_ID,
00733 "shift-offsettab-low"));
00734
00735 check( offset_up = xsh_parameters_get_double( parameters, RECIPE_ID,
00736 "shift-offsettab-up"));
00737
00738
00739 if ( shiftifu_frameset != NULL){
00740 xsh_msg("offset low %f up %f", offset_low, offset_up);
00741 check( nshiftifu_frameset = xsh_shift_offsettab( shiftifu_frameset,
00742 offset_low, offset_up));
00743 }
00744
00745
00746
00747
00748
00749 check( xsh_prepare( raws, bpmap, master_bias, XSH_OBJECT_IFU_STARE,
00750 instrument,pre_overscan_corr));
00751
00752 check( rec_prefix = xsh_set_recipe_file_prefix( raws,
00753 RECIPE_ID));
00754
00755
00756 ftag = XSH_GET_TAG_FROM_ARM( XSH_IFU_STARE_REMOVE_CRH, instrument);
00757 check( crhm_frame = xsh_check_remove_crh_multiple( raws, ftag,
00758 stack_par,crh_clipping_par, instrument, NULL, NULL));
00759
00760
00761 check( xsh_check_get_map( disp_tab_frame, order_tab_edges,
00762 crhm_frame, model_config_frame, calib, instrument,
00763 do_computemap, recipe_use_model, rec_prefix,
00764 &wavemap_frame, &slitmap_frame));
00765
00766
00767 sprintf(prefix,"%s_",rec_prefix);
00768
00769 check( rmbias = xsh_check_subtract_bias( crhm_frame, master_bias,
00770 instrument, rec_prefix,
00771 pre_overscan_corr,0));
00772
00773
00774
00775
00776 check( xsh_check_afc( check_afc, model_config_frame,
00777 rmbias, wavetab_frameset, order_tab_edges, disp_tab_frame,
00778 instrument));
00779
00780
00781 check( rmdark = xsh_check_subtract_dark( rmbias, master_dark,
00782 instrument, rec_prefix));
00783
00784
00785 xsh_msg("Subtract inter-order background");
00786 check(rmbkg = xsh_subtract_background( rmdark,
00787 order_tab_edges,
00788 backg_par, instrument,
00789 rec_prefix,&grid_backg,
00790 &frame_backg,0 ));
00791
00792 if ( nb_raw_frames == 1 ) {
00793 char * nocrh_tag = NULL ;
00794
00795 nocrh_tag = xsh_stringcat_any("NOCRH_",
00796 xsh_instrument_arm_tostring(instrument),
00797 NULL) ;
00798 xsh_msg( "Remove crh (single frame)" ) ;
00799 check( clean_frame = xsh_remove_crh_single( rmbkg, wavemap_frame,
00800 instrument,
00801 crh_single_par,
00802 nocrh_tag ) ) ;
00803 XSH_FREE( nocrh_tag ) ;
00804 }
00805 else {
00806 clean_frame = cpl_frame_duplicate( rmbkg) ;
00807 }
00808
00809 xsh_msg( "---Divide by flat" ) ;
00810 sprintf(div_tag,"%s_DIV_FF_%s",
00811 rec_prefix,xsh_instrument_arm_tostring(instrument)) ;
00812
00813 check( flat_method = xsh_parameters_get_string( parameters, RECIPE_ID,
00814 "flat-method"));
00815
00816 xsh_msg("method %s", flat_method);
00817
00818 if ( strcmp( flat_method, "master") == 0){
00819 check( div_frame = xsh_divide_flat( clean_frame, master_flat,
00820 div_tag, instrument));
00821 }
00822 else{
00823 xsh_msg("---Create blaze image");
00824 check( blaze_frame = xsh_blaze_image( master_flat, order_tab_edges,
00825 instrument));
00826 check( div_frame = xsh_divide_by_blaze( clean_frame,
00827 blaze_frame, instrument));
00828 }
00829
00830
00831
00832 xsh_msg( "---Rectify ifu");
00833 rect_frameset_eso=cpl_frameset_new();
00834 rect_frameset_tab=cpl_frameset_new();
00835 check( rect_frameset = xsh_rectify_ifu( div_frame, order_tab_edges,
00836 wavetab_frameset,
00837 nshiftifu_frameset,
00838 model_config_frame,
00839 instrument, rectify_par,
00840 spectral_format,
00841 slitmap_frame, &rect_frameset_eso,
00842 &rect_frameset_tab,rec_prefix ));
00843
00844
00845 check( loc_table_frameset = xsh_localize_obj_ifu( rect_frameset, NULL,
00846 instrument,
00847 loc_obj_par, NULL));
00848 xsh_msg( "Merge orders with 2D frame" ) ;
00849 check( res_2D_frameset = xsh_merge_ord_ifu( rect_frameset,instrument,
00850 merge_par,rec_prefix ));
00851
00852 xsh_msg( "Build data cube");
00853
00854 check( data_cube = xsh_cube( res_2D_frameset, instrument, rec_prefix));
00855
00856 xsh_msg( "Saving Products for IFU" ) ;
00857
00858 for( i = 0 ; i<3 ; i++ ) {
00859 cpl_frame * rec_frame = NULL ;
00860 cpl_frame * res2d_frame = NULL ;
00861
00862 check( rec_frame = cpl_frameset_get_frame( rect_frameset_eso, i ) ) ;
00863 check( xsh_add_product_image( rec_frame, frameset, parameters,
00864 RECIPE_ID, instrument,NULL));
00865
00866 check( res2d_frame = cpl_frameset_get_frame( res_2D_frameset, i ) ) ;
00867 check( xsh_add_product_pre( res2d_frame, frameset, parameters,
00868 RECIPE_ID, instrument));
00869 }
00870
00871 check( xsh_add_product_pre_3d( data_cube, frameset, parameters,
00872 RECIPE_ID, instrument));
00873
00874 name=cpl_frame_get_filename(data_cube);
00875 plist=cpl_propertylist_load(name,0);
00876 naxis2=xsh_pfits_get_naxis2(plist);
00877 xsh_free_propertylist(&plist);
00878 check( qc_trace_frame=xsh_cube_qc_trace_window(data_cube,
00879 instrument,tag,rec_prefix,
00880 save_size+1,
00881 naxis2-save_size,
00882 peack_search_hsize,
00883 method,0));
00884
00885
00886 #if 1
00887
00888 check( xsh_add_product_pre( rmbias, frameset, parameters,
00889 RECIPE_ID, instrument));
00890
00891 check( xsh_add_product_image( rmbkg, frameset, parameters,
00892 RECIPE_ID, instrument,NULL));
00893
00894 check( xsh_add_product_image( div_frame, frameset, parameters,
00895 RECIPE_ID, instrument,NULL));
00896
00897 if(qc_trace_frame) {
00898 check( xsh_add_product_table( qc_trace_frame, frameset,parameters,
00899 RECIPE_ID, instrument,NULL));
00900 }
00901
00902 #endif
00903
00904 cleanup:
00905 XSH_REGDEBUG("scired_ifu_stare cleanup");
00906 xsh_end( RECIPE_ID, frameset, parameters );
00907
00908 XSH_FREE( rec_prefix);
00909 XSH_FREE(crh_clipping_par);
00910 XSH_FREE( backg_par ) ;
00911 XSH_FREE( crh_single_par ) ;
00912 XSH_FREE( rectify_par ) ;
00913 XSH_FREE( loc_obj_par );
00914 XSH_FREE( merge_par);
00915 XSH_FREE( extract_par);
00916
00917 xsh_instrument_free(&instrument );
00918 xsh_free_frameset( &raws);
00919 xsh_free_frameset( &calib);
00920 xsh_free_frame( &qc_trace_frame);
00921 xsh_free_frame( &crhm_frame);
00922 xsh_free_frame( &slitmap_frame);
00923 xsh_free_frame( &wavemap_frame);
00924 xsh_free_frame( &rmbias);
00925 xsh_free_frame( &rmdark);
00926 xsh_free_frame( &rmbkg);
00927 xsh_free_frame( &grid_backg);
00928 xsh_free_frame( &frame_backg);
00929 xsh_free_frame( &clean_frame);
00930 xsh_free_frame( &div_frame);
00931 xsh_free_frameset( &wavetab_frameset) ;
00932 xsh_free_frameset( &rect_frameset) ;
00933 xsh_free_frameset( &loc_table_frameset) ;
00934 xsh_free_frameset( &shiftifu_frameset);
00935 xsh_free_frameset( &nshiftifu_frameset);
00936
00937 xsh_free_frameset( &res_2D_frameset) ;
00938 xsh_free_frameset(&rect_frameset_eso) ;
00939 xsh_free_frameset(&rect_frameset_tab) ;
00940
00941 xsh_free_frame( &data_cube ) ;
00942 xsh_free_frame( &grid_backg ) ;
00943 xsh_free_frame( &frame_backg ) ;
00944 xsh_free_frame( &blaze_frame);
00945 return;
00946 }
00947