X-shooter Pipeline Reference Manual 3.8.15
xsh_util_physmod.c
Go to the documentation of this file.
1/* $Id: xsh_util_physmod.c,v 1.25 2012-12-18 14:12:51 amodigli Exp $
2 *
3 * This file is part of the ESO X-shooter Pipeline
4 * Copyright (C) 2006 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * $Author: amodigli $
23 * $Date: 2012-12-18 14:12:51 $
24 * $Revision: 1.25 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
41/*----------------------------------------------------------------------------
42 Includes
43 ---------------------------------------------------------------------------*/
44
45#include <cpl.h>
46
47#include "xsh_utils.h"
48//#include "xsh_pfits.h"
49#include "xsh_dfs.h"
50#include "xsh_drl.h"
51#include "xsh_pfits.h"
52#include <xsh_model_kernel.h>
53#include <xsh_model_utils.h>
54#include <xsh_error.h>
55#include <xsh_model_io.h>
56#include <xsh_parameters.h>
57
58#define RECIPE_ID "xsh_util_physmod"
59#define RECIPE_AUTHOR "A.Modigliani, P. Bristow"
60#define RECIPE_CONTACT "amodigli@eso.org"
61
62/*-----------------------------------------------------------------------------
63 Functions prototypes
64 ---------------------------------------------------------------------------*/
65static cpl_frame*
67
68
69static int xsh_util_physmod_create(cpl_plugin *);
70static int xsh_util_physmod_exec(cpl_plugin *);
71static int xsh_util_physmod_destroy(cpl_plugin *);
72static int xsh_util_physmod(cpl_parameterlist *, cpl_frameset *);
73
74
75/*-----------------------------------------------------------------------------
76 Static variables
77 ---------------------------------------------------------------------------*/
78
80 "This recipe generates the theoretical and the spectral format tables. \n"
81 "and possibly the model based wave map.\n"
82 "The sof file contains the names of the input FITS file\n"
83 "tagged with XSH_MOD_CFG_TAB_arm.\n"
84 "tagged with ARC_LINE_LIST_arm.\n"
85 "This recipe has the following products:\n"
86 "Model order traces for nine pinholes (PRO CATG = THEO_TAB_MULT_arm)\n"
87 "Model order traces for nine pinholes (PRO CATG = THEO_TAB_IFU_arm)\n"
88 "Model order traces for central pinhole (PRO CATG = THEO_TAB_SING_arm)\n"
89 "Spectral format table (PRO CATG = SPECTRAL_FORMAT_TAB_arm)\n"
90 "Wave map image (PRO CATG = WAVE_MAP_arm)\n"
91 "Slit map image (PRO CATG = SLIT_MAP_arm)\n" ;
92
93static char xsh_util_physmod_description_short[] ="Generate physical model products";
94
95/*-----------------------------------------------------------------------------
96 Functions code
97 ---------------------------------------------------------------------------*/
98
99/*---------------------------------------------------------------------------*/
107/*---------------------------------------------------------------------------*/
108int cpl_plugin_get_info(cpl_pluginlist * list)
109{
110 cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe));
111 cpl_plugin * plugin = &recipe->interface;
112
113 cpl_plugin_init(plugin,
114 CPL_PLUGIN_API,
115 XSH_BINARY_VERSION,
116 CPL_PLUGIN_TYPE_RECIPE,
117 "xsh_util_physmod",
120 "Andrea Modigliani",
121 "amodigli@eso.org",
126
127 cpl_pluginlist_append(list, plugin);
128
129 return 0 ;
130}
131
132/*---------------------------------------------------------------------------*/
141/*---------------------------------------------------------------------------*/
142static int xsh_util_physmod_create(cpl_plugin * plugin)
143{
144 cpl_recipe * recipe ;
145 cpl_parameter* p=NULL;
146 /* Reset library state */
147 xsh_init();
148
149 /* Get the recipe out of the plugin */
150 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
151 recipe = (cpl_recipe *)plugin ;
152 else return -1 ;
153
154 /* Create the parameters list in the cpl_recipe object */
155 recipe->parameters = cpl_parameterlist_new() ;
156
157 /* Set generic parameters (common to all recipes) */
158 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
159 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
160 p = cpl_parameter_new_value("xsh.xsh_model.binx",
161 CPL_TYPE_INT,
162 "X binning ",
163 "xsh.xsh_model", 1);
164
165 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"binx");
166 cpl_parameterlist_append(recipe->parameters,p);
167
168
169 p = cpl_parameter_new_value("xsh.xsh_model.biny",
170 CPL_TYPE_INT,
171 "X binning ",
172 "xsh.xsh_model", 1);
173
174 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"biny");
175 cpl_parameterlist_append(recipe->parameters,p);
176
177
178 p = cpl_parameter_new_value("xsh.xsh_model.spectral_format_tab",
179 CPL_TYPE_BOOL,
180 "Generate spectral format table ",
181 "xsh.xsh_model", FALSE);
182
183 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"spectral-format-tab");
184 cpl_parameterlist_append(recipe->parameters,p);
185
186 p = cpl_parameter_new_value("xsh.xsh_model.wavemap",
187 CPL_TYPE_BOOL,
188 "Generate slit and wave maps (time consuming) ",
189 "xsh.xsh_model", FALSE);
190
191 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"wavemap");
192 cpl_parameterlist_append(recipe->parameters,p);
193
194
195 cleanup:
196
197 return 0 ;
198}
199
200/*---------------------------------------------------------------------------*/
206/*---------------------------------------------------------------------------*/
207static int xsh_util_physmod_exec(cpl_plugin * plugin)
208{
209 cpl_recipe * recipe ;
210
211 /* Get the recipe out of the plugin */
212 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
213 recipe = (cpl_recipe *)plugin ;
214 else return -1 ;
215
216 return xsh_util_physmod(recipe->parameters, recipe->frames) ;
217}
218
219/*---------------------------------------------------------------------------*/
225/*---------------------------------------------------------------------------*/
226static int xsh_util_physmod_destroy(cpl_plugin * plugin)
227{
228 cpl_recipe * recipe ;
229
230 /* Get the recipe out of the plugin */
231 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
232 recipe = (cpl_recipe *)plugin ;
233 else return -1 ;
234
235 cpl_parameterlist_delete(recipe->parameters) ;
236 return 0 ;
237}
238
239/*---------------------------------------------------------------------------*/
247/*---------------------------------------------------------------------------*/
249 cpl_parameterlist * parameters,
250 cpl_frameset * frameset)
251{
252
253
254 const char* recipe_tags[1] = {XSH_MOD_CFG};
255 char wave_map_tag[256];
256 char slit_map_tag[256];
257
258 int recipe_tags_size = 1;
259
260 cpl_frameset* raws=NULL;
261 cpl_frameset* calib=NULL;
262 cpl_frame* wave_list=NULL ;
263 cpl_frame* xsh_config=NULL ;
264 cpl_frame* model_THE1_frm=NULL ;
265 cpl_frame* model_THE9_frm=NULL ;
266 cpl_frame* model_THE_IFU_frm=NULL ;
267
268 cpl_frame* spf_frm=NULL ;
269 cpl_frame* wavemap_frame=NULL ;
270 cpl_frame* slitmap_frame=NULL ;
272 int gen_map=true;
273 int gen_spf=true;
274 cpl_parameter* p=NULL;
275 int binx=0;
276 int biny=0;
277 char *prefix = NULL ;
278
279
280
281 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
282 recipe_tags, recipe_tags_size, RECIPE_ID,
283 XSH_BINARY_VERSION,
285 check(xsh_config = xsh_find_frame_with_tag( calib,XSH_MOD_CFG,
286 instrument));
288 instrument));
289
290 check(p = cpl_parameterlist_find(parameters,"xsh.xsh_model.binx"));
291 check(binx = cpl_parameter_get_int(p));
292
293 check(p = cpl_parameterlist_find(parameters,"xsh.xsh_model.biny"));
294 check(biny = cpl_parameter_get_int(p));
295
296
299
300 check(model_THE9_frm=xsh_util_physmod_model_THE_create(xsh_config,
302 wave_list,
303 binx,biny,9,0));
304
305 check(xsh_add_product_table(model_THE9_frm,frameset,parameters,
306 RECIPE_ID,instrument,NULL));
307
308 check(model_THE_IFU_frm=cpl_frame_duplicate(model_THE9_frm));
309 xsh_free_frame(&model_THE9_frm);
310
311 cpl_frame_set_tag(model_THE_IFU_frm,
313
314 check(xsh_add_product_table(model_THE_IFU_frm,frameset,parameters,
315 RECIPE_ID,instrument,NULL));
316 xsh_free_frame(&model_THE_IFU_frm);
317
318
319 check(model_THE1_frm=xsh_util_physmod_model_THE_create(xsh_config,
321 wave_list,
322 binx,biny,1,0));
323
324
325 check(xsh_add_product_table(model_THE1_frm,frameset,parameters,
326 RECIPE_ID,instrument,NULL));
327 xsh_free_frame(&model_THE1_frm);
328 check(p = cpl_parameterlist_find(parameters,"xsh.xsh_model.spectral_format_tab"));
329 check(gen_spf = cpl_parameter_get_bool(p));
330
331 if(gen_spf) {
332 check(spf_frm=xsh_util_model_SPF_create(xsh_config,instrument));
333
334 check(xsh_add_product_table(spf_frm, frameset, parameters, RECIPE_ID,
335 instrument,NULL));
336
337 }
338
339 check(p = cpl_parameterlist_find(parameters,"xsh.xsh_model.wavemap"));
340 check(gen_map = cpl_parameter_get_bool(p));
341
342 if(gen_map) {
343
344 check(sprintf(wave_map_tag,"%s",
346
347 check(sprintf(slit_map_tag,"%s",
349
350
352 wave_map_tag, slit_map_tag,
353 &wavemap_frame, &slitmap_frame,1));
354
355
356 XSH_PREFIX(prefix,"WAVE_MAP",instrument);
357 check(xsh_add_product_image( wavemap_frame, frameset,
358 parameters, RECIPE_ID, instrument, prefix ));
359
360 XSH_PREFIX(prefix,"SLIT_MAP",instrument);
361 check(xsh_add_product_image( slitmap_frame, frameset,
362 parameters, RECIPE_ID, instrument, prefix ));
363
364 }
365
366 cleanup:
367 xsh_free_frame(&model_THE_IFU_frm);
368 xsh_free_frame(&model_THE1_frm);
369 xsh_free_frame(&model_THE9_frm);
371 xsh_free_frameset(&raws);
372 xsh_free_frameset(&calib);
373 XSH_FREE( prefix ) ;
374 return 0 ;
375}
376
377
378
379
380
381
382
383/*--------------------------------------------------------------------------*/
393/*--------------------------------------------------------------------------*/
394
395static cpl_frame*
397
398{
399 struct xs_3* p_xs_3_config=NULL;
400 struct xs_3 xs_3_config;
401 cpl_frame* spf_frame=NULL;
402 char SPF_name[256];
403 const char* pro_catg=NULL;
404 //Load xsh model configuration
405 p_xs_3_config=&xs_3_config;
406
407 if (xsh_model_config_load_best(config_frame,p_xs_3_config)!=CPL_ERROR_NONE) {
408 xsh_msg_error("Cannot load %s as a config",
409 cpl_frame_get_filename(config_frame)) ;
410 return NULL ;
411 }
412
413
415
416 sprintf(SPF_name,"%s%s",pro_catg,".fits");
417
418 check(spf_frame= xsh_model_spectralformat_create(p_xs_3_config,SPF_name));
419
420 xsh_free_frame(&spf_frame);
421
422
423 check(spf_frame=xsh_frame_product(SPF_name,pro_catg,
424 CPL_FRAME_TYPE_TABLE,
425 CPL_FRAME_GROUP_PRODUCT,
426 CPL_FRAME_LEVEL_FINAL));
427
428
429 cleanup:
430
431
432 if(cpl_error_get_code() == CPL_ERROR_NONE) {
433 return spf_frame;
434 } else {
436 return NULL;
437 }
438
439
440
441}
442
443
444
445
446
static xsh_instrument * instrument
int binx
int biny
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
Definition: xsh_2dmap.c:151
#define check(COMMAND)
Definition: xsh_error.h:71
void xsh_instrument_set_biny(xsh_instrument *instrument, const int biny)
void xsh_instrument_set_binx(xsh_instrument *instrument, const int binx)
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
cpl_error_code xsh_model_config_load_best(cpl_frame *config_frame, xsh_xs_3 *p_xs_3)
Load the config model table and fill the struct.
Definition: xsh_model_io.c:174
cpl_frame * xsh_model_spectralformat_create(xsh_xs_3 *p_xs_3, const char *tab_filename)
creates the model spectral format table
static int xsh_util_physmod_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static int xsh_util_physmod(cpl_parameterlist *, cpl_frameset *)
The FITS file creation occurs here.
static int xsh_util_physmod_create(cpl_plugin *)
Setup the recipe options
static char xsh_util_physmod_description[]
static cpl_frame * xsh_util_model_SPF_create(cpl_frame *config_frame, xsh_instrument *instrument)
#define RECIPE_ID
static char xsh_util_physmod_description_short[]
static int xsh_util_physmod_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
#define xsh_msg_error(...)
Print an error message.
Definition: xsh_msg.h:62
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
Definition: xsh_utils.c:2254
const char * xsh_get_license(void)
Get the pipeline copyright and license.
Definition: xsh_utils.c:1193
void xsh_init(void)
Reset library state.
Definition: xsh_utils.c:1160
cpl_error_code xsh_begin(cpl_frameset *frames, const cpl_parameterlist *parameters, xsh_instrument **instrument, cpl_frameset **raws, cpl_frameset **calib, const char *tag_list[], int tag_list_size, const char *recipe_id, unsigned int binary_version, const char *short_descr)
Recipe initialization.
Definition: xsh_utils.c:1244
void xsh_create_model_map(cpl_frame *model_frame, xsh_instrument *instrument, const char *wtag, const char *stag, cpl_frame **wavemap_frame, cpl_frame **slitmap_frame, const int save_tmp)
int xsh_print_rec_status(const int val)
Check if an error has happened and returns error kind and location.
Definition: xsh_dfs.c:877
void xsh_add_product_image(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instrument, const char *final_prefix)
Definition: xsh_dfs.c:2965
void xsh_add_product_table(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instrument, const char *final_prefix)
Save Table product (input frame has several extensions, 1 table per extension)
Definition: xsh_dfs.c:3146
cpl_frame * xsh_frame_product(const char *fname, const char *tag, cpl_frame_type type, cpl_frame_group group, cpl_frame_level level)
Creates a frame with given characteristics.
Definition: xsh_dfs.c:930
cpl_frame * xsh_find_frame_with_tag(cpl_frameset *frames, const char *tag, xsh_instrument *instr)
Find frame with a given tag.
Definition: xsh_dfs.c:3347
#define XSH_MOD_CFG
Definition: xsh_dfs.h:1261
#define XSH_WAVE_MAP
Definition: xsh_dfs.h:928
#define XSH_THEO_TAB_IFU
Definition: xsh_dfs.h:1094
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
Definition: xsh_dfs.h:1548
#define XSH_SLIT_MAP
Definition: xsh_dfs.h:907
#define XSH_SPECTRAL_FORMAT
Definition: xsh_dfs.h:1196
#define XSH_ARC_LINE_LIST
Definition: xsh_dfs.h:955
cpl_frame * xsh_util_physmod_model_THE_create(cpl_frame *config_frame, xsh_instrument *instrument, cpl_frame *wave_list, const int binx, const int biny, const int num_ph, const int sky)
cpl_error_code xsh_parameters_decode_bp(const char *recipe_id, cpl_parameterlist *plist, const int ival)
void xsh_parameters_generic(const char *recipe_id, cpl_parameterlist *plist)
#define XSH_FREE(POINTER)
Definition: xsh_utils.h:92
#define XSH_PREFIX(prefix, name, instr)
Definition: xsh_utils.h:96