CRIRES Pipeline Reference Manual 2.3.17
crires_test_model_compute.c
1/* $Id: crires_test_model_compute.c,v 1.3 2009-05-08 09:37:12 yjung Exp $
2 *
3 * This file is part of the CRIRES Pipeline
4 * Copyright (C) 2002,2003 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: yjung $
23 * $Date: 2009-05-08 09:37:12 $
24 * $Revision: 1.3 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32/*-----------------------------------------------------------------------------
33 Includes
34 -----------------------------------------------------------------------------*/
35
36
37#include <cpl.h>
38#include <math.h>
39
40#include "crires_utils.h"
41#include "crires_pfits.h"
42#include "crires_dfs.h"
43#include "crires_model_computation.h"
44
45/*-----------------------------------------------------------------------------
46 Functions prototypes
47 -----------------------------------------------------------------------------*/
48
49static int crires_test_model_compute_create(cpl_plugin *) ;
50static int crires_test_model_compute_exec(cpl_plugin *) ;
51static int crires_test_model_compute_destroy(cpl_plugin *) ;
52static int crires_test_model_compute(cpl_parameterlist *, cpl_frameset *) ;
53
54/*-----------------------------------------------------------------------------
55 Static variables
56 -----------------------------------------------------------------------------*/
57
58static struct {
59 int order_calc_flag ;
60 int order_out_flag ;
61 int trace_out_flag ;
62 int is_out_flag ;
63 int back_map_flag ;
64 int continuum ;
65 int morder ;
66 double flux_scale ;
67 double spotsize ;
68} crires_test_model_compute_config ;
69
70static char crires_test_model_compute_description[] =
71" This recipe uses a specified physical model configuration\n (model-cfg.fits in the sof, see below), to generate a variety of\n simulated datasets. There are three principle tasks that may be\n performed with this recipe:\n1. Generate a 2D simulated image of a calibration emission lamp and\n write it to the FITS file <chips_out.fits>. Statistics are also\n written to the ascii file <centres.dat>. The calibration source\n line list should be a FITS table with two columns: wavelength(nm);\n relative intensity. This is the line-list.fits wile in the sof (see\n below).\n2. Generate a wavelength map and write to FITS. This is now superseded\n by the crires_model_wlmap recipe.\n3. Trace the locus of the spectrum for a given instrument\n configuration (see the crires_model_profile function above) and\n write the result to the ascii file <trace.dat>\nThe files listed in the Set Of Frames (sof-file) must be tagged:\n model-cfg.fits CRIRES_MODEL_CONFIG\n line-list.fits CRIRES_MODEL_WAVE_EG\n";
72
73/*-----------------------------------------------------------------------------
74 Functions code
75 -----------------------------------------------------------------------------*/
76
77/*----------------------------------------------------------------------------*/
86/*----------------------------------------------------------------------------*/
87int cpl_plugin_get_info(cpl_pluginlist * list)
88{
89 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
90 cpl_plugin * plugin = &recipe->interface ;
91
92 cpl_plugin_init(plugin,
93 CPL_PLUGIN_API,
94 CRIRES_BINARY_VERSION,
95 CPL_PLUGIN_TYPE_RECIPE,
96 "crires_test_model_compute",
97 "Compute detector locations for given wavelength and cfg",
98 crires_test_model_compute_description,
99 "Paul Bristow",
100 "bristowp@eso.org",
101 crires_get_license(),
102 crires_test_model_compute_create,
103 crires_test_model_compute_exec,
104 crires_test_model_compute_destroy) ;
105
106 cpl_pluginlist_append(list, plugin) ;
107
108 return 0;
109}
110
111/*----------------------------------------------------------------------------*/
119/*----------------------------------------------------------------------------*/
120static int crires_test_model_compute_create(cpl_plugin * plugin)
121{
122 cpl_recipe * recipe ;
123 cpl_parameter * p ;
124
125 /* Check that the plugin is part of a valid recipe */
126 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
127 recipe = (cpl_recipe *)plugin ;
128 else return -1 ;
129
130 /* Create the parameters list in the cpl_recipe object */
131 recipe->parameters = cpl_parameterlist_new() ;
132
133 /* Fill the parameters list */
134 /* --order_calc */
135 p = cpl_parameter_new_value("crires.crires_test_model_compute.order_calc",
136 CPL_TYPE_BOOL,"order_calc flag","crires.crires_test_model_compute",
137 FALSE);
138 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "order_calc") ;
139 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
140 cpl_parameterlist_append(recipe->parameters, p) ;
141 /* --order_out */
142 p = cpl_parameter_new_value("crires.crires_test_model_compute.order_out",
143 CPL_TYPE_BOOL,"order_out flag","crires.crires_test_model_compute",FALSE);
144 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "order_out") ;
145 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
146 cpl_parameterlist_append(recipe->parameters, p) ;
147 /* --trace_out */
148 p = cpl_parameter_new_value("crires.crires_test_model_compute.trace_out",
149 CPL_TYPE_BOOL,"trace_out flag","crires.crires_test_model_compute",FALSE);
150 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "trace_out") ;
151 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
152 cpl_parameterlist_append(recipe->parameters, p) ;
153 /* --is_out */
154 p = cpl_parameter_new_value("crires.crires_test_model_compute.is_out",
155 CPL_TYPE_BOOL, "is_out flag", "crires.crires_test_model_compute", FALSE);
156 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "is_out") ;
157 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
158 cpl_parameterlist_append(recipe->parameters, p) ;
159 /* --back_map */
160 p = cpl_parameter_new_value("crires.crires_test_model_compute.back_map",
161 CPL_TYPE_BOOL, "back_map flag","crires.crires_test_model_compute",FALSE);
162 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "back_map") ;
163 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
164 cpl_parameterlist_append(recipe->parameters, p) ;
165 /* --continuum */
166 p = cpl_parameter_new_value("crires.crires_test_model_compute.continuum",
167 CPL_TYPE_INT, "continuum", "crires.crires_test_model_compute", 0);
168 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "continuum") ;
169 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
170 cpl_parameterlist_append(recipe->parameters, p) ;
171 /* --morder */
172 p = cpl_parameter_new_value("crires.crires_test_model_compute.morder",
173 CPL_TYPE_INT, "morder", "crires.crires_test_model_compute", 31);
174 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "morder") ;
175 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
176 cpl_parameterlist_append(recipe->parameters, p) ;
177 /* --flux_scale */
178 p = cpl_parameter_new_value("crires.crires_test_model_compute.flux_scale",
179 CPL_TYPE_DOUBLE, "flux_scale", "crires.crires_test_model_compute",100.0);
180 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "flux_scale") ;
181 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
182 cpl_parameterlist_append(recipe->parameters, p) ;
183 /* --spotsize1000 */
184 p = cpl_parameter_new_value("crires.crires_test_model_compute.spotsize",
185 CPL_TYPE_DOUBLE, "spotsize", "crires.crires_test_model_compute", 0.025);
186 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "spotsize") ;
187 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
188 cpl_parameterlist_append(recipe->parameters, p) ;
189
190 /* Return */
191 return 0;
192}
193
194/*----------------------------------------------------------------------------*/
200/*----------------------------------------------------------------------------*/
201static int crires_test_model_compute_exec(cpl_plugin * plugin)
202{
203 cpl_recipe * recipe ;
204
205 /* Get the recipe out of the plugin */
206 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
207 recipe = (cpl_recipe *)plugin ;
208 else return -1 ;
209
210 return crires_test_model_compute(recipe->parameters, recipe->frames) ;
211}
212
213/*----------------------------------------------------------------------------*/
219/*----------------------------------------------------------------------------*/
220static int crires_test_model_compute_destroy(cpl_plugin * plugin)
221{
222 cpl_recipe * recipe ;
223
224 /* Get the recipe out of the plugin */
225 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
226 recipe = (cpl_recipe *)plugin ;
227 else return -1 ;
228
229 cpl_parameterlist_delete(recipe->parameters) ;
230 return 0 ;
231}
232
233/*----------------------------------------------------------------------------*/
240/*----------------------------------------------------------------------------*/
241static int crires_test_model_compute(
242 cpl_parameterlist * parlist,
243 cpl_frameset * frameset)
244{
245 cpl_parameter * par ;
246 cpl_frame * cri_config ;
247 cpl_frame * wave_eg ;
248
249 /* Retrieve input parameters */
250 /* order_calc */
251 par = cpl_parameterlist_find(parlist,
252 "crires.crires_test_model_compute.order_calc");
253 crires_test_model_compute_config.order_calc_flag = cpl_parameter_get_bool(par) ;
254 /* order_out */
255 par = cpl_parameterlist_find(parlist,
256 "crires.crires_test_model_compute.order_out");
257 crires_test_model_compute_config.order_out_flag = cpl_parameter_get_bool(par) ;
258 /* trace_out */
259 par = cpl_parameterlist_find(parlist,
260 "crires.crires_test_model_compute.trace_out");
261 crires_test_model_compute_config.trace_out_flag = cpl_parameter_get_bool(par) ;
262 /* is_out */
263 par = cpl_parameterlist_find(parlist, "crires.crires_test_model_compute.is_out");
264 crires_test_model_compute_config.is_out_flag = cpl_parameter_get_bool(par) ;
265 /* back_map */
266 par = cpl_parameterlist_find(parlist,
267 "crires.crires_test_model_compute.back_map");
268 crires_test_model_compute_config.back_map_flag = cpl_parameter_get_bool(par) ;
269 /* continuum */
270 par = cpl_parameterlist_find(parlist,
271 "crires.crires_test_model_compute.continuum");
272 crires_test_model_compute_config.continuum = cpl_parameter_get_int(par) ;
273 /* morder */
274 par = cpl_parameterlist_find(parlist,
275 "crires.crires_test_model_compute.morder");
276 crires_test_model_compute_config.morder = cpl_parameter_get_int(par) ;
277 /* flux_scale */
278 par = cpl_parameterlist_find(parlist,
279 "crires.crires_test_model_compute.flux_scale");
280 crires_test_model_compute_config.flux_scale = cpl_parameter_get_double(par) ;
281 /* spotsize */
282 par = cpl_parameterlist_find(parlist,
283 "crires.crires_test_model_compute.spotsize");
284 crires_test_model_compute_config.spotsize = cpl_parameter_get_double(par) ;
285
286 /* Identify the RAW and CALIB frames in the input frameset */
287 if (crires_dfs_set_groups(frameset, NULL)) {
288 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
289 return -1 ;
290 }
291
292 /* RETRIEVE INPUT DATA */
293 cri_config = cpl_frameset_find(frameset, CRIRES_CALPRO_MODEL_CONFIG) ;
294 wave_eg = cpl_frameset_find(frameset, CRIRES_CALPRO_MODEL_WAVEEG) ;
295
296 /* Apply the computation here */
297 if (crires_model_computation(cpl_frame_get_filename(cri_config),
298 cpl_frame_get_filename(wave_eg),
299 crires_test_model_compute_config.order_calc_flag,
300 crires_test_model_compute_config.order_out_flag,
301 crires_test_model_compute_config.trace_out_flag,
302 crires_test_model_compute_config.is_out_flag,
303 crires_test_model_compute_config.back_map_flag,
304 crires_test_model_compute_config.continuum,
305 crires_test_model_compute_config.morder,
306 crires_test_model_compute_config.flux_scale,
307 crires_test_model_compute_config.spotsize) == -1) {
308 cpl_msg_error(__func__, "Failed computing the model") ;
309 return -1 ;
310 }
311
312 /* Return */
313 if (cpl_error_get_code())
314 return -1 ;
315 else
316 return 0 ;
317}
318