FORS Pipeline Reference Manual 4.9.20
|
00001 /* $Id: vimos_calib.c,v 1.21 2010/09/14 07:38:16 cizzo Exp $ 00002 * 00003 * This file is part of the FORS Data Reduction Pipeline 00004 * Copyright (C) 2002-2010 European Southern Observatory 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 /* 00022 * $Author: cizzo $ 00023 * $Date: 2010/09/14 07:38:16 $ 00024 * $Revision: 1.21 $ 00025 * $Name: fors-4_9_20 $ 00026 */ 00027 00028 #ifdef HAVE_CONFIG_H 00029 #include <config.h> 00030 #endif 00031 00032 #include <math.h> 00033 #include <vimos_calib_impl.h> 00034 #include <cpl.h> 00035 #include <moses.h> 00036 #include <fors_dfs.h> 00037 #include <fors_qc.h> 00038 00039 static int vimos_calib_create(cpl_plugin *); 00040 static int vimos_calib_exec(cpl_plugin *); 00041 static int vimos_calib_destroy(cpl_plugin *); 00042 static int vimos_calib(cpl_parameterlist *, cpl_frameset *); 00043 00044 static char vimos_calib_description[] = 00045 "This recipe is used to identify reference lines on MOS arc lamp\n" 00046 "exposures, and trace the spectral edges on the corresponding flat field\n" 00047 "exposures. This information is used to determine the spectral extraction\n" 00048 "mask to be applied in the scientific data reduction, performed with the\n" 00049 "recipe vimos_science. The input arc lamp and flat field exposures are\n" 00050 "assumed to be obtained quasi-simultaneously, so that they would be\n" 00051 "described by exactly the same instrument distortions.\n" 00052 "A line catalog must be specified, containing the wavelengths of the\n" 00053 "reference arc lamp lines used for the wavelength calibration. A grism\n" 00054 "table (typically depending on the instrument mode, and in particular on\n" 00055 "the grism used) may also be specified: this table contains a default\n" 00056 "recipe parameter setting to control the way spectra are extracted for\n" 00057 "a specific instrument mode, as it is used for automatic run of the\n" 00058 "pipeline on Paranal and in Garching. If this table is specified, it\n" 00059 "will modify the default recipe parameter setting, with the exception of\n" 00060 "those parameters which have been explicitly modifyed on the command line.\n" 00061 "If a grism table is not specified, the input recipe parameters values\n" 00062 "will always be read from the command line, or from an esorex configuration\n" 00063 "file if present, or from their generic default values (that are rarely\n" 00064 "meaningful). Finally a master bias frame must be input to this recipe.\n" 00065 "In the table below the MOS_CURV_COEFF, MOS_CURV_TRACES, MOS_SPATIAL_MAP\n" 00066 "MOS_ARC_SPECTRUM_EXTRACTED, MOS_SPECTRA_DETECTION, MOS_SLIT_MAP, and\n" 00067 "MOS_SLIT_LOCATION, are never created in case of long-slit-like data.\n" 00068 "The products MOS_SPECTRA_DETECTION, MOS_SLIT_MAP, and MOS_DISP_RESIDUALS,\n" 00069 "are just created if the --check parameter is set to true. The product\n" 00070 "GLOBAL_DISTORTION_TABLE is just created if more than 12 separate spectra\n" 00071 "are found in the CCD.\n\n" 00072 "Input files:\n\n" 00073 " DO category: Type: Explanation: Required:\n" 00074 " MOS_SCREEN_FLAT Raw Flat field exposures Y\n" 00075 " MOS_ARC_SPECTRUM Raw Arc lamp exposure Y\n" 00076 " MASTER_BIAS or BIAS Calib Bias frame Y\n" 00077 " LINE_CATALOG Calib Line catalog Y\n" 00078 " GRISM_TABLE Calib Grism table .\n\n" 00079 "Output files:\n\n" 00080 " DO category: Data type: Explanation:\n" 00081 " MOS_COMBINED_SCREEN_FLAT FITS image Combined (sum) flat field\n" 00082 " MOS_MASTER_SCREEN_FLAT FITS image Normalised flat field\n" 00083 " MOS_ARC_SPECTRUM_EXTRACTED FITS image Wavelength calibrated arc spectrum\n" 00084 " MOS_DISP_COEFF FITS table Inverse dispersion coefficients\n" 00085 " MOS_DISP_RESIDUALS FITS image Residuals in wavelength calibration\n" 00086 " MOS_DISP_RESIDUALS_TABLE FITS table Residuals in wavelength calibration\n" 00087 " MOS_DELTA_IMAGE FITS image Offset vs linear wavelength calib\n" 00088 " MOS_WAVELENGTH_MAP FITS image Wavelength for each pixel on CCD\n" 00089 " MOS_SPECTRA_DETECTION FITS image Check for preliminary detection\n" 00090 " MOS_SLIT_MAP FITS image Map of central wavelength on CCD\n" 00091 " MOS_CURV_TRACES FITS table Spectral curvature traces\n" 00092 " MOS_CURV_COEFF FITS table Spectral curvature coefficients\n" 00093 " MOS_SPATIAL_MAP FITS image Spatial position along slit on CCD\n" 00094 " MOS_SPECTRAL_RESOLUTION FITS table Resolution at reference arc lines\n" 00095 " MOS_SLIT_LOCATION FITS table Slits on product frames and CCD\n" 00096 " GLOBAL_DISTORTION_TABLE FITS table Global distortions table\n\n"; 00097 00109 int cpl_plugin_get_info(cpl_pluginlist *list) 00110 { 00111 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe ); 00112 cpl_plugin *plugin = &recipe->interface; 00113 00114 cpl_plugin_init(plugin, 00115 CPL_PLUGIN_API, 00116 FORS_BINARY_VERSION, 00117 CPL_PLUGIN_TYPE_RECIPE, 00118 "vimos_calib", 00119 "Determination of the extraction mask", 00120 vimos_calib_description, 00121 "Carlo Izzo", 00122 PACKAGE_BUGREPORT, 00123 "This file is currently part of the FORS Instrument Pipeline\n" 00124 "Copyright (C) 2002-2010 European Southern Observatory\n\n" 00125 "This program is free software; you can redistribute it and/or modify\n" 00126 "it under the terms of the GNU General Public License as published by\n" 00127 "the Free Software Foundation; either version 2 of the License, or\n" 00128 "(at your option) any later version.\n\n" 00129 "This program is distributed in the hope that it will be useful,\n" 00130 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 00131 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" 00132 "GNU General Public License for more details.\n\n" 00133 "You should have received a copy of the GNU General Public License\n" 00134 "along with this program; if not, write to the Free Software Foundation,\n" 00135 "Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n", 00136 vimos_calib_create, 00137 vimos_calib_exec, 00138 vimos_calib_destroy); 00139 00140 cpl_pluginlist_append(list, plugin); 00141 00142 return 0; 00143 } 00144 00145 00156 static int vimos_calib_create(cpl_plugin *plugin) 00157 { 00158 cpl_recipe *recipe; 00159 cpl_parameter *p; 00160 00161 00162 /* 00163 * Check that the plugin is part of a valid recipe 00164 */ 00165 00166 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 00167 recipe = (cpl_recipe *)plugin; 00168 else 00169 return -1; 00170 00171 /* 00172 * Create the parameters list in the cpl_recipe object 00173 */ 00174 00175 recipe->parameters = cpl_parameterlist_new(); 00176 00177 00178 /* 00179 * Dispersion 00180 */ 00181 00182 p = cpl_parameter_new_value("fors.vimos_calib.dispersion", 00183 CPL_TYPE_DOUBLE, 00184 "Expected spectral dispersion (Angstrom/pixel)", 00185 "fors.vimos_calib", 00186 0.0); 00187 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dispersion"); 00188 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00189 cpl_parameterlist_append(recipe->parameters, p); 00190 00191 /* 00192 * Peak detection level 00193 */ 00194 00195 p = cpl_parameter_new_value("fors.vimos_calib.peakdetection", 00196 CPL_TYPE_DOUBLE, 00197 "Initial peak detection threshold (ADU)", 00198 "fors.vimos_calib", 00199 0.0); 00200 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "peakdetection"); 00201 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00202 cpl_parameterlist_append(recipe->parameters, p); 00203 00204 /* 00205 * Degree of wavelength calibration polynomial 00206 */ 00207 00208 p = cpl_parameter_new_value("fors.vimos_calib.wdegree", 00209 CPL_TYPE_INT, 00210 "Degree of wavelength calibration polynomial", 00211 "fors.vimos_calib", 00212 0); 00213 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "wdegree"); 00214 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00215 cpl_parameterlist_append(recipe->parameters, p); 00216 00217 /* 00218 * Reference lines search radius 00219 */ 00220 00221 p = cpl_parameter_new_value("fors.vimos_calib.wradius", 00222 CPL_TYPE_INT, 00223 "Search radius if iterating pattern-matching " 00224 "with first-guess method", 00225 "fors.vimos_calib", 00226 4); 00227 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "wradius"); 00228 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00229 cpl_parameterlist_append(recipe->parameters, p); 00230 00231 /* 00232 * Rejection threshold in dispersion relation polynomial fitting 00233 */ 00234 00235 p = cpl_parameter_new_value("fors.vimos_calib.wreject", 00236 CPL_TYPE_DOUBLE, 00237 "Rejection threshold in dispersion " 00238 "relation fit (pixel)", 00239 "fors.vimos_calib", 00240 0.7); 00241 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "wreject"); 00242 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00243 cpl_parameterlist_append(recipe->parameters, p); 00244 00245 /* 00246 * Wavelength solution interpolation (for LSS data) 00247 */ 00248 00249 p = cpl_parameter_new_value("fors.vimos_calib.wmode", 00250 CPL_TYPE_INT, 00251 "Interpolation mode of wavelength solution " 00252 "applicable to LSS-like data (0 = no " 00253 "interpolation, 1 = fill gaps, 2 = global " 00254 "model)", 00255 "fors.vimos_calib", 00256 2); 00257 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "wmode"); 00258 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00259 cpl_parameterlist_append(recipe->parameters, p); 00260 00261 /* 00262 * Line catalog table column containing the reference wavelengths 00263 */ 00264 00265 p = cpl_parameter_new_value("fors.vimos_calib.wcolumn", 00266 CPL_TYPE_STRING, 00267 "Name of line catalog table column " 00268 "with wavelengths", 00269 "fors.vimos_calib", 00270 "WLEN"); 00271 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "wcolumn"); 00272 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00273 cpl_parameterlist_append(recipe->parameters, p); 00274 00275 /* 00276 * Degree of spectral curvature polynomial 00277 */ 00278 00279 p = cpl_parameter_new_value("fors.vimos_calib.cdegree", 00280 CPL_TYPE_INT, 00281 "Degree of spectral curvature polynomial", 00282 "fors.vimos_calib", 00283 0); 00284 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "cdegree"); 00285 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00286 cpl_parameterlist_append(recipe->parameters, p); 00287 00288 /* 00289 * Curvature solution interpolation (for MOS-like data) 00290 */ 00291 00292 p = cpl_parameter_new_value("fors.vimos_calib.cmode", 00293 CPL_TYPE_INT, 00294 "Interpolation mode of curvature solution " 00295 "applicable to MOS-like data (0 = no " 00296 "interpolation, 1 = fill gaps, 2 = global " 00297 "model)", 00298 "fors.vimos_calib", 00299 1); 00300 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "cmode"); 00301 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00302 cpl_parameterlist_append(recipe->parameters, p); 00303 00304 /* 00305 * Start wavelength for spectral extraction 00306 */ 00307 00308 p = cpl_parameter_new_value("fors.vimos_calib.startwavelength", 00309 CPL_TYPE_DOUBLE, 00310 "Start wavelength in spectral extraction", 00311 "fors.vimos_calib", 00312 0.0); 00313 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "startwavelength"); 00314 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00315 cpl_parameterlist_append(recipe->parameters, p); 00316 00317 /* 00318 * End wavelength for spectral extraction 00319 */ 00320 00321 p = cpl_parameter_new_value("fors.vimos_calib.endwavelength", 00322 CPL_TYPE_DOUBLE, 00323 "End wavelength in spectral extraction", 00324 "fors.vimos_calib", 00325 0.0); 00326 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "endwavelength"); 00327 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00328 cpl_parameterlist_append(recipe->parameters, p); 00329 00330 /* 00331 * Reference wavelength for wavelength calibration 00332 */ 00333 00334 p = cpl_parameter_new_value("fors.vimos_calib.reference", 00335 CPL_TYPE_DOUBLE, 00336 "Reference wavelength for calibration", 00337 "fors.vimos_calib", 00338 0.0); 00339 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "reference"); 00340 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00341 cpl_parameterlist_append(recipe->parameters, p); 00342 00343 /* 00344 * Try slit identification 00345 */ 00346 00347 p = cpl_parameter_new_value("fors.vimos_calib.slit_ident", 00348 CPL_TYPE_BOOL, 00349 "Attempt slit identification", 00350 "fors.vimos_calib", 00351 TRUE); 00352 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "slit_ident"); 00353 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00354 cpl_parameterlist_append(recipe->parameters, p); 00355 00356 /* 00357 * Degree of flat field fitting polynomial along spatial direction 00358 * (used for LSS data) 00359 */ 00360 00361 p = cpl_parameter_new_value("fors.vimos_calib.sdegree", 00362 CPL_TYPE_INT, 00363 "Degree of flat field fitting polynomial " 00364 "along spatial direction (used for LSS-like " 00365 "data only)", 00366 "fors.vimos_calib", 00367 -1); 00368 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "sdegree"); 00369 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00370 cpl_parameterlist_append(recipe->parameters, p); 00371 00372 /* 00373 * Degree of flat field fitting polynomial along dispersion direction 00374 * (used for MOS data) 00375 */ 00376 00377 p = cpl_parameter_new_value("fors.vimos_calib.ddegree", 00378 CPL_TYPE_INT, 00379 "Degree of flat field fitting polynomial " 00380 "along dispersion direction (not used for " 00381 "long-slit-like data)", 00382 "fors.vimos_calib", 00383 -1); 00384 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ddegree"); 00385 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00386 cpl_parameterlist_append(recipe->parameters, p); 00387 00388 /* 00389 * Smooth box radius for flat field along dispersion direction 00390 */ 00391 00392 p = cpl_parameter_new_value("fors.vimos_calib.dradius", 00393 CPL_TYPE_INT, 00394 "Smooth box radius for flat field along " 00395 "dispersion direction", 00396 "fors.vimos_calib", 00397 10); 00398 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "dradius"); 00399 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00400 cpl_parameterlist_append(recipe->parameters, p); 00401 00402 /* 00403 * Smooth box radius for flat field along spatial direction 00404 * (used for LSS data only) 00405 */ 00406 00407 p = cpl_parameter_new_value("fors.vimos_calib.sradius", 00408 CPL_TYPE_INT, 00409 "Smooth box radius for flat field along " 00410 "spatial direction", 00411 "fors.vimos_calib", 00412 10); 00413 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "sradius"); 00414 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00415 cpl_parameterlist_append(recipe->parameters, p); 00416 00417 /* 00418 * Computation of QC1 parameters 00419 */ 00420 00421 p = cpl_parameter_new_value("fors.vimos_calib.qc", 00422 CPL_TYPE_BOOL, 00423 "Compute QC1 parameters", 00424 "fors.vimos_calib", 00425 TRUE); 00426 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "qc"); 00427 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00428 cpl_parameterlist_append(recipe->parameters, p); 00429 00430 /* 00431 * Create check products 00432 */ 00433 00434 p = cpl_parameter_new_value("fors.vimos_calib.check", 00435 CPL_TYPE_BOOL, 00436 "Create intermediate products", 00437 "fors.vimos_calib", 00438 FALSE); 00439 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "check"); 00440 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); 00441 cpl_parameterlist_append(recipe->parameters, p); 00442 00443 return 0; 00444 } 00445 00446 00455 static int vimos_calib_exec(cpl_plugin *plugin) 00456 { 00457 cpl_recipe *recipe; 00458 00459 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 00460 recipe = (cpl_recipe *)plugin; 00461 else 00462 return -1; 00463 00464 return vimos_calib(recipe->parameters, recipe->frames); 00465 } 00466 00467 00476 static int vimos_calib_destroy(cpl_plugin *plugin) 00477 { 00478 cpl_recipe *recipe; 00479 00480 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 00481 recipe = (cpl_recipe *)plugin; 00482 else 00483 return -1; 00484 00485 cpl_parameterlist_delete(recipe->parameters); 00486 00487 return 0; 00488 } 00489 00490 00500 static int vimos_calib(cpl_parameterlist *parlist, cpl_frameset *frameset) 00501 { 00502 cpl_table *maskslits; 00503 cpl_propertylist *header; 00504 int mos; 00505 int multiplex; 00506 00507 /* 00508 * Check whether there is spectral multiplexing here 00509 */ 00510 00511 mos = cpl_frameset_count_tags(frameset, "MOS_ARC_SPECTRUM"); 00512 00513 if (mos == 0) { 00514 cpl_msg_error("vimos_calib", "Missing input arc lamp frame"); 00515 return -1; 00516 } 00517 00518 if (mos > 1) { 00519 cpl_msg_error("vimos_calib", 00520 "Just one input arc lamp frame is allowed"); 00521 return -1; 00522 } 00523 00524 header = dfs_load_header(frameset, "MOS_ARC_SPECTRUM", 0); 00525 00526 if (header == NULL) { 00527 cpl_msg_error("vimos_calib", "Cannot load arc lamp header"); 00528 return -1; 00529 } 00530 00531 maskslits = mos_load_slits_vimos(header); 00532 cpl_propertylist_delete(header); 00533 multiplex = mos_check_multiplex(maskslits); 00534 00535 if (multiplex == 1) 00536 return vimos_calib_impl(frameset, parlist); 00537 00538 cpl_msg_info("vimos_calib", "Spectral multiplexing: %d", multiplex); 00539 cpl_msg_error("vimos_calib", "Cannot handle such data"); 00540 return -1; 00541 }