X-shooter Pipeline Reference Manual 3.8.15
test-xsh_extract_clean.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: 2013-05-14 07:02:49 $
23 * $Revision: 1.3 $
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_rec.h>
51#include <xsh_drl.h>
52#include <xsh_pfits.h>
53
54#include <xsh_badpixelmap.h>
55#include <xsh_parameters.h>
56
57#include <cpl.h>
58#include <math.h>
59
60#include <getopt.h>
61
62/*--------------------------------------------------------------------------
63 Defines
64 --------------------------------------------------------------------------*/
65
66#define MODULE_ID "XSH_EXTRACT_CLEAN"
67
68enum {
70} ;
71
72static struct option long_options[] = {
73 {"decode-bp", required_argument, 0, DECODEBP_OPT},
74 {"method", required_argument, 0, METHOD_OPT},
75 {"debug", required_argument, 0, DEBUG_OPT},
76 {"help", 0, 0, HELP_OPT},
77 {0, 0, 0, 0}
78};
79
80static void Help( void )
81{
82 puts( "Unitary test of xsh_extract_clean");
83 puts( "Usage: test_xsh_extract_clean [options] <input_files>");
84
85 puts( "Options" ) ;
86 puts( " --decode-bp=<n> : Integer representation of the bits to be considered bad when decoding the bad pixel mask pixel values.");
87 puts( " --method=<n> : method for extraction CLEAN | LOCALIZATION | FULL | NOD");
88 puts( " --debug=<n> : Level of debug LOW | MEDIUM | HIGH [MEDIUM]" );
89 puts( " --help : What you see" ) ;
90 puts( "\nInput Files" ) ;
91 puts( "The input files argument MUST be in this order:" ) ;
92 puts( " 1. Rectified frame 2D" ) ;
93 puts( " 2. Localization table");
94 TEST_END();
95 exit(0);
96}
97
98static void HandleOptions( int argc, char **argv,
99 xsh_extract_param *extract_par,int* decode_bp)
100{
101 int opt ;
102 int option_index = 0;
103
104 while (( opt = getopt_long (argc, argv, "slit_position:slit_height:method",
105 long_options, &option_index)) != EOF ){
106
107 switch ( opt ) {
108 case METHOD_OPT:
109 if ( strcmp(optarg, EXTRACT_METHOD_PRINT( LOCALIZATION_METHOD)) == 0){
110 extract_par->method = LOCALIZATION_METHOD;
111 }
112 else if ( strcmp(optarg, EXTRACT_METHOD_PRINT( FULL_METHOD)) == 0){
113 extract_par->method = FULL_METHOD;
114 }
115 else if ( strcmp(optarg, EXTRACT_METHOD_PRINT( CLEAN_METHOD)) == 0){
116 extract_par->method = CLEAN_METHOD;
117 }
118 else if ( strcmp(optarg, EXTRACT_METHOD_PRINT( NOD_METHOD)) == 0){
119 extract_par->method = NOD_METHOD;
120 }
121 else{
122 xsh_msg("WRONG method %s", optarg);
123 exit(-1);
124 }
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 DECODEBP_OPT:
135 *decode_bp=atoi(optarg);
136 break;
137
138 case HELP_OPT:
139 Help();
140 break;
141 default:
142 Help();
143 break;
144 }
145 }
146 return;
147}
148
149
150
151static void analyse_extraction( cpl_frame* rec_frame, xsh_instrument* instr);
152
153/*--------------------------------------------------------------------------
154 Implementation
155 --------------------------------------------------------------------------*/
156static void analyse_extraction( cpl_frame* rec_frame, xsh_instrument* instr)
157{
158 const char* rec_name = NULL;
159 xsh_rec_list* rec_list = NULL;
160 int iorder;
161
162 XSH_ASSURE_NOT_NULL( rec_frame);
163
164 check( rec_name = cpl_frame_get_filename( rec_frame));
165
166 printf("RECTIFY frame : %s\n", rec_name);
167 check( rec_list = xsh_rec_list_load( rec_frame, instr));
168
169 for(iorder=0; iorder< rec_list->size; iorder++){
170 int order = 0, ilambda = 0;
171 int nlambda = 0;
172 float *flux = NULL;
173 float *err = NULL;
174 double *lambda = NULL;
175 char name[256];
176 FILE* datfile = NULL;
177
178 check( order = xsh_rec_list_get_order(rec_list, iorder));
179 check( nlambda = xsh_rec_list_get_nlambda(rec_list, iorder));
180 check( flux = xsh_rec_list_get_data1( rec_list, iorder));
181 check( err = xsh_rec_list_get_errs1( rec_list, iorder));
182 check( lambda = xsh_rec_list_get_lambda( rec_list, iorder));
183
184 sprintf( name, "extract_order%d.dat",order);
185 xsh_msg("Save file %s",name);
186 datfile = fopen( name, "w");
187
188 for(ilambda=0; ilambda < nlambda; ilambda++){
189 fprintf( datfile,"%f %f\n",lambda[ilambda],flux[ilambda]);
190 }
191 fclose(datfile);
192
193 sprintf( name, "extract_err_order%d.dat",order);
194 xsh_msg("Save file %s",name);
195 datfile = fopen( name, "w");
196
197 for(ilambda=0; ilambda < nlambda; ilambda++){
198 fprintf( datfile,"%f %f\n",lambda[ilambda],err[ilambda]);
199 }
200 fclose(datfile);
201 }
202 cleanup:
203 xsh_rec_list_free( &rec_list);
204 return;
205}
206
214int main( int argc, char **argv)
215{
216 /* Declarations */
217 int ret = 0 ;
219 xsh_extract_param extract_obj = { CLEAN_METHOD};
220 cpl_propertylist *header= NULL;
221 const char *tag = NULL;
222 cpl_frame* result = NULL;
223 cpl_frame* result_eso = NULL;
224
225 char* rec_name = NULL;
226 cpl_frame* rec_frame = NULL;
227 char* loc_name = NULL;
228 cpl_frame* loc_frame = NULL;
229 XSH_ARM arm;
230 int decode_bp=DECODE_BP_FLAG_DEF;
231 xsh_interpolate_bp_param ipol_bp_par={7 };
232
233 /* Initialize libraries */
235
236 cpl_msg_set_level(CPL_MSG_DEBUG);
238
239
240 /* Analyse parameters */
241 HandleOptions( argc, argv, &extract_obj,&decode_bp);
242 xsh_msg("argc=%d optind=%d",argc,optind);
243 if ( (argc - optind) > 0 ) {
244 rec_name = argv[optind];
245 if ( (argc - optind) > 1){
246 loc_name = argv[optind+1];
247 }
248 }
249 else{
250 Help();
251 }
252 rec_frame = cpl_frame_new();
253 XSH_ASSURE_NOT_NULL (rec_frame);
254 cpl_frame_set_filename( rec_frame, rec_name) ;
255
256 check( header = cpl_propertylist_load( rec_name, 0));
257 check( tag = xsh_pfits_get_pcatg( header));
258 check( arm = xsh_pfits_get_arm( header))
259;
260 cpl_frame_set_level( rec_frame, CPL_FRAME_LEVEL_TEMPORARY);
261 cpl_frame_set_group( rec_frame, CPL_FRAME_GROUP_RAW ) ;
262 cpl_frame_set_tag( rec_frame, tag);
263
264 /* Create instrument structure and fill */
270 //xsh_msg("decode_bp=%d",decode_bp);
271
272
273 if ( loc_name != NULL){
274 loc_frame = cpl_frame_new();
275 cpl_frame_set_filename( loc_frame, loc_name);
276 cpl_frame_set_level( rec_frame, CPL_FRAME_LEVEL_TEMPORARY);
277 cpl_frame_set_group( rec_frame, CPL_FRAME_GROUP_RAW );
278 }
279 /* Create REGION FILES for rectify */
280 xsh_msg("Extract Parameters");
281 xsh_msg("Rectified frame : %s", rec_name);
282 if (loc_name != NULL){
283 xsh_msg("Localization table : %s", loc_name);
284 }
285
286 check(result = xsh_extract_clean(rec_frame, loc_frame, instrument,
287 &extract_obj,&ipol_bp_par,&result_eso,
288 "test"));
289
291
292 cleanup:
293
295 xsh_free_frame( &rec_frame);
296 xsh_free_frame( &result);
297 xsh_free_frame( &result_eso);
298 xsh_free_frame( &loc_frame);
299 xsh_free_frame( &rec_frame);
300 xsh_free_propertylist( &header);
301
302 if (cpl_error_get_code() != CPL_ERROR_NONE) {
303 xsh_error_dump(CPL_MSG_ERROR);
304 ret= 1;
305 }
306 TEST_END();
307 return ret ;
308}
309
int main()
Unit test of xsh_bspline_interpol.
static void analyse_extraction(cpl_frame *rec_frame, xsh_instrument *instr)
static void HandleOptions(int argc, char **argv, xsh_extract_param *extract_par, int *decode_bp)
static void Help(void)
#define MODULE_ID
static struct option long_options[]
@ DECODEBP_OPT
static xsh_instrument * instrument
double * xsh_rec_list_get_lambda(xsh_rec_list *list, int idx)
xsh_rec_list * xsh_rec_list_load(cpl_frame *frame, xsh_instrument *instrument)
load an rec list from a frame
Definition: xsh_data_rec.c:289
float * xsh_rec_list_get_data1(xsh_rec_list *list, int idx)
float * xsh_rec_list_get_errs1(xsh_rec_list *list, int idx)
int xsh_rec_list_get_order(xsh_rec_list *list, int idx)
Definition: xsh_data_rec.c:846
int xsh_rec_list_get_nlambda(xsh_rec_list *list, int idx)
Definition: xsh_data_rec.c:865
void xsh_rec_list_free(xsh_rec_list **list)
free memory associated to a rec_list
Definition: xsh_data_rec.c:760
#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
cpl_frame * xsh_extract_clean(cpl_frame *rec_frame, cpl_frame *loc_frame, xsh_instrument *instrument, xsh_extract_param *extract_par, xsh_interpolate_bp_param *ipol_bp, cpl_frame **res_frame_ext, const char *rec_prefix)
simple 1D extraction of point source like object
Definition: xsh_extract.c:836
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.
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
xsh_instrument * xsh_instrument_new(void)
create new instrument structure
void xsh_instrument_set_decode_bp(xsh_instrument *i, const int decode_bp)
Set bad pixel code.
#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
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
enum extract_method method
#define TEST_END()
Definition: tests.h:111
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
@ XSH_LAMP_QTH
@ XSH_MODE_IFU
int order
Definition: xsh_detmon_lg.c:80
#define DECODE_BP_FLAG_DEF
#define EXTRACT_METHOD_PRINT(method)
@ FULL_METHOD
@ NOD_METHOD
@ LOCALIZATION_METHOD
@ CLEAN_METHOD
@ 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