X-shooter Pipeline Reference Manual 3.8.15
test-xsh_subtract_dark.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.10 $
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_DARK"
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
70static void Help( void )
71{
72 puts( "Unitary test of xsh_subtract_dark");
73 puts( "Usage: test_xsh_subtract_dark [options] <input_files>");
74
75 puts( "Options" ) ;
76 puts( " --debug=<n> : Level of debug LOW | MEDIUM | HIGH [MEDIUM]" );
77 puts( " --help : What you see" ) ;
78 puts( "\nInput Files" ) ;
79 puts( "The input files argument MUST be in this order:" ) ;
80 puts( " 1. Science frame in PRE format" ) ;
81 puts( " 2. SOF [MASTER_DARK]");
83 TEST_END();
84 exit(0);
85}
86
87static void HandleOptions( int argc, char **argv)
88{
89 int opt ;
90 int option_index = 0;
91 while (( opt = getopt_long (argc, argv, "debug:help",
92 long_options, &option_index)) != EOF ){
93
94 switch ( opt ) {
95 case DEBUG_OPT:
96 if ( strcmp( optarg, "LOW")==0){
98 }
99 else if ( strcmp( optarg, "HIGH")==0){
101 }
102 break;
103 case HELP_OPT:
104 Help();
105 break;
106 default:
107 break;
108 }
109 }
110 return;
111}
112/*---------------------------------------------------------------------------
113 Functions prototypes
114 ---------------------------------------------------------------------------*/
115
116/*--------------------------------------------------------------------------*/
123/*--------------------------------------------------------------------------*/
124
125int main(int argc, char** argv)
126{
127 xsh_instrument * instrument = NULL ;
128 cpl_frameset* set = NULL;
129 cpl_frame* frame = NULL;
130 cpl_frame* dark = NULL;
131 char* sci_name = NULL;
132 char* sof_name = NULL;
133 cpl_frame* temp = NULL;
134 int i = 0;
135 xsh_pre* pre1 = NULL;
136 xsh_pre* pre2 = NULL;
137 xsh_pre* pre3 = NULL;
138 float *data1 = NULL,*errs1 = NULL;
139 int * qual1 = NULL;
140 float *data2 = NULL,*errs2 = NULL;
141 int * qual2 = NULL;
142 float *data3 = NULL,*errs3 = NULL;
143 int * qual3 = NULL;
144 int ret=0;
145 const int decode_bp=2147483647;
146 /* Initialize libraries */
149 cpl_msg_set_level( CPL_MSG_DEBUG);
151
152 HandleOptions( argc, argv);
153
154 if ( (argc-optind) >= 2 ) {
155 sci_name = argv[optind];
156 sof_name = argv[optind+1];
157
158 /* Create frameset from sof */
159 check( set = sof_to_frameset( sof_name));
160
161 /* Validate frame set */
163 check( dark = xsh_find_master_dark( set, instrument));
164 TESTS_XSH_FRAME_CREATE( frame, "OBJECT_SLIT_STARE_arm", sci_name);
165 }
166 else{
167 xsh_msg("-------------------------------------------");
168 xsh_msg("Execute default test : do --help for option");
169 xsh_msg("-------------------------------------------");
170 /* Create valid instrument */
175
176 /* Create two frames in frameset */
177 set = cpl_frameset_new();
178 for(i=0;i<2;i++){
179 char framename[256];
180
181 sprintf(framename,"frame%d.fits",i);
182 frame = xsh_test_create_frame(framename,10,10,
183 XSH_LINEARITY_UVB,CPL_FRAME_GROUP_RAW, instrument);
184 cpl_frameset_insert(set,frame);
185 }
186
187 /* USE prepare function */
188 check(xsh_prepare(set, NULL, NULL,"PRE",instrument,0,CPL_FALSE));
189
190 /* TEST2 : test the subtract_dark function */
191
192 check( frame = cpl_frame_duplicate(cpl_frameset_get_frame(set,0)));
193 check( dark = cpl_frameset_get_frame(set,1));
194 }
195
196 xsh_msg("SCI : %s",
197 cpl_frame_get_filename( frame));
198 XSH_ASSURE_NOT_NULL( dark);
199 xsh_msg("DARK : %s",
200 cpl_frame_get_filename( dark));
202 check( temp = xsh_subtract_dark(frame,dark, "tmp_sub.fits", instrument));
203
204 check(pre1 = xsh_pre_load(temp,instrument));
205 check(pre2 = xsh_pre_load(frame,instrument));
206 check(pre3 = xsh_pre_load(dark,instrument));
207
208 data1 = cpl_image_get_data_float(pre1->data);
209 data2 = cpl_image_get_data_float(pre2->data);
210 data3 = cpl_image_get_data_float(pre3->data);
211 errs1 = cpl_image_get_data_float(pre1->errs);
212 errs2 = cpl_image_get_data_float(pre2->errs);
213 errs3 = cpl_image_get_data_float(pre3->errs);
214 qual1 = cpl_image_get_data_int(pre1->qual);
215 qual2 = cpl_image_get_data_int(pre2->qual);
216 qual3 = cpl_image_get_data_int(pre3->qual);
217
218 /* verify data, errs and qual */
219 xsh_msg("exptime %f",pre2->exptime);
220 for(i=0;i<100;i++){
221 assure(data1[i] -(data2[i] -data3[i]*pre2->exptime) < XSH_FLOAT_PRECISION,
222 CPL_ERROR_ILLEGAL_OUTPUT,"Wrong data part");
223 assure(errs1[i] - (sqrt(errs2[i]*errs2[i]+errs3[i]*errs3[i]*pre2->exptime*
224 pre2->exptime)) <
225 XSH_FLOAT_PRECISION,CPL_ERROR_ILLEGAL_OUTPUT,"Wrong errs part");
226 assure(qual1[i] == (qual2[i] + qual3[i]),CPL_ERROR_ILLEGAL_OUTPUT,
227 "Wrong qual part");
228 }
229 xsh_msg("subtract dark ok");
230
231 cleanup:
232 xsh_free_frame( &frame);
233 xsh_pre_free(&pre1);
234 xsh_pre_free(&pre2);
235 xsh_pre_free(&pre3);
237 xsh_free_frameset(&set);
238 xsh_free_frame(&temp);
239
240 if (cpl_error_get_code() != CPL_ERROR_NONE) {
241 xsh_error_dump(CPL_MSG_ERROR);
242 ret=1;
243 }
245 TEST_END();
246 return ret;
247}
248
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
#define XSH_ASSURE_NOT_NULL(pointer)
Definition: xsh_error.h:99
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_dark(cpl_frame *frame, cpl_frame *dark, const char *filename, xsh_instrument *instr)
subtract the master dark frame from PRE frame
Definition: xsh_subtract.c:247
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
float exptime
Definition: xsh_data_pre.h:92
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_dark(cpl_frameset *frames, xsh_instrument *instr)
Find master dark frame.
Definition: xsh_dfs.c:3404
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