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
00039
00041
00042
00043
00044
00045 #include <cpl.h>
00046
00047 #include "xsh_utils.h"
00048
00049 #include "xsh_dfs.h"
00050 #include "xsh_drl.h"
00051 #include "xsh_pfits.h"
00052 #include <xsh_model_kernel.h>
00053 #include <xsh_model_utils.h>
00054 #include <xsh_error.h>
00055 #include <xsh_model_io.h>
00056 #include <xsh_parameters.h>
00057
00058 #define RECIPE_ID "xsh_util_physmod"
00059 #define RECIPE_AUTHOR "A.Modigliani, P. Bristow"
00060 #define RECIPE_CONTACT "amodigli@eso.org"
00061
00062
00063
00064
00065 static cpl_frame*
00066 xsh_util_model_SPF_create(cpl_frame* config_frame,xsh_instrument* instrument);
00067
00068
00069 static int xsh_util_physmod_create(cpl_plugin *);
00070 static int xsh_util_physmod_exec(cpl_plugin *);
00071 static int xsh_util_physmod_destroy(cpl_plugin *);
00072 static int xsh_util_physmod(cpl_parameterlist *, cpl_frameset *);
00073
00074
00075
00076
00077
00078
00079 static char xsh_util_physmod_description[] =
00080 "This recipe generates the theoretical and the spectral format tables. \n"
00081 "and possibly the model based wave map.\n"
00082 "The sof file contains the names of the input FITS file\n"
00083 "tagged with XSH_MOD_CFG_TAB_arm.\n"
00084 "tagged with ARC_LINE_LIST_arm.\n"
00085 "This recipe has the following products:\n"
00086 "Model order traces for nine pinholes (PRO CATG = THEO_TAB_MULT_arm)\n"
00087 "Model order traces for nine pinholes (PRO CATG = THEO_TAB_IFU_arm)\n"
00088 "Model order traces for central pinhole (PRO CATG = THEO_TAB_SING_arm)\n"
00089 "Spectral format table (PRO CATG = SPECTRAL_FORMAT_TAB_arm)\n"
00090 "Wave map image (PRO CATG = WAVE_MAP_arm)\n"
00091 "Slit map image (PRO CATG = SLIT_MAP_arm)\n" ;
00092
00093 static char xsh_util_physmod_description_short[] ="Generate physical model products";
00094
00095
00096
00097
00098
00099
00107
00108 int cpl_plugin_get_info(cpl_pluginlist * list)
00109 {
00110 cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe));
00111 cpl_plugin * plugin = &recipe->interface;
00112
00113 cpl_plugin_init(plugin,
00114 CPL_PLUGIN_API,
00115 XSH_BINARY_VERSION,
00116 CPL_PLUGIN_TYPE_RECIPE,
00117 "xsh_util_physmod",
00118 xsh_util_physmod_description_short,
00119 xsh_util_physmod_description,
00120 "Andrea Modigliani",
00121 "amodigli@eso.org",
00122 xsh_get_license(),
00123 xsh_util_physmod_create,
00124 xsh_util_physmod_exec,
00125 xsh_util_physmod_destroy);
00126
00127 cpl_pluginlist_append(list, plugin);
00128
00129 return 0 ;
00130 }
00131
00132
00141
00142 static int xsh_util_physmod_create(cpl_plugin * plugin)
00143 {
00144 cpl_recipe * recipe ;
00145 cpl_parameter* p=NULL;
00146
00147 xsh_init();
00148
00149
00150 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00151 recipe = (cpl_recipe *)plugin ;
00152 else return -1 ;
00153
00154
00155 recipe->parameters = cpl_parameterlist_new() ;
00156
00157
00158 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
00159 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
00160 p = cpl_parameter_new_value("xsh.xsh_model.binx",
00161 CPL_TYPE_INT,
00162 "X binning ",
00163 "xsh.xsh_model", 1);
00164
00165 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"binx");
00166 cpl_parameterlist_append(recipe->parameters,p);
00167
00168
00169 p = cpl_parameter_new_value("xsh.xsh_model.biny",
00170 CPL_TYPE_INT,
00171 "X binning ",
00172 "xsh.xsh_model", 1);
00173
00174 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"biny");
00175 cpl_parameterlist_append(recipe->parameters,p);
00176
00177
00178 p = cpl_parameter_new_value("xsh.xsh_model.spectral_format_tab",
00179 CPL_TYPE_BOOL,
00180 "Generate spectral format table ",
00181 "xsh.xsh_model", FALSE);
00182
00183 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"spectral-format-tab");
00184 cpl_parameterlist_append(recipe->parameters,p);
00185
00186 p = cpl_parameter_new_value("xsh.xsh_model.wavemap",
00187 CPL_TYPE_BOOL,
00188 "Generate slit and wave maps (time consuming) ",
00189 "xsh.xsh_model", FALSE);
00190
00191 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"wavemap");
00192 cpl_parameterlist_append(recipe->parameters,p);
00193
00194
00195 cleanup:
00196
00197 return 0 ;
00198 }
00199
00200
00206
00207 static int xsh_util_physmod_exec(cpl_plugin * plugin)
00208 {
00209 cpl_recipe * recipe ;
00210
00211
00212 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00213 recipe = (cpl_recipe *)plugin ;
00214 else return -1 ;
00215
00216 return xsh_util_physmod(recipe->parameters, recipe->frames) ;
00217 }
00218
00219
00225
00226 static int xsh_util_physmod_destroy(cpl_plugin * plugin)
00227 {
00228 cpl_recipe * recipe ;
00229
00230
00231 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00232 recipe = (cpl_recipe *)plugin ;
00233 else return -1 ;
00234
00235 cpl_parameterlist_delete(recipe->parameters) ;
00236 return 0 ;
00237 }
00238
00239
00247
00248 static int xsh_util_physmod(
00249 cpl_parameterlist * parameters,
00250 cpl_frameset * frameset)
00251 {
00252
00253
00254 const char* recipe_tags[1] = {XSH_MOD_CFG};
00255 char wave_map_tag[256];
00256 char slit_map_tag[256];
00257
00258 int recipe_tags_size = 1;
00259
00260 cpl_frameset* raws=NULL;
00261 cpl_frameset* calib=NULL;
00262 cpl_frame* wave_list=NULL ;
00263 cpl_frame* xsh_config=NULL ;
00264 cpl_frame* model_THE1_frm=NULL ;
00265 cpl_frame* model_THE9_frm=NULL ;
00266 cpl_frame* model_THE_IFU_frm=NULL ;
00267
00268 cpl_frame* spf_frm=NULL ;
00269 cpl_frame* wavemap_frame=NULL ;
00270 cpl_frame* slitmap_frame=NULL ;
00271 xsh_instrument* instrument=NULL;
00272 int gen_map=true;
00273 int gen_spf=true;
00274 cpl_parameter* p=NULL;
00275 int binx=0;
00276 int biny=0;
00277 char *prefix = NULL ;
00278
00279
00280
00281 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
00282 recipe_tags, recipe_tags_size, RECIPE_ID,
00283 XSH_BINARY_VERSION,
00284 xsh_util_physmod_description_short ) ) ;
00285 check(xsh_config = xsh_find_frame_with_tag( calib,XSH_MOD_CFG,
00286 instrument));
00287 check(wave_list = xsh_find_frame_with_tag( calib, XSH_ARC_LINE_LIST,
00288 instrument));
00289
00290 check(p = cpl_parameterlist_find(parameters,"xsh.xsh_model.binx"));
00291 check(binx = cpl_parameter_get_int(p));
00292
00293 check(p = cpl_parameterlist_find(parameters,"xsh.xsh_model.biny"));
00294 check(biny = cpl_parameter_get_int(p));
00295
00296
00297 xsh_instrument_set_binx(instrument,binx);
00298 xsh_instrument_set_biny(instrument,biny);
00299
00300 check(model_THE9_frm=xsh_util_physmod_model_THE_create(xsh_config,
00301 instrument,
00302 wave_list,
00303 binx,biny,9,0));
00304
00305 check(xsh_add_product_table(model_THE9_frm,frameset,parameters,
00306 RECIPE_ID,instrument,NULL));
00307
00308 check(model_THE_IFU_frm=cpl_frame_duplicate(model_THE9_frm));
00309 xsh_free_frame(&model_THE9_frm);
00310
00311 cpl_frame_set_tag(model_THE_IFU_frm,
00312 XSH_GET_TAG_FROM_ARM(XSH_THEO_TAB_IFU,instrument));
00313
00314 check(xsh_add_product_table(model_THE_IFU_frm,frameset,parameters,
00315 RECIPE_ID,instrument,NULL));
00316 xsh_free_frame(&model_THE_IFU_frm);
00317
00318
00319 check(model_THE1_frm=xsh_util_physmod_model_THE_create(xsh_config,
00320 instrument,
00321 wave_list,
00322 binx,biny,1,0));
00323
00324
00325 check(xsh_add_product_table(model_THE1_frm,frameset,parameters,
00326 RECIPE_ID,instrument,NULL));
00327 xsh_free_frame(&model_THE1_frm);
00328 check(p = cpl_parameterlist_find(parameters,"xsh.xsh_model.spectral_format_tab"));
00329 check(gen_spf = cpl_parameter_get_bool(p));
00330
00331 if(gen_spf) {
00332 check(spf_frm=xsh_util_model_SPF_create(xsh_config,instrument));
00333
00334 check(xsh_add_product_table(spf_frm, frameset, parameters, RECIPE_ID,
00335 instrument,NULL));
00336
00337 }
00338
00339 check(p = cpl_parameterlist_find(parameters,"xsh.xsh_model.wavemap"));
00340 check(gen_map = cpl_parameter_get_bool(p));
00341
00342 if(gen_map) {
00343
00344 check(sprintf(wave_map_tag,"%s",
00345 XSH_GET_TAG_FROM_ARM(XSH_WAVE_MAP,instrument)));
00346
00347 check(sprintf(slit_map_tag,"%s",
00348 XSH_GET_TAG_FROM_ARM(XSH_SLIT_MAP,instrument)));
00349
00350
00351 check( xsh_create_model_map( xsh_config, instrument,
00352 wave_map_tag, slit_map_tag,
00353 &wavemap_frame, &slitmap_frame,1));
00354
00355
00356 XSH_PREFIX(prefix,"WAVE_MAP",instrument);
00357 check(xsh_add_product_image( wavemap_frame, frameset,
00358 parameters, RECIPE_ID, instrument, prefix ));
00359
00360 XSH_PREFIX(prefix,"SLIT_MAP",instrument);
00361 check(xsh_add_product_image( slitmap_frame, frameset,
00362 parameters, RECIPE_ID, instrument, prefix ));
00363
00364 }
00365
00366 cleanup:
00367 xsh_free_frame(&model_THE_IFU_frm);
00368 xsh_free_frame(&model_THE1_frm);
00369 xsh_free_frame(&model_THE9_frm);
00370 xsh_instrument_free(&instrument);
00371 xsh_free_frameset(&raws);
00372 xsh_free_frameset(&calib);
00373 XSH_FREE( prefix ) ;
00374 return 0 ;
00375 }
00376
00377
00378
00379
00380
00381
00382
00383
00393
00394
00395 static cpl_frame*
00396 xsh_util_model_SPF_create(cpl_frame* config_frame,xsh_instrument* instrument)
00397
00398 {
00399 struct xs_3* p_xs_3_config=NULL;
00400 struct xs_3 xs_3_config;
00401 cpl_frame* spf_frame=NULL;
00402 char SPF_name[256];
00403 const char* pro_catg=NULL;
00404
00405 p_xs_3_config=&xs_3_config;
00406
00407 if (xsh_model_config_load_best(config_frame,p_xs_3_config)!=CPL_ERROR_NONE) {
00408 xsh_msg_error("Cannot load %s as a config",
00409 cpl_frame_get_filename(config_frame)) ;
00410 return NULL ;
00411 }
00412
00413
00414 check(pro_catg=XSH_GET_TAG_FROM_ARM(XSH_SPECTRAL_FORMAT,instrument));
00415
00416 sprintf(SPF_name,"%s%s",pro_catg,".fits");
00417
00418 check(spf_frame= xsh_model_spectralformat_create(p_xs_3_config,SPF_name));
00419
00420 xsh_free_frame(&spf_frame);
00421
00422
00423 check(spf_frame=xsh_frame_product(SPF_name,pro_catg,
00424 CPL_FRAME_TYPE_TABLE,
00425 CPL_FRAME_GROUP_PRODUCT,
00426 CPL_FRAME_LEVEL_FINAL));
00427
00428
00429 cleanup:
00430
00431
00432 if(cpl_error_get_code() == CPL_ERROR_NONE) {
00433 return spf_frame;
00434 } else {
00435 xsh_print_rec_status(0);
00436 return NULL;
00437 }
00438
00439
00440
00441 }
00442
00443
00444
00445
00446