X-shooter Pipeline Reference Manual 3.8.15
test-xsh_data_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-12-07 16:51:34 $
23 * $Revision: 1.22 $
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>
51#include <xsh_utils_table.h>
52#include <cpl.h>
53#include <math.h>
54#include <getopt.h>
55
56/*---------------------------------------------------------------------------
57 Defines
58 ---------------------------------------------------------------------------*/
59#define MODULE_ID "XSH_DATA_ORDER"
60
61#define SYNTAX "Test the order table\n"\
62 "usage : ./the_xsh_data_order [options] ORDER_TAB \n"\
63 "ORDER_TAB => the order table\n"\
64 "Options:\n"\
65 " --binx=<n> : binning in X (default 1)\n"\
66 " --biny=<n> : binning in Y (default 1)\n"\
67 " --point=<str> : Point Type (cross, x, diamond, ...)\n"\
68 " Default is 'cross'\n"\
69 " --size=<n> : Point size (pixels). Default is default DS9 value\n"\
70 " --step=<nn> : Step in pixels. Default '8'\n"
71
72
73static const char * Options = "?" ;
74
75enum {
77} ;
78
79static struct option LongOptions[] = {
80 {"point", required_argument, 0, POINT_OPT},
81 {"size", required_argument, 0, SIZE_OPT},
82 {"step", required_argument, 0, STEP_OPT},
83 {"c-color", required_argument, 0, C_COLOR_OPT},
84 {"binx", required_argument, 0, BINX_OPT},
85 {"biny", required_argument, 0, BINY_OPT},
86 {NULL, 0, 0, 0}
87} ;
88
89static char PointType[16] ;
90static char PointSize[8] ;
91static int PointStep = 8 ;
92static char CentralColor[32] ;
93int binx =1;
94int biny =1;
95/*--------------------------------------------------------------------------
96 Implementation
97 --------------------------------------------------------------------------*/
98
99static void HandleOptions( int argc, char ** argv )
100{
101 int opt ;
102 int option_index = 0;
103
104 /* Set default values */
105 strcpy( PointType, "cross" ) ;
106 strcpy( PointSize, "" ) ;
107 strcpy( CentralColor, "green" ) ;
108
109 while( (opt = getopt_long( argc, argv, Options,
110 LongOptions, &option_index )) != EOF )
111 switch( opt ) {
112 case POINT_OPT:
113 strcpy( PointType, optarg ) ;
114 break ;
115 case SIZE_OPT:
116 strcpy( PointSize, optarg ) ;
117 break ;
118 case STEP_OPT:
119 sscanf( optarg, "%64d", &PointStep ) ;
120 break ;
121 case C_COLOR_OPT:
122 strcpy( CentralColor, optarg ) ;
123 case BINX_OPT:
124 binx = atoi(optarg);
125 case BINY_OPT:
126 biny = atoi(optarg);
127 break ;
128 default:
129 printf( SYNTAX ) ;
130 TEST_END();
131 exit( 0 ) ;
132 }
133}
134
135/*--------------------------------------------------------------------------*/
143/*--------------------------------------------------------------------------*/
144int main(int argc, char** argv)
145{
146 int ret = 0;
147 xsh_instrument * instrument = NULL ;
148 XSH_INSTRCONFIG* iconfig = NULL;
149
150 char* order_tab_name = NULL;
151 cpl_frame* order_tab_frame = NULL;
152 cpl_table* table = NULL;
153 int nbcol;
154 xsh_order_list* order_tab = NULL;
155 int order_tab_size = 0;
156 int iy, iorder;
157 int ny;
158 FILE* order_tab_file = NULL;
159 cpl_propertylist *header = NULL;
160 const char* pro_catg = NULL;
161
162 /* Initialize libraries */
164 cpl_msg_set_level(CPL_MSG_DEBUG);
166
167 HandleOptions( argc, argv );
168
169 /* Analyse parameters */
170 if ( optind < argc ) {
171 order_tab_name = argv[optind] ;
172 }
173 else{
174 printf(SYNTAX);
175 TEST_END();
176 return 0;
177 }
178
179 /* Create frames */
180 XSH_ASSURE_NOT_NULL( order_tab_name);
181 order_tab_frame = cpl_frame_new();
182 cpl_frame_set_filename( order_tab_frame, order_tab_name) ;
183 cpl_frame_set_level( order_tab_frame, CPL_FRAME_LEVEL_TEMPORARY);
184 cpl_frame_set_group( order_tab_frame, CPL_FRAME_GROUP_RAW );
185
186 XSH_TABLE_LOAD( table, order_tab_name);
187 check( nbcol = cpl_table_get_nrow(table));
190
192
194 iconfig->orders = nbcol;
195
196 ny = iconfig->ny;
197 check( order_tab = xsh_order_list_load( order_tab_frame, instrument));
198 order_tab_size = order_tab->size;
199 xsh_order_list_set_bin_x( order_tab, binx);
200 xsh_order_list_set_bin_y( order_tab, biny);
201 check ( header = cpl_propertylist_load( order_tab_name, 0));
202 check( pro_catg = xsh_pfits_get_pcatg( header));
203
204 xsh_msg( "Order Table of type %s bin %dx%d",pro_catg, binx, biny);
205
206 xsh_msg("Save order tab in ORDER_TAB.reg");
207 order_tab_file = fopen( "ORDER_TAB.reg", "w");
208 fprintf( order_tab_file, "# Region file format: DS9 version 4.0\n"\
209 "global color=red font=\"helvetica 10 normal\""\
210 "select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 "\
211 "source\nimage\n");
212 fprintf( order_tab_file,
213 "# GREEN center_x center_y (pixels)\n"\
214 "# RED low_x low_y (pixels)\n"\
215 "# BLUE up_x up_y (pixels)\n");
216
217 xsh_msg("Using step %d", PointStep);
218 for( iorder=0; iorder< order_tab_size; iorder++){
219 int starty, endy, absorder;
220
221 check( starty = xsh_order_list_get_starty( order_tab, iorder));
222 check( endy = xsh_order_list_get_endy( order_tab, iorder));
223
224 absorder = order_tab->list[iorder].absorder;
225 xsh_msg(" Dump order %d (%d => %d)", absorder, starty, endy);
226 if (starty == 0 && endy == 0){
227 xsh_msg("Warning starty and endy equal zero, put endy to %d",ny);
228 starty =1;
229 endy = ny;
230 }
231 for( iy=starty; iy<=endy; iy= iy+PointStep){
232 float dx;
233
234 check ( dx = xsh_order_list_eval( order_tab, order_tab->list[iorder].cenpoly,
235 iy));
236
237 if (iy==starty){
238 fprintf( order_tab_file, "point(%f,%d) #point=%s %s color=%s font="\
239 "\"helvetica 10 normal\" text={absorder %d}\n", dx, iy, PointType,
240 PointSize, CentralColor, absorder);
241 } else if (iy==endy){
242 fprintf( order_tab_file, "point(%f,%d) #point=%s %s color=%s font="\
243 "\"helvetica 10 normal\" text={absorder %d}\n", dx, iy, PointType,
244 PointSize, CentralColor, absorder);
245 }
246 else{
247 fprintf( order_tab_file, "point(%f,%d) #point=%s %s color=%s font="\
248 "\"helvetica 10 normal\"\n", dx, iy, PointType, PointSize,
250 }
252 check ( dx = xsh_order_list_eval( order_tab, order_tab->list[iorder].edglopoly,
253 iy));
254
255 fprintf( order_tab_file, "point(%f,%d) #point=cross color=red font="\
256 "\"helvetica 10 normal\"\n", dx, iy);
257 check ( dx = xsh_order_list_eval( order_tab, order_tab->list[iorder].edguppoly,
258 iy));
259 fprintf( order_tab_file, "point(%f,%d) #point=cross color=blue font="\
260 "\"helvetica 10 normal\"\n", dx, iy);
261 /* Check if IFU */
262 if ( order_tab->list[iorder].slicuppoly != NULL ) {
263 check ( dx = xsh_order_list_eval( order_tab, order_tab->list[iorder].slicuppoly,
264 iy));
265 fprintf( order_tab_file,
266 "point(%f,%d) #point=diamond color=blue font=" \
267 "\"helvetica 10 normal\"\n", dx, iy);
268 }
269 if ( order_tab->list[iorder].sliclopoly != NULL ) {
270 check ( dx = xsh_order_list_eval( order_tab, order_tab->list[iorder].sliclopoly,
271 iy));
272 fprintf( order_tab_file,
273 "point(%f,%d) #point=diamond color=red font=" \
274 "\"helvetica 10 normal\"\n", dx, iy);
275 }
276 }
277 /* force to do last point */
278 if ( (iy+PointStep > endy) && (iy != endy)){
279 iy=endy-PointStep;
280 }
281 }
282 }
283
284
285 cleanup:
286 if (cpl_error_get_code() != CPL_ERROR_NONE) {
287 xsh_error_dump(CPL_MSG_ERROR);
288 ret = 1;
289 }
290 if ( NULL != order_tab_file ) {
291 fclose( order_tab_file);
292 }
293 xsh_free_frame( &order_tab_frame);
295 xsh_free_propertylist( &header);
296 xsh_order_list_free( &order_tab);
297 XSH_TABLE_FREE( table);
298 TEST_END();
299 return ret ;
300}
301
int main()
Unit test of xsh_bspline_interpol.
static int starty
static int endy
static xsh_instrument * instrument
static void HandleOptions(int argc, char **argv)
int binx
static const char * Options
static char PointSize[8]
static int PointStep
int biny
static char CentralColor[32]
#define MODULE_ID
static struct option LongOptions[]
#define SYNTAX
static char PointType[16]
@ C_COLOR_OPT
@ BINX_OPT
@ STEP_OPT
@ BINY_OPT
@ SIZE_OPT
@ POINT_OPT
void xsh_order_list_set_bin_y(xsh_order_list *list, int bin)
Set the bin of image in y.
void xsh_order_list_set_bin_x(xsh_order_list *list, int bin)
Set the bin of image in x.
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
void xsh_order_list_free(xsh_order_list **list)
free memory associated to an order_list
double xsh_order_list_eval(xsh_order_list *list, cpl_polynomial *poly, double y)
Evaluate an order list poly.
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
#define XSH_ASSURE_NOT_NULL(pointer)
Definition: xsh_error.h:99
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_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
const char * xsh_pfits_get_pcatg(const cpl_propertylist *plist)
find out the pcatg
Definition: xsh_pfits.c:1627
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
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
xsh_order * list
cpl_polynomial * edguppoly
cpl_polynomial * edglopoly
cpl_polynomial * slicuppoly
cpl_polynomial * sliclopoly
cpl_polynomial * cenpoly
#define TEST_END()
Definition: tests.h:111
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
@ XSH_ARM_UVB
int ny
#define XSH_ORDER_TAB_EDGES
Definition: xsh_dfs.h:554
#define XSH_CMP_TAG_MODE(tag_in, TAG)
Definition: xsh_dfs.h:1528
#define XSH_ORDER_TAB_AFC
Definition: xsh_dfs.h:712
#define XSH_CMP_TAG_LAMP(tag_in, TAG)
Definition: xsh_dfs.h:1536
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138
#define XSH_TABLE_LOAD(TABLE, NAME)
#define XSH_TABLE_FREE(TABLE)