X-shooter Pipeline Reference Manual 3.8.15
test-xsh_create_map.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:10:13 $
23 * $Revision: 1.5 $
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_pre.h>
45#include <xsh_error.h>
46#include <xsh_msg.h>
47#include <xsh_data_instrument.h>
48#include <xsh_parameters.h>
49#include <xsh_dfs.h>
50#include <xsh_pfits.h>
51#include <tests.h>
52#include <cpl.h>
53#include <math.h>
54#include <getopt.h>
55#include <string.h>
56#include <xsh_model_utils.h>
57/*---------------------------------------------------------------------------
58 Defines
59 ---------------------------------------------------------------------------*/
60#define MODULE_ID "XSH_CREATE_MAP"
61
62enum {
64};
65
66static struct option LongOptions[] = {
67 {"debug", required_argument, 0, DEBUG_OPT},
68 {"help", 0, 0, HELP_OPT},
69 {NULL, 0, 0, 0}
70};
71
72static void Help( void )
73{
74 puts ("Unitary test : Create a slitmap and a wavemap from a set of files (SOF)");
75 puts( "Usage : ./the_xsh_data_wave_tab_2d [options] <SOF>");
76
77 puts( "Options" ) ;
78 puts( " --debug=<n> : Level of debug LOW | MEDIUM | HIGH [MEDIUM]" );
79 puts( " --help : What you see" ) ;
80
81 puts( "The input files argument MUST be in this order:" );
82 puts( " 1. PRE frame");
83 puts( " 2. SOF a) MODEL : [XSH_MOD_CFG_TAB_UVB]");
84 puts( " b) POLYNOMIAL: [DISP_TAB, ORDER_TAB_EDGES]");
85
86 TEST_END();
87 exit(0);
88}
89
90static void HandleOptions( int argc, char ** argv)
91{
92 int opt ;
93 int option_index = 0;
94
95 while( (opt = getopt_long( argc, argv, "debug:help",
96 LongOptions, &option_index )) != EOF){
97 switch( opt ) {
98 case DEBUG_OPT:
99 if ( strcmp( optarg, "LOW")==0){
101 }
102 else if ( strcmp( optarg, "HIGH")==0){
104 }
105 break;
106 case HELP_OPT:
107 Help();
108 break;
109 default:
110 break;
111 }
112 }
113}
114/*---------------------------------------------------------------------------
115 Functions prototypes
116 ---------------------------------------------------------------------------*/
117
118/*--------------------------------------------------------------------------*/
125/*--------------------------------------------------------------------------*/
126
127int main( int argc, char** argv)
128{
129 xsh_instrument * instrument = NULL ;
130 cpl_frameset* set = NULL;
131 char *sof_name = NULL;
132 char *pre_name = NULL;
133 cpl_frame *pre_frame = NULL;
134 cpl_propertylist *pre_header = NULL;
135 cpl_frame *model_frame = NULL;
136 cpl_frame *disptab_frame = NULL;
137 cpl_frame *ordertab_frame = NULL;
138 cpl_frame *wavemap_frame = NULL;
139 cpl_frame *slitmap_frame = NULL;
140 bool use_model;
141 int binx=1;
142 int biny=1;
143 int ret =0;
144 char wavemap_name[256];
145 char slitmap_name[256];
146
147 /* Initialize libraries */
149 cpl_msg_set_level( CPL_MSG_DEBUG);
151
152 HandleOptions( argc, argv);
153
154 /* Analyse parameters */
155 if ( (argc-optind) >= 2) {
156 pre_name = argv[optind];
157 sof_name = argv[optind+1];
158 /* Create frameset from sof */
159 check( set = sof_to_frameset( sof_name));
160
161 /* Validate frame set */
163 check( pre_header = cpl_propertylist_load( pre_name, 0));
165 check( binx = xsh_pfits_get_binx( pre_header));
166 check( biny = xsh_pfits_get_biny( pre_header));
167 }
170 TESTS_XSH_FRAME_CREATE( pre_frame, "PRE", pre_name);
171
172 /* one should have either model config frame or wave sol frame */
173 if((model_frame = xsh_find_frame_with_tag( set,
175 instrument)) == NULL) {
176
178
179 if ((model_frame = xsh_find_frame_with_tag( set,XSH_MOD_CFG_TAB,
180 instrument)) == NULL) {
182 }
183
184 }
186
187 cpl_error_reset();
188 if ( model_frame == NULL){
189 xsh_msg("Using polynomial solution to produce map");
190 check( disptab_frame = xsh_find_disp_tab( set, instrument));
191 check( ordertab_frame = xsh_find_order_tab_edges( set, instrument));
192 use_model = FALSE;
193 }
194 else{
195 xsh_msg("Using model to produce map");
196 use_model = TRUE;
197 }
198 }
199 else{
200 Help();
201 }
202 xsh_msg("PRE binning %dx%d : %s", binx, biny, cpl_frame_get_filename( pre_frame));
203
204 if (use_model){
205 int found_temp=true;
206
207 sprintf( wavemap_name, "model_%dx%d_WAVE_MAP", binx, biny);
208 sprintf( slitmap_name, "model_%dx%d_SLIT_MAP", binx, biny);
209 xsh_msg("MODEL : %s", cpl_frame_get_filename( model_frame));
210 check( xsh_model_temperature_update_frame(&model_frame, pre_frame,
211 instrument,&found_temp));
213 wavemap_name, slitmap_name,
214 &wavemap_frame, &slitmap_frame,0));
215 }
216 else{
217 xsh_msg("DISPERSION TAB : %s", cpl_frame_get_filename( disptab_frame));
218 xsh_msg("ORDER TAB : %s", cpl_frame_get_filename( ordertab_frame));
219
220 sprintf( wavemap_name, "poly_%dx%d", binx, biny);
221
222 check( xsh_create_map( disptab_frame, ordertab_frame, pre_frame,
223 instrument, &wavemap_frame, &slitmap_frame, wavemap_name));
224 }
225
226 xsh_msg( "Created SLITMAP: %s", cpl_frame_get_filename( slitmap_frame));
227 xsh_msg( "Created WAVEMAP: %s", cpl_frame_get_filename( wavemap_frame));
228 cleanup:
230 xsh_free_frameset( &set);
231 xsh_free_frame( &pre_frame);
232 xsh_free_propertylist( &pre_header);
233 xsh_free_frame( &wavemap_frame);
234 xsh_free_frame( &slitmap_frame);
235
236 if (cpl_error_get_code() != CPL_ERROR_NONE) {
237 xsh_error_dump( CPL_MSG_ERROR);
238 ret = 1;
239 }
240 TEST_END();
241 return ret;
242}
243
int main()
Unit test of xsh_bspline_interpol.
static xsh_instrument * instrument
int binx
int biny
#define MODULE_ID
static struct option LongOptions[]
@ HELP_OPT
@ DEBUG_OPT
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
#define xsh_error_reset()
Definition: xsh_error.h:87
XSH_ARM xsh_instrument_get_arm(xsh_instrument *i)
Get an arm on instrument structure.
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
int xsh_pfits_get_binx(const cpl_propertylist *plist)
find out the BINX value
Definition: xsh_pfits.c:289
int xsh_pfits_get_biny(const cpl_propertylist *plist)
find out the BINY value
Definition: xsh_pfits.c:306
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
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
static void HandleOptions(int argc, char **argv)
static void Help(void)
#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
void xsh_create_map(cpl_frame *dispsol_frame, cpl_frame *ordertab_frame, cpl_frame *pre_frame, xsh_instrument *instrument, cpl_frame **wavemap_frame, cpl_frame **slitmap_frame, const char *rec_prefix)
void xsh_create_model_map(cpl_frame *model_frame, xsh_instrument *instrument, const char *wtag, const char *stag, cpl_frame **wavemap_frame, cpl_frame **slitmap_frame, const int save_tmp)
@ XSH_ARM_NIR
cpl_frame * xsh_find_disp_tab(cpl_frameset *frames, xsh_instrument *instr)
Find Dispersol tab frame. The frame returned should not be free by the caller.
Definition: xsh_dfs.c:4066
cpl_frame * xsh_find_order_tab_edges(cpl_frameset *frames, xsh_instrument *instr)
Find an order tab EDGES.
Definition: xsh_dfs.c:3595
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_frame_with_tag(cpl_frameset *frames, const char *tag, xsh_instrument *instr)
Find frame with a given tag.
Definition: xsh_dfs.c:3347
#define XSH_MOD_CFG_OPT_2D
Definition: xsh_dfs.h:1233
#define XSH_MOD_CFG_TAB
Definition: xsh_dfs.h:1251
cpl_error_code xsh_model_temperature_update_frame(cpl_frame **model_config_frame, cpl_frame *ref_frame, xsh_instrument *instrument, int *found_temp)
@ 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