X-shooter Pipeline Reference Manual 3.8.15
test-xsh_localize_ifu.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_spectrum.h>
51#include <xsh_drl.h>
52#include <xsh_pfits.h>
53#include <xsh_parameters.h>
54#include <xsh_badpixelmap.h>
55#include <xsh_utils_ifu.h>
56#include <xsh_utils_table.h>
57#include <cpl.h>
58#include <math.h>
59
60#include <string.h>
61#include <getopt.h>
62
63/*--------------------------------------------------------------------------
64 Defines
65 --------------------------------------------------------------------------*/
66
67#define MODULE_ID "XSH_LOCALIZE_IFU"
68
69enum {
74} ;
75
76static struct option long_options[] = {
77 {"smooth-hsize", required_argument, 0, SMOOTH_HSIZE_OPT},
78 {"nscales", required_argument, 0, NSCALES_OPT},
79 {"HF-skip", required_argument, 0, HF_SKIP_OPT},
80 {"cut-sigma-low", required_argument, 0, SIGMA_LOW_OPT},
81 {"cut-sigma-up", required_argument, 0, SIGMA_UP_OPT},
82 {"cut-snr-low", required_argument, 0, SNR_LOW_OPT},
83 {"cut-snr-up", required_argument, 0, SNR_UP_OPT},
84 {"box-hsize", required_argument, 0, BOX_HSIZE_OPT},
85 {"slit-min", required_argument, 0, SLIT_MIN_OPT},
86 {"slit-max", required_argument, 0, SLIT_MAX_OPT},
87 {"deg", required_argument, 0, DEG_OPT},
88 {"skymask", required_argument, 0, SKYMASK_OPT},
89 {"help", 0, 0, HELP_OPT},
90 {0, 0, 0, 0}
91};
92
93static void Help( void )
94{
95 puts( "Unitary test of xsh_localize_ifu");
96 puts( "Usage: test_xsh_localize_ifu [options] DATA_FILE");
97
98 puts( "Options" ) ;
99 puts( " --help : What you see" ) ;
100 puts( " --smooth-hsize= : Half size of median smooth filter");
101 puts( " --nscales= : Number of scales");
102 puts( " --HF-skip= : Number of skipping High Frequency");
103 puts( " --cut-sigma-low= : Gaussian fits of the cross-dispersion profile whose FWHM is lower than this value are rejected.[0.05]");
104 puts( " --cut-sigma-up = : Gaussian fits of the cross-dispersion profile whose FWHM is upper than this value are rejected.[0.95]");
105 puts( " --cut-snr-low= : Gaussian fits of the cross-dispersion profile whose SNR is lower than this value are rejected.[0.05]");
106 puts( " --cut-snr-up= : Gaussian fits of the cross-dispersion profile whose SNR is upper than this value are rejected.0.95]");
107 puts( " --box-hsize= : Half size of running chunk box");
108 puts( " --slit-min= : Maximum slit in arcsec [-6.0]");
109 puts( " --slit-max= : Minimum slit in arcsec [6.0]");
110 puts( " --deg = : Minimum slit in arcsec [2]");
111 puts( " --skymask=<file> : Sky mask file");
112 puts( "\nInput Files" ) ;
113 puts( "DATA_FILE : Merge 2D frame");
114 TEST_END();
115}
116
117
118static void HandleOptions( int argc, char **argv,
119 int *smooth_hsize, int *nscales, int *HF_skip,
120 double *sigma_low, double *sigma_up, double *snr_low, double *snr_up,
121 int *box_hsize, double *slitmin, double *slitmax, int *deg, char **skymask_name)
122{
123 int opt ;
124 int option_index = 0;
125
126 while (( opt = getopt_long (argc, argv,
127 "cut-sigma:smooth-hsize:nscales:HF-skip:deg",
128 long_options, &option_index)) != EOF ){
129
130 switch ( opt ) {
131 case SMOOTH_HSIZE_OPT:
132 *smooth_hsize = atoi(optarg);
133 break;
134 case NSCALES_OPT:
135 *nscales = atoi(optarg);
136 break ;
137 case HF_SKIP_OPT:
138 *HF_skip = atoi(optarg);
139 break ;
140 case SIGMA_LOW_OPT:
141 *sigma_low = atof( optarg);
142 break;
143 case SIGMA_UP_OPT:
144 *sigma_up = atof( optarg);
145 break;
146 case SNR_LOW_OPT:
147 *snr_low = atof( optarg);
148 break;
149 case SNR_UP_OPT:
150 *snr_up = atof( optarg);
151 break;
152 case BOX_HSIZE_OPT:
153 *box_hsize = atoi( optarg);
154 break;
155 case SLIT_MIN_OPT:
156 *slitmin = atof( optarg);
157 break;
158 case SLIT_MAX_OPT:
159 *slitmax = atof( optarg);
160 break;
161 case DEG_OPT:
162 *deg = atoi( optarg);
163 break;
164 case SKYMASK_OPT:
165 *skymask_name = optarg;
166 break;
167 default:
168 Help(); exit(-1);
169 }
170 }
171 return;
172}
173
174
175int main( int argc, char **argv)
176{
177 /* Declarations */
178 int ret = 0 ;
179 int nscales = 5;
180 int HF_skip = 2;
181 int smooth_hsize = 2;
182
183 const char *file_name = NULL;
184 cpl_frame *merge2d_frame = NULL;
185 cpl_frame *result = NULL;
186 char result_name[256];
187 int i;
188 cpl_table *result_tab = NULL;
189 int result_size;
190 double *wave_result_data = NULL;
191 double *slit_result_data = NULL;
192 FILE *result_file = NULL;
193
194 double sigma_low = 0.05;
195 double sigma_up = 0.95;
196 double snr_low = 0.05;
197 double snr_up = 0.95;
198
199 int box_hsize = 0;
200 double slitmin =-6;
201 double slitmax = 6;
202
203 int deg =2;
204
205 char * skymask_name = NULL;
206 cpl_frame *skymask_frame = NULL;
207
208 cpl_propertylist *plist = NULL;
211 const char* tag = NULL;
212
213
214 //const int decode_bp=2147483647;
215
216 /* Initialize libraries */
218
219 cpl_msg_set_level(CPL_MSG_DEBUG);
221
222 /* Analyse parameters */
223 HandleOptions( argc, argv, &smooth_hsize, &nscales, &HF_skip,
224 &sigma_low, &sigma_up, &snr_low, &snr_up,
225 &box_hsize, &slitmin, &slitmax, &deg, &skymask_name);
226
227 if ( (argc - optind) > 0 ) {
228 file_name = argv[optind];
229 }
230 else {
231 Help();
232 exit( 0);
233 }
234
235 check( plist = cpl_propertylist_load( file_name, 0));
236 check( arm = xsh_pfits_get_arm( plist));
238 XSH_LAMP_UNDEFINED, "xsh_geom_ifu");
239
240 xsh_msg("---Input Files");
241 xsh_msg("File : %s ", file_name);
242 xsh_msg("---Options");
243 xsh_msg("SMOOTH_HSIZE : %d ", smooth_hsize);
244 xsh_msg("NSCALES : %d ", nscales);
245 xsh_msg("HF_SKIP : %d ", HF_skip);
246 xsh_msg("SIGMA : [%f %f]", sigma_low, sigma_up);
247 xsh_msg("SNR : [%f %f]", snr_low, snr_up);
248 xsh_msg("BOX HSIZE: %d", box_hsize);
249 xsh_msg("SLIT MIN: %f", slitmin);
250 xsh_msg("SLIT MAX: %f", slitmax);
251 xsh_msg("DEG : %d", deg);
252 if ( skymask_name){
253 xsh_msg("SKYMASK : %s", skymask_name);
255 TESTS_XSH_FRAME_CREATE( skymask_frame, tag, skymask_name);
256 }
257 /* Create frames */
259 TESTS_XSH_FRAME_CREATE( merge2d_frame, tag, file_name);
260
261 if ( strstr( file_name, "CEN") != NULL){
262 sprintf( result_name, "decomp_CEN.fits");
263 }
264 else if ( strstr( file_name, "UP") != NULL){
265 sprintf( result_name, "decomp_UP.fits");
266 }
267 else if ( strstr( file_name, "DOWN") != NULL){
268 sprintf( result_name, "decomp_DOWN.fits");
269 }
270 else{
271 sprintf( result_name, "decomp.fits");
272 }
273
274 check( result = xsh_localize_ifu_slitlet( merge2d_frame,
275 skymask_frame, smooth_hsize, nscales,
276 HF_skip, result_name, sigma_low, sigma_up,
277 snr_low, snr_up, slitmin, slitmax, deg, box_hsize, instrument));
278
279 xsh_msg( "Produce file %s", result_name);
280
281 XSH_TABLE_LOAD( result_tab, result_name);
282 check( wave_result_data = cpl_table_get_data_double( result_tab,
284 check( slit_result_data = cpl_table_get_data_double( result_tab,
286 result_size = cpl_table_get_nrow( result_tab);
287
288 result_file = fopen("LOCALIZE_IFU.reg", "w+");
289
290 fprintf( result_file, "# Region file format: DS9 version 4.0\n");
291
292 fprintf( result_file, "#yellow center\n");
293 fprintf( result_file, "global color=red font=\"helvetica 4 normal\"select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 source=1\n");
294 fprintf( result_file, "wcs\n");
295
296 for( i=0; i< result_size; i++){
297 double wave, slit;
298
299 wave = wave_result_data[i];
300 slit = slit_result_data[i];
301
302 fprintf( result_file, "point(%f,%f)\n #point=cross color=yellow font=\"helvetica 4 normal\"\n", wave, slit);
303 }
304
305 fclose( result_file);
306
307 xsh_msg( "Produce ds9 region file LOCALIZE_IFU.reg");
308 cleanup:
309 if (cpl_error_get_code() != CPL_ERROR_NONE) {
310 xsh_error_dump(CPL_MSG_ERROR);
311 ret=1;
312 }
313 xsh_free_frame( &skymask_frame);
315 xsh_free_propertylist( &plist);
316 xsh_free_frame( &result);
317 xsh_free_frame( &merge2d_frame);
318 XSH_TABLE_FREE( result_tab);
319 TEST_END();
320 return ret ;
321}
322
int main()
Unit test of xsh_bspline_interpol.
static void HandleOptions(int argc, char **argv, int *smooth_hsize, int *nscales, int *HF_skip, double *sigma_low, double *sigma_up, double *snr_low, double *snr_up, int *box_hsize, double *slitmin, double *slitmax, int *deg, char **skymask_name)
#define MODULE_ID
static struct option long_options[]
@ SNR_LOW_OPT
@ BOX_HSIZE_OPT
@ SNR_UP_OPT
@ HF_SKIP_OPT
@ SMOOTH_HSIZE_OPT
@ SKYMASK_OPT
@ SIGMA_UP_OPT
@ SLIT_MAX_OPT
@ SIGMA_LOW_OPT
@ SLIT_MIN_OPT
@ NSCALES_OPT
static xsh_instrument * instrument
#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
cpl_frame * xsh_localize_ifu_slitlet(cpl_frame *merge2d_slitlet, cpl_frame *skymask_frame, int smooth_hsize, int nscales, int HF_skip, const char *resname, double cut_sigma_low, double cut_sigma_up, double cut_snr_low, double cut_snr_up, double slit_min, double slit_max, int deg, int box_hsize, xsh_instrument *instr)
Localize center of object on a merge 2D IFU slitlet.
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
XSH_ARM xsh_pfits_get_arm(const cpl_propertylist *plist)
Definition: xsh_pfits.c:270
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
static void Help(void)
#define TESTS_XSH_INSTRUMENT_CREATE(instr, mode, arm, lamp, recipe)
Definition: tests.h:115
#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
@ XSH_LAMP_UNDEFINED
@ XSH_ARM_UNDEFINED
@ XSH_MODE_IFU
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
Definition: xsh_dfs.h:1548
#define XSH_MERGE2D
Definition: xsh_dfs.h:594
#define XSH_SKY_LINE_LIST
Definition: xsh_dfs.h:944
#define XSH_OBJPOS_COLNAME_SLIT
Definition: xsh_drl.h:498
#define XSH_OBJPOS_COLNAME_WAVELENGTH
Definition: xsh_drl.h:496
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138
#define XSH_TABLE_LOAD(TABLE, NAME)
#define XSH_TABLE_FREE(TABLE)