X-shooter Pipeline Reference Manual 3.8.15
xsh_util_guess_xy.c
Go to the documentation of this file.
1/* $Id: xsh_util_guess_xy.c,v 1.4 2012-04-26 14:08:55 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-04-26 14:08:55 $
24 * $Revision: 1.4 $
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_io.h>
53#include <xsh_model_kernel.h>
54#include <xsh_model_utils.h>
55#include <xsh_error.h>
56#include <xsh_model_io.h>
57#include <xsh_parameters.h>
58
59#define RECIPE_ID "xsh_util_guess_xy"
60#define RECIPE_AUTHOR "A.Modigliani, P. Bristow"
61#define RECIPE_CONTACT "amodigli@eso.org"
62
63/*-----------------------------------------------------------------------------
64 Functions prototypes
65 ---------------------------------------------------------------------------*/
66/*
67static cpl_frame*
68xsh_util_model_SPF_create(cpl_frame* config_frame,xsh_instrument* instrument);
69*/
70
71static int xsh_util_guess_xy_create(cpl_plugin *);
72static int xsh_util_guess_xy_exec(cpl_plugin *);
73static int xsh_util_guess_xy_destroy(cpl_plugin *);
74static int xsh_util_guess_xy(cpl_parameterlist *, cpl_frameset *);
75
76
77/*-----------------------------------------------------------------------------
78 Static variables
79 ---------------------------------------------------------------------------*/
80
82 "This recipe finds X-Y guesses corresponding to 'grating_order','wavelength','slit' as in input tab. \n"
83 "The sof file contains the names of the input FITS file\n"
84 "tagged with XSH_MOD_CFG_arm.\n"
85 "tagged with ARC_LINE_LIST_arm.\n"
86 "This recipe has the following products:\n"
87 "Model predictions (PRO CATG = MOD_arm)\n" ;
88
89static char xsh_util_guess_xy_description_short[] ="Generate physical model guesses";
90
91/*-----------------------------------------------------------------------------
92 Functions code
93 ---------------------------------------------------------------------------*/
94
95/*---------------------------------------------------------------------------*/
103/*---------------------------------------------------------------------------*/
104int cpl_plugin_get_info(cpl_pluginlist * list)
105{
106 cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe));
107 cpl_plugin * plugin = &recipe->interface;
108
109 cpl_plugin_init(plugin,
110 CPL_PLUGIN_API,
111 XSH_BINARY_VERSION,
112 CPL_PLUGIN_TYPE_RECIPE,
113 "xsh_util_guess_xy",
116 "Andrea Modigliani",
117 "amodigli@eso.org",
122
123 cpl_pluginlist_append(list, plugin);
124
125 return 0 ;
126}
127
128/*---------------------------------------------------------------------------*/
137/*---------------------------------------------------------------------------*/
138static int xsh_util_guess_xy_create(cpl_plugin * plugin)
139{
140 cpl_recipe * recipe ;
141 cpl_parameter* p=NULL;
142 /* Reset library state */
143 xsh_init();
144
145 /* Get the recipe out of the plugin */
146 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
147 recipe = (cpl_recipe *)plugin ;
148 else return -1 ;
149
150 /* Create the parameters list in the cpl_recipe object */
151 recipe->parameters = cpl_parameterlist_new() ;
152
153 /* Set generic parameters (common to all recipes) */
154 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
155 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
156 p = cpl_parameter_new_value("xsh.xsh_model.binx",
157 CPL_TYPE_INT,
158 "X binning ",
159 "xsh.xsh_model", 1);
160
161 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"binx");
162 cpl_parameterlist_append(recipe->parameters,p);
163
164
165 p = cpl_parameter_new_value("xsh.xsh_model.biny",
166 CPL_TYPE_INT,
167 "X binning ",
168 "xsh.xsh_model", 1);
169
170 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"biny");
171 cpl_parameterlist_append(recipe->parameters,p);
172
173
174
175 cleanup:
176
177 return 0 ;
178}
179
180/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187static int xsh_util_guess_xy_exec(cpl_plugin * plugin)
188{
189 cpl_recipe * recipe ;
190
191 /* Get the recipe out of the plugin */
192 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
193 recipe = (cpl_recipe *)plugin ;
194 else return -1 ;
195
196 return xsh_util_guess_xy(recipe->parameters, recipe->frames) ;
197}
198
199/*---------------------------------------------------------------------------*/
205/*---------------------------------------------------------------------------*/
206static int xsh_util_guess_xy_destroy(cpl_plugin * plugin)
207{
208 cpl_recipe * recipe ;
209
210 /* Get the recipe out of the plugin */
211 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
212 recipe = (cpl_recipe *)plugin ;
213 else return -1 ;
214
215 cpl_parameterlist_delete(recipe->parameters) ;
216 return 0 ;
217}
218
219/*---------------------------------------------------------------------------*/
227/*---------------------------------------------------------------------------*/
229 cpl_parameterlist * parameters,
230 cpl_frameset * frameset)
231{
232
233
234 const char* recipe_tags[1] = {XSH_MOD_CFG};
235
236 int recipe_tags_size = 1;
237
238 cpl_frameset* raws=NULL;
239 cpl_frameset* calib=NULL;
240 cpl_frame* wave_list=NULL ;
241 cpl_frame* xsh_config=NULL ;
243 cpl_parameter* p=NULL;
244 int binx=0;
245 int biny=0;
246 int i=0;
247 int nrow=0;
248 double* pord=NULL;
249 double* pwav=NULL;
250 double* pslit=NULL;
251 double x=0;
252 double y=0;
253 xsh_xs_3 model_config ;
254 cpl_table* input_table=NULL;
255 const char* input_table_name = NULL;
256 //double mm2nm=1.E6;
257 double wave=0;
258 int ord=0;
259 double s=0;
260
261 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
262 recipe_tags, recipe_tags_size, RECIPE_ID,
263 XSH_BINARY_VERSION,
265 check(xsh_config = xsh_find_frame_with_tag( calib,XSH_MOD_CFG,
266 instrument));
268 instrument));
269 check(p = cpl_parameterlist_find(parameters,"xsh.xsh_model.binx"));
270 check(binx = cpl_parameter_get_int(p));
271
272 check(p = cpl_parameterlist_find(parameters,"xsh.xsh_model.biny"));
273 check(biny = cpl_parameter_get_int(p));
274 xsh_msg("cfg frm name=%s",cpl_frame_get_filename(xsh_config));
275 check( xsh_model_config_load_best( xsh_config, &model_config));
276 xsh_model_binxy(&model_config,binx,biny);
277
278
279 input_table_name=cpl_frame_get_filename(wave_list);
280 input_table=cpl_table_load(input_table_name,1,0);
281 check(nrow=cpl_table_get_nrow(input_table));
282 //cpl_table_dump(input_table,1,3,stdout);
283 check(pwav=cpl_table_get_data_double(input_table,"wavelength"));
284 check(pord=cpl_table_get_data_double(input_table,"grating_order"));
285 check(pslit=cpl_table_get_data_double(input_table,"slit"));
286 //xsh_model_io_dump(&model_config);
287 for(i=0;i<nrow;i++) {
288 //wave=pwav[i]*mm2nm;
289 wave=pwav[i];
290 ord=(int)pord[i];
291 s=pslit[i];
292 check(xsh_model_get_xy(&model_config,instrument,wave,ord,s,&x,&y));
293 xsh_msg("ord=%d wav=%10.8g s=%g ==>x=%16.13g y=%16.13g",ord,wave,s,x,y);
294 }
295
296 cleanup:
298 xsh_free_frameset(&raws);
299 xsh_free_frameset(&calib);
300
301 return 0 ;
302}
303
304
305
306
307
308
309
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_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
void xsh_model_get_xy(xsh_xs_3 *p_xs_3, xsh_instrument *instr, double lambda_nm, int morder, double ent_slit_pos, double *x, double *y)
Compute the detector location (floating point pixels) of a given wavelength/entrance slit position.
void xsh_model_binxy(xsh_xs_3 *p_xs_3, int bin_X, int bin_Y)
corrects model for detector's binning
static int xsh_util_guess_xy(cpl_parameterlist *, cpl_frameset *)
The FITS file creation occurs here.
int * y
static char xsh_util_guess_xy_description[]
static int xsh_util_guess_xy_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static char xsh_util_guess_xy_description_short[]
static int xsh_util_guess_xy_create(cpl_plugin *)
Setup the recipe options
#define RECIPE_ID
int * x
static int xsh_util_guess_xy_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static SimAnneal s
Definition: xsh_model_sa.c:99
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
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
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_ARC_LINE_LIST
Definition: xsh_dfs.h:955
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)