IIINSTRUMENT Pipeline Reference Manual 4.5.1
visir_spc_wcal_ech.c
1/* $Id: visir_spc_wcal_ech.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 Defines
42 -----------------------------------------------------------------------------*/
43
44#define RECIPE_STRING "visir_old_spc_wcal_ech"
45
46/*-----------------------------------------------------------------------------
47 Private Functions prototypes
48 -----------------------------------------------------------------------------*/
49static cpl_error_code visir_spc_wcal_ech_save(cpl_frameset *,
50 const cpl_parameterlist *,
51 const cpl_propertylist *,
52 const cpl_propertylist *,
53 const cpl_table *);
54
55VISIR_RECIPE_DEFINE(visir_old_spc_wcal_ech,
56 VISIR_PARAM_ZERODIST | VISIR_PARAM_ORDEROFF |
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 in Echelle",
63 "This recipe estimates the dispersion relation using the "
64 "atmospheric spectrum\n"
65 "in a grism spectroscopy half-cycle frame.\n"
66 "The files listed in the Set Of Frames (sof-file) "
67 "must be tagged:\n"
68 "VISIR-Echelle-Spectroscopy-file.fits "
69 VISIR_SPC_WCAL_ECH_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_ech(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_table * spc_table = NULL;
108 cpl_image * order = NULL;
109 double wlen, slitw, temp, fwhm;
110 int icol1, icol2;
111 int jcol1, jcol2;
112 visir_spc_resol resol;
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 cfg.orderoffset = visir_parameterlist_get_int(
129 parlist, RECIPE_STRING, VISIR_PARAM_ORDEROFF);
130
131 jcol1 = visir_parameterlist_get_int(parlist, RECIPE_STRING,
132 VISIR_PARAM_REJLEFT);
133 jcol2 = visir_parameterlist_get_int(parlist, RECIPE_STRING,
134 VISIR_PARAM_REJRIGHT);
135
136 skip_if (0);
137
138 /* Identify the RAW and CALIB frames in the input frameset */
139 skip_if (visir_dfs_set_groups(framelist));
140
141 /* Objects observation */
142 allframes = irplib_framelist_cast(framelist);
143 skip_if(allframes == NULL);
144 rawframes = irplib_framelist_extract(allframes, VISIR_SPC_WCAL_ECH_RAW);
145 skip_if (rawframes == NULL);
146
147 irplib_framelist_empty(allframes);
148
149 skip_if(irplib_framelist_load_propertylist_all(rawframes, 0, ".*", CPL_FALSE));
150
151 skip_if(visir_dfs_check_framelist_tag(rawframes));
152
153 /* Quantum efficiency file */
154 spc_cal_qeff = irplib_frameset_find_file(framelist, VISIR_CALIB_QEFF_SPC);
155
156 /* Spectral lines calibration file */
157 spc_cal_lines = irplib_frameset_find_file(framelist, VISIR_CALIB_LINES_SPC);
158
159 /* Get Resolution and Central Wavelength */
160 resol = visir_spc_get_res_wl(rawframes, &wlen, &slitw, &temp, &fwhm, 0);
161
162 skip_if (0);
163
164 if (resol != VISIR_SPC_R_GHR) {
165 if (cfg.orderoffset == 0) {
166 cpl_msg_warning(cpl_func,"Reducing non-HR Grism data as main order");
167 } else {
168 cpl_msg_error(cpl_func, "This recipe cannot reduce non-HR Grism "
169 "data with an order-offset of %d",
170 cfg.orderoffset);
171 visir_error_set(CPL_ERROR_TYPE_MISMATCH);
172 skip_if(1);
173 }
174 }
175
176 /* Get the hcycle image from the reference file */
177 hcycle = visir_load_hcycle(rawframes, 0);
178 skip_if (0);
179
180 imhcycle = cpl_imagelist_unset(hcycle, 0);
181
182 /* Convert the combined image
183 * recipe only supported with drs data */
184 flipped = visir_spc_flip(imhcycle, wlen, resol, VISIR_DATA_CUBE2, NULL);
185 skip_if (0);
186 cpl_image_delete(imhcycle);
187 imhcycle = flipped;
188 flipped = NULL;
189
190 skip_if (visir_spc_det_fix(&imhcycle, 1, CPL_FALSE, wlen, resol, cfg.phi,
191 cfg.ksi, cfg.eps, cfg.delta, cfg.plot));
192
193 skip_if (visir_spc_echelle_limit(&icol1, &icol2, wlen, &cfg, 1,
194 cpl_image_get_size_y(imhcycle), 0));
195
196 skip_if(visir_qc_append_background(qclist, rawframes, icol1, icol2));
197
198 if (jcol1 != 0) {
199 cpl_msg_info(cpl_func, "Ignoring %d leftmost columns from %d to %d",
200 jcol1, icol1, icol1 + jcol1);
201 icol1 += jcol1;
202 }
203 if (jcol2 != 0) {
204 cpl_msg_info(cpl_func, "Ignoring %d rightmost columns from %d to %d",
205 jcol2, icol2 - jcol2, icol2);
206 icol2 -= jcol2;
207 }
208
209 if (icol1 != 1 || icol2 != cpl_image_get_size_x(imhcycle)) {
210
211 order = visir_spc_column_extract(imhcycle, icol1, icol2, cfg.plot);
212 skip_if (0);
213 } else {
214 /* Cannot really succeed from here... */
215 order = imhcycle;
216 }
217
218 skip_if (visir_spc_wavecal(order, qclist, wlen, slitw, temp, fwhm, resol,
219 &cfg, spc_cal_lines, spc_cal_qeff, &spc_table,
220 0));
221
222 /* This column is not part of the product */
223 skip_if (cpl_table_erase_column(spc_table, "SPC_EMISSIVITY"));
224
225 bug_if (visir_spectro_qc(qclist, paflist, CPL_FALSE, rawframes, NULL,
226 "^(" VISIR_PFITS_REGEXP_SPC_WCAL_PAF ")$"));
227 irplib_framelist_empty(rawframes);
228
229 /* Save the spectrum */
230 cpl_msg_info(cpl_func, "Saving the produced spectrum");
231
232 /* PRO.CATG */
233 bug_if (cpl_propertylist_append_string(paflist, CPL_DFS_PRO_CATG,
234 VISIR_SPC_WCAL_ECH_TAB_PROCATG));
235
236 skip_if (visir_spc_wcal_ech_save(framelist, parlist, qclist, paflist,
237 spc_table));
238
239 end_skip;
240
241 cpl_propertylist_delete(qclist);
242 cpl_propertylist_delete(paflist);
243 irplib_framelist_delete(allframes);
244 irplib_framelist_delete(rawframes);
245 cpl_table_delete(spc_table);
246 if (order != imhcycle) cpl_image_delete(order);
247 cpl_imagelist_delete(hcycle);
248 cpl_image_delete(imhcycle);
249 cpl_image_delete(flipped);
250
251 return cpl_error_get_code();
252}
253
254/*----------------------------------------------------------------------------*/
264/*----------------------------------------------------------------------------*/
265static cpl_error_code visir_spc_wcal_ech_save(cpl_frameset * set,
266 const cpl_parameterlist * parlist,
267 const cpl_propertylist * qclist,
268 const cpl_propertylist * paflist,
269 const cpl_table * table)
270{
271 bug_if (0);
272
273 /* THE TABLE */
274 skip_if (irplib_dfs_save_table(set, parlist, set, table, NULL, RECIPE_STRING,
275 VISIR_SPC_WCAL_ECH_TAB_PROCATG,
276 qclist, NULL, visir_pipe_id,
277 RECIPE_STRING "_spectrum_tab" CPL_DFS_FITS));
278
279#ifdef VISIR_SAVE_PAF
280 /* THE PAF FILE FOR QC PARAMETERS */
281 skip_if (cpl_dfs_save_paf("VISIR", RECIPE_STRING, paflist,
282 RECIPE_STRING CPL_DFS_PAF));
283#else
284 bug_if(paflist == NULL);
285#endif
286
287 end_skip;
288
289 return cpl_error_get_code();
290}
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.