ERIS Pipeline Reference Manual 1.8.14
eris_ifu_stdstar_static.c
1/* $Id$
2 *
3 * This file is part of the ERIS 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 02110-1301 USA
19 */
20
21#ifdef HAVE_CONFIG_H
22#include <config.h>
23#endif
24
25#include <hdrl.h>
26#include "eris_utils.h"
27#include "eris_ifu_jitter_static.h"
28#include "eris_ifu_efficiency_response.h"
29#include "eris_ifu_resample.h"
30#include "eris_ifu_utils.h"
31#include "eris_ifu_strehl.h"
32#include "eris_ifu_error.h"
33#include "eris_ifu_stdstar_static.h"
34
47cpl_error_code
48eris_stdstar_reduction_common(cpl_frameset *frameset,
49 const cpl_parameterlist *parlist,
50 cpl_boolean apply_flat_field,
51 const char *context,
52 const char *recipe_name)
53{
54 struct stdParamStruct stdParams = stdParamStructInit;
55 struct sofStruct sof;
56 struct paramStruct params;
57 int obj_number = 0;
58 char *pipefile_prefix = NULL;
59
60 cpl_ensure(frameset, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
61 cpl_ensure(parlist, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
62 cpl_ensure(context, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
63 cpl_ensure(recipe_name, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
64
65 TRY {
66 if (apply_flat_field) {
67 cpl_msg_info(cpl_func, "=============================================");
68 cpl_msg_info(cpl_func, "Data reduction with flat field");
69 cpl_msg_info(cpl_func, "---------------------------------------------");
70 pipefile_prefix = cpl_sprintf("%s", recipe_name);
71 } else {
72 cpl_msg_info(cpl_func, "=============================================");
73 cpl_msg_info(cpl_func, "Data reduction without flat field");
74 cpl_msg_info(cpl_func, "---------------------------------------------");
75 pipefile_prefix = cpl_sprintf("%s_%s", recipe_name, "no_flat");
76 }
77
78 cpl_boolean is_std_flux = CPL_FALSE;
79 cpl_boolean is_std_norm = CPL_FALSE;
80 cpl_boolean is_pupil_lamp = CPL_FALSE;
81 cpl_boolean is_pupil_sky = CPL_FALSE;
82 cpl_boolean is_psf = CPL_FALSE;
83 if (cpl_frameset_find(frameset,"STD") != NULL){
84 is_std_norm = CPL_TRUE;
85 }
86 else if (cpl_frameset_find(frameset,"PUPIL_SKY") != NULL){
87 is_pupil_sky = CPL_TRUE;
88 }
89 else if (cpl_frameset_find(frameset,"PUPIL_LAMP") != NULL) {
90 is_pupil_lamp = CPL_TRUE;
91 }
92 else if (cpl_frameset_find(frameset,"STD_FLUX") != NULL) {
93 is_std_flux = CPL_TRUE;
94 }
95 else if (cpl_frameset_find(frameset,"PSF_CALIBRATOR") != NULL) {
96 is_psf = CPL_TRUE;
97 }
98
99
100 if (is_std_norm) {
101 obj_number = eris_frameset_count_tag(frameset, "STD");
102 } else if (is_std_flux) {
103 obj_number = eris_frameset_count_tag(frameset, "STD_FLUX");
104 } else if (is_pupil_lamp) {
105 obj_number = eris_frameset_count_tag(frameset, "PUPIL_LAMP");
106 } else if (is_pupil_sky) {
107 obj_number = eris_frameset_count_tag(frameset, "PUPIL_SKY");
108 } else if (is_psf) {
109 obj_number = eris_frameset_count_tag(frameset, "PSF_CALIBRATOR");
110 }
111
112 (void)memset(&sof, 0, sizeof(sof)); /* Rough init so free works on error */
113
114 cpl_msg_info(cpl_func, "Reading recipe parameters");
116 eris_ifu_jitter_fetch_params(context, recipe_name, parlist,
117 &stdParams, &params));
118 cpl_msg_info(cpl_func,
119 "Instrument is %d, requested product level is %d",
120 stdParams.instrument, stdParams.productDepth);
121
123 eris_ifu_jitter_processSof(frameset,
124 stdParams,
125 params,
126 &sof));
127
128 cpl_msg_info(cpl_func,"Instrument %s, band %s, scale %s",
129 eris_ifu_get_instrumentString(sof.instrument),
130 eris_ifu_get_bandString(sof.band),
132
134 eris_ifu_jitter_process_exposures(&sof, stdParams, params,
135 frameset, parlist, pipefile_prefix,
136 context));
137
138 cubeType obj_type = OBJECT_CUBE;
139
141 eris_ifu_jitter_process_cubes(&sof, stdParams, params, frameset,
142 parlist, pipefile_prefix, &obj_type));
143
144 cubeType resampled_obj_type = STD_CUBE_COADD;
145 const char *input_cube_pro_catg = NULL;
146 if (cpl_frameset_count_tags(frameset, ERIS_IFU_PRO_JITTER_DAR_CUBE)
147 > 0) {
148 cpl_msg_info(cpl_func,"case1");
149 if(is_std_norm) {
150 obj_type = DAR_STD_CUBE;
151 resampled_obj_type = DAR_STD_CUBE_COADD;
152 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_DAR_CUBE;
153 } else if(is_std_flux) {
154 obj_type = DAR_STD_FLUX_CUBE;
155 if (apply_flat_field) {
156 resampled_obj_type = STD_FLUX_CUBE_COADD;
157 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD;
158 } else {
159 resampled_obj_type = STD_FLUX_CUBE_COADD_NOFLAT;
160 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_NOFLAT;
161 }
162 } else if(is_psf) {
163 obj_type = DAR_PSF_CUBE;
164 resampled_obj_type = DAR_PSF_CUBE_COADD;
165 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_DAR_CUBE;
166 } else if(is_pupil_lamp || is_pupil_sky) {
167 obj_type = DAR_STD_CUBE;
168 resampled_obj_type = DAR_PUPIL_CUBE_COADD;
169 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_DAR_CUBE;
170 }
171 } else if (cpl_frameset_count_tags(frameset, ERIS_IFU_PRO_JITTER_TWK_CUBE)
172 > 0 ) {
173 cpl_msg_info(cpl_func,"case2");
174 if(is_std_norm) {
175 obj_type = TWEAKED_STD_CUBE;
176 resampled_obj_type = STD_CUBE_COADD;
177 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_CUBE_COADD;
178 } else if(is_std_flux) {
179 obj_type = STD_FLUX_CUBE;
180 if (apply_flat_field) {
181 resampled_obj_type = STD_FLUX_CUBE_COADD;
182 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD;
183 } else {
184 resampled_obj_type = STD_FLUX_CUBE_COADD_NOFLAT;
185 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_NOFLAT;
186 }
187 } else if(is_psf) {
188 obj_type = PSF_CUBE;
189 resampled_obj_type = PSF_CUBE_COADD;
190 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_TWK_CUBE;
191 } else if(is_pupil_lamp || is_pupil_sky) {
192 obj_type = PUPIL_CUBE;
193 resampled_obj_type = PUPIL_CUBE_COADD;
194 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_TWK_CUBE;
195 }
196 } else {
197 cpl_msg_info(cpl_func,"case3");
198 if(is_std_norm) {
199 obj_type = STD_CUBE;
200 resampled_obj_type = STD_CUBE_COADD;
201 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_CUBE_COADD;
202 } else if(is_std_flux) {
203 obj_type = STD_FLUX_CUBE;
204 if (apply_flat_field) {
205 resampled_obj_type = STD_FLUX_CUBE_COADD;
206 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD;
207 } else {
208 resampled_obj_type = STD_FLUX_CUBE_COADD_NOFLAT;
209 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_NOFLAT;
210 }
211
212 } else if(is_psf) {
213 obj_type = PSF_CUBE;
214 resampled_obj_type = PSF_CUBE_COADD;
215 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_PSF_CUBE_COADD;
216 } else if(is_pupil_lamp ||is_pupil_sky) {
217 obj_type = PUPIL_CUBE;
218 resampled_obj_type = PUPIL_CUBE_COADD;
219 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_PUPIL_CUBE_COADD;
220 }
221 }
222
223 cpl_msg_info(cpl_func,"input cube pro catg: %s",input_cube_pro_catg);
224
225 /* combine cubes with HDRL functionality */
226 if (params.combine && obj_number > 1) {
227 // eris_ifu_combine(obj_type, stdParams, params, frameset, parlist,
228 // recipe_name, pipefile_prefix);
229 char *combDoCatg = NULL;
230 char *filenameSpec = NULL;
231 eris_ifu_jitter_get_procatg_and_filename(obj_type, &combDoCatg,
232 &filenameSpec);
233
234 cpl_msg_debug(cpl_func,"GENERATE COMBINED DATA CUBE %s",combDoCatg);
235 eris_ifu_combine_pbp(frameset, parlist, combDoCatg, filenameSpec,
236 NULL, NULL, NULL, recipe_name, pipefile_prefix);
237
238 eris_ifu_free_string(&combDoCatg);
239 eris_ifu_free_string(&filenameSpec);
240 } else if (obj_number == 1) {
241 char *combDoCatg = NULL;
242 char *filenameSpec = NULL;
243 eris_ifu_jitter_get_procatg_and_filename(obj_type, &combDoCatg,
244 &filenameSpec);
245 if(is_std_norm) {
246 eris_frameset_duplicate_cube_tag(frameset,
247 ERIS_IFU_PRO_JITTER_STD_CUBE, apply_flat_field);
248 eris_ifu_cube_collapse_mean_and_save(ERIS_IFU_PRO_JITTER_STD_CUBE,
249 frameset, parlist, recipe_name, /*filenameSpec, */apply_flat_field, CPL_FALSE);
250 //cpl_frameset_dump(frameset, stdout);
251 }
252 else if(is_std_flux) {
253 cpl_msg_debug(cpl_func,"duplicate FLUX cube tag");
254 eris_frameset_duplicate_cube_tag(frameset,
255 ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE, apply_flat_field);
256 eris_ifu_cube_collapse_mean_and_save(ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE,
257 frameset, parlist, recipe_name, /*filenameSpec,*/ apply_flat_field, CPL_FALSE);
258
259 } else if(is_pupil_lamp || is_pupil_sky) {
260 cpl_msg_debug(cpl_func,"duplicate PUPIL cube tag");
261 eris_frameset_duplicate_cube_tag(frameset,
262 ERIS_IFU_PRO_JITTER_OBJ_CUBE, apply_flat_field);
263 eris_ifu_cube_collapse_mean_and_save(ERIS_IFU_PRO_JITTER_OBJ_CUBE,
264 frameset, parlist, recipe_name, /*filenameSpec, */apply_flat_field, CPL_TRUE);
265 } else if(is_psf) {
266 cpl_msg_debug(cpl_func,"duplicate PSF cube tag");
267 eris_frameset_duplicate_cube_tag(frameset,
268 ERIS_IFU_PRO_JITTER_PSF_CUBE, apply_flat_field);
269 eris_ifu_cube_collapse_mean_and_save(ERIS_IFU_PRO_JITTER_PSF_CUBE,
270 frameset, parlist, recipe_name, /*filenameSpec, */apply_flat_field, CPL_FALSE);
271 }
272 cpl_free(combDoCatg);
273 cpl_free(filenameSpec);
274 }
275
276 if( is_pupil_lamp || is_pupil_sky) {
277// hdrl_imagelist* himl = NULL;
278 cpl_table* qclog_tbl = eris_qclog_init();
279 eris_get_pupil_shift(sof.exposureTable[0].cube, 0, &qclog_tbl);
280 cpl_free(qclog_tbl);
281 }
282
283 /* extract spectra and for STD star computes response and efficiency */
284 if (apply_flat_field == CPL_FALSE) {
285 if (is_std_norm) {
286 obj_type = STD_CUBE_COADD_NOFLAT;
287 } else if (is_std_flux) {
288 obj_type = STD_FLUX_CUBE_COADD_NOFLAT;
289 }
290 }
291 if (params.extractSource && eris_can_extract(frameset)) {
292 eris_print_rec_status(102);
293 cpl_msg_info(cpl_func,"input pro catg: %s obj_type: %d",
294 input_cube_pro_catg, resampled_obj_type);
295
296 eris_ifu_jitter_extract(frameset, parlist, resampled_obj_type,
297 input_cube_pro_catg, stdParams, pipefile_prefix, context);
298 eris_print_rec_status(103);
299 }
300 //cpl_frameset_dump(frameset, stdout);
301 char* param_name = NULL;
302
303 param_name = cpl_sprintf("%s.compute-strehl", context);
304 cpl_boolean compute_strehl = cpl_parameter_get_bool(
305 cpl_parameterlist_find_const(parlist, param_name));
306 cpl_free(param_name);
307
308 param_name = cpl_sprintf("%s.flux-calibrate", context);
309 cpl_boolean flux_calibrate = cpl_parameter_get_bool(
310 cpl_parameterlist_find_const(parlist, param_name));
311 cpl_free(param_name);
312
313 eris_ifu_jitter_get_cube_type_string(obj_type);
314 if(obj_type == STD_CUBE || obj_type == STD_CUBE_COADD_NOFLAT ||
315 obj_type == STD_FLUX_CUBE || obj_type == STD_FLUX_CUBE_COADD_NOFLAT||
316 obj_type == DAR_STD_FLUX_CUBE || obj_type == DAR_STD_CUBE_COADD) {
317
318 param_name = cpl_sprintf("%s.compute-efficiency", context);
319 cpl_boolean compute_efficiency = cpl_parameter_get_bool(
320 cpl_parameterlist_find_const(parlist, param_name));
321 cpl_free(param_name);
322
323 param_name = cpl_sprintf("%s.compute-response", context);
324 cpl_boolean compute_response = cpl_parameter_get_bool(
325 cpl_parameterlist_find_const(parlist, param_name));
326 cpl_free(param_name);
327
328 cpl_msg_debug(cpl_func,"compute_response: %d eris_can_compute_response: %d apply_flat_field: %d",
329 compute_response,eris_can_compute_response(frameset),
330 apply_flat_field);
331 if (compute_response && eris_can_compute_response(frameset) &&
332 apply_flat_field == CPL_TRUE) {
333 cpl_msg_info(cpl_func,"Compute response");
334 eris_response_compute(recipe_name, parlist, frameset, frameset);
335 }
336
337 cpl_msg_debug(cpl_func, "compute_efficiency: %d eris_can_compute_efficiency: %d",
338 compute_efficiency,eris_can_compute_efficiency(frameset));
339
340 if (compute_efficiency && apply_flat_field == CPL_FALSE) {
341 if (eris_can_compute_efficiency(frameset)) {
342 cpl_msg_info(cpl_func,"Compute efficiency");
343 cpl_frame * spectrum_frame = NULL;
344 cpl_frame * extcoeff_frame = NULL;
345 cpl_frame * fluxstdcat_frame = NULL;
346
347 spectrum_frame = cpl_frameset_find(frameset,
348 ERIS_IFU_PRO_JITTER_SPECTRUM_NOFLAT);
349 extcoeff_frame = cpl_frameset_find(frameset,
350 ERIS_IFU_CALIB_EXTCOEFF_TABLE);
351 fluxstdcat_frame = cpl_frameset_find(frameset,
352 ERIS_IFU_CALIB_FLUX_STD_CATALOG);
353
354 cpl_table* tab_eff = eris_efficiency_compute(spectrum_frame,
355 fluxstdcat_frame, extcoeff_frame, frameset, parlist,
356 pipefile_prefix);
357
358 cpl_table_delete(tab_eff);
359 }
360 }
361 }
362
363 //cpl_frameset_dump(frameset, stdout);
364 cpl_msg_debug(cpl_func,"flux_calibrate: %d eris_can_flux_calibrate: %d, apply_flat_field:%d",
365 flux_calibrate,eris_can_flux_calibrate(frameset),apply_flat_field);
366 if (flux_calibrate && apply_flat_field == CPL_TRUE) {
367 if (eris_can_flux_calibrate(frameset)) {
368 cpl_msg_info(cpl_func,"Flux calibrate extracted spectrum and combined data cube");
369
370 eris_flux_calibrate_spectra(pipefile_prefix, recipe_name,
371 parlist, frameset, frameset);
372 char* cube_pro_catg = NULL;
373 if (is_std_norm) {
374 cube_pro_catg = cpl_sprintf("%s",ERIS_IFU_PRO_JITTER_STD_CUBE_COADD);
375 } else if (is_std_flux) {
376 cube_pro_catg = cpl_sprintf("%s",ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD);
377 } else {
378 cube_pro_catg = cpl_sprintf("%s",ERIS_IFU_PRO_JITTER_PSF_CUBE_COADD);
379 }
380
381 eris_flux_calibrate_cube2(cube_pro_catg, pipefile_prefix,
382 recipe_name, parlist, /*frameset, */frameset);
383 cpl_free(cube_pro_catg);
384 }
385 }
386
387 //if(compute_strehl && !is_std_flux) {
388 if (compute_strehl && apply_flat_field) {
389 /* for PSF standards we can compute the Strehl */
390 cpl_msg_info(cpl_func,"===============================================");
391 cpl_msg_info(cpl_func,"===========STREHL COMPUTATION==================");
392 cpl_msg_info(cpl_func,"===============================================");
393 eris_ifu_stdstar_strehl_compute(frameset, parlist, context/*, recipe_name*/);
394 }
395 //cpl_frameset_dump(frameset, stdout);
396 } CATCH {
397
398 }
399
400 cpl_free(pipefile_prefix);
401 eris_ifu_jitter_free_sofStruct(&sof);
402 eris_ifu_free_std_param(&stdParams);
403 eris_check_error_code("eris_stdstar_reduction_common");
404
405 return cpl_error_get_code();
406}
#define BRK_IF_ERROR(function)
If function is or returns an error != CPL_ERROR_NONE, then the try-block is exited.
#define TRY
Beginning of a TRY-block.
#define CATCH
End of a TRY-block, beginning of a CATCH-block.
cpl_error_code eris_ifu_combine_pbp(cpl_frameset *frameset, const cpl_parameterlist *parlist, const char *input_cube_pro_catg, const char *filenameSpec, float *offsetx, float *offsety, const char *offunit, const char *recipe_name, const char *pipefile_prefix)
This function resample input cubes plane by plane using HDRL.
cpl_error_code eris_ifu_cube_collapse_mean_and_save(const char *pro_catg, cpl_frameset *frameset, const cpl_parameterlist *parlist, const char *recipe_name, cpl_boolean apply_flat, cpl_boolean is_pupil)
-------------------------------------------------------------------------—‍/
void eris_ifu_free_string(char **item)
free memory and set pointer to null
cpl_table * eris_qclog_init(void)
Initialize QC table.
const char * eris_ifu_get_bandString(ifsBand band)
eris_ifu_get_bandString
cpl_error_code eris_get_pupil_shift(hdrl_imagelist *iml, const int n, cpl_table **qclog_tbl)
Get what object shift.
const char * eris_ifu_get_instrumentString(ifsInstrument instrument)
eris_ifu_get_instrumentString
const char * eris_ifu_get_preopticsScaleString(ifsPreopticsScale scale)
eris_ifu_get_preopticsScaleString
cpl_error_code eris_check_error_code(const char *func_id)
handle CPL errors
Definition: eris_utils.c:56