33 #include <vimos_calib_impl.h>
39 static int vimos_calib_create(cpl_plugin *);
40 static int vimos_calib_exec(cpl_plugin *);
41 static int vimos_calib_destroy(cpl_plugin *);
42 static int vimos_calib(cpl_parameterlist *, cpl_frameset *);
44 static char vimos_calib_description[] =
45 "This recipe is used to identify reference lines on MOS arc lamp\n"
46 "exposures, and trace the spectral edges on the corresponding flat field\n"
47 "exposures. This information is used to determine the spectral extraction\n"
48 "mask to be applied in the scientific data reduction, performed with the\n"
49 "recipe vimos_science. The input arc lamp and flat field exposures are\n"
50 "assumed to be obtained quasi-simultaneously, so that they would be\n"
51 "described by exactly the same instrument distortions.\n"
52 "A line catalog must be specified, containing the wavelengths of the\n"
53 "reference arc lamp lines used for the wavelength calibration. A grism\n"
54 "table (typically depending on the instrument mode, and in particular on\n"
55 "the grism used) may also be specified: this table contains a default\n"
56 "recipe parameter setting to control the way spectra are extracted for\n"
57 "a specific instrument mode, as it is used for automatic run of the\n"
58 "pipeline on Paranal and in Garching. If this table is specified, it\n"
59 "will modify the default recipe parameter setting, with the exception of\n"
60 "those parameters which have been explicitly modifyed on the command line.\n"
61 "If a grism table is not specified, the input recipe parameters values\n"
62 "will always be read from the command line, or from an esorex configuration\n"
63 "file if present, or from their generic default values (that are rarely\n"
64 "meaningful). Finally a master bias frame must be input to this recipe.\n"
65 "In the table below the MOS_CURV_COEFF, MOS_CURV_TRACES, MOS_SPATIAL_MAP\n"
66 "MOS_ARC_SPECTRUM_EXTRACTED, MOS_SPECTRA_DETECTION, MOS_SLIT_MAP, and\n"
67 "MOS_SLIT_LOCATION, are never created in case of long-slit-like data.\n"
68 "The products MOS_SPECTRA_DETECTION, MOS_SLIT_MAP, and MOS_DISP_RESIDUALS,\n"
69 "are just created if the --check parameter is set to true. The product\n"
70 "GLOBAL_DISTORTION_TABLE is just created if more than 12 separate spectra\n"
71 "are found in the CCD.\n\n"
73 " DO category: Type: Explanation: Required:\n"
74 " MOS_SCREEN_FLAT Raw Flat field exposures Y\n"
75 " MOS_ARC_SPECTRUM Raw Arc lamp exposure Y\n"
76 " MASTER_BIAS or BIAS Calib Bias frame Y\n"
77 " LINE_CATALOG Calib Line catalog Y\n"
78 " GRISM_TABLE Calib Grism table .\n\n"
80 " DO category: Data type: Explanation:\n"
81 " MOS_COMBINED_SCREEN_FLAT FITS image Combined (sum) flat field\n"
82 " MOS_MASTER_SCREEN_FLAT FITS image Normalised flat field\n"
83 " MOS_ARC_SPECTRUM_EXTRACTED FITS image Wavelength calibrated arc spectrum\n"
84 " MOS_DISP_COEFF FITS table Inverse dispersion coefficients\n"
85 " MOS_DISP_RESIDUALS FITS image Residuals in wavelength calibration\n"
86 " MOS_DISP_RESIDUALS_TABLE FITS table Residuals in wavelength calibration\n"
87 " MOS_DELTA_IMAGE FITS image Offset vs linear wavelength calib\n"
88 " MOS_WAVELENGTH_MAP FITS image Wavelength for each pixel on CCD\n"
89 " MOS_SPECTRA_DETECTION FITS image Check for preliminary detection\n"
90 " MOS_SLIT_MAP FITS image Map of central wavelength on CCD\n"
91 " MOS_CURV_TRACES FITS table Spectral curvature traces\n"
92 " MOS_CURV_COEFF FITS table Spectral curvature coefficients\n"
93 " MOS_SPATIAL_MAP FITS image Spatial position along slit on CCD\n"
94 " MOS_SPECTRAL_RESOLUTION FITS table Resolution at reference arc lines\n"
95 " MOS_SLIT_LOCATION FITS table Slits on product frames and CCD\n"
96 " GLOBAL_DISTORTION_TABLE FITS table Global distortions table\n\n";
111 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe );
112 cpl_plugin *plugin = &recipe->interface;
114 cpl_plugin_init(plugin,
117 CPL_PLUGIN_TYPE_RECIPE,
119 "Determination of the extraction mask",
120 vimos_calib_description,
123 "This file is currently part of the FORS Instrument Pipeline\n"
124 "Copyright (C) 2002-2010 European Southern Observatory\n\n"
125 "This program is free software; you can redistribute it and/or modify\n"
126 "it under the terms of the GNU General Public License as published by\n"
127 "the Free Software Foundation; either version 2 of the License, or\n"
128 "(at your option) any later version.\n\n"
129 "This program is distributed in the hope that it will be useful,\n"
130 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
131 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
132 "GNU General Public License for more details.\n\n"
133 "You should have received a copy of the GNU General Public License\n"
134 "along with this program; if not, write to the Free Software Foundation,\n"
135 "Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n",
138 vimos_calib_destroy);
140 cpl_pluginlist_append(list, plugin);
156 static int vimos_calib_create(cpl_plugin *plugin)
166 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
167 recipe = (cpl_recipe *)plugin;
175 recipe->parameters = cpl_parameterlist_new();
182 p = cpl_parameter_new_value(
"fors.vimos_calib.dispersion",
184 "Expected spectral dispersion (Angstrom/pixel)",
187 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"dispersion");
188 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
189 cpl_parameterlist_append(recipe->parameters, p);
195 p = cpl_parameter_new_value(
"fors.vimos_calib.peakdetection",
197 "Initial peak detection threshold (ADU)",
200 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"peakdetection");
201 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
202 cpl_parameterlist_append(recipe->parameters, p);
208 p = cpl_parameter_new_value(
"fors.vimos_calib.wdegree",
210 "Degree of wavelength calibration polynomial",
213 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"wdegree");
214 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
215 cpl_parameterlist_append(recipe->parameters, p);
221 p = cpl_parameter_new_value(
"fors.vimos_calib.wradius",
223 "Search radius if iterating pattern-matching "
224 "with first-guess method",
227 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"wradius");
228 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
229 cpl_parameterlist_append(recipe->parameters, p);
235 p = cpl_parameter_new_value(
"fors.vimos_calib.wreject",
237 "Rejection threshold in dispersion "
238 "relation fit (pixel)",
241 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"wreject");
242 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
243 cpl_parameterlist_append(recipe->parameters, p);
249 p = cpl_parameter_new_value(
"fors.vimos_calib.wmode",
251 "Interpolation mode of wavelength solution "
252 "applicable to LSS-like data (0 = no "
253 "interpolation, 1 = fill gaps, 2 = global "
257 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"wmode");
258 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
259 cpl_parameterlist_append(recipe->parameters, p);
265 p = cpl_parameter_new_value(
"fors.vimos_calib.wcolumn",
267 "Name of line catalog table column "
271 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"wcolumn");
272 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
273 cpl_parameterlist_append(recipe->parameters, p);
279 p = cpl_parameter_new_value(
"fors.vimos_calib.cdegree",
281 "Degree of spectral curvature polynomial",
284 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"cdegree");
285 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
286 cpl_parameterlist_append(recipe->parameters, p);
292 p = cpl_parameter_new_value(
"fors.vimos_calib.cmode",
294 "Interpolation mode of curvature solution "
295 "applicable to MOS-like data (0 = no "
296 "interpolation, 1 = fill gaps, 2 = global "
300 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"cmode");
301 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
302 cpl_parameterlist_append(recipe->parameters, p);
308 p = cpl_parameter_new_value(
"fors.vimos_calib.startwavelength",
310 "Start wavelength in spectral extraction",
313 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"startwavelength");
314 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
315 cpl_parameterlist_append(recipe->parameters, p);
321 p = cpl_parameter_new_value(
"fors.vimos_calib.endwavelength",
323 "End wavelength in spectral extraction",
326 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"endwavelength");
327 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
328 cpl_parameterlist_append(recipe->parameters, p);
334 p = cpl_parameter_new_value(
"fors.vimos_calib.reference",
336 "Reference wavelength for calibration",
339 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"reference");
340 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
341 cpl_parameterlist_append(recipe->parameters, p);
347 p = cpl_parameter_new_value(
"fors.vimos_calib.slit_ident",
349 "Attempt slit identification",
352 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"slit_ident");
353 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
354 cpl_parameterlist_append(recipe->parameters, p);
361 p = cpl_parameter_new_value(
"fors.vimos_calib.sdegree",
363 "Degree of flat field fitting polynomial "
364 "along spatial direction (used for LSS-like "
368 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"sdegree");
369 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
370 cpl_parameterlist_append(recipe->parameters, p);
377 p = cpl_parameter_new_value(
"fors.vimos_calib.ddegree",
379 "Degree of flat field fitting polynomial "
380 "along dispersion direction (not used for "
381 "long-slit-like data)",
384 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ddegree");
385 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
386 cpl_parameterlist_append(recipe->parameters, p);
392 p = cpl_parameter_new_value(
"fors.vimos_calib.dradius",
394 "Smooth box radius for flat field along "
395 "dispersion direction",
398 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"dradius");
399 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
400 cpl_parameterlist_append(recipe->parameters, p);
407 p = cpl_parameter_new_value(
"fors.vimos_calib.sradius",
409 "Smooth box radius for flat field along "
413 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"sradius");
414 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
415 cpl_parameterlist_append(recipe->parameters, p);
421 p = cpl_parameter_new_value(
"fors.vimos_calib.qc",
423 "Compute QC1 parameters",
426 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"qc");
427 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
428 cpl_parameterlist_append(recipe->parameters, p);
434 p = cpl_parameter_new_value(
"fors.vimos_calib.check",
436 "Create intermediate products",
439 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"check");
440 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
441 cpl_parameterlist_append(recipe->parameters, p);
455 static int vimos_calib_exec(cpl_plugin *plugin)
459 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
460 recipe = (cpl_recipe *)plugin;
464 return vimos_calib(recipe->parameters, recipe->frames);
476 static int vimos_calib_destroy(cpl_plugin *plugin)
480 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
481 recipe = (cpl_recipe *)plugin;
485 cpl_parameterlist_delete(recipe->parameters);
500 static int vimos_calib(cpl_parameterlist *parlist, cpl_frameset *frameset)
502 cpl_table *maskslits;
503 cpl_propertylist *header;
511 mos = cpl_frameset_count_tags(frameset,
"MOS_ARC_SPECTRUM");
514 cpl_msg_error(
"vimos_calib",
"Missing input arc lamp frame");
519 cpl_msg_error(
"vimos_calib",
520 "Just one input arc lamp frame is allowed");
526 if (header == NULL) {
527 cpl_msg_error(
"vimos_calib",
"Cannot load arc lamp header");
532 cpl_propertylist_delete(header);
536 return vimos_calib_impl(frameset, parlist);
538 cpl_msg_info(
"vimos_calib",
"Spectral multiplexing: %d", multiplex);
539 cpl_msg_error(
"vimos_calib",
"Cannot handle such data");
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
cpl_propertylist * dfs_load_header(cpl_frameset *frameset, const char *category, int ext)
Loading header associated to data of given category.
int mos_check_multiplex(cpl_table *slits)
Determining whether a VIMOS mask has spectral multplexing or not.
cpl_table * mos_load_slits_vimos(cpl_propertylist *header)
Create slit location table from FITS header of VIMOS data.