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