37 static int fors_detect_objects_create(cpl_plugin *);
38 static int fors_detect_objects_exec(cpl_plugin *);
39 static int fors_detect_objects_destroy(cpl_plugin *);
40 static int fors_detect_objects(cpl_parameterlist *, cpl_frameset *);
42 static char fors_detect_objects_description[] =
43 "This recipe is used to detect scientific objects spectra on a resampled\n"
44 "image produced with recipe fors_resample. Please refer to the FORS\n"
45 "Pipeline User's Manual for more details on object detection.\n"
47 "In the table below the MXU acronym can be alternatively read as MOS and\n"
48 "LSS, and SCI as STD.\n\n"
50 " DO category: Type: Explanation: Required:\n"
51 " MAPPED_SCI_MXU Calib Resampled slit spectra Y\n"
52 " SLIT_LOCATION_MXU Calib Slit location on image Y\n"
54 " DO category: Data type: Explanation:\n"
55 " OBJECT_TABLE_SCI_MXU FITS table Object positions in slit spectra\n\n";
57 #define fors_detect_objects_exit(message) \
59 if (message) cpl_msg_error(recipe, message); \
60 cpl_image_delete(dummy); \
61 cpl_image_delete(mapped); \
62 cpl_table_delete(slits); \
63 cpl_propertylist_delete(header); \
64 cpl_msg_indent_less(); \
68 #define fors_detect_objects_exit_memcheck(message) \
70 if (message) cpl_msg_info(recipe, message); \
71 printf("free dummy (%p)\n", dummy); \
72 cpl_image_delete(dummy); \
73 printf("free mapped (%p)\n", mapped); \
74 cpl_image_delete(mapped); \
75 printf("free slits (%p)\n", slits); \
76 cpl_table_delete(slits); \
77 printf("free header (%p)\n", header); \
78 cpl_propertylist_delete(header); \
79 cpl_msg_indent_less(); \
97 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe );
98 cpl_plugin *plugin = &recipe->interface;
100 cpl_plugin_init(plugin,
103 CPL_PLUGIN_TYPE_RECIPE,
104 "fors_detect_objects",
105 "Detect objects in slit spectra",
106 fors_detect_objects_description,
109 "This file is currently part of the FORS Instrument Pipeline\n"
110 "Copyright (C) 2002-2010 European Southern Observatory\n\n"
111 "This program is free software; you can redistribute it and/or modify\n"
112 "it under the terms of the GNU General Public License as published by\n"
113 "the Free Software Foundation; either version 2 of the License, or\n"
114 "(at your option) any later version.\n\n"
115 "This program is distributed in the hope that it will be useful,\n"
116 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
117 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
118 "GNU General Public License for more details.\n\n"
119 "You should have received a copy of the GNU General Public License\n"
120 "along with this program; if not, write to the Free Software Foundation,\n"
121 "Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n",
122 fors_detect_objects_create,
123 fors_detect_objects_exec,
124 fors_detect_objects_destroy);
126 cpl_pluginlist_append(list, plugin);
142 static int fors_detect_objects_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();
166 p = cpl_parameter_new_value(
"fors.fors_detect_objects.slit_margin",
168 "Number of pixels to exclude at each slit "
169 "in object detection and extraction",
170 "fors.fors_detect_objects",
172 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"slit_margin");
173 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
174 cpl_parameterlist_append(recipe->parameters, p);
180 p = cpl_parameter_new_value(
"fors.fors_detect_objects.ext_radius",
182 "Maximum extraction radius for detected "
184 "fors.fors_detect_objects",
186 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ext_radius");
187 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
188 cpl_parameterlist_append(recipe->parameters, p);
194 p = cpl_parameter_new_value(
"fors.fors_detect_objects.cont_radius",
196 "Minimum distance at which two objects "
197 "of equal luminosity do not contaminate "
198 "each other (pixel)",
199 "fors.fors_detect_objects",
201 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"cont_radius");
202 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
203 cpl_parameterlist_append(recipe->parameters, p);
217 static int fors_detect_objects_exec(cpl_plugin *plugin)
221 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
222 recipe = (cpl_recipe *)plugin;
226 return fors_detect_objects(recipe->parameters, recipe->frames);
238 static int fors_detect_objects_destroy(cpl_plugin *plugin)
242 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
243 recipe = (cpl_recipe *)plugin;
247 cpl_parameterlist_delete(recipe->parameters);
262 static int fors_detect_objects(cpl_parameterlist *parlist,
263 cpl_frameset *frameset)
266 const char *recipe =
"fors_detect_objects";
281 cpl_image *mapped = NULL;
282 cpl_image *dummy = NULL;
283 cpl_table *slits = NULL;
284 cpl_propertylist *header = NULL;
291 const char *slit_location_tag;
292 const char *input_tag;
293 const char *outpt_tag;
303 char *instrume = NULL;
306 cpl_msg_set_indentation(2);
313 cpl_msg_info(recipe,
"Recipe %s configuration parameters:", recipe);
314 cpl_msg_indent_more();
317 "fors.fors_detect_objects.slit_margin",
320 fors_detect_objects_exit(
"Value must be zero or positive");
323 "fors.fors_detect_objects.ext_radius",
326 fors_detect_objects_exit(
"Value must be zero or positive");
329 "fors.fors_detect_objects.cont_radius",
332 fors_detect_objects_exit(
"Value must be zero or positive");
334 if (cpl_error_get_code())
335 fors_detect_objects_exit(
"Failure reading configuration parameters");
338 cpl_msg_indent_less();
339 cpl_msg_info(recipe,
"Check input set-of-frames:");
340 cpl_msg_indent_more();
342 nframes = scimxu = cpl_frameset_count_tags(frameset,
"MAPPED_SCI_MXU");
343 nframes += scimos = cpl_frameset_count_tags(frameset,
"MAPPED_SCI_MOS");
344 nframes += scilss = cpl_frameset_count_tags(frameset,
"MAPPED_SCI_LSS");
345 nframes += stdmxu = cpl_frameset_count_tags(frameset,
"MAPPED_STD_MXU");
346 nframes += stdmos = cpl_frameset_count_tags(frameset,
"MAPPED_STD_MOS");
347 nframes += stdlss = cpl_frameset_count_tags(frameset,
"MAPPED_STD_LSS");
350 fors_detect_objects_exit(
"Missing input scientific spectra");
353 cpl_msg_error(recipe,
"Too many input scientific spectra (%d > 1)",
355 fors_detect_objects_exit(NULL);
359 input_tag =
"MAPPED_SCI_MXU";
360 outpt_tag =
"OBJECT_TABLE_SCI_MXU";
361 slit_location_tag =
"SLIT_LOCATION_MXU";
364 input_tag =
"MAPPED_SCI_MOS";
365 outpt_tag =
"OBJECT_TABLE_SCI_MOS";
366 slit_location_tag =
"SLIT_LOCATION_MOS";
369 input_tag =
"MAPPED_SCI_LSS";
370 outpt_tag =
"OBJECT_TABLE_SCI_LSS";
371 slit_location_tag =
"SLIT_LOCATION_LSS";
374 input_tag =
"MAPPED_STD_MXU";
375 outpt_tag =
"OBJECT_TABLE_SCI_MXU";
376 slit_location_tag =
"SLIT_LOCATION_MXU";
379 input_tag =
"MAPPED_STD_MOS";
380 outpt_tag =
"OBJECT_TABLE_SCI_MOS";
381 slit_location_tag =
"SLIT_LOCATION_MOS";
384 input_tag =
"MAPPED_STD_LSS";
385 outpt_tag =
"OBJECT_TABLE_SCI_LSS";
386 slit_location_tag =
"SLIT_LOCATION_LSS";
390 fors_detect_objects_exit(
"Input frames are not from the same grism");
393 fors_detect_objects_exit(
"Input frames are not from the same filter");
396 fors_detect_objects_exit(
"Input frames are not from the same chip");
400 fors_detect_objects_exit(
"Cannot load scientific frame header");
402 instrume = (
char *)cpl_propertylist_get_string(header,
"INSTRUME");
403 if (instrume == NULL)
404 fors_detect_objects_exit(
"Missing keyword INSTRUME in reference frame "
407 if (instrume[4] ==
'1')
408 snprintf(version, 80,
"%s/%s",
"fors1", VERSION);
409 if (instrume[4] ==
'2')
410 snprintf(version, 80,
"%s/%s",
"fors2", VERSION);
412 gain = cpl_propertylist_get_double(header,
"ESO DET OUT1 CONAD");
414 cpl_propertylist_delete(header); header = NULL;
416 if (cpl_error_get_code() != CPL_ERROR_NONE)
417 fors_detect_objects_exit(
"Missing keyword ESO DET OUT1 CONAD in "
418 "scientific frame header");
420 cpl_msg_info(recipe,
"The gain factor is: %.2f e-/ADU", gain);
423 cpl_msg_indent_less();
424 cpl_msg_info(recipe,
"Load input frames...");
425 cpl_msg_indent_more();
427 mapped =
dfs_load_image(frameset, input_tag, CPL_TYPE_FLOAT, 0, 0);
429 fors_detect_objects_exit(
"Cannot load input scientific frame");
433 fors_detect_objects_exit(
"Cannot load slits location table");
435 cpl_msg_indent_less();
436 cpl_msg_info(recipe,
"Object detection...");
437 cpl_msg_indent_more();
441 ext_radius, cont_radius);
443 cpl_image_delete(mapped); mapped = NULL;
444 cpl_image_delete(dummy); dummy = NULL;
448 fors_detect_objects_exit(NULL);
450 cpl_table_delete(slits); slits = 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_image * mos_detect_objects(cpl_image *image, cpl_table *slits, int margin, int maxradius, int conradius)
Detect objects in rectified scientific frame.
int dfs_equal_keyword(cpl_frameset *frameset, const char *keyword)
Saving table data of given category.
cpl_table * dfs_load_table(cpl_frameset *frameset, const char *category, int ext)
Loading table data of given category.
int dfs_get_parameter_int(cpl_parameterlist *parlist, const char *name, const cpl_table *defaults)
Reading a recipe integer parameter value.
int dfs_save_table(cpl_frameset *frameset, const cpl_table *table, const char *category, cpl_propertylist *header, const cpl_parameterlist *parlist, const char *recipename, const char *version)
Saving table data of given category.
cpl_error_code mos_clean_cosmics(cpl_image *image, float gain, float threshold, float ratio)
Remove cosmic rays from sky-subtracted CCD spectral exposure.