X-shooter Pipeline Reference Manual 3.8.15
xsh_util_crh_single.c
Go to the documentation of this file.
1/* $Id: xsh_util_crh_single.c,v 1.11 2012-11-06 16:07:47 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-11-06 16:07:47 $
24 * $Revision: 1.11 $
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 RECIPE_ID "xsh_util_crh_single"
57#define RECIPE_AUTHOR "A.Modigliani"
58#define 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_crh_single_create(cpl_plugin *) ;
66static int xsh_util_crh_single_exec(cpl_plugin *) ;
67static int xsh_util_crh_single_destroy(cpl_plugin *) ;
68static int xsh_util_crh_single(cpl_parameterlist *, cpl_frameset *) ;
69
70/*-----------------------------------------------------------------------------
71 Static variables
72 ----------------------------------------------------------------------------*/
73
74static char
75xsh_util_crh_single_description_short[] = "Remove cosmic ray hits from image";
77"This recipe removes cosmic ray hits from an input image.\n"
78"The input files should be tagged as IMA_arm)\n"
79"Information on relevant parameters can be found with\n"
80"esorex --params xsh_util_crh_single\n"
81"esorex --help xsh_util_crh_single\n"
82"\n";
83
84/*-----------------------------------------------------------------------------
85 Functions code
86 ----------------------------------------------------------------------------*/
87/*---------------------------------------------------------------------------*/
98/*---------------------------------------------------------------------------*/
99
101/*---------------------------------------------------------------------------*/
109/*---------------------------------------------------------------------------*/
110int cpl_plugin_get_info(cpl_pluginlist * list)
111{
112 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
113 cpl_plugin * plugin = &recipe->interface ;
114
115 cpl_plugin_init(plugin,
116 CPL_PLUGIN_API,
117 XSH_BINARY_VERSION,
118 CPL_PLUGIN_TYPE_RECIPE,
119 RECIPE_ID,
128
129 cpl_pluginlist_append(list, plugin) ;
130
131 return 0;
132}
133
134/*---------------------------------------------------------------------------*/
143/*---------------------------------------------------------------------------*/
144static int xsh_util_crh_single_create(cpl_plugin * plugin)
145{
146 cpl_recipe * recipe ;
147 xsh_remove_crh_single_param crh_single = { 0.1, 5, 2.0, 4} ;
148
149 /* Reset library state */
150 xsh_init();
151
152 /* Get the recipe out of the plugin */
153 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
154 recipe = (cpl_recipe *)plugin ;
155 else return -1 ;
156 cpl_error_reset();
157
158
159 /* Create the parameters list in the cpl_recipe object */
160 recipe->parameters = cpl_parameterlist_new() ;
161
162
163 /* Set generic parameters (common to all recipes) */
165 recipe->parameters ) ) ;
166 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
167 /* remove_crh_single */
169 crh_single )) ;
170
171
172
173
174 cleanup:
175
176 /* Return */
177 return 0;
178}
179
180/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187static int xsh_util_crh_single_exec(cpl_plugin * plugin)
188{
189 cpl_recipe * recipe ;
190 int code=0;
191 cpl_errorstate initial_errorstate = cpl_errorstate_get();
192
193 /* Get the recipe out of the plugin */
194 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
195 recipe = (cpl_recipe *)plugin ;
196 else return -1 ;
197 cpl_error_reset();
198
199 code = xsh_util_crh_single(recipe->parameters, recipe->frames) ;
200
201
202 if (!cpl_errorstate_is_equal(initial_errorstate)) {
203 /* Dump the error history since recipe execution start.
204 At this point the recipe cannot recover from the error */
205 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
206 }
207
208 return code ;
209}
210
211/*---------------------------------------------------------------------------*/
217/*---------------------------------------------------------------------------*/
218static int xsh_util_crh_single_destroy(cpl_plugin * plugin)
219{
220 cpl_recipe * recipe ;
221
222 /* Get the recipe out of the plugin */
223 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
224 recipe = (cpl_recipe *)plugin ;
225 else return -1 ;
226
227 cpl_parameterlist_delete(recipe->parameters) ;
228 return 0 ;
229}
230
231
232
233/*---------------------------------------------------------------------------*/
240/*---------------------------------------------------------------------------*/
241static int
242xsh_util_crh_single( cpl_parameterlist * parameters,
243 cpl_frameset * frameset)
244{
245 int i=0;
247 cpl_frameset* raws=NULL;
248 cpl_frameset* calib=NULL;
249 const char* recipe_tags[1] = {XSH_IMA};
250 int recipe_tags_size = 1;
251 xsh_remove_crh_single_param * crh_single_par = NULL ;
252 int nraw=0;
253 const char* name=NULL;
254 char nocrh_tag[256];
255 char nocrh_name[256];
256
257 cpl_frame* frame=NULL;
258 cpl_frame* res_frame=NULL;
259 const char* pro_catg=NULL;
260 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
261 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
263 parameters));
264
265 /**************************************************************************/
266 /* DFS management */
267 /**************************************************************************/
268 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
269 recipe_tags, recipe_tags_size,
270 RECIPE_ID, XSH_BINARY_VERSION,
272
273 check(nraw=cpl_frameset_get_size(raws));
274
275 if(nraw<1) {
276 xsh_msg_error("Please, provide at least opne input frame. Exit");
277 goto cleanup;
278 }
279
280 for(i=0;i<nraw;i++) {
281 frame=cpl_frameset_get_frame(raws,i);
282 name=cpl_frame_get_filename(frame);
283 sprintf(nocrh_tag,"NOCRH_%s_",
285 sprintf(nocrh_name,"%s%s",nocrh_tag,".fits");
286
287 check(res_frame=xsh_remove_crh_single(frame,instrument,NULL,crh_single_par,
288 nocrh_tag ));
289 xsh_free_frame(&frame);
291 check(frame=xsh_frame_product(nocrh_name,pro_catg,
292 CPL_FRAME_TYPE_IMAGE,
293 CPL_FRAME_GROUP_PRODUCT,
294 CPL_FRAME_LEVEL_FINAL));
295
296 check(xsh_add_product_image(frame, frameset,parameters,
297 RECIPE_ID, instrument, pro_catg ));
298 }
299
300
301 cleanup:
302
303 if (cpl_error_get_code()) {
304 xsh_free_frame(&frame);
305 return -1 ;
306 } else {
307 return 0 ;
308 }
309
310}
static xsh_instrument * instrument
#define check(COMMAND)
Definition: xsh_error.h:71
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
#define xsh_msg_error(...)
Print an error message.
Definition: xsh_msg.h:62
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
cpl_frame * xsh_remove_crh_single(cpl_frame *sci_frame, xsh_instrument *instrument, cpl_mask *sky_map, xsh_remove_crh_single_param *single_par, const char *name)
Remove cosmic rays from a single frame.
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int xsh_util_crh_single_create(cpl_plugin *)
Setup the recipe options
static int xsh_util_crh_single_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static int xsh_util_crh_single(cpl_parameterlist *, cpl_frameset *)
Get the command line options and execute the data reduction.
static int xsh_util_crh_single_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
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_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
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
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
Definition: xsh_dfs.h:1548
#define XSH_IMA
Definition: xsh_dfs.h:236
cpl_error_code xsh_parameters_decode_bp(const char *recipe_id, cpl_parameterlist *plist, const int ival)
void xsh_parameters_remove_crh_single_create(const char *recipe_id, cpl_parameterlist *plist, xsh_remove_crh_single_param p)
xsh_remove_crh_single_param * xsh_parameters_remove_crh_single_get(const char *recipe_id, cpl_parameterlist *list)
void xsh_parameters_generic(const char *recipe_id, cpl_parameterlist *plist)
#define RECIPE_CONTACT
static char xsh_util_crh_single_description[]
static char xsh_util_crh_single_description_short[]
#define RECIPE_ID
#define RECIPE_AUTHOR