X-shooter Pipeline Reference Manual 3.8.15
test-xsh_subtract_bias.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-04-26 14:10:08 $
23 * $Revision: 1.11 $
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_dfs.h>
49#include <xsh_pfits.h>
50#include <tests.h>
51#include <cpl.h>
52#include <math.h>
53#include <getopt.h>
54
55/*---------------------------------------------------------------------------
56 Defines
57 ---------------------------------------------------------------------------*/
58#define MODULE_ID "XSH_SUBTRACT_BIAS"
59
60enum {
62};
63
64static struct option long_options[] = {
65 {"debug", required_argument, 0, DEBUG_OPT},
66 {"help", 0, 0, HELP_OPT},
67 {0, 0, 0, 0}
68};
69
70
71static void Help( void )
72{
73 puts( "Unitary test of xsh_subtract_bias");
74 puts( "Usage: test_xsh_subtract_bias [options] <input_files>");
75
76 puts( "Options" ) ;
77 puts( " --debug=<n> : Level of debug LOW | MEDIUM | HIGH [MEDIUM]" );
78 puts( " --help : What you see" ) ;
79 puts( "\nInput Files" ) ;
80 puts( "The input files argument MUST be in this order:" ) ;
81 puts( " 1. Science frame in PRE format" ) ;
82 puts( " 2. SOF [MASTER_BIAS]");
84 TEST_END();
85 exit(0);
86}
87
88
89
90
91static void HandleOptions( int argc, char **argv)
92{
93 int opt ;
94 int option_index = 0;
95 while (( opt = getopt_long (argc, argv, "debug:help",
96 long_options, &option_index)) != EOF ){
97
98 switch ( opt ) {
99 case DEBUG_OPT:
100 if ( strcmp( optarg, "LOW")==0){
102 }
103 else if ( strcmp( optarg, "HIGH")==0){
105 }
106 break;
107 case HELP_OPT:
108 Help();
109 break;
110 default:
111 break;
112 }
113 }
114 return;
115}
116/*---------------------------------------------------------------------------
117 Functions prototypes
118 ---------------------------------------------------------------------------*/
119
120/*--------------------------------------------------------------------------*/
127/*--------------------------------------------------------------------------*/
128
129int main( int argc, char **argv)
130{
131 xsh_instrument * instrument = NULL ;
132 cpl_frameset* set = NULL;
133 cpl_frame* frame = NULL;
134 cpl_frame* bias = NULL;
135 char* sci_name = NULL;
136 char* sof_name = NULL;
137 cpl_frame* temp = NULL;
138 int i = 0;
139 xsh_pre* pre1 = NULL;
140 xsh_pre* pre2 = NULL;
141 xsh_pre* pre3 = NULL;
142 float *data1 = NULL,*errs1 = NULL;
143 int * qual1 = NULL;
144 float *data2 = NULL,*errs2 = NULL;
145 int * qual2 = NULL;
146 float *data3 = NULL,*errs3 = NULL;
147 int * qual3 = NULL;
148 int ret=0;
149 int pre_overscan_corr=0;
150 const int decode_bp=2147483647;
151 /* Initialize libraries */
154 cpl_msg_set_level( CPL_MSG_DEBUG);
156
157 HandleOptions( argc, argv);
158
159 if ( (argc-optind) >= 2 ) {
160 sci_name = argv[optind];
161 sof_name = argv[optind+1];
162
163 /* Create frameset from sof */
164 check( set = sof_to_frameset( sof_name));
165
166 /* Validate frame set */
168 check( bias = xsh_find_master_bias( set, instrument));
169 TESTS_XSH_FRAME_CREATE( frame, "OBJECT_SLIT_STARE_arm", sci_name);
170 }
171 else{
172 xsh_msg("-------------------------------------------");
173 xsh_msg("Execute default test : do --help for option");
174 xsh_msg("-------------------------------------------");
175
176 /* Create valid instrument */
181
182 /* Create two frames in frameset */
183 set = cpl_frameset_new();
184 for(i=0;i<2;i++){
185 char framename[256];
186
187 sprintf(framename,"frame%d.fits",i);
188 frame = xsh_test_create_frame(framename,10,10,
189 XSH_LINEARITY_UVB,CPL_FRAME_GROUP_RAW, instrument);
190 cpl_frameset_insert(set,frame);
191 }
192
193 /* USE prepare function */
194 check(xsh_prepare(set, NULL, NULL,"PRE",instrument,0,CPL_FALSE));
195
196 /* TEST1 : test the subtract_bias function */
197 check( frame = cpl_frame_duplicate(cpl_frameset_get_frame(set,0)));
198 check( bias = cpl_frameset_get_frame(set,1));
199 }
200
201
202 xsh_msg("SCI : %s",
203 cpl_frame_get_filename( frame));
204 xsh_msg("BIAS : %s",
205 cpl_frame_get_filename( bias));
207
208 check( temp = xsh_subtract_bias(frame,bias,instrument,"TEST_BIAS_",pre_overscan_corr,0));
209
210 /* get data errs, qual*/
211 check(pre1 = xsh_pre_load(temp,instrument));
212 check(pre2 = xsh_pre_load(frame,instrument));
213 check(pre3 = xsh_pre_load(bias,instrument));
214
215 data1 = cpl_image_get_data_float(pre1->data);
216 data2 = cpl_image_get_data_float(pre2->data);
217 data3 = cpl_image_get_data_float(pre3->data);
218 errs1 = cpl_image_get_data_float(pre1->errs);
219 errs2 = cpl_image_get_data_float(pre2->errs);
220 errs3 = cpl_image_get_data_float(pre3->errs);
221 qual1 = cpl_image_get_data_int(pre1->qual);
222 qual2 = cpl_image_get_data_int(pre2->qual);
223 qual3 = cpl_image_get_data_int(pre3->qual);
224 /* verify data, errs and qual */
225 for(i=0;i<100;i++){
226 assure(data1[i] -(data2[i] -data3[i]) < XSH_FLOAT_PRECISION,
227 CPL_ERROR_ILLEGAL_OUTPUT,"Wrong data part");
228 assure(errs1[i] - (sqrt(errs2[i]*errs2[i]+errs3[i]*errs3[i])) <
229 XSH_FLOAT_PRECISION,CPL_ERROR_ILLEGAL_OUTPUT,"Wrong errs part");
230 assure(qual1[i] == (qual2[i] + qual3[i]),CPL_ERROR_ILLEGAL_OUTPUT,
231 "Wrong qual part");
232 }
233 xsh_msg("subtract bias ok");
234
235 cleanup:
236 xsh_free_frame( &frame);
237 xsh_pre_free(&pre1);
238 xsh_pre_free(&pre2);
239 xsh_pre_free(&pre3);
241 xsh_free_frameset(&set);
242 xsh_free_frame(&temp);
243
244 if (cpl_error_get_code() != CPL_ERROR_NONE) {
245 xsh_error_dump(CPL_MSG_ERROR);
246 ret=1;
247 }
249 TEST_END();
250 return ret;
251}
252
int main()
Unit test of xsh_bspline_interpol.
static xsh_instrument * instrument
static void HandleOptions(int argc, char **argv)
static void Help(void)
#define MODULE_ID
static struct option long_options[]
cpl_frameset * sof_to_frameset(const char *sof_name)
Definition: tests.c:576
cpl_frame * xsh_test_create_frame(const char *name, int nx, int ny, const char *tag, cpl_frame_group group, xsh_instrument *instrument)
Definition: tests.c:119
xsh_pre * xsh_pre_load(cpl_frame *frame, xsh_instrument *instr)
Load a xsh_pre structure from a frame.
Definition: xsh_data_pre.c:849
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
Definition: xsh_data_pre.c:823
void xsh_prepare(cpl_frameset *frames, cpl_frame *bpmap, cpl_frame *mbias, const char *prefix, xsh_instrument *instr, const int pre_overscan_corr, const bool flag_neg_and_thresh_pix)
This function transform RAW frames dataset in PRE frames dataset attaching the default bad pixel map ...
Definition: xsh_prepare.c:122
#define assure(CONDITION, ERROR_CODE,...)
Definition: xsh_error.h:54
#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.
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
cpl_frame * xsh_subtract_bias(cpl_frame *frame, cpl_frame *bias, xsh_instrument *instr, const char *type, const int pre_overscan_corr, const int save_tmp)
Subtract the master bias frame from PRE frame.
Definition: xsh_subtract.c:120
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
cpl_image * qual
Definition: xsh_data_pre.h:71
cpl_image * data
Definition: xsh_data_pre.h:65
cpl_image * errs
Definition: xsh_data_pre.h:68
#define TESTS_CLEAN_WORKSPACE(DRL_ID)
Definition: tests.h:139
#define TESTS_XSH_FRAME_CREATE(frame, tag, name)
Definition: tests.h:123
#define TESTS_INIT_WORKSPACE(DRL_ID)
Definition: tests.h:133
#define XSH_FLOAT_PRECISION
Definition: tests.h:150
#define TEST_END()
Definition: tests.h:111
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
@ XSH_LAMP_QTH
@ XSH_ARM_UVB
@ XSH_MODE_IFU
cpl_frame * xsh_find_master_bias(cpl_frameset *frames, xsh_instrument *instr)
Find master bias frame.
Definition: xsh_dfs.c:3319
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
#define XSH_LINEARITY_UVB
Definition: xsh_dfs.h:383
@ 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