IIINSTRUMENT Pipeline Reference Manual 4.4.3
visir_spc_wcal.c
1/* $Id: visir_spc_wcal.c,v 1.73 2012-09-27 15:45:07 jtaylor Exp $
2 *
3 * This file is part of the VISIR Pipeline
4 * Copyright (C) 2002,2003 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * $Author: jtaylor $
23 * $Date: 2012-09-27 15:45:07 $
24 * $Revision: 1.73 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32/*-----------------------------------------------------------------------------
33 Includes
34 -----------------------------------------------------------------------------*/
35
36#include "visir_recipe.h"
37#include "visir_spectro.h"
38#include "visir_spc_distortion.h"
39
40
41/*-----------------------------------------------------------------------------
42 Defines
43 -----------------------------------------------------------------------------*/
44
45#define RECIPE_STRING "visir_old_spc_wcal"
46
47/*-----------------------------------------------------------------------------
48 Private Functions prototypes
49 -----------------------------------------------------------------------------*/
50static cpl_error_code visir_spc_wcal_save(cpl_frameset *,
51 const cpl_parameterlist *,
52 const cpl_propertylist *,
53 const cpl_propertylist *,
54 const cpl_table *);
55
56VISIR_RECIPE_DEFINE(visir_old_spc_wcal,
57 VISIR_PARAM_AUTOBPM |
58 VISIR_PARAM_PLOT | VISIR_PARAM_SLITSKEW |
59 VISIR_PARAM_SPECSKEW | VISIR_PARAM_VERTARC |
60 VISIR_PARAM_REJLEFT | VISIR_PARAM_REJRIGHT |
61 VISIR_PARAM_HORIARC,
62 "Old DRS detector: Spectroscopic wavelength calibration recipe",
63 "This recipe estimates the dispersion relation using the "
64 "atmospheric spectrum\n"
65 "in a long-slit spectroscopy half-cycle frame.\n"
66 "The files listed in the Set Of Frames (sof-file) "
67 "must be tagged:\n"
68 "VISIR-Long-Slit-Spectroscopy-file.fits "
69 VISIR_SPC_WCAL_RAW "\n"
70 "VISIR-Quantum-Efficiency-Calibration-file.fits "
71 VISIR_CALIB_QEFF_SPC "\n"
72 "VISIR-Atmospheric-Emission-Lines-Calibration-file.fits "
73 VISIR_CALIB_LINES_SPC
74 "\n"
75 MAN_VISIR_CALIB_BPM_SPC);
76
77/*----------------------------------------------------------------------------*/
81/*----------------------------------------------------------------------------*/
82
83/*-----------------------------------------------------------------------------
84 Functions code
85 -----------------------------------------------------------------------------*/
86
87/*----------------------------------------------------------------------------*/
94/*----------------------------------------------------------------------------*/
95static int visir_old_spc_wcal(cpl_frameset * framelist,
96 const cpl_parameterlist * parlist)
97{
98 irplib_framelist * allframes = NULL;
99 irplib_framelist * rawframes = NULL;
100 cpl_propertylist * qclist = cpl_propertylist_new();
101 cpl_propertylist * paflist = cpl_propertylist_new();
102 const char * spc_cal_qeff;
103 const char * spc_cal_lines;
104 cpl_imagelist * hcycle = NULL;
105 cpl_image * imhcycle = NULL;
106 cpl_image * flipped = NULL;
107 cpl_image * imhcyclenarrow = NULL;
108 cpl_table * spc_table = NULL;
109 double wlen, slitw, temp, fwhm;
110 visir_spc_resol resol;
111 int icol1, icol2;
112 int jcol1, jcol2;
113 visir_spc_config cfg;
114
115
116 cfg.auto_bpm = visir_parameterlist_get_bool(
117 parlist, RECIPE_STRING, VISIR_PARAM_AUTOBPM);
119 parlist, RECIPE_STRING, VISIR_PARAM_PLOT);
121 parlist, RECIPE_STRING, VISIR_PARAM_SLITSKEW);
123 parlist, RECIPE_STRING, VISIR_PARAM_SPECSKEW);
125 parlist, RECIPE_STRING, VISIR_PARAM_VERTARC);
127 parlist, RECIPE_STRING, VISIR_PARAM_HORIARC);
128
129 jcol1 = visir_parameterlist_get_int(parlist, RECIPE_STRING,
130 VISIR_PARAM_REJLEFT);
131 jcol2 = visir_parameterlist_get_int(parlist, RECIPE_STRING,
132 VISIR_PARAM_REJRIGHT);
133
134 skip_if (0);
135
136 /* Identify the RAW and CALIB frames in the input frameset */
137 skip_if (visir_dfs_set_groups(framelist));
138
139 /* Objects observation */
140 allframes = irplib_framelist_cast(framelist);
141 skip_if(allframes == NULL);
142 rawframes = irplib_framelist_extract(allframes, VISIR_SPC_WCAL_RAW);
143 skip_if (rawframes == NULL);
144
145 irplib_framelist_empty(allframes);
146
147 skip_if(irplib_framelist_load_propertylist_all(rawframes, 0, ".*", CPL_FALSE));
148
149 skip_if(visir_dfs_check_framelist_tag(rawframes));
150
151 /* Quantum efficiency file */
152 spc_cal_qeff = irplib_frameset_find_file(framelist, VISIR_CALIB_QEFF_SPC);
153
154 /* Spectral lines calibration file */
155 spc_cal_lines = irplib_frameset_find_file(framelist, VISIR_CALIB_LINES_SPC);
156
157 /* Get Resolution and Central Wavelength */
158 resol = visir_spc_get_res_wl(rawframes, &wlen, &slitw, &temp, &fwhm, 0);
159
160 skip_if (0);
161
162 if (resol == VISIR_SPC_R_GHR) {
163 cpl_msg_error(cpl_func, "This recipe cannot reduce HR Grism data");
164 visir_error_set(CPL_ERROR_TYPE_MISMATCH);
165 skip_if(1);
166 }
167
168 skip_if(visir_qc_append_background(qclist, rawframes, 0, 0));
169
170 /* Get the hcycle image from the reference file */
171 hcycle = visir_load_hcycle(rawframes, 0);
172 skip_if (0);
173
174 imhcycle = cpl_imagelist_unset(hcycle, 0);
175
176 /* Convert the combined image */
177 flipped = visir_spc_flip(imhcycle, wlen, resol, VISIR_DATA_CUBE2, NULL);
178 skip_if (0);
179 cpl_image_delete(imhcycle);
180 imhcycle = flipped;
181 flipped = NULL;
182
183 skip_if (visir_spc_det_fix(&imhcycle, 1, CPL_FALSE, wlen, resol, cfg.phi,
184 cfg.ksi, cfg.eps, cfg.delta, cfg.plot));
185
186 icol1 = 1;
187 icol2 = cpl_image_get_size_x(imhcycle);
188
189 if (jcol1 != 0) {
190 cpl_msg_info(cpl_func, "Ignoring %d leftmost columns", jcol1);
191 icol1 += jcol1;
192 }
193 if (jcol2 != 0) {
194 cpl_msg_info(cpl_func, "Ignoring %d rightmost columns", jcol2);
195 icol2 -= jcol2;
196 }
197
198 if (jcol1 != 0 || jcol2 != 0) {
199 imhcyclenarrow = visir_spc_column_extract(imhcycle, icol1, icol2,
200 cfg.plot);
201 skip_if (0);
202
203 } else {
204 imhcyclenarrow = imhcycle;
205 }
206
207 skip_if (visir_spc_wavecal(imhcyclenarrow, qclist, wlen, slitw, temp, fwhm,
208 resol, &cfg, spc_cal_lines, spc_cal_qeff,
209 &spc_table, 0));
210
211 /* This column is not part of the product */
212 skip_if (cpl_table_erase_column(spc_table, "SPC_EMISSIVITY"));
213
214 bug_if (visir_spectro_qc(qclist, paflist, CPL_FALSE, rawframes, NULL,
215 "^(" VISIR_PFITS_REGEXP_SPC_WCAL_PAF ")$"));
216 irplib_framelist_empty(rawframes);
217
218 /* Save the spectrum */
219 cpl_msg_info(cpl_func, "Saving the produced spectrum");
220
221 /* PRO.CATG */
222 bug_if (cpl_propertylist_append_string(paflist, CPL_DFS_PRO_CATG,
223 VISIR_SPC_WCAL_TAB_PROCATG));
224
225 skip_if (visir_spc_wcal_save(framelist, parlist, qclist, paflist, spc_table));
226
227 end_skip;
228
229 cpl_propertylist_delete(qclist);
230 cpl_propertylist_delete(paflist);
231 irplib_framelist_delete(allframes);
232 irplib_framelist_delete(rawframes);
233 cpl_table_delete(spc_table);
234 cpl_imagelist_delete(hcycle);
235 if (imhcyclenarrow != imhcycle) cpl_image_delete(imhcyclenarrow);
236 cpl_image_delete(imhcycle);
237 cpl_image_delete(flipped);
238
239 return cpl_error_get_code();
240}
241
242/*----------------------------------------------------------------------------*/
252/*----------------------------------------------------------------------------*/
253static cpl_error_code visir_spc_wcal_save(cpl_frameset * set,
254 const cpl_parameterlist * parlist,
255 const cpl_propertylist * qclist,
256 const cpl_propertylist * paflist,
257 const cpl_table * table)
258{
259 bug_if (0);
260
261 /* THE TABLE */
262 skip_if (irplib_dfs_save_table(set, parlist, set, table, NULL, RECIPE_STRING,
263 VISIR_SPC_WCAL_TAB_PROCATG,
264 qclist, NULL, visir_pipe_id,
265 RECIPE_STRING "_spectrum_tab" CPL_DFS_FITS));
266
267#ifdef VISIR_SAVE_PAF
268 /* THE PAF FILE FOR QC PARAMETERS */
269 skip_if (cpl_dfs_save_paf("VISIR", RECIPE_STRING, paflist,
270 RECIPE_STRING CPL_DFS_PAF));
271#else
272 bug_if(paflist == NULL);
273#endif
274
275 end_skip;
276
277 return cpl_error_get_code();
278}
cpl_error_code visir_dfs_check_framelist_tag(const irplib_framelist *self)
Check the tags in a frameset (group raw only)
Definition: visir_dfs.c:234
int visir_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
Definition: visir_dfs.c:72
cpl_imagelist * visir_load_hcycle(const irplib_framelist *rawframes, int pos)
Load the HCYCLE images from a VISIR file.
int visir_parameterlist_get_int(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR integer parameter.
double visir_parameterlist_get_double(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR parameter of type double.
cpl_boolean visir_parameterlist_get_bool(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR boolean parameter.