00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifdef HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030
00031
00039
00042
00043
00044
00045
00046
00047
00048
00049 #include <xsh_error.h>
00050 #include <stdio.h>
00051
00052 #include <xsh_utils.h>
00053 #include <xsh_utils_scired_slit.h>
00054
00055 #include <xsh_msg.h>
00056
00057 #include <xsh_dfs.h>
00058 #include <xsh_pfits.h>
00059 #include <xsh_data_spectrum1D.h>
00060 #include <xsh_model_arm_constants.h>
00061
00062
00063
00064 #include <xsh_drl.h>
00065 #include <xsh_drl_check.h>
00066
00067 #include <cpl.h>
00068
00069
00070
00071
00072
00073 #define RECIPE_ID "xsh_scired_slit_offset"
00074 #define RECIPE_AUTHOR "P.Goldoni, L.Guglielmi, R. Haigron, F. Royer, D. Bramich, A. Modigliani"
00075 #define RECIPE_CONTACT "amodigli@eso.org"
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 static int xsh_scired_slit_offset_create( cpl_plugin *);
00086 static int xsh_scired_slit_offset_exec( cpl_plugin *);
00087 static int xsh_scired_slit_offset_destroy( cpl_plugin *);
00088
00089
00090 static void xsh_scired_slit_offset( cpl_parameterlist *, cpl_frameset *);
00091
00092
00093
00094
00095 static char xsh_scired_slit_offset_description_short[] =
00096 "Reduce science exposure in SLIT configuration and on/off mode";
00097
00098 static char xsh_scired_slit_offset_description[] =
00099 "This recipe reduces science exposure in SLIT configuration and on/off mode\n\
00100 Input Frames : \n\
00101 - A set of n Science frames ( n even ), \
00102 Tag = STD_FLUX_SLIT_OFFSET_arm, SKY_SLIT_arm\n\
00103 - Spectral format table (Tag = SPECTRAL_FORMAT_TAB_arm)\n\
00104 - A master flat frame (Tag = MASTER_FLAT_SLIT_arm)\n\
00105 - An order table frame(Tag = ORDER_TABLE_EDGES_SLIT_arm)\n\
00106 - A wavelength calibration solution frame(Tag = WAVE_TAB_2D_arm)\n\
00107 - [OPTIONAL] Table with dispersion coefficients (Tag = DISP_TAB_arm)\n\
00108 It is required if -rectify-conserve-flux=TRUE\n\
00109 - [OPTIONAL] A non-linear badpixel map (Tag = BP_MAP_NL_arm)\n\
00110 - [OPTIONAL] A reference badpixel map (Tag = BP_MAP_RP_arm)\n\
00111 - [OPTIONAL] The instrument response table (Tag = RESPONSE_MERGE1D_SLIT_arm)\n\
00112 - [OPTIONAL] An atmospheric extinction table (Tag = ATMOS_EXT_arm)\n\
00113 - [OPTIONAL] A telluric mask (Tag = TELL_MASK_arm)\n\
00114 Products : \n\
00115 - PREFIX_ORDER2D_arm extracted spectrum, order-by-order, 2D\n\
00116 - PREFIX_ORDER1D_arm extracted spectrum, order-by-order, 1D\n\
00117 - PREFIX_MERGE2D_arm merged spectrum, 2D\n\
00118 - PREFIX_MERGE1D_arm merged spectrum, 1D\n\
00119 - PREFIX_SKY_arm, 2D sky frame\n\
00120 - SKY_SLIT_ORDER2D_arm, 2D sky image (order-by-order)\n\
00121 - SKY_SLIT_MERGE2D_arm, 2D sky image (merged)\n\
00122 - PREFIX_WAVE_MAP_arm, wave map image\n\
00123 - PREFIX_SLIT_MAP_arm, slit map image\n\
00124 - where PREFIX is SCI, FLUX, TELL if input raw DPR.TYPE contains OBJECT or FLUX or TELLURIC\n\
00125 - [OPTIONAL, if response and atm ext are provided] PREFIX_FLUX_ORDER2D_arm (2 dimension)\n\
00126 - [OPTIONAL, if response and atm ext are provided] PREFIX_FLUX_ORDER1D_arm (1 dimension)\n\
00127 - [OPTIONAL, if response and atm ext are provided] PREFIX_FLUX_MERGE2D_arm (2 dimension)\n\
00128 - [OPTIONAL, if response and atm ext are provided] PREFIX_FLUX_MERGE1D_arm (1 dimension)\n";
00129
00130
00131
00132
00133
00134
00143
00144
00145 int cpl_plugin_get_info(cpl_pluginlist *list) {
00146 cpl_recipe *recipe = NULL;
00147 cpl_plugin *plugin = NULL;
00148
00149 recipe = cpl_calloc(1, sizeof(*recipe));
00150 if ( recipe == NULL ){
00151 return -1;
00152 }
00153
00154 plugin = &recipe->interface ;
00155
00156 cpl_plugin_init(plugin,
00157 CPL_PLUGIN_API,
00158 XSH_BINARY_VERSION,
00159 CPL_PLUGIN_TYPE_RECIPE,
00160 RECIPE_ID,
00161 xsh_scired_slit_offset_description_short,
00162 xsh_scired_slit_offset_description,
00163 RECIPE_AUTHOR,
00164 RECIPE_CONTACT,
00165 xsh_get_license(),
00166 xsh_scired_slit_offset_create,
00167 xsh_scired_slit_offset_exec,
00168 xsh_scired_slit_offset_destroy);
00169
00170 cpl_pluginlist_append(list, plugin);
00171
00172 return (cpl_error_get_code() != CPL_ERROR_NONE);
00173 }
00174
00175
00185
00186
00187 static int xsh_scired_slit_offset_create(cpl_plugin *plugin){
00188 cpl_recipe *recipe = NULL;
00189
00190
00191 xsh_remove_crh_single_param crh_single = { 0.1, 20, 2.0, 4} ;
00192 xsh_rectify_param rectify = { "tanh",
00193 CPL_KERNEL_DEFAULT,
00194 2,
00195 -1.0,
00196 -1.0,
00197 1,0,0.};
00198
00199 xsh_localize_obj_param loc_obj =
00200 {10, 0.1, 0, 0, LOC_MANUAL_METHOD, 0, 2.0,3,3,FALSE};
00201
00202 xsh_combine_nod_param nod_param = { 5, TRUE, 5, 2, 0.1, "throwlist.asc", COMBINE_MEAN_METHOD } ;
00203 xsh_interpolate_bp_param ipol_par = {30 };
00204
00205 xsh_init();
00206
00207
00208 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
00209
00210 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00211 CPL_ERROR_TYPE_MISMATCH,
00212 "Plugin is not a recipe");
00213
00214 recipe = (cpl_recipe *)plugin;
00215
00216
00217 recipe->parameters = cpl_parameterlist_new();
00218 assure( recipe->parameters != NULL,
00219 CPL_ERROR_ILLEGAL_OUTPUT,
00220 "Memory allocation failed!");
00221
00222
00223 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
00224 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
00225 check( xsh_parameters_pre_overscan( RECIPE_ID, recipe->parameters ) ) ;
00226
00227
00228 check(xsh_parameters_remove_crh_single_create(RECIPE_ID,recipe->parameters,
00229 crh_single )) ;
00230
00231 check(xsh_parameters_rectify_create(RECIPE_ID,recipe->parameters,
00232 rectify )) ;
00233
00234 check(xsh_parameters_localize_obj_create(RECIPE_ID,recipe->parameters,
00235 loc_obj )) ;
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 check(xsh_parameters_interpolate_bp_create(RECIPE_ID,
00247 recipe->parameters,ipol_par)) ;
00248
00249 check(xsh_parameters_combine_nod_create(RECIPE_ID,
00250 recipe->parameters,
00251 nod_param )) ;
00252
00253
00254
00255
00256
00257
00258 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00259 "gen-sky", TRUE,
00260 "if TRUE a 2D sky frame, a 2D rectified, a 2D merged sky are generated"));
00261
00262
00263
00264
00265
00266 cleanup:
00267 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
00268 xsh_error_dump(CPL_MSG_ERROR);
00269 return 1;
00270 }
00271 else {
00272 return 0;
00273 }
00274 }
00275
00276
00282
00283
00284 static int xsh_scired_slit_offset_exec(cpl_plugin *plugin) {
00285 cpl_recipe *recipe = NULL;
00286
00287
00288
00289 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
00290
00291
00292 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00293 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00294
00295 recipe = (cpl_recipe *)plugin;
00296
00297
00298 xsh_scired_slit_offset(recipe->parameters, recipe->frames);
00299
00300 cleanup:
00301 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
00302 xsh_error_dump(CPL_MSG_ERROR);
00303 xsh_error_reset();
00304 return 1;
00305 }
00306 else {
00307 return 0;
00308 }
00309 }
00310
00311
00317
00318 static int xsh_scired_slit_offset_destroy(cpl_plugin *plugin)
00319 {
00320 cpl_recipe *recipe = NULL;
00321
00322
00323 xsh_error_reset();
00324
00325 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00326
00327
00328 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00329 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00330
00331 recipe = (cpl_recipe *)plugin;
00332
00333 xsh_free_parameterlist(&recipe->parameters);
00334
00335 cleanup:
00336 if (cpl_error_get_code() != CPL_ERROR_NONE)
00337 {
00338 return 1;
00339 }
00340 else
00341 {
00342 return 0;
00343 }
00344 }
00345
00346
00347 static cpl_error_code
00348 xsh_params_monitor(xsh_rectify_param * rectify_par,
00349 xsh_localize_obj_param * loc_obj_par)
00350 {
00351
00352
00353 xsh_msg_dbg_low("rectify params: radius=%g bin_lambda=%g bin_space=%g",
00354 rectify_par->rectif_radius,rectify_par->rectif_bin_lambda,
00355 rectify_par->rectif_bin_space);
00356
00357 xsh_msg_dbg_low("localize params: chunk_nb=%d nod_step=%g",
00358 loc_obj_par->loc_chunk_nb,loc_obj_par->nod_step);
00359
00360 return cpl_error_get_code();
00361
00362 }
00363
00364
00372
00373 static void xsh_scired_slit_offset( cpl_parameterlist* parameters,
00374 cpl_frameset* frameset)
00375 {
00376 const char* recipe_tags[3] = {XSH_OBJECT_SLIT_OFFSET, XSH_STD_FLUX_SLIT_OFFSET, XSH_SKY_SLIT};
00377 int recipe_tags_size = 3;
00378
00379
00380 cpl_frameset* raws = NULL;
00381
00382 cpl_frameset * raw_object = NULL;
00383 cpl_frameset * raw_sky = NULL;
00384 cpl_frameset * calib = NULL;
00385 int nobj=0;
00386 int nsky=0;
00387
00388 int nb_sub_frames = 0;
00389
00390
00391 cpl_frame* bpmap = NULL;
00392 cpl_frame* master_bias = NULL;
00393 cpl_frame* master_dark = NULL;
00394 cpl_frame* master_flat = NULL;
00395 cpl_frame* order_tab_edges = NULL;
00396 cpl_frame * wave_tab = NULL ;
00397 cpl_frame * model_config_frame = NULL ;
00398 cpl_frame * wavemap = NULL ;
00399 cpl_frame * slitmap = NULL ;
00400 cpl_frame *disp_tab_frame = NULL;
00401 cpl_frame * spectral_format = NULL ;
00402 cpl_frame *tellmask_frame = NULL;
00403
00404 xsh_remove_crh_single_param * crh_single_par = NULL ;
00405 xsh_rectify_param * rectify_par = NULL ;
00406 xsh_localize_obj_param * loc_obj_par = NULL ;
00407
00408 xsh_extract_param * extract_par = NULL ;
00409 xsh_combine_nod_param * combine_nod_param = NULL ;
00410
00411 xsh_instrument* instrument = NULL;
00412
00413
00414
00415 cpl_frame * loc_table_frame = NULL ;
00416 cpl_frame * clean_frame = NULL ;
00417 cpl_frameset * sub_frameset = NULL ;
00418 cpl_frameset * clean_frameset = NULL ;
00419 cpl_frameset * rect_frameset = NULL ;
00420 cpl_frameset * rect2_frameset_tables = NULL ;
00422
00423 cpl_frame * res1D_frame = NULL ;
00424 cpl_frame * res2D_frame = NULL ;
00425 cpl_frame * ext_frame = NULL ;
00426 cpl_frame * ext_frame_eso = NULL ;
00427 cpl_frame * comb_frame = NULL ;
00428 cpl_frame * comb_frame_eso = NULL ;
00429 cpl_frame* response_ord_frame=NULL;
00430
00431 char file_name[256];
00432 char arm_str[16] ;
00433 char file_tag[40];
00434
00435 int i ;
00436 cpl_frame* grid_back=NULL;
00437 cpl_frame* frame_backg=NULL;
00438 int do_flatfield=1;
00439 int gen_sky=0;
00440 char* rec_prefix=NULL;
00441 char sky_prefix[256];
00442 char sky_tag[256];
00443 cpl_frame* avg_sky=NULL;
00444 cpl_frame* rec_sky=NULL;
00445 cpl_frame* rec_sky_eso=NULL;
00446 cpl_frame* mer_sky=NULL;
00447 cpl_frame * rectif_tab = NULL ;
00448 cpl_frame * sky_divided = NULL ;
00449 cpl_frameset* sky_bias=NULL;
00450 cpl_frameset* sky_dark=NULL;
00451 cpl_frame * fluxcal_rect_1D_frame = NULL ;
00452 cpl_frame * fluxcal_rect_2D_frame = NULL ;
00453 cpl_frame * fluxcal_1D_frame = NULL ;
00454 cpl_frame * fluxcal_2D_frame = NULL ;
00455 cpl_frame* frm_atmext=NULL;
00456 cpl_frameset* crh_clean_obj = NULL;
00457 cpl_frameset* crh_clean_sky = NULL;
00458
00459 int pre_overscan_corr=0;
00460 int merge_par=0;
00461 xsh_interpolate_bp_param *ipol_bp=NULL;
00462 int do_computemap=1;
00463 int use_model=0;
00464
00465
00466
00467 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
00468 recipe_tags, recipe_tags_size,
00469 RECIPE_ID, XSH_BINARY_VERSION,
00470 xsh_scired_slit_offset_description_short));
00471
00472 check(xsh_ensure_raws_input_offset_recipe_is_proper(&raws,instrument));
00473 assure( instrument->mode == XSH_MODE_SLIT, CPL_ERROR_ILLEGAL_INPUT,
00474 "Instrument NOT in Slit Mode" ) ;
00475 xsh_recipe_params_check(parameters,instrument,RECIPE_ID);
00476 if(instrument->arm == XSH_ARM_NIR) {
00477 xsh_instrument_nir_corr_if_JH(raws,instrument);
00478 }
00479
00480
00481
00482 check(xsh_slit_offset_get_calibs(calib,instrument,&bpmap,&master_bias,
00483 &master_dark,&order_tab_edges,
00484 &model_config_frame,&wave_tab,&master_flat,
00485 &wavemap,&slitmap,&spectral_format,RECIPE_ID));
00486
00487 if((response_ord_frame=xsh_find_frame_with_tag(calib,XSH_MRESPONSE_MERGE1D_SLIT,
00488 instrument)) == NULL ) {
00489 check( response_ord_frame = xsh_find_frame_with_tag(calib,
00490 XSH_RESPONSE_MERGE1D_SLIT,
00491 instrument));
00492 }
00493
00494 if(response_ord_frame != NULL) {
00495 frm_atmext=xsh_find_frame_with_tag(calib,XSH_ATMOS_EXT,instrument);
00496 if(frm_atmext==NULL) {
00497 xsh_msg_error("Provide atmospheric extinction frame");
00498 }
00499 }
00500
00501 tellmask_frame = xsh_find_frame_with_tag(calib,XSH_TELL_MASK, instrument);
00502
00503
00504
00505 check(xsh_slit_offset_get_params(parameters,RECIPE_ID,
00506 &loc_obj_par,&rectify_par,&crh_single_par,
00507 &extract_par,
00508 &combine_nod_param,&do_flatfield,&gen_sky));
00509
00510 check(ipol_bp = xsh_parameters_interpolate_bp_get(RECIPE_ID,parameters));
00511
00512 check(xsh_rectify_params_set_defaults(parameters,RECIPE_ID,instrument,rectify_par));
00513 rectify_par->conserve_flux=FALSE;
00514
00515 check(xsh_params_monitor(rectify_par,loc_obj_par));
00516
00517 if ( rectify_par->conserve_flux){
00518 check_msg( disp_tab_frame = xsh_find_disp_tab( calib, instrument),
00519 "if rectify-conserve-flux=TRUE DISP_TAB_ARM is required input");
00520 }
00521 check( pre_overscan_corr = xsh_parameters_get_int( parameters, RECIPE_ID,
00522 "pre-overscan-corr"));
00523
00524
00525
00526
00527 check(xsh_prepare(raws, bpmap, master_bias, XSH_OBJECT_SLIT_OFFSET,
00528 instrument,pre_overscan_corr,CPL_TRUE));
00529
00530
00531 check(xsh_frameset_check_uniform_exptime(raws,instrument));
00532
00533
00534 check( nb_sub_frames = xsh_dfs_split_offset( raws, XSH_OBJECT_SLIT_OFFSET,
00535 XSH_SKY_SLIT, &raw_object,
00536 &raw_sky ) );
00537
00538 nobj=cpl_frameset_get_size(raw_object);
00539 nsky=cpl_frameset_get_size(raw_sky);
00540 rec_prefix=xsh_set_recipe_file_prefix(raw_object,"xsh_scired_slit_offset");
00541 sprintf(sky_prefix,xsh_set_recipe_sky_file_prefix(rec_prefix));
00542
00543 xsh_msg("cmap=%d wavemap=%p slitmap=%p",do_computemap,wavemap,slitmap);
00544 if( (do_computemap == 1) &&
00545 (wavemap ==NULL || slitmap ==NULL )
00546 ) {
00547 if (model_config_frame != NULL) {
00548 use_model=1;
00549 }
00550
00551 check( xsh_check_get_map( disp_tab_frame, order_tab_edges,
00552 master_flat, model_config_frame, calib, instrument,
00553 do_computemap, use_model, rec_prefix,
00554 &wavemap, &slitmap));
00555
00556 }
00557
00558
00559 if( nb_sub_frames==0 ) {
00560 xsh_msg_error("nb_sub_frames=%d something wrong check your input raws",nb_sub_frames);
00561 goto cleanup;
00562
00563 }
00564
00565
00566
00567 crh_clean_obj = xsh_frameset_crh_single(raw_object, crh_single_par,instrument,rec_prefix,"OBJ");
00568 crh_clean_sky = xsh_frameset_crh_single(raw_sky, crh_single_par, instrument,rec_prefix,"SKY");
00569
00570 check(
00571 sub_frameset = xsh_subtract_sky_offset( crh_clean_obj, crh_clean_sky, nb_sub_frames,instrument));
00572
00573 xsh_msg_dbg_low(
00574 "Nb of Subtracted Frames: %" CPL_SIZE_FORMAT "", cpl_frameset_get_size( sub_frameset ));
00575
00576 sprintf(arm_str, "%s", xsh_instrument_arm_tostring(instrument));
00577
00578 if (gen_sky) {
00579
00580 if (master_bias != NULL && pre_overscan_corr == 0) {
00581 check(
00582 sky_bias=xsh_pre_frameset_subtract_frame(crh_clean_sky,master_bias,"MBIAS_",instrument));
00583 } else {
00584 sky_bias = cpl_frameset_duplicate(crh_clean_sky);
00585 }
00586 if (master_dark != NULL) {
00587 check(
00588 sky_dark=xsh_pre_frameset_subtract_frame(sky_bias,master_dark,"MDARK",instrument));
00589 } else {
00590 sky_dark = cpl_frameset_duplicate(sky_bias);
00591 }
00592 sprintf(sky_tag, "%s_SKY_%s", rec_prefix, arm_str);
00593 check(avg_sky=xsh_frameset_average_pre(sky_dark,instrument,sky_tag));
00594 if (do_flatfield == 1) {
00595 sprintf(sky_tag, "%s_FF_SKY_%s", rec_prefix, arm_str);
00596 check(
00597 sky_divided = xsh_divide_flat( avg_sky,master_flat, sky_tag, instrument ));
00598 } else {
00599 sky_divided = cpl_frame_duplicate(avg_sky);
00600 }
00601 xsh_add_temporary_file(cpl_frame_get_filename(sky_divided));
00602 }
00603
00604 if (do_flatfield == 1) {
00605 clean_frameset=xsh_frameset_mflat_divide(sub_frameset,master_flat,instrument);
00606 } else {
00607 clean_frameset = cpl_frameset_duplicate(sub_frameset);
00608 }
00609
00610 {
00611 int clean_size ;
00612
00613 check( clean_size = cpl_frameset_get_size( clean_frameset ) ) ;
00614 xsh_msg( "Nb of clean Frames: %d", clean_size ) ;
00615 }
00616
00617
00618
00619 check( rect_frameset = cpl_frameset_new() ) ;
00620 for( i = 0 ; i < nb_sub_frames ; i++ ) {
00621 cpl_frame * rectif = NULL ;
00622 cpl_frame * rectif_eso = NULL ;
00623 cpl_frame * clean = NULL ;
00624 char str[16] ;
00625
00626 sprintf( str, "%d", i ) ;
00627 check( clean = cpl_frameset_get_frame( clean_frameset, i ) ) ;
00628 xsh_msg( "Rectifying Frame '%s'", cpl_frame_get_filename( clean ) ) ;
00629 sprintf(file_name,"RECTIFIED_SLIT_OFFSET_%s_%s.fits",arm_str,str) ;
00630 check( rectif = xsh_rectify( clean, order_tab_edges, wave_tab,
00631 model_config_frame, instrument,
00632 rectify_par, spectral_format,
00633 disp_tab_frame,
00634 file_name,&rectif_eso,&rectif_tab,
00635 rec_prefix) ) ;
00636 xsh_add_temporary_file(file_name);
00637 check( cpl_frameset_insert( rect_frameset, cpl_frame_duplicate(rectif) ) ) ;
00638 check( cpl_frameset_insert( rect_frameset, cpl_frame_duplicate(rectif_eso) ) ) ;
00639 xsh_free_frame(&rectif_tab);
00640 xsh_free_frame(&rectif_eso);
00641 xsh_free_frame(&rectif);
00642 }
00643
00644 if(gen_sky) {
00645 xsh_msg("rectify sky frame");
00646 sprintf(file_name,"%s_RECTIFIED_SKY_%s.fits",sky_prefix,arm_str) ;
00647 xsh_msg("file_name=%s",file_name);
00648 check( rec_sky = xsh_rectify(sky_divided, order_tab_edges, wave_tab,
00649 model_config_frame, instrument,
00650 rectify_par, spectral_format,
00651 disp_tab_frame,
00652 file_name,&rec_sky_eso,&rectif_tab,
00653 sky_prefix) ) ;
00654
00655 xsh_add_temporary_file(file_name);
00656
00657 xsh_msg("Merge 2D sky frame");
00658 check( mer_sky = xsh_merge_ord( rec_sky, instrument,
00659 merge_par,sky_prefix ));
00660
00661
00662 }
00663
00664
00665 sprintf(file_tag,"%s_%s_%s",rec_prefix,XSH_ORDER2D, arm_str) ;
00666 check(rect2_frameset_tables=xsh_frameset_ext_table_frames(rect_frameset));
00667 check( comb_frame = xsh_combine_nod(rect2_frameset_tables, combine_nod_param,
00668 file_tag,instrument,&comb_frame_eso));
00669 xsh_free_frameset(&rect2_frameset_tables);
00670
00671
00672 if ( extract_par->method == LOCALIZATION_METHOD ||
00673 extract_par->method == CLEAN_METHOD) {
00674 xsh_msg( "Localize before extraction" ) ;
00675 sprintf(file_name,"LOCALIZE_%s_ALL.fits",arm_str) ;
00676 check( loc_table_frame = xsh_localize_obj( comb_frame, NULL,instrument,
00677 loc_obj_par, NULL,
00678 file_name) ) ;
00679 xsh_add_temporary_file(file_name);
00680 }
00681
00682 xsh_msg( "Calling xsh_extract" ) ;
00683 check(ext_frame = xsh_extract_clean(comb_frame, loc_table_frame,
00684 instrument, extract_par,ipol_bp, &ext_frame_eso,
00685 rec_prefix )) ;
00686 xsh_msg( "Calling xsh_merge_ord with 1D frame" ) ;
00687 check( res1D_frame = xsh_merge_ord( ext_frame, instrument,
00688 merge_par,rec_prefix ));
00689 check( xsh_mark_tell( res1D_frame, tellmask_frame));
00690
00691
00692
00693
00694
00695
00696 xsh_msg( "Calling xsh_merge_ord with 2D frame" ) ;
00697 check( res2D_frame = xsh_merge_ord( comb_frame, instrument, merge_par,
00698 rec_prefix) ) ;
00699
00700 if(response_ord_frame != NULL && frm_atmext != NULL) {
00701 check(xsh_flux_calibrate(comb_frame_eso,ext_frame_eso,frm_atmext,
00702 response_ord_frame,merge_par,instrument,rec_prefix,
00703 &fluxcal_rect_2D_frame,&fluxcal_rect_1D_frame,
00704 &fluxcal_2D_frame,&fluxcal_1D_frame));
00705
00706 }
00707
00708
00709 if(model_config_frame!=NULL && wavemap != NULL&& slitmap != NULL) {
00710
00711 check(xsh_compute_resampling_accuracy(wavemap,slitmap,order_tab_edges,model_config_frame,comb_frame_eso,instrument));
00712 check(xsh_compute_resampling_accuracy(wavemap,slitmap,order_tab_edges,model_config_frame,res2D_frame,instrument));
00713
00714 check(xsh_compute_wavelength_resampling_accuracy(wavemap,order_tab_edges,model_config_frame,res1D_frame,instrument));
00715 check(xsh_compute_wavelength_resampling_accuracy(wavemap,order_tab_edges,model_config_frame,ext_frame_eso,instrument));
00716
00717 xsh_add_afc_info(model_config_frame,wavemap);
00718 xsh_add_afc_info(model_config_frame,slitmap);
00719
00720 if(fluxcal_rect_2D_frame != NULL) {
00721
00722 check(xsh_compute_resampling_accuracy(wavemap,slitmap,order_tab_edges,model_config_frame,fluxcal_rect_2D_frame,instrument));
00723 check(xsh_compute_resampling_accuracy(wavemap,slitmap,order_tab_edges,model_config_frame,fluxcal_2D_frame,instrument));
00724
00725 check(xsh_compute_wavelength_resampling_accuracy(wavemap,order_tab_edges,model_config_frame,fluxcal_rect_1D_frame,instrument));
00726 check(xsh_compute_wavelength_resampling_accuracy(wavemap,order_tab_edges,model_config_frame,fluxcal_1D_frame,instrument));
00727
00728 }
00729
00730 if(gen_sky) {
00731 check(xsh_compute_resampling_accuracy(wavemap,slitmap,order_tab_edges,model_config_frame,rec_sky_eso,instrument));
00732 check(xsh_compute_resampling_accuracy(wavemap,slitmap,order_tab_edges,model_config_frame,mer_sky,instrument));
00733 }
00734
00735 }
00736
00737
00738 xsh_msg( "Saving products" ) ;
00739
00740
00741
00742
00743
00744
00745 check( xsh_add_product_image( comb_frame_eso, frameset,
00746 parameters, RECIPE_ID, instrument,NULL));
00747
00748
00749
00750
00751
00752
00753 check( xsh_add_product_image( ext_frame_eso, frameset,
00754 parameters, RECIPE_ID, instrument,NULL));
00755
00756
00757 check( xsh_add_product_spectrum( res2D_frame, frameset, parameters,
00758 RECIPE_ID, instrument));
00759
00760 check(xsh_monitor_spectrum1D_flux(res1D_frame,instrument));
00761 check( xsh_add_product_spectrum( res1D_frame, frameset, parameters,
00762 RECIPE_ID, instrument));
00763
00764
00765 if(gen_sky) {
00766 check( xsh_add_product_image( avg_sky, frameset, parameters,
00767 RECIPE_ID, instrument,NULL));
00768
00769
00770 sprintf(file_tag,"%s_%s_%s",sky_prefix,XSH_ORDER2D, arm_str) ;
00771 check( xsh_add_product_image( rec_sky_eso, frameset, parameters,
00772 RECIPE_ID, instrument,NULL));
00773
00774
00775 sprintf(file_tag,"%s_%s_%s",sky_prefix,XSH_MERGE2D, arm_str) ;
00776 check( xsh_add_product_image( mer_sky, frameset, parameters,
00777 RECIPE_ID, instrument,NULL));
00778
00779 }
00780
00781 if(fluxcal_rect_2D_frame != NULL) {
00782 check( xsh_add_product_image(fluxcal_rect_2D_frame,frameset,parameters,
00783 RECIPE_ID, instrument,NULL));
00784 check( xsh_add_product_image(fluxcal_rect_1D_frame,frameset,parameters,
00785 RECIPE_ID, instrument,NULL));
00786 check( xsh_add_product_spectrum( fluxcal_2D_frame, frameset, parameters,
00787 RECIPE_ID, instrument));
00788 check( xsh_add_product_spectrum( fluxcal_1D_frame, frameset, parameters,
00789 RECIPE_ID, instrument));
00790 }
00791 if (do_computemap){
00792
00793
00794
00795 check(xsh_add_product_image( wavemap, frameset,
00796 parameters, RECIPE_ID, instrument, NULL));
00797
00798
00799
00800 check(xsh_add_product_image( slitmap, frameset,
00801 parameters, RECIPE_ID, instrument,NULL));
00802 }
00803
00804 cleanup:
00805
00806 xsh_end( RECIPE_ID, frameset, parameters );
00807 XSH_FREE( rec_prefix);
00808 XSH_FREE( crh_single_par ) ;
00809 XSH_FREE( rectify_par ) ;
00810 XSH_FREE( loc_obj_par ) ;
00811 XSH_FREE(extract_par);
00812 XSH_FREE(ipol_bp);
00813 XSH_FREE(combine_nod_param);
00814 xsh_instrument_free(&instrument );
00815 xsh_free_frameset(&rect2_frameset_tables);
00816 xsh_free_frameset(&raws);
00817
00818
00819 if(nobj>0) {
00820 xsh_free_frameset( &raw_object);
00821 }
00822 if(nsky>0) {
00823 xsh_free_frameset( &raw_sky);
00824 }
00825
00826 xsh_free_frameset(&calib);
00827
00828
00829 xsh_free_frameset(&clean_frameset);
00830
00831 xsh_free_frameset(&crh_clean_obj);
00832 xsh_free_frameset(&crh_clean_sky);
00833
00834
00835 xsh_free_frameset(&rect_frameset);
00836
00837 xsh_free_frameset(&sky_bias);
00838 xsh_free_frameset(&sky_dark);
00839
00840 xsh_free_frame(&wavemap) ;
00841 xsh_free_frame(&slitmap) ;
00842 xsh_free_frame(&loc_table_frame) ;
00843 xsh_free_frame(&clean_frame) ;
00844 xsh_free_frame(&res1D_frame) ;
00845 xsh_free_frame(&res2D_frame) ;
00846 xsh_free_frame( &comb_frame ) ;
00847 xsh_free_frame( &comb_frame_eso ) ;
00848 xsh_free_frame( &ext_frame ) ;
00849 xsh_free_frame( &ext_frame_eso ) ;
00850
00851 xsh_free_frame( &avg_sky ) ;
00852 xsh_free_frame( &sky_divided ) ;
00853 xsh_free_frame( &rec_sky ) ;
00854 xsh_free_frame( &rec_sky_eso ) ;
00855 xsh_free_frame( &mer_sky ) ;
00856
00857 xsh_free_frame( &frame_backg ) ;
00858 xsh_free_frame( &grid_back ) ;
00859 xsh_free_frame(&fluxcal_rect_1D_frame) ;
00860 xsh_free_frame(&fluxcal_rect_2D_frame) ;
00861 xsh_free_frame(&fluxcal_1D_frame) ;
00862 xsh_free_frame(&fluxcal_2D_frame) ;
00863
00864 return;
00865 }
00866