37 static int fors_subtract_sky_lss_create(cpl_plugin *);
38 static int fors_subtract_sky_lss_exec(cpl_plugin *);
39 static int fors_subtract_sky_lss_destroy(cpl_plugin *);
40 static int fors_subtract_sky_lss(cpl_parameterlist *, cpl_frameset *);
42 static char fors_subtract_sky_lss_description[] =
43 "This recipe is used to subtract the sky from wavelength calibrated\n"
44 "scientific spectra produced by the recipe fors_resample. A simple median\n"
45 "signal level is subtracted from each image column.\n"
46 "In the table below the MXU acronym can be read alternatively as MOS\n"
47 "and LSS, depending on the instrument mode of the input data. The acronym\n"
48 "SCI may be read STD in case of standard stars observations.\n"
49 "Note that only LSS or LSS-like MOS/MXU data are to be processed by this\n"
52 " DO category: Type: Explanation: Required:\n"
53 " MAPPED_ALL_SCI_MXU Raw Scientific exposure Y\n\n"
55 " DO category: Data type: Explanation:\n"
56 " MAPPED_SCI_MXU FITS image Rectified scientific spectra\n"
57 " MAPPED_SKY_SCI_MXU FITS image Rectified sky spectra\n\n";
59 #define fors_subtract_sky_lss_exit(message) \
61 if ((const char *)message != NULL) cpl_msg_error(recipe, message); \
62 cpl_image_delete(skymap); \
63 cpl_image_delete(sky); \
64 cpl_image_delete(spectra); \
65 cpl_propertylist_delete(header); \
66 cpl_msg_indent_less(); \
71 #define fors_subtract_sky_lss_exit_memcheck(message) \
73 if ((const char *)message != NULL) cpl_msg_info(recipe, message); \
74 cpl_image_delete(skymap); \
75 cpl_image_delete(sky); \
76 cpl_image_delete(spectra); \
77 cpl_propertylist_delete(header); \
78 cpl_msg_indent_less(); \
96 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe );
97 cpl_plugin *plugin = &recipe->interface;
99 cpl_plugin_init(plugin,
102 CPL_PLUGIN_TYPE_RECIPE,
103 "fors_subtract_sky_lss",
104 "Subtract sky from calibrated long slit exposure",
105 fors_subtract_sky_lss_description,
108 "This file is currently part of the FORS Instrument Pipeline\n"
109 "Copyright (C) 2002-2010 European Southern Observatory\n\n"
110 "This program is free software; you can redistribute it and/or modify\n"
111 "it under the terms of the GNU General Public License as published by\n"
112 "the Free Software Foundation; either version 2 of the License, or\n"
113 "(at your option) any later version.\n\n"
114 "This program is distributed in the hope that it will be useful,\n"
115 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
116 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
117 "GNU General Public License for more details.\n\n"
118 "You should have received a copy of the GNU General Public License\n"
119 "along with this program; if not, write to the Free Software Foundation,\n"
120 "Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n",
121 fors_subtract_sky_lss_create,
122 fors_subtract_sky_lss_exec,
123 fors_subtract_sky_lss_destroy);
125 cpl_pluginlist_append(list, plugin);
141 static int fors_subtract_sky_lss_create(cpl_plugin *plugin)
152 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
153 recipe = (cpl_recipe *)plugin;
161 recipe->parameters = cpl_parameterlist_new();
175 static int fors_subtract_sky_lss_exec(cpl_plugin *plugin)
179 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
180 recipe = (cpl_recipe *)plugin;
184 return fors_subtract_sky_lss(recipe->parameters, recipe->frames);
196 static int fors_subtract_sky_lss_destroy(cpl_plugin *plugin)
200 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
201 recipe = (cpl_recipe *)plugin;
205 cpl_parameterlist_delete(recipe->parameters);
220 static int fors_subtract_sky_lss(cpl_parameterlist *parlist,
221 cpl_frameset *frameset)
224 const char *recipe =
"fors_subtract_sky_lss";
235 cpl_image *spectra = NULL;
236 cpl_image *skymap = NULL;
237 cpl_image *sky = NULL;
238 cpl_table *maskslits = NULL;
240 cpl_propertylist *header = NULL;
247 char *instrume = NULL;
248 const char *mapped_science_tag;
249 const char *mapped_science_sky_tag;
250 const char *mapped_sky_tag;
252 int treat_as_lss = 0;
262 snprintf(version, 80,
"%s-%s", PACKAGE, PACKAGE_VERSION);
264 cpl_msg_set_indentation(2);
275 cpl_msg_indent_less();
276 cpl_msg_info(recipe,
"Check input set-of-frames:");
277 cpl_msg_indent_more();
279 mxu = cpl_frameset_count_tags(frameset,
"MAPPED_ALL_SCI_MXU");
280 mos = cpl_frameset_count_tags(frameset,
"MAPPED_ALL_SCI_MOS");
281 lss = cpl_frameset_count_tags(frameset,
"MAPPED_ALL_SCI_LSS");
284 if (mxu + mos + lss == 0) {
285 mxu = cpl_frameset_count_tags(frameset,
"MAPPED_ALL_STD_MXU");
286 mos = cpl_frameset_count_tags(frameset,
"MAPPED_ALL_STD_MOS");
287 lss = cpl_frameset_count_tags(frameset,
"MAPPED_ALL_STD_LSS");
291 if (mxu + mos + lss == 0)
292 fors_subtract_sky_lss_exit(
"Missing input scientific frame");
294 nscience = mxu + mos + lss;
297 fors_subtract_sky_lss_exit(
"More than one scientific frame in input");
301 cpl_msg_info(recipe,
"MXU data found");
302 mapped_science_tag =
"MAPPED_STD_MXU";
303 mapped_science_sky_tag =
"MAPPED_ALL_STD_MXU";
304 mapped_sky_tag =
"MAPPED_SKY_STD_MXU";
307 cpl_msg_info(recipe,
"MXU data found");
308 mapped_science_tag =
"MAPPED_SCI_MXU";
309 mapped_science_sky_tag =
"MAPPED_ALL_SCI_MXU";
310 mapped_sky_tag =
"MAPPED_SKY_SCI_MXU";
316 cpl_msg_info(recipe,
"LSS data found");
317 mapped_science_tag =
"MAPPED_STD_LSS";
318 mapped_science_sky_tag =
"MAPPED_ALL_STD_LSS";
319 mapped_sky_tag =
"MAPPED_SKY_STD_LSS";
322 cpl_msg_info(recipe,
"LSS data found");
323 mapped_science_tag =
"MAPPED_SCI_LSS";
324 mapped_science_sky_tag =
"MAPPED_ALL_SCI_LSS";
325 mapped_sky_tag =
"MAPPED_SKY_SCI_LSS";
331 cpl_msg_info(recipe,
"MOS data found");
332 mapped_science_tag =
"MAPPED_STD_MOS";
333 mapped_science_sky_tag =
"MAPPED_ALL_STD_MOS";
334 mapped_sky_tag =
"MAPPED_SKY_STD_MOS";
337 cpl_msg_info(recipe,
"MOS data found");
338 mapped_science_tag =
"MAPPED_SCI_MOS";
339 mapped_science_sky_tag =
"MAPPED_ALL_SCI_MOS";
340 mapped_sky_tag =
"MAPPED_SKY_SCI_MOS";
348 cpl_msg_info(recipe,
"Load mapped scientific exposure...");
349 cpl_msg_indent_more();
352 CPL_TYPE_FLOAT, 0, 0);
355 fors_subtract_sky_lss_exit(
"Cannot load input frame");
360 fors_subtract_sky_lss_exit(
"Cannot load input frame header");
362 instrume = (
char *)cpl_propertylist_get_string(header,
"INSTRUME");
363 if (instrume == NULL)
364 fors_subtract_sky_lss_exit(
"Missing keyword INSTRUME in scientific header");
365 instrume = cpl_strdup(instrume);
367 if (instrume[4] ==
'1')
368 snprintf(version, 80,
"%s/%s",
"fors1", VERSION);
369 if (instrume[4] ==
'2')
370 snprintf(version, 80,
"%s/%s",
"fors2", VERSION);
372 cpl_free(instrume); instrume = NULL;
374 cpl_msg_indent_less();
377 int nslits_out_det = 0;
389 treat_as_lss = fors_mos_is_lss_like(maskslits, nslits_out_det);
391 cpl_table_delete(maskslits); maskslits = NULL;
394 cpl_msg_info(recipe,
"All MOS slits have the same offset: %.2f\n"
395 "The LSS data reduction strategy is applied.",
398 fors_subtract_sky_lss_exit(
"This recipe can only be used "
399 "with LSS-like data");
402 nx = cpl_image_get_size_x(spectra);
403 ny = cpl_image_get_size_y(spectra);
405 skymap = cpl_image_new(nx, ny, CPL_TYPE_FLOAT);
406 sky = cpl_image_collapse_median_create(spectra, 0, 0, 1);
408 data = cpl_image_get_data(skymap);
410 for (i = 0; i < ny; i++) {
411 sdata = cpl_image_get_data(sky);
412 for (j = 0; j < nx; j++) {
417 cpl_image_delete(sky); sky = NULL;
418 cpl_image_subtract(spectra, skymap);
421 parlist, recipe, version))
422 fors_subtract_sky_lss_exit(NULL);
424 cpl_image_delete(skymap); skymap = NULL;
427 parlist, recipe, version))
428 fors_subtract_sky_lss_exit(NULL);
430 cpl_image_delete(spectra); spectra = NULL;
432 cpl_propertylist_delete(header); header = NULL;
434 if (cpl_error_get_code()) {
435 cpl_msg_error(cpl_error_get_where(),
"%s", cpl_error_get_message());
436 fors_subtract_sky_lss_exit(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.
cpl_table * mos_load_slits_fors_mxu(cpl_propertylist *header)
Create slit location table from FITS header of FORS2-MXU data.
cpl_table * mos_load_slits_fors_mos(cpl_propertylist *header, int *nslits_out_det)
Create slit location table from FITS header of FORS1/2 MOS data.
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.