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 = { "tanh",
00184 CPL_KERNEL_DEFAULT,
00185 2,
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.};
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 xsh_interpolate_bp_param ipol_par = {30 };
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 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
00220 check( xsh_parameters_pre_overscan( RECIPE_ID, recipe->parameters ) ) ;
00221 check(xsh_parameters_stack_create(RECIPE_ID,recipe->parameters,stack_param));
00222
00223 check(xsh_parameters_clipping_crh_create(RECIPE_ID,recipe->parameters,
00224 crh_clip_param));
00225
00226
00227 check(xsh_parameters_background_create(RECIPE_ID,recipe->parameters));
00228
00229
00230 check(xsh_parameters_remove_crh_single_create(RECIPE_ID,recipe->parameters,
00231 crh_single )) ;
00232
00233
00234 check(xsh_parameters_rectify_create(RECIPE_ID,recipe->parameters,
00235 rectify )) ;
00236
00237
00238 check(xsh_parameters_localize_obj_create(RECIPE_ID,recipe->parameters,
00239 loc_obj )) ;
00240
00241
00242
00243 check(xsh_parameters_extract_create(RECIPE_ID,
00244 recipe->parameters,
00245 extract_par,LOCALIZATION_METHOD )) ;
00246
00247 check(xsh_parameters_interpolate_bp_create(RECIPE_ID,
00248 recipe->parameters,ipol_par)) ;
00249 check( xsh_parameters_new_double( recipe->parameters, RECIPE_ID,
00250 "shift-offsettab-low", 0.0,
00251 "Global shift of the lower slitlet slit positions, relative to the central one[arcsec]."));
00252 check( xsh_parameters_new_double( recipe->parameters, RECIPE_ID,
00253 "shift-offsettab-up", 0.0,
00254 "Global shift of the upper slitlet slit positions, relative to the central one[arcsec]."));
00255
00256 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00257 "compute-map", TRUE,
00258 "if TRUE recompute (wave and slit) maps from the dispersion solution. If sky-subtract is set to TRUE this must be set to TRUE."));
00259
00260 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00261 "check-afc", TRUE,
00262 "Input AFC corrected model/wave solution and science frame check."\
00263 "If TRUE the recipe verify that the input mode/wave solution is AFC corrected,"\
00264 " its INS.OPTIi.NAME is 'Pin_0.5 ', and its OBS.ID and OBS.TARG.NAME values"\
00265 " matches with the corresponding values of the science frame."));
00266
00267 sprintf(recipename,"xsh.%s",RECIPE_ID);
00268 sprintf(paramname,"%s.%s",recipename,"flat-method");
00269 check( p = cpl_parameter_new_enum( paramname,CPL_TYPE_STRING,
00270 "method adopted for flat:",
00271 recipename,"master",
00272 2,"master","blaze"));
00273
00274 check(cpl_parameter_set_alias( p,CPL_PARAMETER_MODE_CLI,
00275 "flat-method"));
00276 check(cpl_parameterlist_append( recipe->parameters, p));
00277
00278 cleanup:
00279 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
00280 xsh_error_dump(CPL_MSG_ERROR);
00281 return 1;
00282 }
00283 else {
00284 return 0;
00285 }
00286 }
00287
00288
00294
00295
00296 static int xsh_scired_ifu_stare_exec(cpl_plugin *plugin) {
00297 cpl_recipe *recipe = NULL;
00298
00299
00300
00301 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00302
00303
00304 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00305 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00306
00307 recipe = (cpl_recipe *)plugin;
00308
00309
00310 xsh_scired_ifu_stare(recipe->parameters, recipe->frames);
00311
00312 cleanup:
00313 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
00314 xsh_error_dump(CPL_MSG_ERROR);
00315 xsh_error_reset();
00316 return 1;
00317 }
00318 else {
00319 return 0;
00320 }
00321 }
00322
00323
00329
00330 static int xsh_scired_ifu_stare_destroy(cpl_plugin *plugin)
00331 {
00332 cpl_recipe *recipe = NULL;
00333
00334
00335 xsh_error_reset();
00336
00337 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00338
00339
00340 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00341 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00342
00343 recipe = (cpl_recipe *)plugin;
00344
00345 xsh_free_parameterlist(&recipe->parameters);
00346
00347 cleanup:
00348 if (cpl_error_get_code() != CPL_ERROR_NONE)
00349 {
00350 return 1;
00351 }
00352 else
00353 {
00354 return 0;
00355 }
00356 }
00357
00358
00359 static cpl_error_code
00360 xsh_params_monitor(xsh_background_param* backg,
00361 xsh_rectify_param * rectify_par,
00362 xsh_localize_obj_param * loc_obj_par)
00363 {
00364
00365
00366 xsh_msg_dbg_low("bkg params: sampley=%d radius_y=%d",
00367 backg->sampley,backg->radius_y);
00368
00369 xsh_msg_dbg_low("bkg params: radius_x=%d",
00370 backg->radius_x);
00371
00372 xsh_msg_dbg_low("rectify params: radius=%g bin_lambda=%g bin_space=%g",
00373 rectify_par->rectif_radius,rectify_par->rectif_bin_lambda,
00374 rectify_par->rectif_bin_space);
00375
00376 xsh_msg_dbg_low("localize params: chunk_nb=%d nod_step=%g",
00377 loc_obj_par->loc_chunk_nb,loc_obj_par->nod_step);
00378
00379 return cpl_error_get_code();
00380
00381 }
00382
00390
00391
00392 static cpl_error_code
00393 xsh_params_bin_scale(cpl_frameset* raws,
00394 xsh_background_param* backg)
00395 {
00396
00397 cpl_frame* frame=NULL;
00398 const char* name=NULL;
00399 cpl_propertylist* plist=NULL;
00400 int binx=0;
00401 int biny=0;
00402
00403 check(frame=cpl_frameset_get_first(raws));
00404 check(name=cpl_frame_get_filename(frame));
00405 check(plist=cpl_propertylist_load(name,0));
00406 check(binx=xsh_pfits_get_binx(plist));
00407 check(biny=xsh_pfits_get_biny(plist));
00408 xsh_free_propertylist(&plist);
00409
00410 if(biny>1) {
00411
00412
00413
00414
00415
00416
00417 backg->radius_y=backg->radius_y/biny;
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440 }
00441
00442
00443 if(binx>1) {
00444
00445 backg->radius_x=backg->radius_x/binx;
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459 }
00460
00461 cleanup:
00462 xsh_free_propertylist(&plist);
00463 return cpl_error_get_code();
00464
00465 }
00466
00467
00475
00476 static void xsh_scired_ifu_stare(cpl_parameterlist* parameters,
00477 cpl_frameset* frameset)
00478 {
00479 const char* recipe_tags[3] = {XSH_OBJECT_IFU_STARE,
00480 XSH_STD_TELL_IFU_STARE,
00481 XSH_STD_FLUX_IFU_STARE};
00482 int recipe_tags_size = 3;
00483
00484
00485 xsh_instrument *instrument = NULL;
00486 int nb_raw_frames ;
00487 cpl_frameset *raws = NULL;
00488 cpl_frameset *calib = NULL;
00489
00490
00491 cpl_frame *bpmap = NULL;
00492 cpl_frame *master_bias = NULL;
00493 cpl_frame *master_dark = NULL;
00494 cpl_frame *master_flat = NULL;
00495 cpl_frame *order_tab_edges = NULL;
00496 cpl_frame *wavetab_frame = NULL;
00497 cpl_frameset *wavetab_frameset = NULL ;
00498 cpl_frame *model_config_frame = NULL ;
00499 cpl_frame *spectral_format = NULL ;
00500 cpl_frame *disp_tab_frame = NULL;
00501 cpl_frame *shifttab_frame = NULL;
00502
00503
00504 xsh_clipping_param *crh_clipping_par = NULL;
00505 xsh_background_param *backg_par = NULL;
00506 xsh_remove_crh_single_param *crh_single_par = NULL ;
00507 xsh_rectify_param *rectify_par = NULL ;
00508 xsh_localize_obj_param *loc_obj_par = NULL ;
00509 int merge_par = 0;
00510 xsh_extract_param *extract_par = NULL ;
00511 double offset_low =0.0;
00512 double offset_up =0.0;
00513
00514 xsh_stack_param* stack_par=NULL;
00515
00516 int recipe_use_model = FALSE;
00517 int do_computemap = 0;
00518 int check_afc = TRUE;
00519
00520
00521 cpl_frame *slitmap_frame = NULL;
00522 cpl_frame *wavemap_frame = NULL;
00523 cpl_frame *crhm_frame = NULL ;
00524 cpl_frame *rmbias = NULL;
00525 cpl_frame *rmdark = NULL;
00526 cpl_frame *rmbkg = NULL ;
00527 cpl_frame *clean_frame = NULL ;
00528 cpl_frame *div_frame = NULL ;
00529 cpl_frameset *rect_frameset = NULL ;
00530 cpl_frameset *loc_table_frameset = NULL ;
00532
00533 cpl_frameset *res_2D_frameset = NULL ;
00534 cpl_frame *data_cube = NULL ;
00535 char div_tag[256];
00536 char prefix[256];
00537 const char * ftag=NULL;
00538 cpl_frame* grid_backg=NULL;
00539 cpl_frame* frame_backg=NULL;
00540 cpl_frameset* rect_frameset_eso=NULL;
00541 cpl_frameset* rect_frameset_tab=NULL;
00542 char *rec_prefix = NULL;
00543 int pre_overscan_corr=0;
00544
00545 cpl_frameset *shiftifu_frameset = NULL;
00546 cpl_frameset *nshiftifu_frameset = NULL;
00547 int i;
00548
00549 cpl_propertylist* plist=NULL;
00550 const char* name=NULL;
00551 const char* tag="";
00552 int naxis2=0;
00553 cpl_frame* qc_trace_frame=NULL;
00554 int save_size=0;
00555 const int peack_search_hsize=5;
00556 int method=0;
00557 char* flat_method = NULL;
00558
00559
00560 cpl_frame * blaze_frame = NULL;
00561
00562
00563
00564
00565 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
00566 recipe_tags, recipe_tags_size,
00567 RECIPE_ID, XSH_BINARY_VERSION,
00568 xsh_scired_ifu_stare_description_short ) ) ;
00569
00570 assure( instrument->mode == XSH_MODE_IFU, CPL_ERROR_ILLEGAL_INPUT,
00571 "Instrument NOT in IFU Mode" ) ;
00572
00573 xsh_recipe_params_check(parameters,instrument,RECIPE_ID);
00574
00575 check( nb_raw_frames = cpl_frameset_get_size( raws));
00576
00577 XSH_ASSURE_NOT_ILLEGAL_MSG( nb_raw_frames == 1 || nb_raw_frames >= 3,
00578 "This recipe expects either one or at least 3 input raw frames" );
00579
00580
00581
00582
00583
00584 bpmap = xsh_find_master_bpmap(calib);
00585
00586
00587 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR){
00588
00589 check( master_bias = xsh_find_frame_with_tag(calib,XSH_MASTER_BIAS,
00590 instrument));
00591 }
00592
00593 if(NULL==(order_tab_edges=xsh_find_frame_with_tag(calib,XSH_ORDER_TAB_AFC_IFU,
00594 instrument))) {
00595 xsh_msg_error("Missing frame %s_%s", XSH_ORDER_TAB_AFC_IFU,
00596 xsh_instrument_arm_tostring( instrument ));
00597 goto cleanup;
00598 }
00599
00600
00601 check(model_config_frame=xsh_find_frame_with_tag(calib,XSH_MOD_CFG_OPT_AFC,
00602 instrument));
00603 if(model_config_frame==NULL) {
00604 wavetab_frame = xsh_find_wave_tab( calib, instrument);
00605 }
00606
00607
00608
00609 if ( model_config_frame == NULL){
00610 xsh_msg("RECIPE USE WAVE SOLUTION");
00611 recipe_use_model = FALSE;
00612 }
00613 else{
00614 xsh_msg("RECIPE USE MODEL");
00615 recipe_use_model = TRUE;
00616 }
00617 XSH_ASSURE_NOT_ILLEGAL( (model_config_frame != NULL && wavetab_frame == NULL ) ||
00618 (model_config_frame == NULL && wavetab_frame != NULL ) );
00619
00620 check( master_flat = xsh_find_master_flat( calib, instrument ) ) ;
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 check(spectral_format=xsh_find_spectral_format( calib, instrument ) ) ;
00627 check( xsh_instrument_update_from_spectralformat( instrument,
00628 spectral_format));
00629
00630
00631 shiftifu_frameset = xsh_find_offset_tab_ifu( calib,
00632 instrument);
00633 xsh_error_reset();
00634
00635
00636
00637
00638
00639 shifttab_frame = xsh_find_frame_with_tag( calib, XSH_SHIFT_TAB_IFU,
00640 instrument);
00641 xsh_error_reset() ;
00642
00643 if ( recipe_use_model == FALSE){
00644 check( wavetab_frameset = xsh_ifu_wavetab_create( wavetab_frame,
00645 shifttab_frame, instrument));
00646 }
00647
00648
00649
00650
00651 check( stack_par = xsh_stack_frames_get( RECIPE_ID, parameters));
00652 check( crh_clipping_par = xsh_parameters_clipping_crh_get(RECIPE_ID,
00653 parameters));
00654 check( backg_par = xsh_parameters_background_get(RECIPE_ID,
00655 parameters));
00656
00657 check( loc_obj_par = xsh_parameters_localize_obj_get(RECIPE_ID,
00658 parameters));
00659 check( rectify_par = xsh_parameters_rectify_get(RECIPE_ID,
00660 parameters));
00661 rectify_par->conserve_flux=FALSE;
00662 check( crh_single_par = xsh_parameters_remove_crh_single_get(RECIPE_ID,
00663 parameters));
00664
00665 check( extract_par = xsh_parameters_extract_get( RECIPE_ID, parameters));
00666
00667 check( do_computemap = xsh_parameters_get_boolean( parameters, RECIPE_ID,
00668 "compute-map"));
00669
00670 check( check_afc = xsh_parameters_get_boolean( parameters, RECIPE_ID,
00671 "check-afc"));
00672
00673 if ( do_computemap && recipe_use_model==FALSE){
00674 check( disp_tab_frame = xsh_find_disp_tab( calib, instrument));
00675 }
00676
00677 check(xsh_rectify_params_set_defaults(parameters,RECIPE_ID,instrument,rectify_par));
00678
00679
00680 if ( xsh_instrument_get_arm( instrument ) != XSH_ARM_NIR ) {
00681 check(xsh_params_bin_scale(raws,backg_par));
00682 }
00683 check(xsh_params_monitor(backg_par,rectify_par,loc_obj_par));
00684
00685 check( offset_low = xsh_parameters_get_double( parameters, RECIPE_ID,
00686 "shift-offsettab-low"));
00687
00688 check( offset_up = xsh_parameters_get_double( parameters, RECIPE_ID,
00689 "shift-offsettab-up"));
00690
00691
00692 if ( shiftifu_frameset != NULL){
00693 xsh_msg("offset low %f up %f", offset_low, offset_up);
00694 check( nshiftifu_frameset = xsh_shift_offsettab( shiftifu_frameset,
00695 offset_low, offset_up));
00696 }
00697
00698
00699
00700
00701
00702 check( xsh_prepare( raws, bpmap, master_bias, XSH_OBJECT_IFU_STARE,
00703 instrument,pre_overscan_corr,CPL_TRUE));
00704
00705 check( rec_prefix = xsh_set_recipe_file_prefix( raws,
00706 RECIPE_ID));
00707
00708
00709 ftag = XSH_GET_TAG_FROM_ARM( XSH_IFU_STARE_REMOVE_CRH, instrument);
00710 check( crhm_frame = xsh_check_remove_crh_multiple( raws, ftag,
00711 stack_par,NULL, instrument, NULL, NULL));
00712
00713
00714 check( xsh_check_get_map( disp_tab_frame, order_tab_edges,
00715 crhm_frame, model_config_frame, calib, instrument,
00716 do_computemap, recipe_use_model, rec_prefix,
00717 &wavemap_frame, &slitmap_frame));
00718
00719
00720 sprintf(prefix,"%s_",rec_prefix);
00721
00722 check( rmbias = xsh_check_subtract_bias( crhm_frame, master_bias,
00723 instrument, rec_prefix,
00724 pre_overscan_corr,0));
00725
00726
00727
00728
00729 check( xsh_check_afc( check_afc, model_config_frame,
00730 rmbias, wavetab_frameset, order_tab_edges, disp_tab_frame,
00731 instrument));
00732
00733
00734 check( rmdark = xsh_check_subtract_dark( rmbias, master_dark,
00735 instrument, rec_prefix));
00736
00737
00738 xsh_msg("Subtract inter-order background");
00739 check(rmbkg = xsh_subtract_background( rmdark,
00740 order_tab_edges,
00741 backg_par, instrument,
00742 rec_prefix,&grid_backg,
00743 &frame_backg,1,1,1 ));
00744
00745 if ( nb_raw_frames == 1 ) {
00746 char * nocrh_tag = NULL ;
00747
00748 nocrh_tag = xsh_stringcat_any("NOCRH_",
00749 xsh_instrument_arm_tostring(instrument),
00750 NULL) ;
00751 xsh_msg( "Remove crh (single frame)" ) ;
00752 check( clean_frame = xsh_remove_crh_single( rmbkg,
00753 instrument,
00754 crh_single_par,
00755 nocrh_tag ) ) ;
00756 XSH_FREE( nocrh_tag ) ;
00757 }
00758 else {
00759 clean_frame = cpl_frame_duplicate( rmbkg) ;
00760 }
00761
00762 xsh_msg( "---Divide by flat" ) ;
00763 sprintf(div_tag,"%s_DIV_FF_%s",
00764 rec_prefix,xsh_instrument_arm_tostring(instrument)) ;
00765
00766 check( flat_method = xsh_parameters_get_string( parameters, RECIPE_ID,
00767 "flat-method"));
00768
00769 xsh_msg("method %s", flat_method);
00770
00771 if ( strcmp( flat_method, "master") == 0){
00772 check( div_frame = xsh_divide_flat( clean_frame, master_flat,
00773 div_tag, instrument));
00774 }
00775 else{
00776 xsh_msg("---Create blaze image");
00777 check( blaze_frame = xsh_blaze_image( master_flat, order_tab_edges,
00778 instrument));
00779 check( div_frame = xsh_divide_by_blaze( clean_frame,
00780 blaze_frame, instrument));
00781 }
00782
00783
00784
00785 xsh_msg( "---Rectify ifu");
00786 rect_frameset_eso=cpl_frameset_new();
00787 rect_frameset_tab=cpl_frameset_new();
00788 check( rect_frameset = xsh_rectify_ifu( div_frame, order_tab_edges,
00789 wavetab_frameset,
00790 nshiftifu_frameset,
00791 model_config_frame,
00792 instrument, rectify_par,
00793 spectral_format,
00794 slitmap_frame, &rect_frameset_eso,
00795 &rect_frameset_tab,rec_prefix ));
00796
00797
00798 check( loc_table_frameset = xsh_localize_obj_ifu( rect_frameset, NULL,
00799 instrument,
00800 loc_obj_par, NULL));
00801 xsh_msg( "Merge orders with 2D frame" ) ;
00802 check( res_2D_frameset = xsh_merge_ord_ifu( rect_frameset,instrument,
00803 merge_par,rec_prefix ));
00804
00805 xsh_msg( "Build data cube");
00806
00807 check( data_cube = xsh_cube( res_2D_frameset, instrument, rec_prefix));
00808
00809 xsh_msg( "Saving Products for IFU" ) ;
00810
00811 for( i = 0 ; i<3 ; i++ ) {
00812 cpl_frame * rec_frame = NULL ;
00813 cpl_frame * res2d_frame = NULL ;
00814
00815 check( rec_frame = cpl_frameset_get_frame( rect_frameset_eso, i ) ) ;
00816 check( xsh_add_product_image( rec_frame, frameset, parameters,
00817 RECIPE_ID, instrument,NULL));
00818
00819 check( res2d_frame = cpl_frameset_get_frame( res_2D_frameset, i ) ) ;
00820 check( xsh_add_product_pre( res2d_frame, frameset, parameters,
00821 RECIPE_ID, instrument));
00822 }
00823
00824 check( xsh_add_product_pre_3d( data_cube, frameset, parameters,
00825 RECIPE_ID, instrument));
00826
00827 name=cpl_frame_get_filename(data_cube);
00828 plist=cpl_propertylist_load(name,0);
00829 naxis2=xsh_pfits_get_naxis2(plist);
00830 xsh_free_propertylist(&plist);
00831 check( qc_trace_frame=xsh_cube_qc_trace_window(data_cube,
00832 instrument,tag,rec_prefix,
00833 save_size+1,
00834 naxis2-save_size,
00835 peack_search_hsize,
00836 method,0));
00837
00838
00839 #if 1
00840
00841 check( xsh_add_product_pre( rmbias, frameset, parameters,
00842 RECIPE_ID, instrument));
00843
00844 check( xsh_add_product_image( rmbkg, frameset, parameters,
00845 RECIPE_ID, instrument,NULL));
00846
00847 check( xsh_add_product_image( div_frame, frameset, parameters,
00848 RECIPE_ID, instrument,NULL));
00849
00850 if(qc_trace_frame) {
00851 check( xsh_add_product_table( qc_trace_frame, frameset,parameters,
00852 RECIPE_ID, instrument,NULL));
00853 }
00854
00855 #endif
00856
00857 cleanup:
00858 XSH_REGDEBUG("scired_ifu_stare cleanup");
00859 xsh_end( RECIPE_ID, frameset, parameters );
00860
00861 XSH_FREE( rec_prefix);
00862 XSH_FREE(crh_clipping_par);
00863 XSH_FREE( backg_par ) ;
00864 XSH_FREE( crh_single_par ) ;
00865 XSH_FREE( rectify_par ) ;
00866 XSH_FREE( loc_obj_par );
00867 XSH_FREE( extract_par);
00868 XSH_FREE( stack_par);
00869
00870 xsh_instrument_free(&instrument );
00871 xsh_free_frameset( &raws);
00872 xsh_free_frameset( &calib);
00873 xsh_free_frame( &qc_trace_frame);
00874 xsh_free_frame( &crhm_frame);
00875 xsh_free_frame( &slitmap_frame);
00876 xsh_free_frame( &wavemap_frame);
00877 xsh_free_frame( &rmbias);
00878 xsh_free_frame( &rmdark);
00879 xsh_free_frame( &rmbkg);
00880 xsh_free_frame( &grid_backg);
00881 xsh_free_frame( &frame_backg);
00882 xsh_free_frame( &clean_frame);
00883 xsh_free_frame( &div_frame);
00884 xsh_free_frameset( &wavetab_frameset) ;
00885 xsh_free_frameset( &rect_frameset) ;
00886 xsh_free_frameset( &loc_table_frameset) ;
00887 xsh_free_frameset( &shiftifu_frameset);
00888 xsh_free_frameset( &nshiftifu_frameset);
00889
00890 xsh_free_frameset( &res_2D_frameset) ;
00891 xsh_free_frameset(&rect_frameset_eso) ;
00892 xsh_free_frameset(&rect_frameset_tab) ;
00893
00894 xsh_free_frame( &data_cube ) ;
00895 xsh_free_frame( &grid_backg ) ;
00896 xsh_free_frame( &frame_backg ) ;
00897 xsh_free_frame( &blaze_frame);
00898 return;
00899 }
00900