37 static int fors_flatfield_create(cpl_plugin *);
38 static int fors_flatfield_exec(cpl_plugin *);
39 static int fors_flatfield_destroy(cpl_plugin *);
40 static int fors_flatfield(cpl_parameterlist *, cpl_frameset *);
42 static char fors_flatfield_description[] =
43 "This recipe is used to divide the input frame by the normalised flat\n"
44 "field frame produced by recipe fors_normalise_flat. The input frame must\n"
45 "be already bias subtracted (e.g., by recipe fors_remove_bias).\n"
46 "In the table below the MXU acronym can be alternatively read as MOS and\n"
49 " DO category: Type: Explanation: Required:\n"
50 " SCIENCE_UNBIAS_MXU\n"
51 " or STANDARD_UNBIAS_MXU Raw Bias subtracted frame Y\n"
52 " MASTER_NORM_FLAT_MXU Calib Normalised flat frame Y\n\n"
54 " DO category: Data type: Explanation:\n"
55 " SCIENCE_UNFLAT_MXU\n"
56 " or STANDARD_UNFLAT_MXU FITS image Flat field corrected frame\n\n";
58 #define fors_flatfield_exit(message) \
60 if ((const char *)message != NULL) cpl_msg_error(recipe, message); \
61 cpl_image_delete(raw_image); \
62 cpl_image_delete(norm_flat); \
63 cpl_propertylist_delete(header); \
64 cpl_msg_indent_less(); \
68 #define fors_flatfield_exit_memcheck(message) \
70 if ((const char *)message != NULL) cpl_msg_info(recipe, message); \
71 printf("free raw_image (%p)\n", raw_image); \
72 cpl_image_delete(raw_image); \
73 printf("free norm_flat (%p)\n", norm_flat); \
74 cpl_image_delete(norm_flat); \
75 printf("free header (%p)\n", header); \
76 cpl_propertylist_delete(header); \
77 cpl_msg_indent_less(); \
95 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe );
96 cpl_plugin *plugin = &recipe->interface;
98 cpl_plugin_init(plugin,
101 CPL_PLUGIN_TYPE_RECIPE,
103 "Flat field correction of input frame",
104 fors_flatfield_description,
107 "This file is currently part of the FORS Instrument Pipeline\n"
108 "Copyright (C) 2002-2010 European Southern Observatory\n\n"
109 "This program is free software; you can redistribute it and/or modify\n"
110 "it under the terms of the GNU General Public License as published by\n"
111 "the Free Software Foundation; either version 2 of the License, or\n"
112 "(at your option) any later version.\n\n"
113 "This program is distributed in the hope that it will be useful,\n"
114 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
115 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
116 "GNU General Public License for more details.\n\n"
117 "You should have received a copy of the GNU General Public License\n"
118 "along with this program; if not, write to the Free Software Foundation,\n"
119 "Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n",
120 fors_flatfield_create,
122 fors_flatfield_destroy);
124 cpl_pluginlist_append(list, plugin);
140 static int fors_flatfield_create(cpl_plugin *plugin)
151 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
152 recipe = (cpl_recipe *)plugin;
160 recipe->parameters = cpl_parameterlist_new();
174 static int fors_flatfield_exec(cpl_plugin *plugin)
178 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
179 recipe = (cpl_recipe *)plugin;
183 return fors_flatfield(recipe->parameters, recipe->frames);
195 static int fors_flatfield_destroy(cpl_plugin *plugin)
199 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
200 recipe = (cpl_recipe *)plugin;
204 cpl_parameterlist_delete(recipe->parameters);
219 static int fors_flatfield(cpl_parameterlist *parlist, cpl_frameset *frameset)
222 const char *recipe =
"fors_flatfield";
229 cpl_image *raw_image = NULL;
230 cpl_image *norm_flat = NULL;
231 cpl_propertylist *header = NULL;
238 const char *norm_flat_tag;
239 const char *raw_image_tag;
240 const char *pro_image_tag;
241 char *instrume = NULL;
251 cpl_msg_set_indentation(2);
254 cpl_msg_info(recipe,
"Check input set-of-frames:");
255 cpl_msg_indent_more();
257 nframe = science_mxu = cpl_frameset_count_tags(frameset,
258 "SCIENCE_UNBIAS_MXU");
259 nframe += science_mos = cpl_frameset_count_tags(frameset,
260 "SCIENCE_UNBIAS_MOS");
261 nframe += science_lss = cpl_frameset_count_tags(frameset,
262 "SCIENCE_UNBIAS_LSS");
263 nframe += standard_mxu = cpl_frameset_count_tags(frameset,
264 "STANDARD_UNBIAS_MXU");
265 nframe += standard_mos = cpl_frameset_count_tags(frameset,
266 "STANDARD_UNBIAS_MOS");
267 nframe += standard_lss = cpl_frameset_count_tags(frameset,
268 "STANDARD_UNBIAS_LSS");
271 fors_flatfield_exit(
"Missing required input scientific frame");
274 cpl_msg_error(recipe,
"Too many input scientific frames (%d > 1)",
276 fors_flatfield_exit(NULL);
280 norm_flat_tag =
"MASTER_NORM_FLAT_MXU";
281 pro_image_tag =
"SCIENCE_UNFLAT_MXU";
282 raw_image_tag =
"SCIENCE_UNBIAS_MXU";
284 else if (science_mos) {
285 norm_flat_tag =
"MASTER_NORM_FLAT_MOS";
286 pro_image_tag =
"SCIENCE_UNFLAT_MOS";
287 raw_image_tag =
"SCIENCE_UNBIAS_MOS";
289 else if (science_lss) {
290 norm_flat_tag =
"MASTER_NORM_FLAT_LSS";
291 pro_image_tag =
"SCIENCE_UNFLAT_LSS";
292 raw_image_tag =
"SCIENCE_UNBIAS_LSS";
294 else if (standard_mxu) {
295 norm_flat_tag =
"MASTER_NORM_FLAT_MXU";
296 pro_image_tag =
"STANDARD_UNFLAT_MXU";
297 raw_image_tag =
"STANDARD_UNBIAS_MXU";
299 else if (standard_mos) {
300 norm_flat_tag =
"MASTER_NORM_FLAT_MOS";
301 pro_image_tag =
"STANDARD_UNFLAT_MOS";
302 raw_image_tag =
"STANDARD_UNBIAS_MOS";
304 else if (standard_lss) {
305 norm_flat_tag =
"MASTER_NORM_FLAT_LSS";
306 pro_image_tag =
"STANDARD_UNFLAT_LSS";
307 raw_image_tag =
"STANDARD_UNBIAS_LSS";
310 nflat = cpl_frameset_count_tags(frameset, norm_flat_tag);
312 cpl_msg_error(recipe,
"Missing required input: %s", norm_flat_tag);
313 fors_flatfield_exit(NULL);
316 cpl_msg_error(recipe,
"Too many in input (%d > 1): %s",
317 nflat, norm_flat_tag);
318 fors_flatfield_exit(NULL);
322 cpl_msg_warning(cpl_func,
"Input frames are not from the same grism");
325 cpl_msg_warning(cpl_func,
"Input frames are not from the same filter");
328 cpl_msg_warning(cpl_func,
"Input frames are not from the same chip");
332 if (header == NULL) {
333 cpl_msg_error(recipe,
"Cannot load header of %s frame", raw_image_tag);
334 fors_flatfield_exit(NULL);
337 instrume = (
char *)cpl_propertylist_get_string(header,
"INSTRUME");
338 if (instrume == NULL) {
339 cpl_msg_error(recipe,
"Missing keyword INSTRUME in %s header",
341 fors_flatfield_exit(NULL);
344 if (instrume[4] ==
'1')
345 snprintf(version, 80,
"%s/%s",
"fors1", VERSION);
346 if (instrume[4] ==
'2')
347 snprintf(version, 80,
"%s/%s",
"fors2", VERSION);
349 cpl_msg_indent_less();
350 cpl_msg_info(recipe,
"Load input frames:");
351 cpl_msg_indent_more();
353 norm_flat =
dfs_load_image(frameset, norm_flat_tag, CPL_TYPE_FLOAT, 0, 1);
354 if (norm_flat == NULL)
355 fors_flatfield_exit(
"Cannot load normalised flat field");
357 raw_image =
dfs_load_image(frameset, raw_image_tag, CPL_TYPE_FLOAT, 0, 0);
358 if (raw_image == NULL) {
359 cpl_msg_error(recipe,
"Cannot load %s frame", raw_image_tag);
360 fors_flatfield_exit(NULL);
363 cpl_msg_indent_less();
364 cpl_msg_info(recipe,
"Divide input %s by flat field...", raw_image_tag);
365 cpl_msg_indent_more();
367 if (cpl_image_divide(raw_image, norm_flat) != CPL_ERROR_NONE) {
368 cpl_msg_error(recipe,
"Failure of flat field correction: %s",
369 cpl_error_get_message());
370 fors_flatfield_exit(NULL);
372 cpl_image_delete(norm_flat); norm_flat = NULL;
374 cpl_msg_indent_less();
377 header, parlist, recipe, version))
378 fors_flatfield_exit(NULL);
380 cpl_propertylist_delete(header); header = NULL;
381 cpl_image_delete(raw_image); raw_image = NULL;
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
cpl_image * dfs_load_image(cpl_frameset *frameset, const char *category, cpl_type type, int ext, int calib)
Loading image data of given category.
cpl_propertylist * dfs_load_header(cpl_frameset *frameset, const char *category, int ext)
Loading header associated to data of given category.
int dfs_equal_keyword(cpl_frameset *frameset, const char *keyword)
Saving table data of given category.
int dfs_save_image(cpl_frameset *frameset, const cpl_image *image, const char *category, cpl_propertylist *header, const cpl_parameterlist *parlist, const char *recipename, const char *version)
Saving image data of given category.