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
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00040
00043
00044
00045
00046
00047
00048
00049
00050
00051 #include <xsh_error.h>
00052
00053 #include <xsh_utils.h>
00054 #include <xsh_msg.h>
00055 #include <xsh_model_utils.h>
00056 #include <xsh_utils_scired_slit.h>
00057 #include <xsh_data_instrument.h>
00058 #include <xsh_data_spectrum1D.h>
00059
00060 #include <xsh_dfs.h>
00061 #include <xsh_pfits.h>
00062
00063 #include <xsh_drl.h>
00064 #include <xsh_drl_check.h>
00065 #include <xsh_model_arm_constants.h>
00066
00067
00068 #include <cpl.h>
00069
00070
00071
00072
00073
00074
00075 #define RECIPE_ID "xsh_scired_slit_nod"
00076 #define RECIPE_AUTHOR "P.Goldoni, L.Guglielmi, R. Haigron, F. Royer"
00077 #define RECIPE_CONTACT "amodigli@eso.org"
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 static int xsh_scired_slit_nod_create(cpl_plugin *);
00088 static int xsh_scired_slit_nod_exec(cpl_plugin *);
00089 static int xsh_scired_slit_nod_destroy(cpl_plugin *);
00090
00091
00092 static void xsh_scired_slit_nod(cpl_parameterlist *, cpl_frameset *);
00093
00094
00095
00096
00097 static char xsh_scired_slit_nod_description_short[] =
00098 "Reduce science frames in SLIT configuration and nod mode";
00099
00100 static char xsh_scired_slit_nod_description[] =
00101 "This recipe reduces science exposure in SLIT configuration and NOD mode\n\
00102 Input Frames : \n\
00103 - A set of n Science frames ( n even ), \
00104 Tag = OBJECT_SLIT_NOD_arm\n\
00105 - Spectral format table (Tag = SPECTRAL_FORMAT_TAB_arm)\n\
00106 - [UVB,VIS] A master bias frame (Tag = MASTER_BIAS_arm)\n\
00107 - A master flat frame (Tag = MASTER_FLAT_SLIT_arm)\n\
00108 - An order table frame(Tag = ORDER_TABLE_EDGES_SLIT_arm)\n\
00109 - [poly mode] A wave solution frame(Tag = WAVE_TAB_2D_arm)\n\
00110 - [poly mode] A wave map frame(Tag = WAVE_MAP_arm)\n\
00111 - [poly mode] A disp table frame(Tag = DISP_TAB_arm)\n\
00112 - [physical model mode]A model cfg table (Format = TABLE, Tag = XSH_MOD_CFG_TAB_arm)\n\
00113 - [OPTIONAL] A non-linear badpixel map (Tag = BP_MAP_NL_arm)\n\
00114 - [OPTIONAL] A reference badpixel map (Tag = BP_MAP_RP_arm)\n\
00115 - [OPTIONAL] The instrument response table (Tag = RESPONSE_MERGE1D_SLIT_arm)\n\
00116 - [OPTIONAL] An atmospheric extinction table (Tag = ATMOS_EXT_arm)\n\
00117 - [OPTIONAL] A telluric mask (Tag = TELL_MASK_arm)\n\
00118 Products : \n\
00119 - PREFIX_ORDER2D_arm (2 dimension)\n\
00120 - PREFIX_ORDER1D_arm (1 dimension)\n\
00121 - PREFIX_MERGE2D_arm (2 dimension)\n\
00122 - PREFIX_MERGE1D_arm (1 dimension)\n\
00123 - [OPTIONAL, if response and atm ext are provided] PREFIX_FLUXCAL2D_arm (2 dimension)\n\
00124 - [OPTIONAL, if response and atm ext are provided] PREFIX_FLUXCAL1D_arm (1 dimension)\n\
00125 - where PREFIX is SCI, FLUX, TELL if input raw DPR.TYPE contains OBJECT or FLUX or TELLURIC";
00126
00127
00128
00129
00138
00139
00140 int cpl_plugin_get_info(cpl_pluginlist *list) {
00141 cpl_recipe *recipe = NULL;
00142 cpl_plugin *plugin = NULL;
00143
00144 recipe = cpl_calloc(1, sizeof(*recipe));
00145 if ( recipe == NULL ){
00146 return -1;
00147 }
00148
00149 plugin = &recipe->interface ;
00150
00151 cpl_plugin_init(plugin,
00152 CPL_PLUGIN_API,
00153 XSH_BINARY_VERSION,
00154 CPL_PLUGIN_TYPE_RECIPE,
00155 RECIPE_ID,
00156 xsh_scired_slit_nod_description_short,
00157 xsh_scired_slit_nod_description,
00158 RECIPE_AUTHOR,
00159 RECIPE_CONTACT,
00160 xsh_get_license(),
00161 xsh_scired_slit_nod_create,
00162 xsh_scired_slit_nod_exec,
00163 xsh_scired_slit_nod_destroy);
00164
00165 cpl_pluginlist_append(list, plugin);
00166
00167 return (cpl_error_get_code() != CPL_ERROR_NONE);
00168 }
00169
00170
00171
00172
00173
00183
00184
00185 static int xsh_scired_slit_nod_create(cpl_plugin *plugin){
00186 cpl_parameter* p=NULL;
00187 cpl_recipe *recipe = NULL;
00188 xsh_remove_crh_single_param crh_single = { 0.1, 5.0, 2.0, 4} ;
00189 xsh_rectify_param rectify = { "default",
00190 CPL_KERNEL_DEFAULT,
00191 4,
00192 -1.0,
00193 -1.0,
00194 1,
00195 0,0. };
00196 xsh_localize_obj_param loc_obj =
00197 {10, 0.1, 0, 0, LOC_GAUSSIAN_METHOD, 0, 0.5,3,3, FALSE};
00198 xsh_extract_param extract_par =
00199 { NOD_METHOD};
00200 xsh_combine_nod_param nod_param = { 5, TRUE, 5, 2, 0.1, "throwlist.asc", COMBINE_MEAN_METHOD} ;
00201 xsh_slit_limit_param slit_limit_param = { MIN_SLIT, MAX_SLIT, 0, 0 } ;
00202 xsh_clipping_param crh_clip_param = {5.0, 5, 0.7, 0, 0.3};
00203 xsh_stack_param stack_param = {"median",5.,5.,5};
00204
00205
00206 xsh_init();
00207
00208
00209 nod_param.nod_min = 5;
00210 nod_param.nod_clip = TRUE;
00211 nod_param.nod_clip_sigma = 5.;
00212 nod_param.nod_clip_niter = 2;
00213 nod_param.nod_clip_diff = 0.1;
00214 nod_param.throwname = "throwlist.asc";
00215
00216
00217 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
00218
00219
00220 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00221 CPL_ERROR_TYPE_MISMATCH,
00222 "Plugin is not a recipe");
00223
00224 recipe = (cpl_recipe *)plugin;
00225
00226
00227 recipe->parameters = cpl_parameterlist_new();
00228 assure( recipe->parameters != NULL,
00229 CPL_ERROR_ILLEGAL_OUTPUT,
00230 "Memory allocation failed!");
00231
00232
00233 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
00234 check( xsh_parameters_pre_overscan( RECIPE_ID, recipe->parameters ) ) ;
00235 check(xsh_parameters_stack_create(RECIPE_ID,recipe->parameters,stack_param));
00236
00237 check(xsh_parameters_background_create(RECIPE_ID,recipe->parameters));
00238 check(p=xsh_parameters_find(recipe->parameters,RECIPE_ID,"background-method"));
00239 cpl_parameter_set_default_string(p,"poly");
00240
00241
00242 check( xsh_parameters_remove_crh_single_create( RECIPE_ID,
00243 recipe->parameters, crh_single));
00244
00245
00246 check(xsh_parameters_rectify_create(RECIPE_ID,recipe->parameters,
00247 rectify )) ;
00248 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00249 "rectify-fast", TRUE,
00250 "Fast if TRUE (Rect[B-A] = -Rect[A-B]), in that case only entire pixel shifts are applied. "));
00251
00252
00253
00254 check(xsh_parameters_localize_obj_create(RECIPE_ID,recipe->parameters,
00255 loc_obj )) ;
00256
00257 check( xsh_parameters_new_double( recipe->parameters, RECIPE_ID,
00258 "localize-nod-throw", loc_obj.nod_step,
00259 "Step (arcsec) between A and B images in nodding mode."));
00260
00261
00262
00263 check(xsh_parameters_extract_create(RECIPE_ID,
00264 recipe->parameters,
00265 extract_par,NOD_METHOD )) ;
00266
00267 check(xsh_parameters_merge_ord_create(RECIPE_ID,
00268 recipe->parameters,
00269 WEIGHTED_MERGE_METHOD)) ;
00270
00271 check(xsh_parameters_combine_nod_create(RECIPE_ID,
00272 recipe->parameters,
00273 nod_param )) ;
00274
00275 check(xsh_parameters_slit_limit_create(RECIPE_ID,
00276 recipe->parameters,
00277 slit_limit_param )) ;
00278
00279 check(xsh_parameters_clipping_crh_create(RECIPE_ID,recipe->parameters,
00280 crh_clip_param));
00281
00282 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00283 "compute-map", TRUE,
00284 "if TRUE recompute (wave and slit) maps from the dispersion solution. Use FALSE only if you are sure to have wave and slit maps better than what this recipe may compute."));
00285 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00286 "do-flatfield", TRUE,
00287 "TRUE if we do the flatfielding"));
00288
00289 cleanup:
00290 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
00291 xsh_error_dump(CPL_MSG_ERROR);
00292 return 1;
00293 }
00294 else {
00295 return 0;
00296 }
00297 }
00298
00299
00305
00306
00307 static int xsh_scired_slit_nod_exec(cpl_plugin *plugin) {
00308 cpl_recipe *recipe = NULL;
00309
00310
00311
00312 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00313
00314
00315 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00316 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00317
00318 recipe = (cpl_recipe *)plugin;
00319
00320
00321 xsh_scired_slit_nod(recipe->parameters, recipe->frames);
00322
00323 cleanup:
00324 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
00325 xsh_error_dump(CPL_MSG_ERROR);
00326 xsh_error_reset();
00327 return 1;
00328 }
00329 else {
00330 return 0;
00331 }
00332 }
00333
00334
00340
00341 static int xsh_scired_slit_nod_destroy(cpl_plugin *plugin)
00342 {
00343 cpl_recipe *recipe = NULL;
00344
00345
00346 xsh_error_reset();
00347
00348 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00349
00350
00351 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00352 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00353
00354 recipe = (cpl_recipe *)plugin;
00355
00356 xsh_free_parameterlist(&recipe->parameters);
00357
00358 cleanup:
00359 if (cpl_error_get_code() != CPL_ERROR_NONE)
00360 {
00361 return 1;
00362 }
00363 else
00364 {
00365 return 0;
00366 }
00367 }
00368 #if 0
00369 static void change_file_name( cpl_frame * frame, const char * name )
00370 {
00371 const char * old_name ;
00372 char * cmd ;
00373
00374 old_name = cpl_frame_get_filename( frame ) ;
00375 cmd = xsh_stringcat_any( "mv ", old_name, " ", name, NULL ) ;
00376 cpl_frame_set_filename( frame, name ) ;
00377
00378 system( cmd ) ;
00379 XSH_FREE( cmd ) ;
00380 }
00381 #endif
00382
00383
00391 static void
00392 xsh_get_binning(cpl_frameset* raws,int* binx, int* biny)
00393 {
00394 cpl_frame* frame=NULL;
00395 const char* name=NULL;
00396 cpl_propertylist* plist=NULL;
00397 int nraw=0;
00398
00399 XSH_ASSURE_NOT_NULL_MSG(raws,"Null pointer for input raw frameset");
00400 nraw=cpl_frameset_get_size(raws);
00401
00402 XSH_ASSURE_NOT_ILLEGAL_MSG(nraw > 0,"nraw = 0 Provide at least a raw frame");
00403
00404 check(frame=cpl_frameset_get_first(raws));
00405 check(name=cpl_frame_get_filename(frame));
00406 check(plist=cpl_propertylist_load(name,0));
00407 check(*binx=xsh_pfits_get_binx(plist));
00408 check(*biny=xsh_pfits_get_biny(plist));
00409
00410 cleanup:
00411 xsh_free_propertylist(&plist);
00412
00413 return;
00414 }
00415
00416
00417
00425
00426
00427 static cpl_error_code
00428 xsh_params_bin_scale(int binx,int biny)
00429 {
00430
00431
00432 if(biny>1) {
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457 }
00458
00459
00460 if(binx>1) {
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474 }
00475
00476
00477 return cpl_error_get_code();
00478
00479 }
00480
00481
00482
00490
00491 static void xsh_scired_slit_nod( cpl_parameterlist* parameters,
00492 cpl_frameset* frameset)
00493 {
00494 const char* recipe_tags[3] = {XSH_OBJECT_SLIT_NOD,XSH_STD_TELL_SLIT_NOD,XSH_STD_FLUX_SLIT_NOD};
00495 int recipe_tags_size = 3;
00496
00497
00498 cpl_frameset *raws = NULL;
00499 cpl_frameset *raws_ord_set = NULL;
00500 cpl_frameset *calib = NULL;
00501
00502
00503 cpl_frame* bpmap = NULL;
00504 cpl_frame *master_bias = NULL;
00505 cpl_frame* master_flat = NULL;
00506 cpl_frame* order_tab_edges = NULL;
00507 cpl_frame * wave_tab = NULL ;
00508 cpl_frame * model_config_frame = NULL;
00509 cpl_frame * wavemap = NULL;
00510 cpl_frame * spectral_format = NULL;
00511 cpl_frame *tellmask_frame = NULL;
00512
00513
00514 int rectify_fast = 0 ;
00515 xsh_clipping_param* crh_clipping_par = NULL;
00516 xsh_instrument* instrument = NULL;
00517 xsh_remove_crh_single_param * crh_single_par = NULL;
00518 xsh_rectify_param * rectify_par = NULL;
00519 xsh_localize_obj_param * loc_obj_par = NULL;
00520 xsh_merge_param* merge_par = NULL;
00521 xsh_extract_param * extract_par = NULL;
00522 xsh_combine_nod_param * combine_nod_par = NULL;
00523 xsh_slit_limit_param * slit_limit_par = NULL;
00524 xsh_stack_param* stack_par=NULL;
00525
00526 char comb_tag[80];
00527 int binx=0;
00528 int biny=0;
00529
00530 int nb_raw_frames;
00531 int nb_pairs ;
00532
00533
00534
00535
00536
00537
00538 cpl_frameset* raws_avg=NULL;
00539 cpl_frame* disp_tab_frame=NULL;
00540 cpl_frame* slitmap=NULL;
00541 cpl_frame *skymask_frame = NULL;
00542
00543 int do_computemap=0;
00544 int do_flatfield = CPL_TRUE;
00545 int even_nb ;
00546
00547 char *rec_prefix = NULL;
00548
00549 cpl_frameset *nod_set = NULL;
00550 cpl_frameset *comb_set = NULL;
00551 cpl_frameset *comb_eff_set = NULL;
00552 cpl_frame *comb_frame = NULL;
00553 cpl_frame *combeso_frame = NULL;
00554 cpl_frame *res2D_frame = NULL;
00555 cpl_frame *loc_table_frame = NULL;
00556 cpl_frame *res1D_frame = NULL;
00557 cpl_frame *res1Deso_frame = NULL;
00558 cpl_frame *s1D_frame = NULL;
00559 cpl_frame* response_ord_frame=NULL;
00560 cpl_frame * fluxcal_1D_frame = NULL ;
00561 cpl_frame * fluxcal_2D_frame = NULL ;
00562 cpl_frame * fluxcal_rect_1D_frame = NULL ;
00563 cpl_frame * fluxcal_rect_2D_frame = NULL ;
00564
00565 cpl_frame* frm_atmext=NULL;
00566 int pre_overscan_corr=0;
00567
00568
00569
00570 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
00571 recipe_tags, recipe_tags_size, RECIPE_ID,
00572 XSH_BINARY_VERSION,
00573 xsh_scired_slit_nod_description_short));
00574
00575
00576 assure( instrument->mode == XSH_MODE_SLIT, CPL_ERROR_ILLEGAL_INPUT,
00577 "Instrument NOT in Slit Mode");
00578
00579 check(xsh_ensure_raws_number_is_even(raws));
00580 xsh_recipe_params_check(parameters,instrument,RECIPE_ID);
00581 if(instrument->arm == XSH_ARM_NIR) {
00582 xsh_instrument_nir_corr_if_JH(raws,instrument);
00583 }
00584
00585
00586
00587 check( rec_prefix = xsh_set_recipe_file_prefix(raws,"xsh_scired_slit_nod"));
00588
00589
00590 check( nb_raw_frames = cpl_frameset_get_size( raws));
00591 check( raws_ord_set = xsh_order_frameset_by_date( raws));
00592
00593 xsh_msg_dbg_low( "Nb of Raw frames: %d", nb_raw_frames);
00594
00595 even_nb = nb_raw_frames % 2 ;
00596 XSH_ASSURE_NOT_ILLEGAL( even_nb == 0);
00597
00598 nb_pairs = nb_raw_frames/2 ;
00599 XSH_ASSURE_NOT_ILLEGAL( nb_pairs != 0 );
00600
00601
00602
00603
00604 check( stack_par = xsh_stack_frames_get( RECIPE_ID, parameters));
00605 check( crh_clipping_par = xsh_parameters_clipping_crh_get(RECIPE_ID,
00606 parameters));
00607 check( do_computemap = xsh_parameters_get_boolean( parameters, RECIPE_ID,
00608 "compute-map"));
00609 check( do_flatfield = xsh_parameters_get_boolean( parameters, RECIPE_ID,
00610 "do-flatfield"));
00611
00612 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR){
00613 xsh_get_binning(raws, &binx, &biny);
00614 } else {
00615 binx=1;
00616 biny=1;
00617 }
00618
00619 check( xsh_scired_nod_get_parameters( parameters,instrument,
00620 &crh_single_par, &rectify_par,
00621 &merge_par, &extract_par,
00622 &combine_nod_par,
00623 &slit_limit_par, &loc_obj_par,
00624 &rectify_fast, &pre_overscan_corr,
00625 RECIPE_ID));
00626
00627 check( xsh_scired_slit_nod_get_calibs(raws,calib,instrument,
00628 &bpmap,&master_bias,&master_flat,
00629 &order_tab_edges,&wave_tab,
00630 &model_config_frame,&wavemap,&slitmap,
00631 &disp_tab_frame,
00632 &spectral_format,
00633 &skymask_frame,
00634 &response_ord_frame,
00635 &frm_atmext,
00636 do_computemap,
00637 loc_obj_par->use_skymask,
00638 pre_overscan_corr,
00639 rec_prefix,RECIPE_ID));
00640
00641 tellmask_frame = xsh_find_frame_with_tag(calib,XSH_TELL_MASK, instrument);
00642
00643 if ( rectify_fast == CPL_FALSE && loc_obj_par->method == LOC_MANUAL_METHOD){
00644 xsh_error_msg( "Mode accurate can not be use with localize-method MANUAL");
00645 }
00646
00647
00648
00649
00650
00651 check( xsh_prepare( raws_ord_set, bpmap, master_bias, XSH_OBJECT_SLIT_NOD,
00652 instrument,pre_overscan_corr));
00653
00654
00655 #if 0
00656 check(offsets=xsh_get_offsets(raws_ord_set));
00657 check(offsets_dif=xsh_get_noffsets(offsets));
00658
00659
00660
00661
00662 ngroups=cpl_vector_get_size(offsets_dif);
00663 xsh_msg("ngroups=%d",ngroups);
00664 #endif
00665
00666 check( raws_avg = xsh_nod_group_by_reloff( raws_ord_set,
00667 instrument,stack_par,crh_clipping_par));
00668 #if 0
00669 check( raws_avg = xsh_nod_prepare_set( raws_ord_set,
00670 instrument,crh_clipping_par));
00671
00672 noffs=cpl_frameset_get_size(raws_avg);
00673 even_nb = noffs % 2;
00674 xsh_msg("even_nb=%d nb_raw_frames=%d",even_nb,nb_raw_frames);
00675 xsh_msg("nb raws avg=%d",cpl_frameset_get_size(raws_avg));
00676 xsh_frameset_dump_nod_info(raws_avg);
00677 if (even_nb!=0 && nb_raw_frames ==4) {
00678 xsh_msg("special case even_nb!=0 && nb_raw_frames ==4");
00679
00680 xsh_free_frameset(&raws_avg);
00681 check(raws_avg=cpl_frameset_duplicate(raws_ord_set));
00682 } else {
00683 xsh_msg("ensure input nod positions number is even");
00684 check(xsh_ensure_raws_number_is_even(raws_avg));
00685 }
00686 #endif
00687
00688 #if 0
00689 check(raws_avg=xsh_avg_raws_same_off(raws_ord_set,offsets_dif,crh_clipping_par,instrument));
00690 xsh_classif(offsets,&ngroups);
00691 #endif
00692 check( nod_set = xsh_subtract_sky_nod( raws_avg, instrument, rectify_fast));
00693
00694
00695 if ( rectify_fast ){
00696
00697 check(comb_set=xsh_scired_slit_nod_fast(
00698 nod_set,
00699 spectral_format,
00700 master_flat,
00701 order_tab_edges,
00702 wave_tab,
00703 model_config_frame,
00704 disp_tab_frame,
00705 wavemap,
00706 instrument,
00707 crh_single_par,
00708 rectify_par,
00709 do_flatfield,1,
00710 rec_prefix,
00711 &comb_eff_set));
00712
00713 }
00714 else {
00715 check( comb_set = xsh_scired_slit_nod_accurate(
00716 nod_set,
00717 spectral_format,
00718 master_flat,
00719 order_tab_edges,
00720 wave_tab,
00721 model_config_frame,
00722 disp_tab_frame,
00723 wavemap,
00724 skymask_frame,
00725 instrument,
00726 crh_single_par,
00727 rectify_par,
00728 loc_obj_par,
00729 combine_nod_par->throwname,
00730 do_flatfield,
00731 rec_prefix
00732 ));
00733
00734
00735 }
00736
00737
00738
00739
00740 sprintf( comb_tag,"%s_%s",
00741 rec_prefix, XSH_GET_TAG_FROM_ARM( XSH_ORDER2D, instrument));
00742 check( comb_frame = xsh_combine_nod( comb_set, combine_nod_par,
00743 comb_tag, instrument,&combeso_frame));
00744
00745
00746 check( res2D_frame = xsh_merge_ord( comb_frame, instrument,
00747 merge_par,rec_prefix));
00748
00749
00750 if ( extract_par->method == LOCALIZATION_METHOD ) {
00751 xsh_msg( "Re-Localize before extraction" ) ;
00752 check( loc_table_frame = xsh_localize_obj( comb_frame, skymask_frame,instrument,
00753 loc_obj_par, slit_limit_par, "LOCALIZE.fits"));
00754 }
00755
00756 xsh_msg( "Extract 1D order-by-order spectrum" ) ;
00757 check( res1D_frame = xsh_extract( comb_frame, loc_table_frame,
00758 instrument, extract_par, &res1Deso_frame, rec_prefix));
00759 xsh_msg( "Merge orders with 1D frame" ) ;
00760 check( s1D_frame = xsh_merge_ord( res1D_frame, instrument,
00761 merge_par,rec_prefix));
00762 check( xsh_mark_tell( s1D_frame, tellmask_frame));
00763 if(model_config_frame) {
00764 xsh_compute_resampling_accuracy(wavemap,slitmap,order_tab_edges,model_config_frame,res2D_frame,instrument);
00765 }
00766 if(response_ord_frame != NULL && frm_atmext != NULL) {
00767 check(xsh_flux_calibrate(combeso_frame,res1Deso_frame,frm_atmext,
00768 response_ord_frame,merge_par,instrument,rec_prefix,
00769 &fluxcal_rect_2D_frame,&fluxcal_rect_1D_frame,
00770 &fluxcal_2D_frame,&fluxcal_1D_frame));
00771 }
00772
00773
00774 check( xsh_add_product_image( combeso_frame, frameset,
00775 parameters, RECIPE_ID, instrument,NULL));
00776
00777 check( xsh_add_product_image( res1Deso_frame, frameset, parameters,
00778 RECIPE_ID, instrument,NULL));
00779
00780 check( xsh_add_product_pre( res2D_frame, frameset, parameters,
00781 RECIPE_ID, instrument));
00782 check(xsh_monitor_spectrum1D_flux(s1D_frame,instrument));
00783
00784 check( xsh_add_product_spectrum( s1D_frame, frameset, parameters,
00785 RECIPE_ID, instrument));
00786
00787 if ( do_computemap){
00788
00789 check( xsh_add_product_image( wavemap, frameset,
00790 parameters, RECIPE_ID, instrument,NULL));
00791
00792
00793 check( xsh_add_product_image( slitmap, frameset,
00794 parameters, RECIPE_ID, instrument,NULL));
00795 }
00796
00797 if(fluxcal_2D_frame != NULL) {
00798 check( xsh_add_product_image(fluxcal_rect_2D_frame,frameset,parameters,
00799 RECIPE_ID, instrument,NULL));
00800 check( xsh_add_product_image(fluxcal_rect_1D_frame,frameset,parameters,
00801 RECIPE_ID, instrument,NULL));
00802
00803 check( xsh_add_product_spectrum( fluxcal_2D_frame, frameset, parameters,
00804 RECIPE_ID, instrument));
00805 check( xsh_add_product_spectrum( fluxcal_1D_frame, frameset, parameters,
00806 RECIPE_ID, instrument));
00807 }
00808
00809
00810 cleanup:
00811
00812 xsh_end( RECIPE_ID, frameset, parameters);
00813 xsh_instrument_free( &instrument);
00814 xsh_free_frameset( &raws);
00815 xsh_free_frameset( &calib);
00816 XSH_FREE( rec_prefix);
00817 xsh_free_frameset( &raws_ord_set);
00818 xsh_free_frameset( &raws_avg);
00819 xsh_free_frame( &wavemap);
00820 xsh_free_frame( &slitmap);
00821
00822
00823 XSH_FREE( stack_par);
00824 XSH_FREE( rectify_par);
00825 XSH_FREE( crh_clipping_par);
00826 XSH_FREE( crh_single_par);
00827 XSH_FREE( loc_obj_par);
00828 XSH_FREE( slit_limit_par);
00829 XSH_FREE( combine_nod_par);
00830 XSH_FREE( extract_par);
00831 XSH_FREE( merge_par);
00832
00833
00834 xsh_free_frameset( &nod_set);
00835 xsh_free_frameset( &comb_set);
00836 xsh_free_frameset( &comb_eff_set);
00837 xsh_free_frame( &comb_frame);
00838 xsh_free_frame( &combeso_frame);
00839 xsh_free_frame( &res2D_frame);
00840 xsh_free_frame( &loc_table_frame);
00841 xsh_free_frame( &res1D_frame);
00842
00843 xsh_free_frame( &res1Deso_frame);
00844 xsh_free_frame( &s1D_frame);
00845 xsh_free_frame(&fluxcal_1D_frame) ;
00846 xsh_free_frame(&fluxcal_2D_frame) ;
00847 xsh_free_frame(&fluxcal_rect_1D_frame) ;
00848 xsh_free_frame(&fluxcal_rect_2D_frame) ;
00849
00850 return;
00851 }
00852