FORS Pipeline Reference Manual  4.12.5
fors_img_screen_flat-test.c
1 /* $Id: fors_img_screen_flat-test.c,v 1.17 2008-08-07 09:38:01 cizzo Exp $
2  *
3  * This file is part of the FORS Library
4  * Copyright (C) 2002-2006 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /*
22  * $Author: cizzo $
23  * $Date: 2008-08-07 09:38:01 $
24  * $Revision: 1.17 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 #include <fors_img_screen_flat_impl.h>
33 #include <fors_dfs.h>
34 #include <fors_pfits.h>
35 #include <fors_utils.h>
36 
37 #include <test_simulate.h>
38 #include <test.h>
39 
40 #include <cpl.h>
41 #include <math.h>
42 
49 #undef cleanup
50 #define cleanup \
51 do { \
52  cpl_frameset_delete(frames); \
53  cpl_parameterlist_delete(parameters); \
54  fors_image_delete(&raw_sflat); \
55  fors_image_delete(&master_sflat); \
56  fors_image_delete(&master_bias); \
57  fors_setting_delete(&setting); \
58  cpl_propertylist_delete(product_header); \
59 } while(0)
60 
64 static void
66 {
67  /* Input */
68  cpl_frameset *frames = cpl_frameset_new();
69  cpl_parameterlist *parameters = cpl_parameterlist_new();
70 
71  /* Output */
72  fors_image *raw_sflat = NULL;
73  fors_image *master_sflat = NULL;
74  fors_image *master_bias = NULL;
75  fors_setting *setting = NULL;
76  cpl_propertylist *product_header = NULL;
77 
78  /* Simulate data */
79  const char *screen_flat_filename[] = {"img_screen_flat_1.fits",
80  "img_screen_flat_2.fits",
81  "img_screen_flat_3.fits"};
82  const unsigned N = sizeof(screen_flat_filename)/sizeof(char *);
83 
84  {
85  unsigned i;
86 
87  for (i = 0; i < N; i++) {
88  cpl_frameset_insert(
89  frames,
90  create_screen_flat(screen_flat_filename[i],
91  SCREEN_FLAT_IMG, CPL_FRAME_GROUP_RAW));
92  }
93  }
94 
95  cpl_frameset_insert(frames,
96  create_master_bias("img_screen_flat_master_bias.fits",
97  MASTER_BIAS, CPL_FRAME_GROUP_CALIB));
98 
99  /* Define parameters */
100  fors_img_screen_flat_define_parameters(parameters);
101 
102  assure( !cpl_error_get_code(), return,
103  "Create parameters failed");
104 
106 
107  cpl_parameter_set_int(cpl_parameterlist_find(parameters,
108  "fors.fors_img_screen_flat.xradius"),
109  1);
110  cpl_parameter_set_int(cpl_parameterlist_find(parameters,
111  "fors.fors_img_screen_flat.yradius"),
112  1);
113 
114  cpl_parameter_set_int(cpl_parameterlist_find(parameters,
115  "fors.fors_img_screen_flat.degree"),
116  -1);
117 
118  /* Call recipe */
119  fors_img_screen_flat(frames, parameters);
120  assure( !cpl_error_get_code(), return,
121  "Execution error");
122 
123  /* Test results */
124 
125  /* Existence */
126  const char *const product_tags[] = {MASTER_SCREEN_FLAT_IMG,
127  MASTER_NORM_FLAT_IMG};
128  const char *const qc[] = {"QC OVEREXPO",
129  "QC FLAT EFF",
130  "QC FLAT PHN",
131  "QC FLAT FPN",
132  "QC FLAT CONAD",
133  "QC FLAT CONADERR"};
134 
135  test_recipe_output(frames,
136  product_tags, sizeof product_tags / sizeof *product_tags,
137  MASTER_NORM_FLAT_IMG,
138  qc, sizeof qc / sizeof *qc);
139 
140 
141  setting = fors_setting_new(cpl_frameset_find(frames,
142  SCREEN_FLAT_IMG));
143 
144  {
145  /* New and previous frames */
146  test( cpl_frameset_find(frames, MASTER_SCREEN_FLAT_IMG) != NULL );
147  test( cpl_frameset_find(frames, MASTER_NORM_FLAT_IMG) != NULL );
148  test( cpl_frameset_find(frames, MASTER_BIAS) != NULL );
149  test( cpl_frameset_find(frames, SCREEN_FLAT_IMG) != NULL );
150 
151  master_sflat = fors_image_load(
152  cpl_frameset_find(frames, MASTER_NORM_FLAT_IMG));
153  master_bias = fors_image_load(
154  cpl_frameset_find(frames, MASTER_BIAS));
155 
156  raw_sflat = fors_image_load(
157  cpl_frameset_find(frames, SCREEN_FLAT_IMG));
158  cpl_image_subtract_scalar(raw_sflat->data, 200); //Hard-coded bias level
159  //fors_subtract_bias(raw_sflat, master_bias); //Sizes are different now that trimming is done before
160 
161  /* Verify that relative error decreased */
162  test( fors_image_get_error_mean(master_sflat, NULL) /
163  fors_image_get_mean(master_sflat, NULL)
164  <
165  fors_image_get_error_mean(raw_sflat, NULL) /
166  fors_image_get_mean(raw_sflat, NULL));
167 
168  /* Verify normalization */
169  test_rel( fors_image_get_mean(master_sflat, NULL),
170  1.0, 0.01);
171 
172  /* Test QC values */
173  product_header =
174  cpl_propertylist_load(cpl_frame_get_filename(
175  cpl_frameset_find(frames,
176  MASTER_NORM_FLAT_IMG)),
177  0);
178  assure( product_header != NULL, return, NULL );
179 
180 
181  test_rel( cpl_propertylist_get_double(product_header,
182  "ESO QC FLAT EFF"),
183  fors_image_get_median(raw_sflat, NULL) / setting->exposure_time,
184  0.03 );
185 
186  /* QC.FLAT.PHN is the master flat photon noise in ADU.
187  But the master flat is normalized to one, so
188  multiply by the normalization factor */
189 /* %%%
190  test_rel( cpl_propertylist_get_double(product_header,
191  "ESO QC FLAT PHN"),
192  fors_image_get_stdev(master_sflat, NULL) *
193  fors_image_get_median(raw_sflat, NULL),
194  0.1 );
195 %%% */
196 
197 
198  /* CONAD */
199  test_rel( cpl_propertylist_get_double(product_header,
200  "ESO QC FLAT CONAD"),
201  cpl_propertylist_get_double(product_header,
202  FORS_PFITS_CONAD[0]),
203  /* Compare with propagated CONAD value */
204  0.1);
205 
206  test( cpl_propertylist_get_double(product_header,
207  "ESO QC FLAT CONADERR") <
208  0.1 * cpl_propertylist_get_double(product_header,
209  "ESO QC FLAT CONAD") );
210  }
211 
212  cleanup;
213  return;
214 }
215 
219 int main(void)
220 {
221  TEST_INIT;
222 
224 
225  TEST_END;
226 }
227 
fors_setting * fors_setting_new(const cpl_frame *raw)
Create setting from FITS header.
Definition: fors_setting.c:64
cpl_frame * create_master_bias(const char *filename, const char *tag, cpl_frame_group group)
Simulate master bias image.
#define assure(EXPR)
Definition: list.c:101
fors_image * fors_image_load(const cpl_frame *frame)
Load image.
Definition: fors_image.c:298
double fors_image_get_mean(const fors_image *image, double *dmean)
Get mean data value.
Definition: fors_image.c:970
int main(void)
Test of image module.
cpl_frame * create_screen_flat(const char *filename, const char *tag, cpl_frame_group group)
Simulate screen flat image.
void test_recipe_output(const cpl_frameset *frames, const char *const product_tags[], int n_prod, const char *main_product, const char *const qc[], int n_qc)
Test existence of recipe products.
Definition: test.c:428
static void test_img_screen_flat(void)
Test screen flat recipe.
double fors_image_get_median(const fors_image *image, double *dmedian)
Get median data value.
Definition: fors_image.c:987
void fors_parameterlist_set_defaults(cpl_parameterlist *parlist)
Set unset parameters to default value.
Definition: fors_utils.c:545
double fors_image_get_error_mean(const fors_image *image, double *dmean)
Get mean of error bars.
Definition: fors_image.c:1441