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
00042
00045
00046
00047
00048
00049
00050
00051
00052
00053 #include <xsh_error.h>
00054
00055 #include <xsh_utils.h>
00056 #include <xsh_msg.h>
00057
00058 #include <xsh_dfs.h>
00059
00060 #include <xsh_data_order.h>
00061 #include <xsh_drl.h>
00062 #include <xsh_model_kernel.h>
00063
00064 #include <cpl.h>
00065
00066
00067
00068
00069
00070 #define RECIPE_ID "xsh_2dmap"
00071 #define RECIPE_AUTHOR "R. Haigron"
00072 #define RECIPE_CONTACT "amodigli@eso.org"
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 static int xsh_2dmap_create(cpl_plugin *);
00083 static int xsh_2dmap_exec(cpl_plugin *);
00084 static int xsh_2dmap_destroy(cpl_plugin *);
00085
00086
00087 static void xsh_2dmap(cpl_parameterlist *, cpl_frameset *);
00088
00089
00090
00091
00092 static char xsh_2dmap_description_short[] =
00093 "Creates a wavelength and spatial resampling solution, a clean arc line list";
00094
00095 static char xsh_2dmap_description[] =
00096 "This recipe creates a wavelength and spatial resampling solution, a clean arc line list.\n\
00097 a residual map and a wave map.\n\
00098 Input Frames:\n\
00099 Raw Frame (Tag = WAVE_arm)\n\
00100 Arc Line List (Tag = ARC_LINE_LIST_arm)\n\
00101 Order Table (Tag = ORDER_TAB_EDGES_arm)\n\
00102 Master Bias (Tag = MASTER_BIAS_arm)\n\
00103 [poly mode] Wave Solution (Tag = WAVE_TAB_GUESS_arm)\n\
00104 [poly mode] Theoretical Map (Tag = THEO_TAB_MULT_arm)\n\
00105 [physical model mode] model cfg table (Tag = XSH_MOD_CFG_TAB_arm)\n\
00106 [OPTIONAL] Master Dark (Tag = MASTER_DARK_arm)\n\
00107 [OPTIONAL] Bad Pixel Map (Tag = MASTER_BP_MAP_arm)\n\
00108 Prepare the frames.\n\
00109 For UVB,VIS:\n\
00110 Subtract Master Bias.\n\
00111 Subtract Master Dark.\n\
00112 For NIR:\n\
00113 Subtract ON OFF \n\
00114 Compute Wavelength Solution, clean arc line list, residual table, wave map\n\
00115 Products:\n\
00116 A clean arc list PRO.CATG=ARC_LINE_LIST_2DMAP_arm\n\
00117 Wavelength table solution, PRO.CATG = WAVE_TAB_2D_arm [poly mode]\n\
00118 Wavelength image map solution, PRO.CATG = WAVE_RESID_TAB_2D_arm\n\
00119 A Residual tab, PRO.CATG=WAVE_RESID_TAB_SLIT_arm\n\
00120 A Wavelelength map, PRO.CATG=WAVE_MAP_arm. [if model-wavemap-compute=TRUE]\n\
00121 A Slit map image, PRO.CATG=SLIT_MAP_NIR [if model-wavemap-compute=TRUE]\n\
00122 A Dispersion solution table, PRO.CATG=DISP_TAB_NIR\n\
00123 An Arc frame in pre format bias subtracted, \n\
00124 PRO.CATG=WAVE_BIAS_SUBTRACT_arm if arm=UVB|VIS and PRO.CATG=WAVE_NIR_ON if NIR\n\
00125 The optimized model cfg frame, PRO.CATG=MODEL_CONFIG_OPT_arm [if physical model mode].\n";
00126
00127
00128
00129
00130
00131
00132
00133
00142
00143
00144 int cpl_plugin_get_info(cpl_pluginlist *list) {
00145 cpl_recipe *recipe = NULL;
00146 cpl_plugin *plugin = NULL;
00147
00148 recipe = cpl_calloc(1, sizeof(*recipe));
00149 if ( recipe == NULL ){
00150 return -1;
00151 }
00152
00153 plugin = &recipe->interface ;
00154
00155 cpl_plugin_init(plugin,
00156 CPL_PLUGIN_API,
00157 XSH_BINARY_VERSION,
00158 CPL_PLUGIN_TYPE_RECIPE,
00159 RECIPE_ID,
00160 xsh_2dmap_description_short,
00161 xsh_2dmap_description,
00162 RECIPE_AUTHOR,
00163 RECIPE_CONTACT,
00164 xsh_get_license(),
00165 xsh_2dmap_create,
00166 xsh_2dmap_exec,
00167 xsh_2dmap_destroy);
00168
00169 cpl_pluginlist_append(list, plugin);
00170
00171 return (cpl_error_get_code() != CPL_ERROR_NONE);
00172 }
00173
00174
00184
00185
00186 static int xsh_2dmap_create(cpl_plugin *plugin){
00187 cpl_recipe *recipe = NULL;
00188 xsh_clipping_param detarc_clip_param = {2.0, 0, 0.7, 0, 0.3};
00189 xsh_detect_arclines_param detarc_param =
00190 {4, 2, 0, 5, 4, 1, 5, 10.0,
00191 XSH_GAUSSIAN_METHOD, FALSE};
00192 xsh_dispersol_param dispsol_param = { 5, 5 } ;
00193 char paramname[256];
00194 cpl_parameter* p=NULL;
00195
00196
00197 xsh_init();
00198
00199
00200 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
00201
00202
00203 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00204 CPL_ERROR_TYPE_MISMATCH,
00205 "Plugin is not a recipe");
00206
00207 recipe = (cpl_recipe *)plugin;
00208
00209
00210 recipe->parameters = cpl_parameterlist_new();
00211 assure( recipe->parameters != NULL,
00212 CPL_ERROR_ILLEGAL_OUTPUT,
00213 "Memory allocation failed!");
00214
00215
00216 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
00217 check( xsh_parameters_pre_overscan( RECIPE_ID, recipe->parameters ) ) ;
00218
00219
00220
00221
00222 check(xsh_parameters_detect_arclines_create(RECIPE_ID, recipe->parameters,
00223 detarc_param));
00224 check(xsh_parameters_clipping_detect_arclines_create(RECIPE_ID,
00225 recipe->parameters, detarc_clip_param));
00226 check(xsh_parameters_dispersol_create(RECIPE_ID,
00227 recipe->parameters,
00228 dispsol_param ) ) ;
00229
00230
00231 check( xsh_parameters_new_int( recipe->parameters, RECIPE_ID,
00232 "model-maxit",200,
00233 "Number/10 of annealing iterations "
00234 "(physical model mode)."));
00235
00236
00237 check( xsh_parameters_new_double( recipe->parameters, RECIPE_ID,
00238 "model-anneal-factor",1.0,
00239 "Multiplier applied to the automatic "
00240 "parameter ranges (i.e. when scenario!=0). "
00241 "For routine operations should be 1.0. "
00242 "(physical model mode)."));
00243
00244
00245 sprintf(paramname,"xsh.%s.%s",RECIPE_ID,"model-scenario");
00246
00247
00248 check(p=cpl_parameter_new_enum(paramname,CPL_TYPE_INT,
00249 "selects preset flag and range combinations "
00250 "appropriate to common scenarios: \n"
00251
00252
00253 " 0 - No scenario, input cfg flags and limits"
00254 "used.\n"
00255 " 1 - scenario appropriate for the startup"
00256 "recipe (large ranges for parameters "
00257 "affecting single ph exposures, dist "
00258 "coeff fixed)\n"
00259 " 2 - Like 1, but includes parameters "
00260 "affecting all ph positions\n"
00261 " 3 - Scenario for use in fine tuning cfg "
00262 "to match routine single pinhole exposures. "
00263 "All parameters affecting 1ph exposures "
00264 "except dist coeffs are included and "
00265 "parameter ranges are small. (For use by "
00266 "predict in 1ph case).\n"
00267 " 4 - Like 3 but includes parameters "
00268 "affecting all ph positions (Standard for "
00269 "use by predict in 9ph case and 2dmap).\n"
00270
00271
00272 ,RECIPE_ID,4,9,-1,0,1,2,3,4,5,6,8));
00273
00274 check(cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,
00275 "model-scenario"));
00276 check(cpl_parameterlist_append(recipe->parameters,p));
00277
00278 check( xsh_parameters_new_boolean( recipe->parameters, RECIPE_ID,
00279 "model-compute-map",
00280 TRUE,
00281 "Compute the wavemap and the slitmap for the physical model."));
00282
00283
00284
00285
00286 cleanup:
00287 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
00288 xsh_error_dump(CPL_MSG_ERROR);
00289 return 1;
00290 }
00291 else {
00292 return 0;
00293 }
00294 }
00295
00296
00302
00303
00304 static int xsh_2dmap_exec(cpl_plugin *plugin) {
00305 cpl_recipe *recipe = NULL;
00306
00307
00308 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00309
00310
00311 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00312 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00313
00314 recipe = (cpl_recipe *)plugin;
00315
00316 xsh_2dmap(recipe->parameters, recipe->frames);
00317
00318 cleanup:
00319 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
00320 xsh_error_dump(CPL_MSG_ERROR);
00321 cpl_error_reset();
00322 return 1;
00323 }
00324 else {
00325 return 0;
00326 }
00327 }
00328
00329
00335
00336 static int xsh_2dmap_destroy(cpl_plugin *plugin)
00337 {
00338 cpl_recipe *recipe = NULL;
00339
00340
00341 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00342
00343
00344 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00345 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00346
00347 recipe = (cpl_recipe *)plugin;
00348
00349 xsh_free_parameterlist(&recipe->parameters);
00350
00351 cleanup:
00352 if (cpl_error_get_code() != CPL_ERROR_NONE)
00353 {
00354 return 1;
00355 }
00356 else
00357 {
00358 return 0;
00359 }
00360 }
00361
00362
00363
00364 static cpl_error_code
00365 xsh_verify_2dmap_poly_input(cpl_frame* order_tab_edges_frame,
00366 cpl_frame* spectralformat_frame,
00367 cpl_frame* theo_tab_frame)
00368 {
00369
00370 cpl_table* tab_edges=NULL;
00371 cpl_table* tab_spectral_format=NULL;
00372 cpl_table* theo_tab=NULL;
00373 const char* name=NULL;
00374 int ord_min_ref=0;
00375 int ord_max_ref=0;
00376 int ord_min=0;
00377 int ord_max=0;
00378
00379 check(name=cpl_frame_get_filename(order_tab_edges_frame));
00380 check(tab_edges=cpl_table_load(name,1,0));
00381 check(ord_min_ref=cpl_table_get_column_min(tab_edges,"ABSORDER"));
00382 check(ord_max_ref=cpl_table_get_column_max(tab_edges,"ABSORDER"));
00383
00384 check(name=cpl_frame_get_filename(spectralformat_frame));
00385 check(tab_spectral_format=cpl_table_load(name,1,0));
00386 check(ord_min=cpl_table_get_column_min(tab_spectral_format,"ORDER"));
00387 check(ord_max=cpl_table_get_column_max(tab_spectral_format,"ORDER"));
00388
00389 if(ord_min != ord_min_ref) {
00390 xsh_msg_error("Edge order table's ord_min != spectral format table's ord_min");
00391 return CPL_ERROR_INCOMPATIBLE_INPUT;
00392 }
00393
00394
00395 if(ord_max != ord_max_ref) {
00396 xsh_msg_error("Edge order table's ord_max != spectral format table's ord_max");
00397 return CPL_ERROR_INCOMPATIBLE_INPUT;
00398 }
00399
00400
00401 if(theo_tab_frame != NULL) {
00402 check(name=cpl_frame_get_filename(theo_tab_frame));
00403 check(theo_tab=cpl_table_load(name,1,0));
00404 check(ord_min=cpl_table_get_column_min(theo_tab,"Order"));
00405 check(ord_max=cpl_table_get_column_max(theo_tab,"Order"));
00406
00407 if(ord_min != ord_min_ref) {
00408 xsh_msg_error("Theo table's ord_min != spectral format table's ord_min");
00409 return CPL_ERROR_INCOMPATIBLE_INPUT;
00410 }
00411
00412
00413 if(ord_max != ord_max_ref) {
00414 xsh_msg_error("Theo table's ord_max != spectral format table's ord_max");
00415 return CPL_ERROR_INCOMPATIBLE_INPUT;
00416 }
00417
00418
00419 }
00420
00421
00422
00423 cleanup:
00424 xsh_free_table(&tab_edges);
00425 xsh_free_table(&tab_spectral_format);
00426 xsh_free_table(&theo_tab);
00427
00428 return cpl_error_get_code();
00429
00430 }
00431
00432 static cpl_error_code
00433 xsh_params_set_defaults(cpl_parameterlist* pars,
00434 xsh_detect_arclines_param* arclines_p,
00435 xsh_instrument* inst)
00436 {
00437 cpl_parameter* p=NULL;
00438 check(p=xsh_parameters_find(pars,RECIPE_ID,"detectarclines-min-sn"));
00439 if(xsh_parameter_get_default_flag(p) == 0) {
00440 if (xsh_instrument_get_arm(inst) == XSH_ARM_UVB){
00441 arclines_p->min_sn=3;
00442 } else if (xsh_instrument_get_arm(inst) == XSH_ARM_VIS) {
00443 arclines_p->min_sn=6;
00444 }
00445 }
00446
00447 check(p=xsh_parameters_find(pars,RECIPE_ID,"detectarclines-fit-window-half-size"));
00448 if(xsh_parameter_get_default_flag(p) == 0) {
00449 if (xsh_instrument_get_arm(inst) == XSH_ARM_NIR){
00450 arclines_p->fit_window_hsize=3;
00451 }
00452 }
00453 cleanup:
00454
00455 return cpl_error_get_code();
00456
00457 }
00458
00459
00467
00468 static void xsh_2dmap(cpl_parameterlist* parameters, cpl_frameset* frameset)
00469 {
00470 const char* recipe_tags[1] = {XSH_WAVE};
00471 int recipe_tags_size = 1;
00472
00473
00474 xsh_clipping_param* detect_arclines_clipping = NULL;
00475 xsh_detect_arclines_param* detect_arclines_p = NULL;
00476 xsh_dispersol_param *dispsol_param = NULL ;
00477 int model_map_compute= FALSE;
00478
00479
00480 cpl_frameset* raws = NULL;
00481 cpl_frameset* calib = NULL;
00482 cpl_frameset* on = NULL;
00483 cpl_frameset* off = NULL;
00484 cpl_frameset* on_off = NULL;
00485 cpl_frame* dmap_rmbias = NULL;
00486 cpl_frame* dmap_rmdark = NULL;
00487 xsh_instrument* instrument = NULL;
00488
00489 cpl_frame* model_config_frame = NULL;
00490 cpl_frame* opt_model_config_frame = NULL;
00491 cpl_frame* spectralformat_frame = NULL;
00492 cpl_frame* bpmap = NULL;
00493 cpl_frame* master_bias = NULL;
00494 cpl_frame* master_dark = NULL;
00495 cpl_frame* theo_tab_mult = NULL;
00496 cpl_frame* resid_map = NULL;
00497 cpl_frame* arclines = NULL;
00498 cpl_frame* clean_arclines = NULL;
00499 cpl_frame* wave_tab_guess = NULL;
00500 cpl_frame* wave_tab_2d = NULL;
00501 cpl_frame * order_tab_edges = NULL ;
00502 cpl_frame * wave_map = NULL ;
00503 char wave_map_tag[80];
00504 char slit_map_tag[80];
00505
00506 char *prefix = NULL ;
00507 char filename[256];
00508 int maxit=200;
00509 double ann_fac=1.0;
00510 int scenario=4;
00511
00512 char paramname[256];
00513 cpl_parameter * p =NULL;
00514 cpl_frame *dispersol_frame = NULL;
00515 cpl_frame *slitmap_frame = NULL;
00516 int pre_overscan_corr=0;
00517
00518
00519
00520
00521
00522 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib, recipe_tags,
00523 recipe_tags_size,
00524 RECIPE_ID, XSH_BINARY_VERSION,
00525 xsh_2dmap_description_short ));
00526
00527
00528
00529
00530 bpmap = xsh_find_master_bpmap(calib);
00531
00532 cknull_msg(arclines = xsh_find_frame_with_tag(calib,
00533 XSH_ARC_LINE_LIST,
00534 instrument),
00535 "Missing %s frame",XSH_ARC_LINE_LIST);
00536 check(order_tab_edges = xsh_find_order_tab_edges(calib,instrument));
00537
00538
00539 if((theo_tab_mult = xsh_find_frame_with_tag( calib,XSH_THEO_TAB_MULT,
00540 instrument)) == NULL) {
00541 xsh_error_reset();
00542
00543 }
00544
00545 if((model_config_frame = xsh_find_frame_with_tag(calib,
00546 XSH_MOD_CFG_OPT_FMT,
00547 instrument)) == NULL) {
00548
00549 xsh_error_reset();
00550
00551 if ((model_config_frame = xsh_find_frame_with_tag(calib,XSH_MOD_CFG_TAB,
00552 instrument)) == NULL) {
00553 xsh_error_reset();
00554 }
00555
00556 }
00557
00558
00559 if( (model_config_frame!=NULL) && (theo_tab_mult != NULL) ) {
00560
00561 xsh_msg_error("You cannot provide both a %s and a %s frame. Decide if you are in poly or physical model mode. We exit",
00562 XSH_THEO_TAB_MULT,XSH_MOD_CFG_TAB);
00563 goto cleanup;
00564 }
00565
00566 if((model_config_frame==NULL) && (theo_tab_mult == NULL) ) {
00567 xsh_msg_error("You must provide either a %s or a %s frame",
00568 XSH_THEO_TAB_MULT,XSH_MOD_CFG_TAB);
00569 goto cleanup;
00570
00571 }
00572
00573
00574 check( spectralformat_frame = xsh_find_frame_with_tag( calib,
00575 XSH_SPECTRAL_FORMAT, instrument));
00576
00577
00578 if( (spectralformat_frame = xsh_find_frame_with_tag( calib,
00579 XSH_SPECTRAL_FORMAT,
00580 instrument)) == NULL) {
00581 xsh_msg("Frame %s not provided",
00582 XSH_SPECTRAL_FORMAT);
00583 xsh_error_reset();
00584 }
00585
00586
00587
00588
00589
00590
00591
00592 if(theo_tab_mult!=NULL) {
00593 check(xsh_verify_2dmap_poly_input(order_tab_edges, spectralformat_frame,
00594 theo_tab_mult));
00595 }
00596
00597
00598
00599 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR){
00600
00601 XSH_ASSURE_NOT_ILLEGAL(cpl_frameset_get_size(raws) == 1);
00602 if((master_bias = xsh_find_frame_with_tag(calib,XSH_MASTER_BIAS,
00603 instrument)) == NULL) {
00604
00605 xsh_msg_warning("Frame %s not provided",XSH_MASTER_BIAS);
00606 xsh_error_reset();
00607 }
00608
00609
00610 if((master_dark = xsh_find_frame_with_tag(calib,XSH_MASTER_DARK,
00611 instrument)) == NULL){
00612 xsh_msg_warning("Frame %s not provided",XSH_MASTER_DARK);
00613 xsh_error_reset();
00614 }
00615 }
00616
00617 else {
00618
00619 check(xsh_dfs_split_nir(raws,&on,&off));
00620 XSH_ASSURE_NOT_ILLEGAL(cpl_frameset_get_size(on) == 1);
00621 XSH_ASSURE_NOT_ILLEGAL(cpl_frameset_get_size(off) == 1);
00622 }
00623 check( xsh_instrument_update_from_spectralformat( instrument,
00624 spectralformat_frame));
00625
00626
00627
00628
00629 check( pre_overscan_corr = xsh_parameters_get_int( parameters, RECIPE_ID,
00630 "pre-overscan-corr"));
00631
00632 check( detect_arclines_clipping =
00633 xsh_parameters_clipping_detect_arclines_get( RECIPE_ID, parameters));
00634 check( detect_arclines_p = xsh_parameters_detect_arclines_get( RECIPE_ID,
00635 parameters));
00636 check( dispsol_param = xsh_parameters_dispersol_get( RECIPE_ID,parameters)) ;
00637 check( model_map_compute = xsh_parameters_get_boolean( parameters,
00638 RECIPE_ID,
00639 "model-compute-map"));
00640
00641
00642 check(xsh_params_set_defaults(parameters,detect_arclines_p,instrument));
00643
00644
00645
00646
00647
00648 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR){
00649 cpl_frame* fmtchk = NULL;
00650
00651
00652 check(xsh_prepare(raws,bpmap, master_bias, XSH_WAVE, instrument,
00653 pre_overscan_corr));
00654 check(fmtchk = cpl_frameset_get_first(raws));
00655 if(master_bias != NULL) {
00656
00657 check(dmap_rmbias = xsh_subtract_bias(fmtchk,master_bias,
00658 instrument,"WAVE_",pre_overscan_corr));
00659 } else {
00660 dmap_rmbias=cpl_frame_duplicate(fmtchk);
00661 }
00662 if(master_dark != NULL) {
00663
00664 strcpy(filename,xsh_stringcat_any( "WAVE_DARK_",
00665 xsh_instrument_arm_tostring( instrument ),
00666 ".fits", NULL )) ;
00667
00668 check(dmap_rmdark = xsh_subtract_dark(dmap_rmbias, master_dark,
00669 filename, instrument));
00670 } else {
00671 dmap_rmdark=cpl_frame_duplicate(dmap_rmbias);
00672 }
00673 }
00674
00675 else{
00676
00677 check(xsh_prepare(on,bpmap, NULL, "ON", instrument,pre_overscan_corr));
00678
00679 check(xsh_prepare(off,bpmap, NULL, "OFF", instrument,pre_overscan_corr));
00680
00681
00682
00683 check(on_off = xsh_subtract_nir_on_off(on, off, instrument));
00684 check(dmap_rmdark = cpl_frame_duplicate(
00685 cpl_frameset_get_first(on_off)));
00686 }
00687
00688 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR){
00689 check(xsh_check_input_is_unbinned(dmap_rmdark));
00690 }
00691
00692 check( xsh_detect_arclines(dmap_rmdark, theo_tab_mult,
00693 arclines, wave_tab_guess, NULL,
00694 model_config_frame, spectralformat_frame, NULL,
00695 &clean_arclines, &wave_tab_2d,
00696 &resid_map, XSH_SOLUTION_ABSOLUTE,
00697 detect_arclines_p, detect_arclines_clipping,
00698 instrument,RECIPE_ID));
00699
00700
00701
00702 sprintf(slit_map_tag,"SLIT_MAP_%s",
00703 xsh_instrument_arm_tostring( instrument )) ;
00704
00705 sprintf(wave_map_tag,"WAVE_MAP_%s",
00706 xsh_instrument_arm_tostring( instrument )) ;
00707
00708
00709 check( xsh_data_check_spectralformat( spectralformat_frame,
00710 order_tab_edges, wave_tab_2d, model_config_frame, instrument));
00711
00712 if ( model_config_frame == NULL){
00713
00714 check( wave_map = xsh_create_poly_wavemap( dmap_rmdark, wave_tab_2d,
00715 order_tab_edges,
00716 spectralformat_frame,
00717 dispsol_param, instrument,
00718 wave_map_tag, &dispersol_frame,
00719 &slitmap_frame));
00720 }
00721 else {
00722
00723 sprintf(paramname,"xsh.%s.%s",RECIPE_ID, "model-maxit");
00724 check(p = cpl_parameterlist_find(parameters,paramname));
00725 check(maxit=cpl_parameter_get_int(p));
00726
00727 sprintf(paramname,"xsh.%s.%s",RECIPE_ID, "model-anneal-factor");
00728 check(p = cpl_parameterlist_find(parameters,paramname));
00729 check(ann_fac=cpl_parameter_get_double(p));
00730
00731 sprintf(paramname,"xsh.%s.%s",RECIPE_ID, "model-scenario");
00732 check(p = cpl_parameterlist_find(parameters,paramname));
00733 check(scenario=cpl_parameter_get_int(p));
00734 xsh_msg_dbg_low("maxit=%d ann_fac=%g scenario=%d",maxit,ann_fac,scenario);
00735
00736 check(opt_model_config_frame=xsh_model_pipe_anneal(model_config_frame,
00737 resid_map,
00738 maxit,ann_fac,
00739 scenario,2));
00740
00741
00742 if (model_map_compute){
00743 check( xsh_create_model_map( opt_model_config_frame, instrument,
00744 wave_map_tag,slit_map_tag,
00745 &wave_map, &slitmap_frame));
00746
00747
00748
00749 check(dispersol_frame=xsh_create_dispersol_physmod(dmap_rmdark,
00750 order_tab_edges,
00751 opt_model_config_frame,
00752 wave_map,
00753 slitmap_frame,
00754 dispsol_param,
00755 spectralformat_frame,
00756 instrument));
00757 }
00758 }
00759 if(wave_map!=NULL) {
00760 check(xsh_wavemap_qc(wave_map,order_tab_edges));
00761 }
00762
00763 xsh_msg_dbg_low("QC wavetab");
00764 if ( model_config_frame == NULL){
00765 check(xsh_wavetab_qc(resid_map,true));
00766 } else {
00767 check(xsh_wavetab_qc(resid_map,false));
00768 }
00769
00770
00771
00772 xsh_msg("Saving products");
00773
00774 check(xsh_add_product_table(clean_arclines, frameset,
00775 parameters, RECIPE_ID, instrument));
00776
00777 if ( wave_tab_2d != NULL){
00778 check(xsh_add_product_table_multi(wave_tab_2d, frameset,
00779 parameters, RECIPE_ID, instrument));
00780 }
00781
00782
00783 check(xsh_add_product_table_multi( resid_map, frameset,
00784 parameters, RECIPE_ID, instrument));
00785
00786 if ( wave_map != NULL){
00787 XSH_PREFIX(prefix,"WAVE_MAP",instrument);
00788 check(xsh_add_product_image( wave_map, frameset,
00789 parameters, RECIPE_ID, instrument, prefix ));
00790 }
00791 if (slitmap_frame != NULL){
00792 XSH_PREFIX(prefix,"SLIT_MAP",instrument);
00793 check(xsh_add_product_image( slitmap_frame, frameset,
00794 parameters, RECIPE_ID, instrument, prefix ));
00795 }
00796 if ( dispersol_frame != NULL){
00797 XSH_PREFIX(prefix, "DISP_TAB", instrument);
00798 check(xsh_add_product_table( dispersol_frame, frameset,
00799 parameters, RECIPE_ID, instrument));
00800 }
00801
00802 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR){
00803
00804 check(xsh_add_product_pre(dmap_rmbias,frameset,parameters,
00805 RECIPE_ID,instrument));
00806 } else {
00807 check(xsh_add_product_pre(dmap_rmdark,frameset,parameters,
00808 RECIPE_ID,instrument));
00809
00810 }
00811
00812 if(opt_model_config_frame!=NULL) {
00813 check(xsh_add_product_table_multi(opt_model_config_frame, frameset,
00814 parameters, RECIPE_ID, instrument));
00815 }
00816
00817 xsh_msg("xsh_2dmap success!!");
00818
00819 cleanup:
00820 xsh_end( RECIPE_ID, frameset, parameters );
00821
00822 XSH_FREE( detect_arclines_clipping);
00823 XSH_FREE( detect_arclines_p);
00824 XSH_FREE( dispsol_param);
00825 xsh_free_frameset(&raws);
00826 xsh_free_frameset(&calib);
00827 xsh_free_frameset(&on);
00828 xsh_free_frameset(&off);
00829 xsh_free_frameset(&on_off);
00830 xsh_free_frame(&clean_arclines);
00831 xsh_free_frame(&resid_map);
00832 xsh_free_frame(&wave_tab_2d);
00833 xsh_free_frame(&dmap_rmbias);
00834 xsh_free_frame(&dmap_rmdark);
00835 xsh_free_frame(&dispersol_frame);
00836 xsh_free_frame(&slitmap_frame);
00837 xsh_free_frame(&opt_model_config_frame);
00838
00839
00840 xsh_instrument_free(&instrument);
00841 xsh_free_frame( &wave_map ) ;
00842 XSH_FREE( prefix ) ;
00843 return;
00844 }
00845