X-shooter Pipeline Reference Manual 3.8.15
test-xsh_data_wave_tab_2d.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-12-07 16:51:34 $
23 * $Revision: 1.10 $
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
44#include <xsh_data_order.h>
45#include <xsh_error.h>
46#include <xsh_msg.h>
47#include <xsh_data_instrument.h>
48#include <xsh_dfs.h>
49#include <xsh_pfits.h>
50#include <tests.h>
52#include <xsh_data_wavesol.h>
53#include <xsh_data_arclist.h>
54#include <xsh_utils_table.h>
55#include <cpl.h>
56#include <math.h>
57#include <getopt.h>
58
59/*---------------------------------------------------------------------------
60 Defines
61 ---------------------------------------------------------------------------*/
62#define MODULE_ID "XSH_DATA_WAVE_TAB_2D"
63
64enum {
66} ;
67
68static float lambda_step = 0.5;
69static float slit_step = 1.458;
70int binx =1;
71int biny =1;
72
73static struct option LongOptions[] = {
74 {"lambda-step", required_argument, 0, LAMBDA_STEP_OPT},
75 {"slit-step", required_argument, 0, SLIT_STEP_OPT},
76 {"binx", required_argument, 0, BINX_OPT},
77 {"biny", required_argument, 0, BINY_OPT},
78 {"debug", required_argument, 0, DEBUG_OPT},
79 {"help", 0, 0, HELP_OPT},
80 {NULL, 0, 0, 0}
81} ;
82
83
84static void Help( void )
85{
86 puts ("Unitary test of wave tab 2d");
87 puts( "Usage : ./the_xsh_data_wave_tab_2d [options] <SOF>");
88
89 puts( "Options" ) ;
90 puts( " --binx=<n> : Binning in X (default 1)" );
91 puts( " --biny=<n> : Binning in Y (default 1)" );
92 puts( " --lambda-step=<n> : Step in lambda. Default 0.2" );
93 puts( " --slit-step=<n> : Step in slit. Default 0.2" );
94 puts( " --debug=<n> : Level of debug LOW | MEDIUM | HIGH [MEDIUM]" );
95 puts( " --help : What you see" ) ;
96
97 puts( "The input files argument MUST be in this order:" ) ;
98 puts( " 1. SOF [WAVE_TAB_2D, SPECTRAL_FORMAT, ARC_LIST]");
99 TEST_END();
100 exit(0);
101}
102
103/*--------------------------------------------------------------------------
104 Implementation
105 --------------------------------------------------------------------------*/
106
107static void HandleOptions( int argc, char ** argv)
108{
109 int opt ;
110 int option_index = 0;
111
112 while( (opt = getopt_long( argc, argv, "debug:help",
113 LongOptions, &option_index )) != EOF )
114 switch( opt ) {
115 case LAMBDA_STEP_OPT:
116 lambda_step = atof(optarg);
117 break ;
118 case SLIT_STEP_OPT:
119 slit_step = atof(optarg);
120 break ;
121 case BINX_OPT:
122 binx = atoi(optarg);
123 case BINY_OPT:
124 biny = atoi(optarg);
125 break ;
126 case DEBUG_OPT:
127 if ( strcmp( optarg, "LOW")==0){
129 }
130 else if ( strcmp( optarg, "HIGH")==0){
132 }
133 break;
134 case HELP_OPT:
135 Help();
136 break;
137 default:
138 break;
139 }
140}
141
142/*--------------------------------------------------------------------------*/
150/*--------------------------------------------------------------------------*/
151int main(int argc, char** argv)
152{
153 int ret = 0;
154 int i;
155 float j,k;
156 xsh_instrument * instrument = NULL ;
157 cpl_frameset* set = NULL;
158 char *sof_name = NULL;
159 cpl_frame *wave_tab_2d_frame = NULL;
160 cpl_frame *spectralformat_frame = NULL;
161 cpl_frame *arclist_frame = NULL;
162 xsh_spectralformat_list *spec_list = NULL;
163 xsh_wavesol *wave_tab_2d = NULL;
164 xsh_arclist* arclist = NULL;
165 FILE* wave_tab_2d_file = NULL;
166 FILE* wave_tab_2d_dat_file = NULL;
167
168 /* Initialize libraries */
170 cpl_msg_set_level(CPL_MSG_DEBUG);
172
173 HandleOptions( argc, argv);
174
175 /* Analyse parameters */
176 if ( (argc-optind) >= 1) {
177 sof_name = argv[optind];
178 /* Create frameset from sof */
179 check( set = sof_to_frameset( sof_name));
180
181 /* Validate frame set */
183
184 check( wave_tab_2d_frame = xsh_find_wave_tab_2d( set, instrument));
185 check( spectralformat_frame = xsh_find_spectral_format( set, instrument));
186 arclist_frame = xsh_find_arc_line_list( set, instrument);
187 }
188 else{
189 Help();
190 }
191 xsh_msg("Wave tab 2d : %s", cpl_frame_get_filename(wave_tab_2d_frame));
192 xsh_msg("Spectral format : %s", cpl_frame_get_filename(spectralformat_frame));
193 if ( arclist_frame != NULL){
194 xsh_msg("Arclines : %s", cpl_frame_get_filename( arclist_frame));
195 }
196 xsh_msg(" Options : lambda-step %f slit-step %f", lambda_step, slit_step);
197
198 check( spec_list = xsh_spectralformat_list_load( spectralformat_frame,
199 instrument));
200 check( wave_tab_2d = xsh_wavesol_load( wave_tab_2d_frame, instrument));
201 xsh_wavesol_set_bin_x( wave_tab_2d, binx);
202 xsh_wavesol_set_bin_y( wave_tab_2d, biny);
203 xsh_msg("bin %dx%d",binx, biny);
204 xsh_msg("Wavesol lambda (%f,%f)", wave_tab_2d->min_lambda,
205 wave_tab_2d->max_lambda);
206 xsh_msg("Wavesol order (%f,%f)", wave_tab_2d->min_order,
207 wave_tab_2d->max_order);
208 xsh_msg("Wavesol slit (%f,%f)", wave_tab_2d->min_slit,
209 wave_tab_2d->max_slit);
210
211 wave_tab_2d_file = fopen( "WAVE_TAB_2D.reg", "w");
212 wave_tab_2d_dat_file = fopen( "WAVE_TAB_2D.dat", "w");
213 fprintf( wave_tab_2d_file, "# Region file format: DS9 version 4.0\n"\
214 "global color=red font=\"helvetica 10 normal\""\
215 "select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 "\
216 "source\nimage\n");
217 fprintf( wave_tab_2d_dat_file, "# x y lambda slit\n");
218
219 if ( arclist_frame == NULL){
220 for( i=0; i< spec_list->size; i++){
221 double absorder;
222 float lambda_min, lambda_max;
223 float lambda_min_full, lambda_max_full;
224
225 absorder= (double)spec_list->list[i].absorder;
226 lambda_min = spec_list->list[i].lambda_min;
227 lambda_max = spec_list->list[i].lambda_max;
228 lambda_min_full = spec_list->list[i].lambda_min_full;
229 lambda_max_full = spec_list->list[i].lambda_max_full;
230 xsh_msg("order %f lambda %f->%f-%f<-%f",absorder, lambda_min_full,
231 lambda_min, lambda_max, lambda_max_full);
232
233 for(j=lambda_min_full; j <= lambda_max_full; j+=lambda_step){
234 double x, y;
235 const char* full_lambda_color = "yellow";
236 const char* lambda_color = "red";
237 const char* color = NULL;
238
239 if ( (j < lambda_min)|| (j > lambda_max) ){
240 color = full_lambda_color;
241 }
242 else{
243 color = lambda_color;
244 }
245 check( x = xsh_wavesol_eval_polx( wave_tab_2d, j, absorder, 0.0));
246 check( y = xsh_wavesol_eval_poly( wave_tab_2d, j, absorder, 0.0));
247
248
249 fprintf( wave_tab_2d_file, "point(%f,%f) #point=cross color=%s font="\
250 "\"helvetica 10 normal\" text={ %.3f}\n", x, y, color, j);
251 fprintf( wave_tab_2d_dat_file, "%f %f %f %f\n", x, y, j, 0.0);
252
253 for( k=wave_tab_2d->min_slit; k <= wave_tab_2d->max_slit; k+=slit_step){
254 check( x = xsh_wavesol_eval_polx( wave_tab_2d, j, absorder, k));
255 check( y = xsh_wavesol_eval_poly( wave_tab_2d, j, absorder, k));
256 fprintf( wave_tab_2d_file, "point(%f,%f) #point=cross color=green font="\
257 "\"helvetica 10 normal\" text={ %.3f}\n", x, y, k);
258 fprintf( wave_tab_2d_dat_file, "%f %f %f %f\n", x, y, j, k);
259 }
260 }
261 }
262 }
263 else{
264 int size;
265
266 arclist = xsh_arclist_load( arclist_frame);
267 size = arclist->size;
268
269 for( i=0; i< size; i++){
270 float lambda = 0.0;
271 cpl_vector *orders = NULL;
272 int order_size;
273
274 lambda = xsh_arclist_get_wavelength( arclist, i);
275 orders = xsh_spectralformat_list_get_orders( spec_list, lambda);
276 order_size = cpl_vector_get_size( orders);
277
278 for( j=0; j < order_size; j++){
279 double absorder;
280 double x, y;
281
282 absorder = cpl_vector_get( orders, j);
283
284 check( x = xsh_wavesol_eval_polx( wave_tab_2d, lambda, absorder, 0.0));
285 check( y = xsh_wavesol_eval_poly( wave_tab_2d, lambda, absorder, 0.0));
286
287 fprintf( wave_tab_2d_file, "point(%f,%f) #point=cross color=red font="\
288 "\"helvetica 10 normal\" text={ %.3f}\n", x, y, lambda);
289 fprintf( wave_tab_2d_dat_file, "%f %f %f %f\n", x, y, lambda, 0.0);
290
291 for( k=slit_step; k < wave_tab_2d->max_slit; k+=slit_step){
292 check( x = xsh_wavesol_eval_polx( wave_tab_2d, lambda, absorder, k));
293 check( y = xsh_wavesol_eval_poly( wave_tab_2d, lambda, absorder, k));
294 fprintf( wave_tab_2d_file, "point(%f,%f) #point=cross color=green font="\
295 "\"helvetica 10 normal\" text={ %.3f}\n", x, y, k);
296 fprintf( wave_tab_2d_dat_file, "%f %f %f %f\n", x, y, lambda, k);
297 check( x = xsh_wavesol_eval_polx( wave_tab_2d, lambda, absorder, -k));
298 check( y = xsh_wavesol_eval_poly( wave_tab_2d, lambda, absorder, -k));
299 fprintf( wave_tab_2d_file, "point(%f,%f) #point=cross color=green font="\
300 "\"helvetica 10 normal\" text={ %.3f}\n", x, y, -k);
301 fprintf( wave_tab_2d_dat_file, "%f %f %f %f\n", x, y, lambda, -k);
302 }
303 }
304 xsh_free_vector( &orders);
305 }
306 }
307
308
309 cleanup:
311 xsh_free_frameset( &set);
312
313 xsh_arclist_free( &arclist);
314 xsh_spectralformat_list_free( &spec_list);
315 xsh_wavesol_free( &wave_tab_2d);
316
317 TEST_END();
318 if (cpl_error_get_code() != CPL_ERROR_NONE) {
319 xsh_error_dump(CPL_MSG_ERROR);
320 ret = 1;
321 }
322 if ( NULL != wave_tab_2d_dat_file) {
323 fclose( wave_tab_2d_dat_file);
324 }
325 if ( NULL != wave_tab_2d_file) {
326 fclose( wave_tab_2d_file);
327 }
328
329 return ret ;
330}
331
int main()
Unit test of xsh_bspline_interpol.
static xsh_instrument * instrument
static float slit_step
static void Help(void)
#define MODULE_ID
static float lambda_step
static struct option LongOptions[]
cpl_frameset * sof_to_frameset(const char *sof_name)
Definition: tests.c:576
float xsh_arclist_get_wavelength(xsh_arclist *list, int idx)
get wavelength of a line in the arcline list
void xsh_arclist_free(xsh_arclist **list)
free memory associated to a arclist
xsh_arclist * xsh_arclist_load(cpl_frame *frame)
load an arcline list frame in arclist structure
cpl_vector * xsh_spectralformat_list_get_orders(xsh_spectralformat_list *list, float lambda)
Returns list of absolute orders containing lambda.
xsh_spectralformat_list * xsh_spectralformat_list_load(cpl_frame *frame, xsh_instrument *instr)
Load a spectralformat list from a frame.
void xsh_spectralformat_list_free(xsh_spectralformat_list **list)
Free memory associated to an spactralformat_list.
void xsh_wavesol_set_bin_y(xsh_wavesol *wsol, int bin)
Set the bin of wave table in y.
void xsh_wavesol_set_bin_x(xsh_wavesol *wsol, int bin)
Set the bin of wave table in x.
xsh_wavesol * xsh_wavesol_load(cpl_frame *frame, xsh_instrument *instrument)
load a wavelength solution
double xsh_wavesol_eval_poly(xsh_wavesol *sol, double lambda, double order, double slit)
eval the polynomial solution in Y
void xsh_wavesol_free(xsh_wavesol **w)
free wavelength solution structure
double xsh_wavesol_eval_polx(xsh_wavesol *sol, double lambda, double order, double slit)
eval the polynomial solution in X
#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
int size
int * y
int * x
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
void xsh_free_vector(cpl_vector **v)
Deallocate a vector and set the pointer to NULL.
Definition: xsh_utils.c:2284
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
static void HandleOptions(int argc, char **argv)
#define TEST_END()
Definition: tests.h:111
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
cpl_frame * xsh_find_spectral_format(cpl_frameset *frames, xsh_instrument *instr)
Find spectral format frame.
Definition: xsh_dfs.c:4318
cpl_frame * xsh_find_wave_tab_2d(cpl_frameset *frames, xsh_instrument *instr)
Find a wave tab 2D.
Definition: xsh_dfs.c:3650
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
cpl_frame * xsh_find_arc_line_list(cpl_frameset *frames, xsh_instrument *instr)
Find an arc line list frame.
Definition: xsh_dfs.c:3908
@ 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