X-shooter Pipeline Reference Manual 3.8.15
test-xsh_detect_order.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 21:09:42 $
23 * $Revision: 1.7 $
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_data_the_map.h>
52
53#include <xsh_drl.h>
54#include <xsh_pfits.h>
55
56#include <xsh_badpixelmap.h>
57
58#include <cpl.h>
59#include <math.h>
60
61#include <getopt.h>
62
63/*--------------------------------------------------------------------------
64 Defines
65 --------------------------------------------------------------------------*/
66
67#define MODULE_ID "XSH_DETECT_ORDER"
68
69/*--------------------------------------------------------------------------
70 Implementation
71 --------------------------------------------------------------------------*/
72enum {
76} ;
77
78static const char * Options = "";
79
80static struct option long_options[] = {
81 {"search-window-hsize", required_argument, 0, SEARCH_WINDOW_HSIZE_OPT},
82 {"flux-thresh", required_argument, 0, FLUX_THRESH_OPT},
83 {"min-sn", required_argument, 0, MIN_SN_OPT},
84 {"min-order-size-x", required_argument, 0, MIN_ORDER_SIZE_X_OPT},
85 {"chunk-hsize", required_argument, 0, CHUNK_HSIZE_OPT},
86 {"slitlet-low-factor", required_argument, 0, SLITLET_LOW_FACTOR_OPT},
87 {"slitlet-up-factor",required_argument, 0, SLITLET_UP_FACTOR_OPT},
88 {"fixed-slice",required_argument, 0, FIXED_SLICE_OPT},
89 {"method",required_argument, 0, METHOD_OPT},
90 {"help", 0, 0, HELP_OPT},
91 {0, 0, 0, 0}
92};
93
94static void Help( void )
95{
96 puts( "Unitary test of xsh_detect_order" ) ;
97 puts( "Usage: test_xsh_detect_order [options] <input_files>" ) ;
98 puts( "Options" ) ;
99 puts( " --search-window-hsize=<n> : Half size of the search box" ) ;
100 puts( " --flux-thresh=<nn> : Threshold in flux" ) ;
101 puts( " --min-sn=<n> : Minimum s/n ratio" ) ;
102 puts( " --min-order-size-x=<n> : Minimum pixel size of an order in cross dispersion" ) ;
103 puts( " --chunk-hsize=<n> : Pixel half size of chunk of an order in dispersion" );
104 puts( " --slitlet-low-factor=<n> : ????" );
105 puts( " --slitlet-up-factor=<n> : ????" );
106 puts( " --fixed-slice=<n> : if TRUE used slitlet ratio" );
107 puts( " --method=<n> : ????" );
108 puts( " --help : What you see" ) ;
109 puts( "\nInput Files" ) ;
110 puts( "The input files argument MUST be in this order:" ) ;
111 puts( " 1. Science frame FLAT" ) ;
112 puts( " 2. SOF (ORDER_TAB_CEN]\n" ) ;
113 TEST_END();
114}
115
116static void HandleOptions( int argc, char **argv,
117 xsh_detect_order_param* detectorder_par)
118{
119 int opt ;
120 int option_index = 0;
121
122 while (( opt = getopt_long (argc, argv, Options,
123 long_options, &option_index)) != EOF )
124 switch ( opt ) {
126 detectorder_par->search_window_hsize = atoi( optarg);
127 break ;
128 case FLUX_THRESH_OPT:
129 detectorder_par->flux_thresh = atof( optarg);
130 break ;
131 case MIN_SN_OPT:
132 detectorder_par->min_sn = atof( optarg);
133 break ;
135 detectorder_par->min_order_size_x = atoi( optarg);
136 break ;
137 case CHUNK_HSIZE_OPT:
138 detectorder_par->chunk_hsize = atoi( optarg);
139 break;
141 detectorder_par->slitlet_low_factor = atof( optarg);
142 break;
144 detectorder_par->slitlet_up_factor = atof( optarg);
145 break ;
146 case FIXED_SLICE_OPT:
147 detectorder_par->fixed_slice = atoi( optarg);
148 break ;
149 case METHOD_OPT:
150 detectorder_par->method = optarg;
151 break;
152 default: Help() ; exit( 0);
153 }
154}
155
164int main( int argc, char **argv)
165{
166 /* Declarations */
167 int ret = 0 ;
168
170
171 const char *sof_name = NULL;
172 cpl_frameset *set = NULL;
173
174 const char * sci_name = NULL ;
175
176 cpl_frame *sci_frame = NULL;
177 cpl_frame *orderlist_frame = NULL;
178 cpl_frame *edges_order_tab_frame = NULL;
179 xsh_detect_order_param detectorder_par;
180 const int decode_bp=2147483647;
181 /* Initialize libraries */
183 cpl_msg_set_level(CPL_MSG_DEBUG);
185
186 /* Set detectorder default params */
187 detectorder_par.search_window_hsize = 50;
188 detectorder_par.flux_thresh = 0.05;
189 detectorder_par.min_sn = 35.;
190 detectorder_par.min_order_size_x = 60;
191 detectorder_par.chunk_hsize = 1;
192 detectorder_par.slitlet_low_factor = 1.0;
193 detectorder_par.slitlet_up_factor = 1.0;
194 detectorder_par.fixed_slice = CPL_TRUE;
195 detectorder_par.method = "fixed";
196
197 HandleOptions( argc, argv, &detectorder_par);
198
199 if ( (argc - optind) >=2 ) {
200 sci_name = argv[optind];
201 sof_name = argv[optind+1];
202 }
203 else {
204 Help();
205 exit(0);
206 }
207 /* Create frameset from sof */
208 check( set = sof_to_frameset( sof_name));
209 /* Validate frame set */
212 check( orderlist_frame = xsh_find_order_tab_centr( set, instrument));
213
214 TESTS_XSH_FRAME_CREATE( sci_frame, "FLAT_arm", sci_name);
215
216 xsh_msg("SCI : %s",
217 cpl_frame_get_filename( sci_frame));
218 xsh_msg("ORDERLIST : %s",
219 cpl_frame_get_filename( orderlist_frame));
220
221 xsh_msg(" Parameters ");
222 xsh_msg(" search window half size %d", detectorder_par.search_window_hsize);
223 xsh_msg(" flux threshold %f", detectorder_par.flux_thresh);
224 xsh_msg(" min S/N %f", detectorder_par.min_sn);
225 xsh_msg(" min order size cross dispersion %d", detectorder_par.min_order_size_x);
226 xsh_msg(" chunk hsize %d", detectorder_par.chunk_hsize);
227 xsh_msg(" slitlet low factor %f", detectorder_par.slitlet_low_factor);
228 xsh_msg(" slitlet up factor %f", detectorder_par.slitlet_up_factor);
229 xsh_msg(" fixed slice %d", detectorder_par.fixed_slice);
230 xsh_msg(" detect method %s",detectorder_par.method);
231
232 /* Now detect_order the frame */
233 check( edges_order_tab_frame = xsh_detect_order_edge( sci_frame,
234 orderlist_frame, &detectorder_par, instrument));
235
236 cleanup:
237 if (cpl_error_get_code() != CPL_ERROR_NONE) {
238 xsh_error_dump(CPL_MSG_ERROR);
239 ret = 1;
240 }
241 xsh_free_frame( &sci_frame);
242 xsh_free_frame( &edges_order_tab_frame);
243 xsh_free_frameset( &set);
245 TEST_END();
246 return ret;
247}
cpl_frame * xsh_detect_order_edge(cpl_frame *frame, cpl_frame *cen_order_tab_frame, xsh_detect_order_param *detectorder_par, xsh_instrument *instrument)
Detect order edges and compute polynomial description of ordermin and order max.
int main()
Unit test of xsh_bspline_interpol.
static const char * Options
static void HandleOptions(int argc, char **argv, xsh_detect_order_param *detectorder_par)
static void Help(void)
#define MODULE_ID
static struct option long_options[]
@ SLITLET_LOW_FACTOR_OPT
@ METHOD_OPT
@ SLITLET_UP_FACTOR_OPT
@ FIXED_SLICE_OPT
@ CHUNK_HSIZE_OPT
@ SEARCH_WINDOW_HSIZE_OPT
@ MIN_ORDER_SIZE_X_OPT
@ FLUX_THRESH_OPT
@ MIN_SN_OPT
static xsh_instrument * instrument
cpl_frameset * sof_to_frameset(const char *sof_name)
Definition: tests.c:576
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
void xsh_instrument_set_decode_bp(xsh_instrument *i, const int decode_bp)
Set bad pixel code.
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
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
#define TESTS_XSH_FRAME_CREATE(frame, tag, name)
Definition: tests.h:123
#define TEST_END()
Definition: tests.h:111
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
cpl_frame * xsh_find_order_tab_centr(cpl_frameset *frames, xsh_instrument *instr)
Find an order tab CENTR.
Definition: xsh_dfs.c:3570
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_MEDIUM
Definition: xsh_utils.h:138