X-shooter Pipeline Reference Manual 3.8.15
xsh_util_ronbias.c
Go to the documentation of this file.
1/* $Id: xsh_util_ronbias.c,v 1.8 2012-04-26 14:03:20 amodigli Exp $
2 *
3 * This file is part of the XSHOOTER 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: amodigli $
23 * $Date: 2012-04-26 14:03:20 $
24 * $Revision: 1.8 $
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#include <string.h>
36#include <math.h>
37
38/* cpl */
39#include <cpl.h>
40
41#include <xsh_dfs.h>
42#include <xsh_data_pre.h>
43#include <xsh_parameters.h>
44#include <xsh_drl.h>
45#include <xsh_msg.h>
46#include <xsh_pfits.h>
47#include <xsh_pfits_qc.h>
48#include <xsh_error.h>
49#include <xsh_utils_image.h>
50
51
52/*-----------------------------------------------------------------------------
53 Defines
54 ----------------------------------------------------------------------------*/
55
56#define XSH_UTL_RONBIAS_RECIPE_ID "xsh_util_ronbias"
57#define XSH_UTL_RONBIAS_RECIPE_AUTHOR "A.Modigliani"
58#define XSH_UTL_RONBIAS_RECIPE_CONTACT "Andrea.Modigliani@eso.org"
59#define PRO_IMA "PRO_IMA_UVB"
60#define KEY_VALUE_HPRO_DID "PRO-1.15"
61/*-----------------------------------------------------------------------------
62 Functions prototypes
63 ----------------------------------------------------------------------------*/
64
65static int xsh_util_ronbias_create(cpl_plugin *) ;
66static int xsh_util_ronbias_exec(cpl_plugin *) ;
67static int xsh_util_ronbias_destroy(cpl_plugin *) ;
68static int xsh_util_ronbias(cpl_parameterlist *, cpl_frameset *) ;
69
70/*-----------------------------------------------------------------------------
71 Static variables
72 ----------------------------------------------------------------------------*/
73
74static char
77"This recipe performs ron computation on a bias pair.\n"
78"The input files should be tagged as BIAS_arm)\n"
79"The output is a bias frame difference with RON computed as follows:\n"
80"The input biase difference is computed. Then a median on nsampl (100) \n"
81"random boxes of size xsize*ysize (20x20) is computed \n"
82"then the rms of the obtained values is determined and divided by sqrt(2)\n"
83"This gives the RON in [ADU]\n"
84"Information on relevant parameters can be found with\n"
85"esorex --params xsh_util_ronbias\n"
86"esorex --help xsh_util_ronbias\n"
87"\n";
88
89/*-----------------------------------------------------------------------------
90 Functions code
91 ----------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
100/*---------------------------------------------------------------------------*/
108/*---------------------------------------------------------------------------*/
109int cpl_plugin_get_info(cpl_pluginlist * list)
110{
111 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
112 cpl_plugin * plugin = &recipe->interface ;
113
114 cpl_plugin_init(plugin,
115 CPL_PLUGIN_API,
116 XSH_BINARY_VERSION,
117 CPL_PLUGIN_TYPE_RECIPE,
127
128 cpl_pluginlist_append(list, plugin) ;
129
130 return 0;
131}
132
133/*---------------------------------------------------------------------------*/
142/*---------------------------------------------------------------------------*/
143static int xsh_util_ronbias_create(cpl_plugin * plugin)
144{
145 cpl_recipe * recipe ;
146 cpl_parameter * p ;
147
148 /* Reset library state */
149 xsh_init();
150
151 /* Get the recipe out of the plugin */
152 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
153 recipe = (cpl_recipe *)plugin ;
154 else return -1 ;
155 cpl_error_reset();
156
157
158 /* Create the parameters list in the cpl_recipe object */
159 recipe->parameters = cpl_parameterlist_new() ;
160
161
162 /* Set generic parameters (common to all recipes) */
164 recipe->parameters ) ) ;
166 /* Fill the parameters list */
167 p = cpl_parameter_new_value("xsh.xsh_util_ronbias.nsampl",
168 CPL_TYPE_INT,
169 "Number of sampling values",
170 "xsh.xsh_util_ronbias",100);
171 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "nsampl") ;
172 cpl_parameterlist_append(recipe->parameters, p) ;
173
174
175
176 p = cpl_parameter_new_value("xsh.xsh_util_ronbias.hsize",
177 CPL_TYPE_INT,
178 "Random square boxes size",
179 "xsh.xsh_util_ronbias",10);
180 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "hsize") ;
181 cpl_parameterlist_append(recipe->parameters, p) ;
182
183
184 p = cpl_parameter_new_value("xsh.xsh_util_ronbias.llx",
185 CPL_TYPE_INT,
186 "Lower left X of sampling region",
187 "xsh.xsh_util_ronbias",-1);
188 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "llx") ;
189 cpl_parameterlist_append(recipe->parameters, p) ;
190
191
192 p = cpl_parameter_new_value("xsh.xsh_util_ronbias.lly",
193 CPL_TYPE_INT,
194 "Lower left Y of sampling region",
195 "xsh.xsh_util_ronbias",-1);
196 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "lly") ;
197 cpl_parameterlist_append(recipe->parameters, p) ;
198
199
200
201 p = cpl_parameter_new_value("xsh.xsh_util_ronbias.urx",
202 CPL_TYPE_INT,
203 "Upper right X of sampling region",
204 "xsh.xsh_util_ronbias",-1);
205 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "urx") ;
206 cpl_parameterlist_append(recipe->parameters, p) ;
207
208
209 p = cpl_parameter_new_value("xsh.xsh_util_ronbias.ury",
210 CPL_TYPE_INT,
211 "Upper right Y of sampling region",
212 "xsh.xsh_util_ronbias",-1);
213 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ury") ;
214 cpl_parameterlist_append(recipe->parameters, p) ;
215
216
217
218
219
220 cleanup:
221
222 /* Return */
223 return 0;
224}
225
226/*---------------------------------------------------------------------------*/
232/*---------------------------------------------------------------------------*/
233static int xsh_util_ronbias_exec(cpl_plugin * plugin)
234{
235 cpl_recipe * recipe ;
236 int code=0;
237 cpl_errorstate initial_errorstate = cpl_errorstate_get();
238
239 /* Get the recipe out of the plugin */
240 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
241 recipe = (cpl_recipe *)plugin ;
242 else return -1 ;
243 cpl_error_reset();
244
245 code = xsh_util_ronbias(recipe->parameters, recipe->frames) ;
246
247
248 if (!cpl_errorstate_is_equal(initial_errorstate)) {
249 /* Dump the error history since recipe execution start.
250 At this point the recipe cannot recover from the error */
251 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
252 }
253
254 return code ;
255}
256
257/*---------------------------------------------------------------------------*/
263/*---------------------------------------------------------------------------*/
264static int xsh_util_ronbias_destroy(cpl_plugin * plugin)
265{
266 cpl_recipe * recipe ;
267
268 /* Get the recipe out of the plugin */
269 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
270 recipe = (cpl_recipe *)plugin ;
271 else return -1 ;
272
273 cpl_parameterlist_delete(recipe->parameters) ;
274 return 0 ;
275}
276
277
278
279/*---------------------------------------------------------------------------*/
286/*---------------------------------------------------------------------------*/
287static int
288xsh_util_ronbias( cpl_parameterlist * parlist,
289 cpl_frameset * frames)
290{
291 cpl_parameter * param= NULL ;
292
293 int hsize=1;
294 int nsampl=0;
295 int llx=1;
296 int lly=1;
297 int urx=1;
298 int ury=1;
299
300 double ron;
301 double ron_err;
302
303
304 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
305 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
306
307 /* HOW TO RETRIEVE INPUT PARAMETERS */
308 /* --stropt */
309 check(param=cpl_parameterlist_find(parlist,"xsh.xsh_util_ronbias.nsampl"));
310 check(nsampl=cpl_parameter_get_int(param));
311
312 check(param=cpl_parameterlist_find(parlist,"xsh.xsh_util_ronbias.hsize"));
313 check(hsize=cpl_parameter_get_int(param));
314
315
316 check(param=cpl_parameterlist_find(parlist, "xsh.xsh_util_ronbias.llx"));
317 check(llx=cpl_parameter_get_int(param));
318
319 check(param=cpl_parameterlist_find(parlist, "xsh.xsh_util_ronbias.lly"));
320 check(lly=cpl_parameter_get_int(param));
321
322 check(param=cpl_parameterlist_find(parlist, "xsh.xsh_util_ronbias.urx"));
323 check(urx=cpl_parameter_get_int(param));
324
325 check(param=cpl_parameterlist_find(parlist, "xsh.xsh_util_ronbias.ury"));
326 check(ury=cpl_parameter_get_int(param));
327
328 check(xsh_compute_ron(frames,llx,lly,urx,ury,nsampl,hsize,1,&ron,&ron_err));
329
330 xsh_msg("ron=%g ron_err=%g",ron,ron_err);
331
332 cleanup:
333
334 if (cpl_error_get_code()) {
335 return -1 ;
336 } else {
337 return 0 ;
338 }
339
340}
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int xsh_util_ronbias_create(cpl_plugin *)
Setup the recipe options
static int xsh_util_ronbias_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int xsh_util_ronbias(cpl_parameterlist *, cpl_frameset *)
Get the command line options and execute the data reduction.
static int xsh_util_ronbias_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
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
int lly
Definition: xsh_detmon_lg.c:86
int llx
Definition: xsh_detmon_lg.c:85
int urx
Definition: xsh_detmon_lg.c:87
int ury
Definition: xsh_detmon_lg.c:88
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)
static char xsh_util_ronbias_description_short[]
#define XSH_UTL_RONBIAS_RECIPE_AUTHOR
#define XSH_UTL_RONBIAS_RECIPE_ID
static char xsh_util_ronbias_description[]
#define XSH_UTL_RONBIAS_RECIPE_CONTACT
cpl_error_code xsh_compute_ron(cpl_frameset *frames, int llx, int lly, int urx, int ury, int nsampl, int hsize, const int reg_id, double *ron, double *ron_err)
compute ron taking random windows of given size in a given region on 2 frames difference