IIINSTRUMENT Pipeline Reference Manual 4.5.1
visir_util_qc.c
1/*
2 * This file is part of the VISIR Pipeline
3 * Copyright (C) 2012,2015 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27
28#include "visir_recipe.h"
29
30#include <string.h>
31
32/*-----------------------------------------------------------------------------
33 Defines
34 -----------------------------------------------------------------------------*/
35
36#define RECIPE_STRING "visir_util_qc"
37
38/*-----------------------------------------------------------------------------
39 Private Functions prototypes
40 -----------------------------------------------------------------------------*/
41
42#ifdef VISIR_CHAIN
43#define cpl_plugin_get_info visir_util_qc_get_info
44#endif
45// FIXME:
46cpl_recipe_define(visir_util_qc, VISIR_BINARY_VERSION,
47 "Julian Taylor", PACKAGE_BUGREPORT, "2012",
48 "Prepares qc parameters from data where the beam has "
49 "been deteteced and bad images have been removed",
50 "The files listed in the Set Of Frames (sof-file) "
51 "must be tagged:\n"
52 "VISIR-chopnod-corrected-file.fits "VISIR_UTIL_CORRECTED
53 "\nThe product(s) will have a FITS card\n"
54 "'HIERARCH ESO PRO CATG' with a value of: "
55 VISIR_UTIL_QC_PROCATG"\n");
56
57/*----------------------------------------------------------------------------*/
61/*----------------------------------------------------------------------------*/
62
63/*-----------------------------------------------------------------------------
64 Functions code
65 -----------------------------------------------------------------------------*/
66
67
68/*----------------------------------------------------------------------------*/
76/*----------------------------------------------------------------------------*/
77static cpl_error_code
78visir_util_qc_fill_parameterlist(cpl_parameterlist * self)
79{
80 if (self) {}
81 return CPL_ERROR_NONE;
82}
83
84
85/*----------------------------------------------------------------------------*/
92/*----------------------------------------------------------------------------*/
93static int visir_util_qc(cpl_frameset * framelist,
94 const cpl_parameterlist * parlist)
95{
96 cpl_frameset * usedframes = cpl_frameset_new();
97 cpl_propertylist * outlist = cpl_propertylist_new();
98 irplib_framelist * allframes = irplib_framelist_cast(framelist);
99 /* FIXME: macro */
100 irplib_framelist * rawframes =
101 irplib_framelist_extract(allframes, VISIR_UTIL_CORRECTED);
102 const int nrawframes = irplib_framelist_get_size(rawframes);
103 cpl_boolean undefined_beampos = CPL_FALSE;
104 /* only reading headers file, no cache needed */
105 cpl_fits_set_mode(CPL_FITS_STOP_CACHING);
106
107 irplib_framelist_load_propertylist_all(rawframes, 0, ".*", CPL_FALSE);
108
109 double t_exptime = 0;
110 double t_eff_exptime = 0;
111 cpl_size t_nimages = 0;
112 cpl_size t_neff_images = 0;
113 double t_bkg_sum = 0;
114 double t_min_obsstart = 1e300;
115 double t_max_filewrite = 0;
116
117 for (int iframe = 0; iframe < nrawframes; iframe++) {
118 cpl_propertylist * plist =
119 irplib_framelist_get_propertylist(rawframes, iframe);
120 cpl_frame * frm = irplib_framelist_get(rawframes, iframe);
121 float imgwgt = visir_pfits_get_img_weight(plist);
122 visir_data_type dtype;
123 visir_get_data_type(frm, plist, &dtype, NULL);
124 t_max_filewrite =
125 CX_MAX(cpl_propertylist_get_double(plist, "ESO DRS DATE"),
126 t_max_filewrite);
127 t_min_obsstart =
128 CX_MIN(cpl_propertylist_get_double(plist, "ESO DRS DATE-OBS"),
129 t_min_obsstart);
130
131 const int ndit = visir_pfits_get_ndit(plist);
132 const int navrg = visir_pfits_get_navrg(plist);
133
134 const double dit = visir_pfits_get_dit(plist);
135 if (iframe == 0)
136 cpl_propertylist_append(outlist, plist);
137
138 const cpl_size ncycles = visir_pfits_get_chop_ncycles(plist);
139 const char * beamid = cpl_propertylist_get_string(plist, "ESO QC BEAMID");
140
141 double time_per_img;
142 cpl_size nimages;
143 if (visir_data_is_burst(dtype)) {
144 time_per_img = dit * navrg;
145 nimages = ncycles * ndit / navrg;
146 }
147 else if (dtype == VISIR_DATA_AQU_INT) {
148 time_per_img = ncycles * dit * ndit * navrg;
149 nimages = 1;
150 }
151 else {
152 time_per_img = dit * ndit * navrg;
153 nimages = ncycles / navrg;
154 }
155 const cpl_size neff_images = cpl_frame_get_nextensions(frm);
156
157 double exptime = nimages * time_per_img;
158 double eff_exptime = neff_images * time_per_img;
159 double bkg_sum = 0;
160
161 exptime *= imgwgt;
162 eff_exptime *= imgwgt;
163
164 char filename[128];
165 sprintf(filename, "qc_header_%03d.fits", iframe);
166
167 if (cpl_propertylist_has(plist, "ESO QC BACKGD MEAN"))
168 bkg_sum = cpl_propertylist_get_double(plist, "ESO QC BACKGD MEAN");
169
170 if (strcmp(beamid, "UNDEFINED") == 0)
171 undefined_beampos = CPL_TRUE;
172
173 cpl_frame_set_group(frm, CPL_FRAME_GROUP_RAW);
174 cpl_frameset_insert(usedframes, cpl_frame_duplicate(frm));
175
176
177 cpl_propertylist_append_double(outlist, "ESO DRS IMGWGT", imgwgt);
178 /* signal exptime, the real exptime is nbeams times larger due to chop/nodding */
179 cpl_propertylist_append_double(outlist, "ESO QC EXPTIME TOTAL", exptime);
180 cpl_propertylist_append_double(outlist, "ESO QC EXPTIME EFFECTIVE", eff_exptime);
181 cpl_propertylist_append_int(outlist, "ESO QC NIMAGES TOTAL", (int)nimages);
182 cpl_propertylist_append_int(outlist, "ESO QC NIMAGES EFFECTIVE",
183 (int)neff_images);
184 cpl_propertylist_append_double(outlist, "ESO QC BACKGD MEAN", bkg_sum);
185 cpl_propertylist_update_string(outlist, "ESO QC BEAMID", beamid);
186 cpl_propertylist_update_double(outlist, "ESO QC BEAMX",
187 cpl_propertylist_get_double(plist, "ESO QC BEAMX"));
188 cpl_propertylist_update_double(outlist, "ESO QC BEAMY",
189 cpl_propertylist_get_double(plist, "ESO QC BEAMY"));
190 cpl_propertylist_append_double(outlist, "ESO QC EXECTIME",
191 (t_max_filewrite - t_min_obsstart) * 24 * 3600);
192
193 irplib_dfs_save_propertylist(framelist, parlist, usedframes,
194 RECIPE_STRING,
195 nrawframes > 1 ? VISIR_UTIL_QC_PROCATG :
196 VISIR_UTIL_QC_PROCATG "_COMBINED",
197 outlist, NULL,
198 visir_pipe_id, filename);
199 skip_if(0);
200
201 t_nimages += nimages;
202 t_neff_images += neff_images;
203 t_exptime += exptime;
204 t_eff_exptime += eff_exptime;
205 t_bkg_sum += bkg_sum;
206 }
207
208 double mean_bkg = t_bkg_sum / nrawframes;
209
210 cpl_msg_info(cpl_func, "Total exposure time: %gs", t_exptime);
211 cpl_msg_info(cpl_func, "Total effective exposure time: %gs", t_eff_exptime);
212 cpl_msg_info(cpl_func, "Total input images: %d", (int)t_nimages);
213 cpl_msg_info(cpl_func, "Total accepted input images: %d", (int)t_neff_images);
214 cpl_msg_info(cpl_func, "Mean input background: %g", mean_bkg);
215
216 if (nrawframes > 1) {
217 cpl_propertylist_append_double(outlist, "ESO DRS IMGWGT", 1.);
218 cpl_propertylist_append_double(outlist, "ESO QC EXPTIME TOTAL", t_exptime);
219 cpl_propertylist_append_double(outlist, "ESO QC EXPTIME EFFECTIVE", t_eff_exptime);
220 cpl_propertylist_append_int(outlist, "ESO QC NIMAGES TOTAL", (int)t_nimages);
221 cpl_propertylist_append_int(outlist, "ESO QC NIMAGES EFFECTIVE",
222 (int)t_neff_images);
223 cpl_propertylist_append_double(outlist, "ESO QC BACKGD MEAN", mean_bkg);
224 cpl_propertylist_append_string(outlist, "ESO QC BEAMID",
225 undefined_beampos ? "UNDEFINED" : "COMBINED");
226 cpl_propertylist_erase(outlist, "ESO QC BEAMX");
227 cpl_propertylist_erase(outlist, "ESO QC BEAMY");
228
229 cpl_propertylist_append_double(outlist, "ESO QC EXECTIME",
230 (t_max_filewrite - t_min_obsstart) * 24 * 3600);
231
232 skip_if(irplib_dfs_save_propertylist(framelist, parlist, usedframes,
233 RECIPE_STRING,
234 VISIR_UTIL_QC_PROCATG"_COMBINED",
235 outlist, NULL,
236 visir_pipe_id, "qc_header_all.fits"));
237 }
238
239 end_skip;
240 cpl_frameset_delete(usedframes);
241 irplib_framelist_delete(allframes);
242 irplib_framelist_delete(rawframes);
243 cpl_propertylist_delete(outlist);
244
245 return cpl_error_get_code();
246}
int visir_pfits_get_navrg(const cpl_propertylist *self)
The NAVRG.
Definition: visir_pfits.c:339
double visir_pfits_get_dit(const cpl_propertylist *self)
The DIT.
Definition: visir_pfits.c:325
double visir_pfits_get_img_weight(const cpl_propertylist *self)
The relative weight of the image compared to the other images.
Definition: visir_pfits.c:913
int visir_pfits_get_chop_ncycles(const cpl_propertylist *self)
The number of chopping cycles.
Definition: visir_pfits.c:237
int visir_pfits_get_ndit(const cpl_propertylist *self)
The NDIT keyword.
Definition: visir_pfits.c:535