X-shooter Pipeline Reference Manual 3.8.15
test-xsh_remove_crh_single.c
Go to the documentation of this file.
1/* *
2 * This file is part of the ESO X-shooter Pipeline *
3 * Copyright (C) 2006 European Southern Observatory *
4 * *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
18 * */
19
20/*
21 * $Author: amodigli $
22 * $Date: 2012-11-16 16:27:02 $
23 * $Revision: 1.23 $
24 */
25
26#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
30/*-------------------------------------------------------------------------*/
36/*-------------------------------------------------------------------------*/
39/*--------------------------------------------------------------------------
40 Includes
41 --------------------------------------------------------------------------*/
42
43#include <tests.h>
44
45#include <xsh_data_pre.h>
46#include <xsh_error.h>
47#include <xsh_msg.h>
48#include <xsh_data_instrument.h>
49#include <xsh_drl.h>
50#include <xsh_pfits.h>
51
52#include <xsh_badpixelmap.h>
53
54#include <cpl.h>
55#include <math.h>
56
57#include <getopt.h>
58
59/*--------------------------------------------------------------------------
60 Defines
61 --------------------------------------------------------------------------*/
62
63#define MODULE_ID "XSH_REMOVE_CRH_SINGLE"
64
65static void Help( void)
66{
67 puts( "Unitary test of xsh_remove_crh_single");
68 puts( "Usage: test_xsh_remove_crh_single [options] <input_files>");
69
70 puts( "Options" ) ;
71 puts( " --sigma_lim=<n> : Sigma limit (5.0]" ) ;
72 puts( " --f_lim=<n> : F limit [2.0]" ) ;
73 puts( " --iter=<n> : Number of iteration [4]" ) ;
74 puts( " --frac_max=<n> : Maximum rejected fraction [0.1]");
75 puts( " --debug=<n> : Level of debug LOW | MEDIUM | HIGH [MEDIUM]" );
76 puts( " --help : What you see" ) ;
77 puts( "\nInput Files" ) ;
78 puts( "The input files argument MUST be in this order:" ) ;
79 puts( " 1. Science frame in PRE format sky subtracted" ) ;
80 puts( " 2. SOF [WAVE_MAP]\n" ) ;
82 TEST_END();
83}
84
85enum {
92} ;
93
94static struct option long_options[] = {
95 {"sigma_lim", required_argument, 0, SIGMA_LIM_OPT},
96 {"f_lim", required_argument, 0, F_LIM_OPT},
97 {"iter", required_argument, 0, ITER_OPT},
98 {"frac_max", required_argument, 0, FRAC_MAX_OPT},
99 {"debug", required_argument, 0, DEBUG_OPT},
100 {"help", 0, 0,HELP_OPT},
101 {0, 0, 0, 0}
102};
103
104static void HandleOptions( int argc, char **argv,
105 xsh_remove_crh_single_param *single_par)
106{
107 int opt ;
108 int option_index = 0;
109
110 while (( opt = getopt_long (argc, argv, "sigma_lim:f_lim",
111 long_options, &option_index)) != EOF ){
112 switch ( opt ) {
113 case SIGMA_LIM_OPT:
114 single_par->sigma_lim = atof(optarg);
115 break ;
116 case F_LIM_OPT:
117 single_par->f_lim = atof(optarg);
118 break ;
119 case FRAC_MAX_OPT:
120 single_par->crh_frac_max = atof(optarg);
121 break;
122 case ITER_OPT:
123 sscanf( optarg, "%64d", &single_par->nb_iter ) ;
124 break ;
125 case DEBUG_OPT:
126 if ( strcmp( optarg, "LOW")==0){
128 }
129 else if ( strcmp( optarg, "HIGH")==0){
131 }
132 break;
133 default:
134 Help();
135 exit(-1);
136 }
137 }
138 return;
139}
140
141/*--------------------------------------------------------------------------
142 Implementation
143 --------------------------------------------------------------------------*/
144
153int main( int argc, char **argv)
154{
155 /* Declarations */
156 int ret = 0 ;
157 char name[256];
158 char sof_name[256];
159 char res_name[64] ;
160
161 cpl_frameset* raw = NULL;
162 cpl_frameset *set = NULL;
163 cpl_frame* sciraw_frame = NULL;
164 cpl_frame* sci_frame = NULL;
165 cpl_frame* wavemap_frame = NULL;
166 cpl_frame* frame_rmcrh = NULL;
168 xsh_remove_crh_single_param single_par = { 0.1,2.5,2.0, 4 } ;
169 XSH_INSTRCONFIG* iconfig = NULL;
170 cpl_image* test_image = NULL;
171 cpl_propertylist * header = NULL ;
172
173 /* Initialize libraries */
176 cpl_msg_set_level( CPL_MSG_DEBUG);
178
179
180 /* Analyse parameters */
181 single_par.sigma_lim = 5.0;
182 single_par.f_lim = 2.0;
183 single_par.nb_iter = 4;
184
185 HandleOptions( argc, argv, &single_par);
186
187 if (argc-optind > 1){
188 sprintf(name, argv[optind]);
189 sprintf( sof_name, argv[optind+1]);
190
191 TESTS_XSH_FRAME_CREATE( sci_frame, "OBJECT_SLIT_STARE_arm", name);
192 /* Create frameset from sof */
193 check( set = sof_to_frameset( sof_name));
194
195 /* Validate frame set */
197 check( wavemap_frame = xsh_find_wavemap( set, instrument));
198 }
199 else{
200 xsh_msg("-------------------------------------------");
201 xsh_msg("Execute default test : do --help for option");
202 xsh_msg("-------------------------------------------");
203
209
210 /* Generate tests data */
211 test_image = cpl_image_fill_test_create(10,10);
212 sprintf(name, "remove_crh_single_sci_UVB.fits");
213 header = mkHeader( iconfig, 10, 10, 1.) ;
214 cpl_image_save(test_image, name, CPL_BPP_IEEE_DOUBLE, header,
215 CPL_IO_DEFAULT);
216 sciraw_frame = cpl_frame_new();
217 cpl_frame_set_filename( sciraw_frame, name) ;
218 cpl_frame_set_tag( sciraw_frame, "BIAS_UVB");
219 cpl_frame_set_level( sciraw_frame, CPL_FRAME_LEVEL_TEMPORARY);
220 cpl_frame_set_group( sciraw_frame, CPL_FRAME_GROUP_RAW);
221
222 raw = cpl_frameset_new();
223 check( cpl_frameset_insert( raw, sciraw_frame));
224
225 check( xsh_prepare( raw, NULL, NULL, "BIAS_UVB", instrument,0,CPL_FALSE));
226 check( sci_frame = cpl_frame_duplicate( cpl_frameset_get_first( raw)));
227 }
228
229 xsh_msg("---Input Frames");
230 xsh_msg("sky subtracted frame : %s", name);
231 if ( wavemap_frame != NULL){
232 xsh_msg("Wave map frame : %s", cpl_frame_get_filename( wavemap_frame));
233 }
234
235 xsh_msg("---Parameters");
236 xsh_msg(" frac max : %f", single_par.crh_frac_max);
237 xsh_msg(" sigma_lim : %f", single_par.sigma_lim);
238 xsh_msg(" f_lim : %f", single_par.f_lim);
239 xsh_msg(" niter : %d", single_par.nb_iter);
240
241 /* Call xsh_remove_crh_single */
242 sprintf( res_name, "NOCRH_%s.fits",
244
245
247
248 check(frame_rmcrh = xsh_remove_crh_single( sci_frame,
249 instrument, NULL,&single_par, res_name));
250
251
252 cleanup:
254 xsh_free_frameset( &raw);
255 xsh_free_frameset( &set);
256 xsh_free_propertylist( &header);
257 xsh_free_image ( &test_image);
258 xsh_free_frame( &frame_rmcrh);
259 xsh_free_frame( &sci_frame);
260
261 if (cpl_error_get_code() != CPL_ERROR_NONE) {
262 xsh_error_dump(CPL_MSG_ERROR);
263 ret=1;
264 }
266 TEST_END();
267 return ret ;
268}
int main()
Unit test of xsh_bspline_interpol.
static void HandleOptions(int argc, char **argv, xsh_remove_crh_single_param *single_par)
#define MODULE_ID
static struct option long_options[]
static xsh_instrument * instrument
cpl_frameset * sof_to_frameset(const char *sof_name)
Definition: tests.c:576
cpl_propertylist * mkHeader(XSH_INSTRCONFIG *iconfig, int nx, int ny, double exptime)
Definition: tests.c:221
void xsh_prepare(cpl_frameset *frames, cpl_frame *bpmap, cpl_frame *mbias, const char *prefix, xsh_instrument *instr, const int pre_overscan_corr, const bool flag_neg_and_thresh_pix)
This function transform RAW frames dataset in PRE frames dataset attaching the default bad pixel map ...
Definition: xsh_prepare.c:122
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
void xsh_instrument_set_mode(xsh_instrument *i, XSH_MODE mode)
Set a mode on instrument structure.
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
void xsh_instrument_set_recipe_id(xsh_instrument *instrument, const char *recipe_id)
Set the recipe_id into the instrument structure.
void xsh_instrument_set_arm(xsh_instrument *i, XSH_ARM arm)
Set an arm on instrument structure.
XSH_INSTRCONFIG * xsh_instrument_get_config(xsh_instrument *i)
Get the instrument default set of keywords.
void xsh_instrument_set_lamp(xsh_instrument *i, XSH_LAMP lamp)
Set a lamp on instrument structure.
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
xsh_instrument * xsh_instrument_new(void)
create new instrument structure
#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.
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
Definition: xsh_utils.c:2116
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
int xsh_debug_level_set(int level)
set debug level
Definition: xsh_utils.c:3125
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
static void Help(void)
#define TESTS_CLEAN_WORKSPACE(DRL_ID)
Definition: tests.h:139
#define TESTS_XSH_FRAME_CREATE(frame, tag, name)
Definition: tests.h:123
#define TESTS_INIT_WORKSPACE(DRL_ID)
Definition: tests.h:133
#define TEST_END()
Definition: tests.h:111
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
@ XSH_LAMP_QTH
@ XSH_ARM_UVB
@ XSH_MODE_IFU
cpl_frame * xsh_find_wavemap(cpl_frameset *frames, xsh_instrument *instr)
Find Wave Map frame. The frame returned should not be free by the caller.
Definition: xsh_dfs.c:3983
xsh_instrument * xsh_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset and return the instrument detected.
Definition: xsh_dfs.c:1046
@ XSH_DEBUG_LEVEL_HIGH
Definition: xsh_utils.h:138
@ XSH_DEBUG_LEVEL_LOW
Definition: xsh_utils.h:137
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138