IIINSTRUMENT Pipeline Reference Manual 4.6.1
visir_spc_phot_ech.c
1/* $Id: visir_spc_phot_ech.c,v 1.77 2012-08-21 09:56:14 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-08-21 09:56:14 $
24 * $Revision: 1.77 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32
33/*-----------------------------------------------------------------------------
34 Includes
35 -----------------------------------------------------------------------------*/
36
37#include "visir_recipe.h"
38#include "visir_spectro.h"
39#include "visir_spc_distortion.h"
40#include "visir_spc_photom.h"
41
42/*-----------------------------------------------------------------------------
43 Defines
44 -----------------------------------------------------------------------------*/
45
46#define RECIPE_STRING "visir_old_spc_phot_ech"
47
48/* FITS keys to be loaded for all raw files */
49#define RECIPE_KEYS_REGEXP_ALL \
50 VISIR_PFITS_REGEXP_IMG_RECOMBINE \
51 "|" VISIR_PFITS_REGEXP_SPC_GET_RES_WL \
52 "|" VISIR_PFITS_REGEXP_SPC_SENSIT
53
54/* FITS keys to be loaded for first raw file */
55#define RECIPE_KEYS_REGEXP \
56 RECIPE_KEYS_REGEXP_ALL \
57 "|" VISIR_PFITS_SPC_PHOT_COPY \
58 "|" VISIR_PFITS_REGEXP_CAPA \
59 "|" VISIR_PFITS_REGEXP_SPC_PHOT_PAF
60
61/* FITS keys to be loaded for first raw file, in case WCS is used */
62#define RECIPE_KEYS_REGEXP_WCS \
63 RECIPE_KEYS_REGEXP \
64 "|" IRPLIB_PFITS_WCS_REGEXP
65
66/*-----------------------------------------------------------------------------
67 Private Functions prototypes
68 -----------------------------------------------------------------------------*/
69
70static cpl_error_code visir_spc_phot_ech_save(cpl_frameset *,
71 const cpl_parameterlist *,
72 const cpl_propertylist *,
73 const cpl_propertylist *,
74 const cpl_image *,
75 const cpl_image *,
76 const cpl_table *);
77
78VISIR_RECIPE_DEFINE(visir_old_spc_phot_ech,
79 VISIR_PARAM_EMIS_TOL |
80 VISIR_PARAM_ZERODIST | VISIR_PARAM_ORDEROFF |
81 VISIR_PARAM_REFINE | VISIR_PARAM_XCORR |
82 VISIR_PARAM_OFFSETS | VISIR_PARAM_OBJECTS |
83 VISIR_PARAM_NODPOS | VISIR_PARAM_AUTOBPM |
84 VISIR_PARAM_GLITCH | VISIR_PARAM_PURGE |
85 VISIR_PARAM_UNION | VISIR_PARAM_REJECT |
86 VISIR_PARAM_STRIPITE | VISIR_PARAM_STRIPMOR |
87 VISIR_PARAM_PLOT | VISIR_PARAM_SLITSKEW |
88 VISIR_PARAM_SPECSKEW | VISIR_PARAM_VERTARC |
89 VISIR_PARAM_REJLEFT | VISIR_PARAM_REJRIGHT |
90 VISIR_PARAM_HORIARC | VISIR_PARAM_FIXCOMBI |
91 VISIR_PARAM_GAIN | VISIR_PARAM_RONOISE |
92 VISIR_PARAM_OXSIGMA | VISIR_PARAM_OXNITER |
93 VISIR_PARAM_OXSMOOTH | VISIR_PARAM_OXKERNEL,
94 "Old DRS detector: Sensitivity computation in echelle spectroscopy",
95 "This recipe estimates the dispersion relation using the "
96 "atmospheric spectrum\n"
97 "in a echelle spectroscopy half-cycle frame.\n"
98 "It also extracts the spectrum of an observed object "
99 "using a combined frame.\n"
100 "Lastly, it computes the spectral photometry of an "
101 "observed standard star.\n"
102 "The files listed in the Set Of Frames (sof-file) "
103 "must be tagged:\n"
104 "VISIR-Echelle-Spectroscopy-file.fits "
105 VISIR_SPC_PHOT_ECH_RAW "\n"
106 "VISIR-Quantum-Efficiency-Calibration-file.fits "
107 VISIR_CALIB_QEFF_SPC "\n"
108 "VISIR-Atmospheric-Emission-Lines-Calibration-file.fits "
109 VISIR_CALIB_LINES_SPC
110 "\n"
111 "VISIR-Spectroscopic-Standard-Star-Catalog.fits "
112 VISIR_CALIB_STDSTAR_SPC "\n"
113 MAN_VISIR_CALIB_BPM_SPC);
114
115/*----------------------------------------------------------------------------*/
119/*----------------------------------------------------------------------------*/
120
121/*-----------------------------------------------------------------------------
122 Functions code
123 -----------------------------------------------------------------------------*/
124
125/*----------------------------------------------------------------------------*/
132/*----------------------------------------------------------------------------*/
133static int visir_old_spc_phot_ech(cpl_frameset * framelist,
134 const cpl_parameterlist * parlist)
135{
136 irplib_framelist * allframes = NULL;
137 irplib_framelist * rawframes = NULL;
138 cpl_propertylist * qclist = cpl_propertylist_new();
139 cpl_propertylist * paflist = cpl_propertylist_new();
140 const char * badpix;
141 const char * star_cat;
142 const char * spc_cal_qeff;
143 const char * spc_cal_lines;
144 const char * flat;
145 cpl_image ** combinedpair = NULL;
146 cpl_image * combined = NULL;
147 cpl_table * tab = NULL;
148 cpl_image * weight2d = NULL;
149 double wlen, slitw, temp, fwhm;
150 visir_spc_resol resol;
151 visir_spc_config config;
152 cpl_boolean drop_wcs;
153 const char * keys_regexp = "^(" RECIPE_KEYS_REGEXP_WCS
154 "|" VISIR_PFITS_REGEXP_DIT
155 ")$";
156 const char * dit_key = VISIR_PFITS_DOUBLE_DIT;
157
158 config.recipename = RECIPE_STRING;
159 config.parlist = parlist;
160
161 /* Retrieve input parameters */
162 config.do_fixcombi = visir_parameterlist_get_bool(
163 parlist, RECIPE_STRING, VISIR_PARAM_FIXCOMBI);
164 config.plot = visir_parameterlist_get_int(
165 parlist, RECIPE_STRING, VISIR_PARAM_PLOT);
167 parlist, RECIPE_STRING, VISIR_PARAM_SLITSKEW);
169 parlist, RECIPE_STRING, VISIR_PARAM_SPECSKEW);
171 parlist, RECIPE_STRING, VISIR_PARAM_VERTARC);
172 config.delta = visir_parameterlist_get_double(
173 parlist, RECIPE_STRING, VISIR_PARAM_HORIARC);
174 config.gain = visir_parameterlist_get_double(
175 parlist, RECIPE_STRING, VISIR_PARAM_GAIN);
177 parlist, RECIPE_STRING, VISIR_PARAM_RONOISE);
178 config.ox_sigma = visir_parameterlist_get_double(
179 parlist, RECIPE_STRING, VISIR_PARAM_OXSIGMA);
180 config.ox_niters = visir_parameterlist_get_int(
181 parlist, RECIPE_STRING, VISIR_PARAM_OXNITER);
182 config.ox_smooth = visir_parameterlist_get_int(
183 parlist, RECIPE_STRING, VISIR_PARAM_OXSMOOTH);
184 config.ox_kernel = visir_parameterlist_get_int(
185 parlist, RECIPE_STRING, VISIR_PARAM_OXKERNEL);
186 config.orderoffset = visir_parameterlist_get_int(
187 parlist, RECIPE_STRING, VISIR_PARAM_ORDEROFF);
188 config.phot_emis_tol = visir_parameterlist_get_double(
189 parlist, RECIPE_STRING, VISIR_PARAM_EMIS_TOL);
190 config.bkgcorrect = CPL_FALSE;
191
192 skip_if (0);
193
194 /* Identify the RAW and CALIB frames in the input frameset */
195 skip_if (visir_dfs_set_groups(framelist));
196
197 /* Objects observation */
198 allframes = irplib_framelist_cast(framelist);
199 skip_if (allframes == NULL);
200 rawframes = irplib_framelist_extract(allframes, VISIR_SPC_PHOT_ECH_RAW);
201 skip_if (rawframes == NULL);
202
203 irplib_framelist_empty(allframes);
204
205 skip_if(irplib_framelist_load_propertylist(rawframes, 0, 0, keys_regexp,
206 CPL_FALSE));
207
208 skip_if(irplib_framelist_load_propertylist_all(rawframes, 0, ".*", CPL_FALSE));
209
210 skip_if(visir_dfs_check_framelist_tag(rawframes));
211
212 if (cpl_propertylist_has(irplib_framelist_get_propertylist(rawframes, 0),
213 VISIR_PFITS_DOUBLE_SEQ1_DIT))
214 dit_key = VISIR_PFITS_DOUBLE_SEQ1_DIT;
215 skip_if(0);
216
217 /* Standard star catalog */
218 star_cat = irplib_frameset_find_file(framelist, VISIR_CALIB_STDSTAR_SPC);
219 if (star_cat == NULL) {
220 cpl_msg_error(cpl_func, "The file with the star catalog is missing");
221 skip_if(1);
222 }
223
224 /* Quantum efficiency file */
225 spc_cal_qeff = irplib_frameset_find_file(framelist, VISIR_CALIB_QEFF_SPC);
226
227 /* Spectral lines calibration file */
228 spc_cal_lines = irplib_frameset_find_file(framelist, VISIR_CALIB_LINES_SPC);
229
230 /* Bad pixels calibration file */
231 badpix = irplib_frameset_find_file(framelist, VISIR_CALIB_BPM);
232
233 /* Flatfield calibration file */
234 flat = irplib_frameset_find_file(framelist, VISIR_CALIB_FLAT);
235
236 /* Get the resolution and central wavelength */
237 resol = visir_spc_get_res_wl(rawframes, &wlen, &slitw, &temp, &fwhm, 0);
238
239 skip_if (0);
240
241 if (resol != VISIR_SPC_R_GHR) {
242 if (config.orderoffset == 0) {
243 cpl_msg_warning(cpl_func,"Reducing non-HR Grism data as main order");
244 } else {
245 cpl_msg_error(cpl_func, "This recipe cannot reduce non-HR Grism "
246 "data with an order-offset of %d",
247 config.orderoffset);
248 visir_error_set(CPL_ERROR_TYPE_MISMATCH);
249 skip_if(1);
250 }
251 }
252
253 /* Combine the frames */
254 combinedpair = visir_img_recombine(RECIPE_STRING, parlist, rawframes, badpix,
255 flat, CPL_GEOM_FIRST, &drop_wcs,
256 !config.do_fixcombi, wlen, resol);
257
258 if (combinedpair == NULL) {
259 cpl_msg_error(cpl_func, "Could not combine the input frames");
260 skip_if (1);
261 }
262
263 cpl_image_delete(combinedpair[1]);
264 combined = cpl_image_cast(combinedpair[0], CPL_TYPE_DOUBLE);
265 cpl_image_delete(combinedpair[0]);
266
267 skip_if (0);
268
269 /* Compute here the sensitivity */
270 cpl_msg_info(cpl_func, "Compute the sensitivity");
271 config.phu = qclist;
272 tab = visir_spc_phot_sensit_from_image(&combined, rawframes, &config,
273 star_cat, spc_cal_lines,
274 spc_cal_qeff, &weight2d, qclist,
275 CPL_TRUE, wlen, slitw, temp, fwhm,
276 resol, dit_key);
277
278 if (tab == NULL) {
279 cpl_msg_error(cpl_func, "Cannot compute sensitivity: '%s' in %s",
280 cpl_error_get_message(), cpl_error_get_where());
281 skip_if(1);
282 }
283
284 bug_if (visir_spectro_qc(qclist, paflist, drop_wcs, rawframes,
285 "^(" VISIR_PFITS_SPC_PHOT_COPY ")$",
286 "^(" VISIR_PFITS_REGEXP_SPC_PHOT_PAF ")$"));
287 irplib_framelist_empty(rawframes);
288
289 /* Save the results */
290 cpl_msg_info(cpl_func, "Save the results");
291
292 /* PRO.CATG */
293 bug_if (cpl_propertylist_append_string(paflist, CPL_DFS_PRO_CATG,
294 VISIR_SPC_PHOT_ECH_COMBINED_PROCATG));
295
296 skip_if (visir_spc_phot_ech_save(framelist, parlist, qclist, paflist,
297 combined, weight2d, tab));
298
299 end_skip;
300
301 cpl_propertylist_delete(qclist);
302 cpl_propertylist_delete(paflist);
303 irplib_framelist_delete(allframes);
304 irplib_framelist_delete(rawframes);
305 cpl_image_delete(combined);
306 cpl_table_delete(tab);
307 cpl_image_delete(weight2d);
308
309 cpl_free(combinedpair);
310
311 return cpl_error_get_code();
312}
313
314/*----------------------------------------------------------------------------*/
326/*----------------------------------------------------------------------------*/
327static cpl_error_code visir_spc_phot_ech_save(cpl_frameset * set,
328 const cpl_parameterlist * parlist,
329 const cpl_propertylist * qclist,
330 const cpl_propertylist * paflist,
331 const cpl_image *combined,
332 const cpl_image *weight2d,
333 const cpl_table * table)
334{
335 bug_if (0);
336
337 /* THE TABLE */
338 skip_if (irplib_dfs_save_table(set, parlist, set, table, NULL, RECIPE_STRING,
339 VISIR_SPC_PHOT_ECH_TAB_PROCATG,
340 qclist, NULL, visir_pipe_id,
341 RECIPE_STRING "_tab" CPL_DFS_FITS));
342
343 /* THE COMBINED IMAGE */
344 skip_if (irplib_dfs_save_image(set, parlist, set, combined, CPL_BPP_IEEE_FLOAT,
345 RECIPE_STRING, VISIR_SPC_PHOT_ECH_COMBINED_PROCATG,
346 qclist, NULL, visir_pipe_id,
347 RECIPE_STRING CPL_DFS_FITS));
348
349 /* THE WEIGHT IMAGE */
350 skip_if (irplib_dfs_save_image(set, parlist, set, weight2d, CPL_BPP_IEEE_FLOAT,
351 RECIPE_STRING, VISIR_SPC_PHOT_ECH_WEIGHT_PROCATG,
352 qclist, NULL, visir_pipe_id,
353 RECIPE_STRING "_weight" CPL_DFS_FITS));
354
355#ifdef VISIR_SAVE_PAF
356 /* THE PAF FILE FOR QC PARAMETERS */
357 skip_if (cpl_dfs_save_paf("VISIR", RECIPE_STRING, paflist,
358 RECIPE_STRING CPL_DFS_PAF));
359#else
360 bug_if(paflist == NULL);
361#endif
362
363 end_skip;
364
365 return cpl_error_get_code();
366
367}
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_image ** visir_img_recombine(const char *recipename, const cpl_parameterlist *parlist, const irplib_framelist *rawframes, const char *badpix, const char *flat, cpl_geom_combine combine_mode, cpl_boolean *pdid_resize, cpl_boolean do_spc_fix, double wlen, visir_spc_resol resol)
The VISIR imaging combination using cross correlation.
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.
cpl_table * visir_spc_phot_sensit_from_image(cpl_image **combined, const irplib_framelist *rawframes, const visir_spc_config *pconfig, const char *star_cat, const char *spc_cal_lines, const char *spc_cal_qeff, cpl_image **pweight2d, cpl_propertylist *qclist, cpl_boolean do_ech, double wlen, double slitw, double temp, double fwhm, const visir_spc_resol resol, const char *dit_key)
Extract spectrum from image and compute sensitivity.