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