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
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[80];
00256 char slit_map_tag[80];
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_multi(model_THE9_frm,frameset,parameters, RECIPE_ID,
00306 instrument));
00307
00308
00309 check(model_THE_IFU_frm=cpl_frame_duplicate(model_THE9_frm));
00310 cpl_frame_set_tag(model_THE_IFU_frm,
00311 XSH_GET_TAG_FROM_ARM(XSH_THEO_TAB_IFU,instrument));
00312
00313 check(xsh_add_product_table_multi(model_THE_IFU_frm,frameset,parameters, RECIPE_ID,
00314 instrument));
00315
00316
00317 check(model_THE1_frm=xsh_util_physmod_model_THE_create(xsh_config,
00318 instrument,
00319 wave_list,
00320 binx,biny,1,0));
00321
00322
00323 check(xsh_add_product_table_multi(model_THE1_frm,frameset,parameters, RECIPE_ID,
00324 instrument));
00325
00326
00327 check(p = cpl_parameterlist_find(parameters,"xsh.xsh_model.spectral_format_tab"));
00328 check(gen_spf = cpl_parameter_get_bool(p));
00329
00330 if(gen_spf) {
00331 check(spf_frm=xsh_util_model_SPF_create(xsh_config,instrument));
00332
00333 check(xsh_add_product_table_multi(spf_frm, frameset, parameters, RECIPE_ID,
00334 instrument));
00335
00336 }
00337
00338 check(p = cpl_parameterlist_find(parameters,"xsh.xsh_model.wavemap"));
00339 check(gen_map = cpl_parameter_get_bool(p));
00340
00341 if(gen_map) {
00342
00343 check(sprintf(wave_map_tag,"%s",
00344 XSH_GET_TAG_FROM_ARM(XSH_WAVE_MAP,instrument)));
00345
00346 check(sprintf(slit_map_tag,"%s",
00347 XSH_GET_TAG_FROM_ARM(XSH_SLIT_MAP,instrument)));
00348
00349
00350 check( xsh_create_model_map( xsh_config, instrument,
00351 wave_map_tag, slit_map_tag,
00352 &wavemap_frame, &slitmap_frame));
00353
00354
00355 XSH_PREFIX(prefix,"WAVE_MAP",instrument);
00356 check(xsh_add_product_image( wavemap_frame, frameset,
00357 parameters, RECIPE_ID, instrument, prefix ));
00358
00359 XSH_PREFIX(prefix,"SLIT_MAP",instrument);
00360 check(xsh_add_product_image( slitmap_frame, frameset,
00361 parameters, RECIPE_ID, instrument, prefix ));
00362
00363 }
00364
00365 cleanup:
00366 xsh_instrument_free(&instrument);
00367 xsh_free_frameset(&raws);
00368 xsh_free_frameset(&calib);
00369 XSH_FREE( prefix ) ;
00370 return 0 ;
00371 }
00372
00373
00374
00375
00376
00377
00378
00379
00389
00390
00391 static cpl_frame*
00392 xsh_util_model_SPF_create(cpl_frame* config_frame,xsh_instrument* instrument)
00393
00394 {
00395 struct xs_3* p_xs_3_config=NULL;
00396 struct xs_3 xs_3_config;
00397 cpl_frame* spf_frame=NULL;
00398 char SPF_name[256];
00399 const char* pro_catg=NULL;
00400
00401 p_xs_3_config=&xs_3_config;
00402
00403 if (xsh_model_config_load_best(config_frame,p_xs_3_config)!=CPL_ERROR_NONE) {
00404 xsh_msg_error("Cannot load %s as a config",
00405 cpl_frame_get_filename(config_frame)) ;
00406 return NULL ;
00407 }
00408
00409
00410 check(pro_catg=XSH_GET_TAG_FROM_ARM(XSH_SPECTRAL_FORMAT,instrument));
00411
00412 sprintf(SPF_name,"%s%s",pro_catg,".fits");
00413
00414 check(spf_frame= xsh_model_spectralformat_create(p_xs_3_config,SPF_name));
00415
00416 xsh_free_frame(&spf_frame);
00417
00418
00419 check(spf_frame=xsh_frame_product(SPF_name,pro_catg,
00420 CPL_FRAME_TYPE_TABLE,
00421 CPL_FRAME_GROUP_PRODUCT,
00422 CPL_FRAME_LEVEL_FINAL));
00423
00424
00425 cleanup:
00426
00427
00428 if(cpl_error_get_code() == CPL_ERROR_NONE) {
00429 return spf_frame;
00430 } else {
00431 xsh_print_rec_status(0);
00432 return NULL;
00433 }
00434
00435
00436
00437 }
00438
00439
00440
00441
00442