FORS Pipeline Reference Manual  5.0.9
fors_bias-test.c
1 /* $Id: fors_bias-test.c,v 1.9 2013-04-25 10:00:19 cgarcia 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: cgarcia $
23  * $Date: 2013-04-25 10:00:19 $
24  * $Revision: 1.9 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 #include <fors_bias_impl.h>
33 #include <fors_dfs.h>
34 #include <fors_utils.h>
35 
36 #include <test_simulate.h>
37 #include <test.h>
38 
39 #include <cpl.h>
40 
47 #undef cleanup
48 #define cleanup \
49 do { \
50  cpl_frameset_delete(frames); \
51  cpl_parameterlist_delete(parameters); \
52  fors_setting_delete(&setting); \
53  fors_image_delete(&raw_bias); \
54  fors_image_delete(&master_bias); \
55  cpl_propertylist_delete(product_header); \
56 } while(0)
57 
61 static void
62 test_bias(void)
63 {
64  /* Input */
65  cpl_frameset *frames = cpl_frameset_new();
66  cpl_parameterlist *parameters = cpl_parameterlist_new();
67 
68  /* Output */
69  fors_image *master_bias = NULL;
70  fors_image *raw_bias = NULL;
71  cpl_propertylist *product_header = NULL;
72 
73  fors_setting *setting = NULL;
74 
75  /* Simulate data */
76  const char *bias_filename[] = {"bias_1.fits",
77  "bias_2.fits",
78  "bias_3.fits",
79  "bias_4.fits",
80  "bias_5.fits"};
81 
82  {
83  unsigned i;
84 
85  for (i = 0; i < sizeof(bias_filename)/sizeof(char *); i++) {
86  cpl_frameset_insert(frames,
87  create_bias(bias_filename[i],
88  BIAS, CPL_FRAME_GROUP_RAW));
89  }
90  }
91 
92  setting = fors_setting_new(cpl_frameset_get_position(frames, 0));
93 
94  fors_bias_define_parameters(parameters);
95  assure( !cpl_error_get_code(), return,
96  "Create parameters failed");
97 
99 
100  /* Call recipe */
101  fors_bias(frames, parameters);
102  assure( !cpl_error_get_code(), return,
103  "Execution error");
104 
105  /* Test existence of QC + products */
106  const char *const product_tags[] = {MASTER_BIAS};
107  const char *const qc[] =
108  {"QC BIAS STRUCT", "QC BIAS LEVEL", "QC RON", "QC BIAS FPN",
109  "QC MBIAS LEVEL",
110  "QC MBIAS RONEXP", "QC MBIAS NOISE", "QC MBIAS NRATIO", "QC MBIAS STRUCT"};
111  test_recipe_output(frames,
112  product_tags, sizeof product_tags / sizeof *product_tags,
113  MASTER_BIAS,
114  qc, sizeof qc / sizeof *qc);
115 
116  /* Test results */
117  {
118  /* New and previous frames */
119  test( cpl_frameset_find(frames, BIAS) != NULL );
120 
121  master_bias = fors_image_load(
122  cpl_frameset_find(frames, MASTER_BIAS));
123 
124  raw_bias = fors_image_load(
125  cpl_frameset_find(frames, BIAS));
126 
127  /* Verify that relative error decreased */
128  test( fors_image_get_error_mean(master_bias, NULL) /
129  fors_image_get_mean(master_bias, NULL)
130  <
131  fors_image_get_error_mean(raw_bias, NULL) /
132  fors_image_get_mean(raw_bias, NULL));
133 
134 
135  /* QC numbers */
136  product_header =
137  cpl_propertylist_load(cpl_frame_get_filename(
138  cpl_frameset_find(frames,
139  MASTER_BIAS)),
140  0);
141  assure( product_header != NULL, return, NULL );
142 
143  test_abs( cpl_propertylist_get_double(product_header,
144  "ESO QC BIAS LEVEL"),
145  fors_image_get_median(raw_bias, NULL), 0.01 );
146 
147  test_abs( cpl_propertylist_get_double(product_header,
148  "ESO QC MBIAS LEVEL"),
149  fors_image_get_median(master_bias, NULL), 0.01 );
150 
151  test_rel( cpl_propertylist_get_double(product_header,
152  "ESO QC RON"),
153  fors_image_get_stdev(raw_bias, NULL), 0.10 );
154 
155  /* fixed pattern and structure should be smaller than RON */
156  test_abs( cpl_propertylist_get_double(product_header,"ESO QC BIAS FPN"),
157  cpl_propertylist_get_double(product_header,"ESO QC RON"),
158  cpl_propertylist_get_double(product_header,"ESO QC RON"));
159 
160  test_abs( cpl_propertylist_get_double(product_header,
161  "ESO QC BIAS STRUCT"),
162  0, 0.01*fors_image_get_median(master_bias, NULL));
163  }
164 
165  cleanup;
166  return;
167 }
168 
172 int main(void)
173 {
174  TEST_INIT;
175 
176  test_bias();
177 
178  TEST_END;
179 }
180 
cpl_frame * create_bias(const char *filename, const char *tag, cpl_frame_group group)
Simulate bias image.
fors_setting * fors_setting_new(const cpl_frame *raw)
Create setting from FITS header.
Definition: fors_setting.c:64
double fors_image_get_stdev(const fors_image *image, double *dstdev)
Get empirical stdev of data.
Definition: fors_image.c:1373
#define assure(EXPR)
Definition: list.c:101
fors_image * fors_image_load(const cpl_frame *frame)
Load image.
Definition: fors_image.c:291
double fors_image_get_mean(const fors_image *image, double *dmean)
Get mean data value.
Definition: fors_image.c:966
int main(void)
Test of image module.
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
double fors_image_get_median(const fors_image *image, double *dmedian)
Get median data value.
Definition: fors_image.c:983
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:1437
static void test_bias(void)
Test bias recipe.