X-shooter Pipeline Reference Manual 3.8.15
test-xsh_data_wavemap.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.4 $
24 */
25
26#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
30/*-------------------------------------------------------------------------*/
35/*-------------------------------------------------------------------------*/
38/*--------------------------------------------------------------------------
39 Includes
40 --------------------------------------------------------------------------*/
41
42#include <tests.h>
43
44#include <xsh_data_pre.h>
45#include <xsh_data_order.h>
46#include <xsh_data_wavesol.h>
48#include <xsh_error.h>
49#include <xsh_msg.h>
50#include <xsh_data_instrument.h>
51#include <xsh_drl.h>
52#include <xsh_pfits.h>
53
54
55#include <cpl.h>
56#include <math.h>
57
58/*--------------------------------------------------------------------------
59 Defines
60 --------------------------------------------------------------------------*/
61
62#define MODULE_ID "XSH_DATA_WAVEMAP"
63
64#define SYNTAX "Test the wavemap (work only for vis for now)\n"\
65 "use : ./test_xsh_data_wavemap [OPTIONS] ORDER_TAB WAVESOL WAVEMAP"\
66 " SPECTRALFORMAT\n"\
67 "ORDER_TAB => the order table\n"\
68 "WAVESOL => the wavesolution table\n"\
69 "WAVEMAP => the wavemap frame\n"\
70 "SPECTRALFORMAT => the spectral format table\n"
71
72/*--------------------------------------------------------------------------
73 Implementation
74 --------------------------------------------------------------------------*/
75
83int main( int argc, char **argv)
84{
85 /* Declarations */
86 int ret = 0 ;
88
89 char* order_tab_name = NULL;
90 char* wavesol_name = NULL;
91 char* wavemap_name = NULL;
92 char* spectralformat_name = NULL;
93
94 cpl_frame *order_tab_frame = NULL;
95 cpl_frame *wavesol_frame = NULL;
96 cpl_frame *wavemap_frame = NULL;
97 cpl_frame *spectralformat_frame = NULL;
98
99
100 /* Initialize libraries */
102 cpl_msg_set_level( CPL_MSG_DEBUG);
104
105 /* Analyse parameters */
106 if ( (argc ) >= 4 ) {
107 order_tab_name = argv[1];
108 wavesol_name = argv[2];
109 wavemap_name = argv[3];
110 spectralformat_name = argv[4];
111 }
112 else{
113 printf(SYNTAX);
114 exit(0);
115 }
116 xsh_msg(" order tab frame name %s",order_tab_name);
117 xsh_msg(" wave sol frame name %s", wavesol_name);
118 xsh_msg(" wave map frame name %s",wavemap_name);
119 xsh_msg(" spectral format frame name %s",spectralformat_name);
120
121 TESTS_XSH_FRAME_CREATE( order_tab_frame, "ORDER_TAB_EDGES_arm",
122 order_tab_name);
123 TESTS_XSH_FRAME_CREATE( wavesol_frame, "WAVE_TAB_2D_arm", wavesol_name);
124 TESTS_XSH_FRAME_CREATE( wavemap_frame, "WAVE_MAP_arm", wavemap_name);
125 TESTS_XSH_FRAME_CREATE( spectralformat_frame, "SPECTRAL_FORMAT_TAB_arm",
126 spectralformat_name);
127
128 /* Create instrument structure and fill */
130
133
136
137
138 {
139 cpl_image* wavemap = NULL;
140 float * wavemap_data = NULL;
141 int nx, ny;
142 xsh_order_list *order_list= NULL;
143 xsh_wavesol *wavesol = NULL;
144 int iorder=0, nblines=0;
145 cpl_table *table = NULL;
146
147 check( wavemap = cpl_image_load( cpl_frame_get_filename( wavemap_frame),
148 CPL_TYPE_FLOAT, 0, 0));
149 check (nx = cpl_image_get_size_x( wavemap));
150 check (ny = cpl_image_get_size_y( wavemap));
151 check( wavemap_data = cpl_image_get_data_float( wavemap));
152 check( order_list = xsh_order_list_load( order_tab_frame, instrument));
153 check( wavesol = xsh_wavesol_load( wavesol_frame, instrument ));
154 check( table = cpl_table_new( 6));
155 XSH_TABLE_NEW_COL(table, "absorder", "",CPL_TYPE_INT);
156 XSH_TABLE_NEW_COL(table, "wavelength", "",CPL_TYPE_DOUBLE);
157 XSH_TABLE_NEW_COL(table, "wavemap_x", "",CPL_TYPE_DOUBLE);
158 XSH_TABLE_NEW_COL(table, "wavemap_y", "",CPL_TYPE_DOUBLE);
159 XSH_TABLE_NEW_COL(table, "wavesol_x", "",CPL_TYPE_DOUBLE);
160 XSH_TABLE_NEW_COL(table, "wavesol_y", "",CPL_TYPE_DOUBLE);
161 check(cpl_table_set_size( table, order_list->size*ny));
162 /* Loop on order */
163 for( iorder= 0; iorder < order_list->size; iorder++) {
164 int abs_order, start_y, end_y, y;
165
166 abs_order = order_list->list[iorder].absorder;
167 check( start_y = xsh_order_list_get_starty( order_list, iorder));
168 check( end_y = xsh_order_list_get_endy( order_list, iorder));
169
170 for(y=start_y; y < end_y; y++){
171 double x, x_center, y_center;
172 int int_x;
173 double lambda_wavemap;
174
175 check( x= cpl_polynomial_eval_1d( order_list->list[iorder].cenpoly,
176 y, NULL));
177 int_x = floor(x);
178 lambda_wavemap = wavemap_data[int_x+y*nx];
179 check( x_center = xsh_wavesol_eval_polx( wavesol, lambda_wavemap, abs_order,
180 0.0));
181 check( y_center = xsh_wavesol_eval_poly( wavesol, lambda_wavemap, abs_order,
182 0.0));
183 check(cpl_table_set_int(table, "absorder", nblines, abs_order));
184 check(cpl_table_set_double(table, "wavelength", nblines, lambda_wavemap));
185 check(cpl_table_set_double(table, "wavemap_x", nblines, int_x));
186 check(cpl_table_set_double(table, "wavemap_y", nblines, y));
187 check(cpl_table_set_double(table, "wavesol_x", nblines, x_center));
188 check(cpl_table_set_double(table, "wavesol_y", nblines, y_center));
189 nblines++;
190 }
191 }
192 check( cpl_table_save(table, NULL, NULL, "result.fits", CPL_IO_DEFAULT));
193 }
194 cleanup:
195 if (cpl_error_get_code() != CPL_ERROR_NONE) {
196 xsh_error_dump(CPL_MSG_ERROR);
197 return 1;
198 }
199 else return ret ;
200}
201
int main()
Unit test of xsh_bspline_interpol.
#define MODULE_ID
#define SYNTAX
static xsh_instrument * instrument
xsh_order_list * xsh_order_list_load(cpl_frame *frame, xsh_instrument *instr)
load an order list from a frame
int xsh_order_list_get_starty(xsh_order_list *list, int i)
get position on Y axis of first pixel detected on order
int xsh_order_list_get_endy(xsh_order_list *list, int i)
get position on Y axis of last pixel detected on order
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
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_set_mode(xsh_instrument *i, XSH_MODE mode)
Set a mode on instrument structure.
void xsh_instrument_set_arm(xsh_instrument *i, XSH_ARM arm)
Set an arm on instrument structure.
void xsh_instrument_set_lamp(xsh_instrument *i, XSH_LAMP lamp)
Set a lamp on instrument structure.
xsh_instrument * xsh_instrument_new(void)
create new instrument structure
int * y
int * x
#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
xsh_order * list
cpl_polynomial * cenpoly
#define TESTS_XSH_FRAME_CREATE(frame, tag, name)
Definition: tests.h:123
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
@ XSH_LAMP_QTH_D2
@ XSH_ARM_VIS
@ XSH_MODE_SLIT
int nx
int ny
#define XSH_TABLE_NEW_COL(TABLE, NAME, UNIT, TYPE)
Definition: xsh_utils.h:113
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138