FORS Pipeline Reference Manual  5.0.9
fors_img_sky_flat-test.c
1 /* $Id: fors_img_sky_flat-test.c,v 1.8 2013-09-11 10:04:21 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 10:04:21 $
24  * $Revision: 1.8 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 #include <fors_img_sky_flat_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_sflat); \
53  fors_image_delete(&master_sflat); \
54  fors_image_delete(&master_bias); \
55  fors_setting_delete(&setting); \
56 } while(0)
57 
61 static void
63 {
64  /* Input */
65  cpl_frameset *frames = cpl_frameset_new();
66  cpl_parameterlist *parameters = cpl_parameterlist_new();
67 
68  /* Output */
69  fors_image *raw_sflat = NULL;
70  fors_image *master_sflat = NULL;
71  fors_image *master_bias = NULL;
72 
73  fors_setting *setting = NULL;
74 
75  /* Simulate data */
76  const char *sky_flat_filename[] = {"img_sky_flat_1.fits",
77  "img_sky_flat_2.fits",
78  "img_sky_flat_3.fits"};
79 
80  double sky_flat_exptime[] = {1, 2, 5};
81  {
82  unsigned i;
83 
84  for (i = 0; i < sizeof(sky_flat_filename)/sizeof(char *); i++) {
85  cpl_frame *sflat = create_sky_flat(sky_flat_filename[i],
86  SKY_FLAT_IMG, CPL_FRAME_GROUP_RAW,
87  sky_flat_exptime[i]);
88 
89  cpl_frame_set_group(sflat, CPL_FRAME_GROUP_RAW);
90  cpl_frameset_insert(frames, sflat);
91  }
92  }
93 
94  setting = fors_setting_new(cpl_frameset_get_position(frames, 0));
95 
96  cpl_frameset_insert(frames,
97  create_master_bias("img_sky_flat_master_bias.fits",
98  MASTER_BIAS, CPL_FRAME_GROUP_CALIB));
99 
100  fors_img_sky_flat_define_parameters(parameters);
101  assure( !cpl_error_get_code(), return,
102  "Create parameters failed");
103 
105 
106  /* Call recipe */
107  fors_img_sky_flat(frames, parameters);
108  assure( !cpl_error_get_code(), return,
109  "Execution error");
110 
111  /* Test results */
112 
113  /* Existence */
114  const char *const product_tags[] = {MASTER_SKY_FLAT_IMG};
115  const char *const qc[] = {"QC OVEREXPO"};
116  test_recipe_output(frames,
117  product_tags, sizeof product_tags / sizeof *product_tags,
118  MASTER_SKY_FLAT_IMG,
119  qc, sizeof qc / sizeof *qc);
120 
121  /* Numbers */
122  {
123  /* New and previous frames */
124  test( cpl_frameset_find(frames, MASTER_BIAS) != NULL );
125  test( cpl_frameset_find(frames, SKY_FLAT_IMG) != NULL );
126 
127  master_sflat = fors_image_load(
128  cpl_frameset_find(frames, MASTER_SKY_FLAT_IMG));
129 
130  master_bias = fors_image_load(
131  cpl_frameset_find(frames, MASTER_BIAS));
132 
133  raw_sflat = fors_image_load(
134  cpl_frameset_find(frames, SKY_FLAT_IMG));
135 
136  /* Verify that relative error decreased */
137  test( fors_image_get_error_mean(master_sflat, NULL) /
138  fors_image_get_mean(master_sflat, NULL)
139  <
140  fors_image_get_error_mean(raw_sflat, NULL) /
141  fors_image_get_mean(raw_sflat, NULL));
142 
143  /* Verify normalization */
144  test_rel( fors_image_get_mean(master_sflat, NULL),
145  1.0, 0.01);
146  }
147 
148  cleanup;
149  return;
150 }
151 
155 int main(void)
156 {
157  TEST_INIT;
158 
160 
161  TEST_END;
162 }
163 
fors_setting * fors_setting_new(const cpl_frame *raw)
Create setting from FITS header.
Definition: fors_setting.c:64
int main(void)
Test of image module.
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:291
double fors_image_get_mean(const fors_image *image, double *dmean)
Get mean data value.
Definition: fors_image.c:966
cpl_frame * create_sky_flat(const char *filename, const char *tag, cpl_frame_group group, double exptime)
Simulate sky 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
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_img_sky_flat(void)
Test sky flat recipe.