X-shooter Pipeline Reference Manual 3.8.15
test-xsh_detect_arclines.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-01-16 17:52:47 $
23 * $Revision: 1.19 $
24 * $Name: not supported by cvs2svn $
25 */
26#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
30/*--------------------------------------------------------------------------*/
36/*--------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------
40 Includes
41 ---------------------------------------------------------------------------*/
42
43#include <xsh_data_instrument.h>
44#include <xsh_badpixelmap.h>
45#include <xsh_pfits.h>
46#include <xsh_msg.h>
47#include <xsh_utils.h>
48#include <tests.h>
49#include <cpl.h>
50#include <math.h>
51#include <stdlib.h>
52#include <getopt.h>
53
54/*---------------------------------------------------------------------------
55 Defines
56 ---------------------------------------------------------------------------*/
57#define MODULE_ID "XSH_DETECT_ARCLINES"
58
59#define SYNTAX "Test the detect_arclines function\n"\
60 "use : ./test_xsh_detect_arclines OPTIONS FMTCHK_FRAME LINE_LIST THEMAP "\
61 "[GUESS_WAVE_TAB]\n"\
62 "FMTCHK_FRAME => the frame to detect arclines (PRE format)\n"\
63 "LINE_LIST => the line list\n"\
64 "THEMAP => the theoretical map\n"\
65 "GUESS_WAVE_TAB => the guess wave solution\n"\
66 "SPECTRAL_FORMAT_TAB => the spectral format table \n"\
67 "OPTIONS => \n"\
68 " --half_window_size : half window size (HWS) in pixel around the"\
69 " position to fit the gaussian (total window size = 2*HWS+1)\n"\
70 " --half_window_size_for_max : half window size (HWS) in pixel around the"\
71 " theoritical position to find the maximum flux\n"\
72 " --half_window_size_running_median : half window size of running "\
73 "median\n"\
74 " --deg_lambda : lambda degree in polynomial wavelength solution fit\n"\
75 " --deg_order : order degree in polynomial wavelength solution fit\n"\
76 " --deg_slit : slit degree in polynomial wavelength solution fit\n"\
77 " --poly_degree : Polynomial degree\n"\
78 " --min_sn : minimal S/N allowed\n"\
79 " --clip_sigma : multiple of sigma in sigma clipping\n"\
80 " --clip_niter : number of iterations in sigma clipping\n"\
81 " --clip_frac : minimal fractions of bad pixel allowed\n"
82
83enum {
88} ;
89
90static struct option long_options[] = {
91 {"half_window_size", required_argument, 0, HALF_WINDOW_SIZE_OPT},
92 {"half_window_size_for_max", required_argument, 0,
94 {"half_window_size_running_median", required_argument, 0,
96 {"deg_lambda", required_argument, 0, DEG_LAMBDA_OPT},
97 {"deg_order", required_argument, 0, DEG_ORDER_OPT},
98 {"deg_slit", required_argument, 0, DEG_SLIT_OPT},
99 {"poly_degree", required_argument, 0, POLY_DEGREE_OPT},
100 {"min_sn", required_argument, 0, MIN_SN_OPT},
101 {"clip_sigma", required_argument, 0, CLIP_SIGMA_OPT},
102 {"clip_niter", required_argument, 0, CLIP_NITER_OPT},
103 {"clip_frac", required_argument, 0, CLIP_FRAC_OPT},
104 {0, 0, 0, 0}
105};
106
107static void HandleOptions( int argc, char **argv,
108 xsh_detect_arclines_param *det_arc_par, xsh_clipping_param* clip_par)
109{
110 int opt ;
111 int option_index = 0;
112
113 /* Default parameters */
114 det_arc_par->fit_window_hsize = 10;
115 det_arc_par->search_window_hsize = 30;
116 det_arc_par->running_median_hsize = 1;
117 det_arc_par->wavesol_deg_lambda = 2;
118 det_arc_par->wavesol_deg_order = 2;
119 det_arc_par->wavesol_deg_slit = 0;
120 det_arc_par->ordertab_deg_y = 2;
121 det_arc_par->min_sn = 0.2;
122 clip_par->sigma = 1.0;
123 clip_par->niter = 5;
124 clip_par->frac = 0.7;
125
126 /* Handle options */
127 while (( opt = getopt_long (argc, argv, "half_window_size:deg_lambda:"\
128 "deg_order:deg_slit:poly_degree:min_sn:"\
129 "clip_sigma:clip_niter:clip_frac:half_window_size_for_max:"\
130 "half_window_size_running_median",
131 long_options, &option_index)) != EOF ){
132
133 switch ( opt ) {
135 det_arc_par->fit_window_hsize = atoi(optarg);
136 break ;
138 det_arc_par->search_window_hsize = atoi(optarg);
139 break;
141 det_arc_par->running_median_hsize = atoi(optarg);
142 break;
143 case DEG_LAMBDA_OPT:
144 det_arc_par->wavesol_deg_lambda = atoi(optarg);
145 break;
146 case DEG_ORDER_OPT:
147 det_arc_par->wavesol_deg_order = atoi(optarg);
148 break;
149 case DEG_SLIT_OPT:
150 det_arc_par->wavesol_deg_slit = atoi(optarg);
151 break;
152 case POLY_DEGREE_OPT:
153 det_arc_par->ordertab_deg_y = atoi(optarg);
154 break;
155 case MIN_SN_OPT:
156 det_arc_par->min_sn = atof(optarg);
157 break;
158 case CLIP_SIGMA_OPT:
159 clip_par->sigma = atof(optarg);
160 break;
161 case CLIP_NITER_OPT:
162 clip_par->niter = atoi(optarg);
163 break;
164 case CLIP_FRAC_OPT:
165 clip_par->frac = atof(optarg);
166 break;
167 default:
168 printf(SYNTAX);
169 exit(0);
170 }
171 }
172 return;
173}
174/*---------------------------------------------------------------------------
175 Functions prototypes
176 ---------------------------------------------------------------------------*/
177
178/*--------------------------------------------------------------------------*/
185/*--------------------------------------------------------------------------*/
186
187int main(int argc, char** argv)
188{
189 /* Initialize libraries */
190 cpl_frame* predict = NULL;
191 cpl_frame* theoretical_map = NULL;
192 cpl_frame* arclines = NULL;
193 cpl_frame* clean_arclines = NULL;
194 //cpl_frame * guess_order_table = NULL ;
195 cpl_frame* resid_tab_orders=NULL;
196 cpl_frame* guess_tab = NULL;
197 cpl_frame* wave_sol = NULL;
198 cpl_frame* twodmap_resid = NULL;
199 cpl_frame* spectral_format = NULL;
203 char *fmtchk_name = NULL;
204 char *linelist_name = NULL;
205 char *themap_name = NULL;
206 char *guess_tab_name = NULL;
207 char *spectral_format_name = NULL;
208 int nb_frames = 0;
209 int decode_bp=QFLAG_OUTSIDE_DATA_RANGE;
210
212
213 cpl_msg_set_level(CPL_MSG_DEBUG);
215
216 /* Analyse parameters */
217 HandleOptions( argc, argv, &da, &dac);
218
219 nb_frames = argc - optind;
220 if ( nb_frames > 2 ) {
221 fmtchk_name = argv[optind];
222 linelist_name = argv[optind+1];
223 themap_name = argv[optind+2];
224 if ( nb_frames > 3){
225 guess_tab_name = argv[optind+3];
226 TESTS_XSH_FRAME_CREATE( guess_tab, "GUESS_WAVE_TAB_UVB",
227 guess_tab_name);
228 if ( nb_frames > 4){
229 spectral_format_name = argv[optind+4];
230 TESTS_XSH_FRAME_CREATE( spectral_format, "SPECTRAL_FORMAT_TAB_UVB",
231 spectral_format_name);
232
233 }
234 }
235 }
236 else{
237 xsh_msg( "********** NOT ENOUGH INPUT FRAMES **********" ) ;
238 printf(SYNTAX);
239 exit(0);
240 }
242 XSH_ARM_UVB, XSH_LAMP_QTH, "xsh_predict");
243
244 TESTS_XSH_FRAME_CREATE( predict, "FMTCHK_UVB", fmtchk_name);
245 TESTS_XSH_FRAME_CREATE( theoretical_map, "THEORETICAL_MAP_SLIT_UVB",
246 themap_name);
247 TESTS_XSH_FRAME_CREATE( arclines, "ARC_LINE_LIST_UVB",
248 linelist_name);
249 /* Function Parameters Output */
250 xsh_msg("--------------------------------------------------------");
251 xsh_msg("PARAMETERS");
252 xsh_msg("--------------------------------------------------------");
253 xsh_msg(" fit window half size : %d", da.fit_window_hsize);
254 xsh_msg(" search window half size : %d", da.search_window_hsize);
255 xsh_msg(" running median half size : %d", da.running_median_hsize);
256 xsh_msg(" wave solution order degree : %d", da.wavesol_deg_order);
257 xsh_msg(" wave solution lambda degree : %d", da.wavesol_deg_lambda);
258 xsh_msg(" wave solution slit degree : %d", da.wavesol_deg_slit);
259 xsh_msg(" order tab y degree : %d", da.ordertab_deg_y);
260 xsh_msg(" min S/N : %f", da.min_sn);
261 xsh_msg(" clip sigma : %f", dac.sigma);
262 xsh_msg(" clip niter : %d", dac.niter);
263 xsh_msg(" clip frac : %f", dac.frac);
264 xsh_msg("--------------------------------------------------------");
265 xsh_msg("FRAMES");
266 xsh_msg("--------------------------------------------------------");
267 xsh_msg(" FMTCHK frame : %s", fmtchk_name);
268 xsh_msg(" LINE_LIST frame : %s", linelist_name);
269 xsh_msg(" THEMAP frame : %s", themap_name);
270 if (guess_tab_name != NULL){
271 xsh_msg(" GUESS_TAB frame : %s", guess_tab_name);
272 }
273 if (spectral_format_name != NULL){
274 xsh_msg(" SPECTRAL FORMAT TAB frame : %s", spectral_format_name);
275 }
276 xsh_msg("--------------------------------------------------------");
277 xsh_msg("Function call");
278 xsh_msg("--------------------------------------------------------");
279 /* Start the function */
280 check( xsh_detect_arclines ( predict,
281 theoretical_map,
282 arclines,
283 guess_tab,
284 NULL, /* order tab recover frame */
285 NULL, /* model cfg frame */
286 spectral_format,
287 &resid_tab_orders, &clean_arclines,
288 &wave_sol, &twodmap_resid,
290 &da, &dac,
292 "xsh_predict",decode_bp,0));
293//added "xsh_predict" to fix API change
294
295 xsh_msg("--------------------------------------------------------");
296 xsh_msg("CLEANUP");
297 xsh_msg("--------------------------------------------------------");
298 cleanup:
299 cpl_frame_delete(predict);
300 cpl_frame_delete(theoretical_map);
301 cpl_frame_delete(arclines);
302 if (cpl_error_get_code() != CPL_ERROR_NONE) {
303 xsh_error_dump(CPL_MSG_ERROR);
304 return 1;
305 }
306 else {
307 return 0;
308 }
309}
310
int main()
Unit test of xsh_bspline_interpol.
static void HandleOptions(int argc, char **argv, xsh_detect_arclines_param *det_arc_par, xsh_clipping_param *clip_par)
#define MODULE_ID
static struct option long_options[]
#define SYNTAX
@ INITIAL_CENTER_OPT
@ HALF_WINDOW_SIZE_FOR_MAX_OPT
@ HALF_WINDOW_SIZE_RUNNING_MEDIAN_OPT
@ HALF_WINDOW_SIZE_OPT
static xsh_instrument * instrument
void xsh_detect_arclines(cpl_frame *frame, cpl_frame *theo_tab_frame, cpl_frame *arc_lines_tab_frame, cpl_frame *wave_tab_guess_frame, cpl_frame *order_tab_recov_frame, cpl_frame *config_model_frame, cpl_frame *spectralformat_frame, cpl_frame **resid_tab_orders_frame, cpl_frame **arc_lines_clean_tab_frame, cpl_frame **wave_tab_frame, cpl_frame **resid_tab_frame, xsh_sol_wavelength solwave_type, xsh_detect_arclines_param *da, xsh_clipping_param *dac, xsh_instrument *instr, const char *rec_id, const int clean_tmp, const int resid_tab_name_sw)
detect the position on the detector of emission lines listed in a catalogue, from expected position v...
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
int xsh_debug_level_set(int level)
set debug level
Definition: xsh_utils.c:3125
#define TESTS_XSH_INSTRUMENT_CREATE(instr, mode, arm, lamp, recipe)
Definition: tests.h:115
#define TESTS_XSH_FRAME_CREATE(frame, tag, name)
Definition: tests.h:123
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
#define QFLAG_OUTSIDE_DATA_RANGE
@ XSH_LAMP_QTH
@ XSH_ARM_UVB
@ XSH_MODE_IFU
@ XSH_SOLUTION_RELATIVE
Definition: xsh_drl.h:233
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138