FORS Pipeline Reference Manual  4.12.5
fors_dark-test.c
1 /* $Id: fors_dark-test.c,v 1.6 2013-09-11 13:47:53 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-09-11 13:47:53 $
24  * $Revision: 1.6 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 #include <fors_dark_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_image_delete(&raw_dark); \
53  fors_image_delete(&master_dark); \
54  fors_image_delete(&master_bias); \
55  fors_setting_delete(&setting); \
56 } while(0)
57 
61 static void
62 test_dark(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_dark = NULL;
70  fors_image *master_bias = NULL;
71  fors_image *raw_dark = NULL;
72 
73  fors_setting *setting = NULL;
74 
75  /* Simulate data */
76  const char *dark_filename[] = {"dark_1.fits",
77  "dark_2.fits",
78  "dark_3.fits"};
79 
80  {
81  unsigned i;
82 
83  for (i = 0; i < sizeof(dark_filename)/sizeof(char *); i++) {
84  cpl_frameset_insert(frames,
85  create_dark(dark_filename[i],
86  DARK, CPL_FRAME_GROUP_RAW));
87  }
88  }
89 
90  setting = fors_setting_new(cpl_frameset_get_position(frames, 0));
91 
92  cpl_frameset_insert(frames,
93  create_master_bias("dark_master_bias.fits",
94  MASTER_BIAS, CPL_FRAME_GROUP_CALIB));
95 
96  fors_dark_define_parameters(parameters);
97  assure( !cpl_error_get_code(), return,
98  "Create parameters failed");
99 
101 
102  /* Call recipe */
103  fors_dark(frames, parameters);
104  assure( !cpl_error_get_code(), return,
105  "Execution error");
106 
107  /* Test results */
108  {
109  /* New and previous frames */
110  test( cpl_frameset_find(frames, MASTER_DARK) != NULL );
111  test( cpl_frameset_find(frames, MASTER_BIAS) != NULL );
112  test( cpl_frameset_find(frames, DARK) != NULL );
113 
114  master_dark = fors_image_load(
115  cpl_frameset_find(frames, MASTER_DARK));
116 
117  master_bias = fors_image_load(
118  cpl_frameset_find(frames, MASTER_BIAS));
119 
120  raw_dark = fors_image_load(
121  cpl_frameset_find(frames, DARK));
122 
123  /* Verify relation
124  master_dark = raw_dark - master_bias */
125  test_rel( fors_image_get_mean(master_dark, NULL),
126  fors_image_get_mean(raw_dark, NULL) -
127  fors_image_get_mean(master_bias, NULL) - 200, //Hardcoded overscan level
128  0.03);
129 
130  /* Verify that error decreased */
131  {
132  test( fors_image_get_error_mean(master_dark, NULL) /
133  (fors_image_get_mean(master_dark, NULL) +
134  fors_image_get_mean(master_bias, NULL) + 200) //Hardcoded overscan level
135  <
136  fors_image_get_error_mean(raw_dark, NULL) /
137  fors_image_get_mean(raw_dark, NULL));
138  }
139  }
140 
141  cleanup;
142  return;
143 }
144 
148 int main(void)
149 {
150  TEST_INIT;
151 
152  test_dark();
153 
154  TEST_END;
155 }
156 
fors_setting * fors_setting_new(const cpl_frame *raw)
Create setting from FITS header.
Definition: fors_setting.c:64
cpl_frame * create_dark(const char *filename, const char *tag, cpl_frame_group group)
Simulate dark image.
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.
static void test_dark(void)
Test dark recipe.
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