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 (message) 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 (message) 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;
264 snprintf(version, 80,
"%s-%s", PACKAGE, PACKAGE_VERSION);
266 cpl_msg_set_indentation(2);
277 cpl_msg_indent_less();
278 cpl_msg_info(recipe,
"Check input set-of-frames:");
279 cpl_msg_indent_more();
281 mxu = cpl_frameset_count_tags(frameset,
"MAPPED_ALL_SCI_MXU");
282 mos = cpl_frameset_count_tags(frameset,
"MAPPED_ALL_SCI_MOS");
283 lss = cpl_frameset_count_tags(frameset,
"MAPPED_ALL_SCI_LSS");
286 if (mxu + mos + lss == 0) {
287 mxu = cpl_frameset_count_tags(frameset,
"MAPPED_ALL_STD_MXU");
288 mos = cpl_frameset_count_tags(frameset,
"MAPPED_ALL_STD_MOS");
289 lss = cpl_frameset_count_tags(frameset,
"MAPPED_ALL_STD_LSS");
293 if (mxu + mos + lss == 0)
294 fors_subtract_sky_lss_exit(
"Missing input scientific frame");
296 nscience = mxu + mos + lss;
299 fors_subtract_sky_lss_exit(
"More than one scientific frame in input");
303 cpl_msg_info(recipe,
"MXU data found");
304 mapped_science_tag =
"MAPPED_STD_MXU";
305 mapped_science_sky_tag =
"MAPPED_ALL_STD_MXU";
306 mapped_sky_tag =
"MAPPED_SKY_STD_MXU";
309 cpl_msg_info(recipe,
"MXU data found");
310 mapped_science_tag =
"MAPPED_SCI_MXU";
311 mapped_science_sky_tag =
"MAPPED_ALL_SCI_MXU";
312 mapped_sky_tag =
"MAPPED_SKY_SCI_MXU";
318 cpl_msg_info(recipe,
"LSS data found");
319 mapped_science_tag =
"MAPPED_STD_LSS";
320 mapped_science_sky_tag =
"MAPPED_ALL_STD_LSS";
321 mapped_sky_tag =
"MAPPED_SKY_STD_LSS";
324 cpl_msg_info(recipe,
"LSS data found");
325 mapped_science_tag =
"MAPPED_SCI_LSS";
326 mapped_science_sky_tag =
"MAPPED_ALL_SCI_LSS";
327 mapped_sky_tag =
"MAPPED_SKY_SCI_LSS";
333 cpl_msg_info(recipe,
"MOS data found");
334 mapped_science_tag =
"MAPPED_STD_MOS";
335 mapped_science_sky_tag =
"MAPPED_ALL_STD_MOS";
336 mapped_sky_tag =
"MAPPED_SKY_STD_MOS";
339 cpl_msg_info(recipe,
"MOS data found");
340 mapped_science_tag =
"MAPPED_SCI_MOS";
341 mapped_science_sky_tag =
"MAPPED_ALL_SCI_MOS";
342 mapped_sky_tag =
"MAPPED_SKY_SCI_MOS";
350 cpl_msg_info(recipe,
"Load mapped scientific exposure...");
351 cpl_msg_indent_more();
354 CPL_TYPE_FLOAT, 0, 0);
357 fors_subtract_sky_lss_exit(
"Cannot load input frame");
362 fors_subtract_sky_lss_exit(
"Cannot load input frame header");
364 instrume = (
char *)cpl_propertylist_get_string(header,
"INSTRUME");
365 if (instrume == NULL)
366 fors_subtract_sky_lss_exit(
"Missing keyword INSTRUME in scientific header");
367 instrume = cpl_strdup(instrume);
369 if (instrume[4] ==
'1')
370 snprintf(version, 80,
"%s/%s",
"fors1", VERSION);
371 if (instrume[4] ==
'2')
372 snprintf(version, 80,
"%s/%s",
"fors2", VERSION);
374 cpl_free(instrume); instrume = NULL;
376 cpl_msg_indent_less();
379 int nslits_out_det = 0;
391 treat_as_lss = fors_mos_is_lss_like(maskslits, nslits_out_det);
393 cpl_table_delete(maskslits); maskslits = NULL;
396 cpl_msg_info(recipe,
"All MOS slits have the same offset: %.2f\n"
397 "The LSS data reduction strategy is applied.",
400 fors_subtract_sky_lss_exit(
"This recipe can only be used "
401 "with LSS-like data");
404 nx = cpl_image_get_size_x(spectra);
405 ny = cpl_image_get_size_y(spectra);
407 skymap = cpl_image_new(nx, ny, CPL_TYPE_FLOAT);
408 sky = cpl_image_collapse_median_create(spectra, 0, 0, 1);
410 data = cpl_image_get_data(skymap);
412 for (i = 0; i < ny; i++) {
413 sdata = cpl_image_get_data(sky);
414 for (j = 0; j < nx; j++) {
419 cpl_image_delete(sky); sky = NULL;
420 cpl_image_subtract(spectra, skymap);
423 parlist, recipe, version))
424 fors_subtract_sky_lss_exit(NULL);
426 cpl_image_delete(skymap); skymap = NULL;
429 parlist, recipe, version))
430 fors_subtract_sky_lss_exit(NULL);
432 cpl_image_delete(spectra); spectra = NULL;
434 cpl_propertylist_delete(header); header = NULL;
436 if (cpl_error_get_code()) {
437 cpl_msg_error(cpl_error_get_where(),
"%s", cpl_error_get_message());
438 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.