ERIS Pipeline Reference Manual 1.8.15
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
35/*----------------------------------------------------------------------------*/
63/*----------------------------------------------------------------------------*/
64
67/*----------------------------------------------------------------------------*/
195/*----------------------------------------------------------------------------*/
196cpl_error_code
197eris_stdstar_reduction_common(cpl_frameset *frameset,
198 const cpl_parameterlist *parlist,
199 cpl_boolean apply_flat_field,
200 const char *context,
201 const char *recipe_name)
202{
203 struct stdParamStruct stdParams = stdParamStructInit;
204 struct sofStruct sof;
205 struct paramStruct params;
206 int obj_number = 0;
207 char *pipefile_prefix = NULL;
208
209 cpl_ensure(frameset, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
210 cpl_ensure(parlist, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
211 cpl_ensure(context, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
212 cpl_ensure(recipe_name, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
213
214 TRY {
215 if (apply_flat_field) {
216 cpl_msg_info(cpl_func, "=============================================");
217 cpl_msg_info(cpl_func, "Data reduction with flat field");
218 cpl_msg_info(cpl_func, "---------------------------------------------");
219 pipefile_prefix = cpl_sprintf("%s", recipe_name);
220 } else {
221 cpl_msg_info(cpl_func, "=============================================");
222 cpl_msg_info(cpl_func, "Data reduction without flat field");
223 cpl_msg_info(cpl_func, "---------------------------------------------");
224 pipefile_prefix = cpl_sprintf("%s_%s", recipe_name, "no_flat");
225 }
226
227 cpl_boolean is_std_flux = CPL_FALSE;
228 cpl_boolean is_std_norm = CPL_FALSE;
229 cpl_boolean is_pupil_lamp = CPL_FALSE;
230 cpl_boolean is_pupil_sky = CPL_FALSE;
231 cpl_boolean is_psf = CPL_FALSE;
232 if (cpl_frameset_find(frameset,"STD") != NULL){
233 is_std_norm = CPL_TRUE;
234 }
235 else if (cpl_frameset_find(frameset,"PUPIL_SKY") != NULL){
236 is_pupil_sky = CPL_TRUE;
237 }
238 else if (cpl_frameset_find(frameset,"PUPIL_LAMP") != NULL) {
239 is_pupil_lamp = CPL_TRUE;
240 }
241 else if (cpl_frameset_find(frameset,"STD_FLUX") != NULL) {
242 is_std_flux = CPL_TRUE;
243 }
244 else if (cpl_frameset_find(frameset,"PSF_CALIBRATOR") != NULL) {
245 is_psf = CPL_TRUE;
246 }
247
248
249 if (is_std_norm) {
250 obj_number = eris_frameset_count_tag(frameset, "STD");
251 } else if (is_std_flux) {
252 obj_number = eris_frameset_count_tag(frameset, "STD_FLUX");
253 } else if (is_pupil_lamp) {
254 obj_number = eris_frameset_count_tag(frameset, "PUPIL_LAMP");
255 } else if (is_pupil_sky) {
256 obj_number = eris_frameset_count_tag(frameset, "PUPIL_SKY");
257 } else if (is_psf) {
258 obj_number = eris_frameset_count_tag(frameset, "PSF_CALIBRATOR");
259 }
260
261 (void)memset(&sof, 0, sizeof(sof)); /* Rough init so free works on error */
262
263 cpl_msg_info(cpl_func, "Reading recipe parameters");
265 eris_ifu_jitter_fetch_params(context, recipe_name, parlist,
266 &stdParams, &params));
267 cpl_msg_info(cpl_func,
268 "Instrument is %d, requested product level is %d",
269 stdParams.instrument, stdParams.productDepth);
270
273 stdParams,
274 params,
275 &sof));
276
277 cpl_msg_info(cpl_func,"Instrument %s, band %s, scale %s",
278 eris_ifu_get_instrumentString(sof.instrument),
279 eris_ifu_get_bandString(sof.band),
281
283 eris_ifu_jitter_process_exposures(&sof, stdParams, params,
284 frameset, parlist, pipefile_prefix,
285 context));
286
287 cubeType obj_type = OBJECT_CUBE;
288
290 eris_ifu_jitter_process_cubes(&sof, stdParams, params, frameset,
291 parlist, pipefile_prefix, &obj_type));
292
293 cubeType resampled_obj_type = STD_CUBE_COADD;
294 const char *input_cube_pro_catg = NULL;
295 if (cpl_frameset_count_tags(frameset, ERIS_IFU_PRO_JITTER_DAR_CUBE)
296 > 0) {
297 cpl_msg_info(cpl_func,"case1");
298 if(is_std_norm) {
299 obj_type = DAR_STD_CUBE;
300 resampled_obj_type = DAR_STD_CUBE_COADD;
301 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_DAR_CUBE;
302 } else if(is_std_flux) {
303 obj_type = DAR_STD_FLUX_CUBE;
304 if (apply_flat_field) {
305 resampled_obj_type = STD_FLUX_CUBE_COADD;
306 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD;
307 } else {
308 resampled_obj_type = STD_FLUX_CUBE_COADD_NOFLAT;
309 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_NOFLAT;
310 }
311 } else if(is_psf) {
312 obj_type = DAR_PSF_CUBE;
313 resampled_obj_type = DAR_PSF_CUBE_COADD;
314 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_DAR_CUBE;
315 } else if(is_pupil_lamp || is_pupil_sky) {
316 obj_type = DAR_STD_CUBE;
317 resampled_obj_type = DAR_PUPIL_CUBE_COADD;
318 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_DAR_CUBE;
319 }
320 } else if (cpl_frameset_count_tags(frameset, ERIS_IFU_PRO_JITTER_TWK_CUBE)
321 > 0 ) {
322 cpl_msg_info(cpl_func,"case2");
323 if(is_std_norm) {
324 obj_type = TWEAKED_STD_CUBE;
325 resampled_obj_type = STD_CUBE_COADD;
326 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_CUBE_COADD;
327 } else if(is_std_flux) {
328 obj_type = STD_FLUX_CUBE;
329 if (apply_flat_field) {
330 resampled_obj_type = STD_FLUX_CUBE_COADD;
331 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD;
332 } else {
333 resampled_obj_type = STD_FLUX_CUBE_COADD_NOFLAT;
334 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_NOFLAT;
335 }
336 } else if(is_psf) {
337 obj_type = PSF_CUBE;
338 resampled_obj_type = PSF_CUBE_COADD;
339 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_TWK_CUBE;
340 } else if(is_pupil_lamp || is_pupil_sky) {
341 obj_type = PUPIL_CUBE;
342 resampled_obj_type = PUPIL_CUBE_COADD;
343 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_TWK_CUBE;
344 }
345 } else {
346 cpl_msg_info(cpl_func,"case3");
347 if(is_std_norm) {
348 obj_type = STD_CUBE;
349 resampled_obj_type = STD_CUBE_COADD;
350 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_CUBE_COADD;
351 } else if(is_std_flux) {
352 obj_type = STD_FLUX_CUBE;
353 if (apply_flat_field) {
354 resampled_obj_type = STD_FLUX_CUBE_COADD;
355 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD;
356 } else {
357 resampled_obj_type = STD_FLUX_CUBE_COADD_NOFLAT;
358 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_NOFLAT;
359 }
360
361 } else if(is_psf) {
362 obj_type = PSF_CUBE;
363 resampled_obj_type = PSF_CUBE_COADD;
364 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_PSF_CUBE_COADD;
365 } else if(is_pupil_lamp ||is_pupil_sky) {
366 obj_type = PUPIL_CUBE;
367 resampled_obj_type = PUPIL_CUBE_COADD;
368 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_PUPIL_CUBE_COADD;
369 }
370 }
371
372 cpl_msg_info(cpl_func,"input cube pro catg: %s",input_cube_pro_catg);
373
374 /* combine cubes with HDRL functionality */
375 if (params.combine && obj_number > 1) {
376 // eris_ifu_combine(obj_type, stdParams, params, frameset, parlist,
377 // recipe_name, pipefile_prefix);
378 char *combDoCatg = NULL;
379 char *filenameSpec = NULL;
380 eris_ifu_jitter_get_procatg_and_filename(obj_type, &combDoCatg,
381 &filenameSpec);
382
383 cpl_msg_debug(cpl_func,"GENERATE COMBINED DATA CUBE %s",combDoCatg);
384 eris_ifu_combine_pbp(frameset, parlist, combDoCatg, filenameSpec,
385 NULL, NULL, NULL, recipe_name, pipefile_prefix);
386
387 eris_ifu_free_string(&combDoCatg);
388 eris_ifu_free_string(&filenameSpec);
389 } else if (obj_number == 1) {
390 char *combDoCatg = NULL;
391 char *filenameSpec = NULL;
392 eris_ifu_jitter_get_procatg_and_filename(obj_type, &combDoCatg,
393 &filenameSpec);
394 if(is_std_norm) {
396 ERIS_IFU_PRO_JITTER_STD_CUBE, apply_flat_field);
397 eris_ifu_cube_collapse_mean_and_save(ERIS_IFU_PRO_JITTER_STD_CUBE,
398 frameset, parlist, recipe_name, /*filenameSpec, */apply_flat_field, CPL_FALSE);
399 //cpl_frameset_dump(frameset, stdout);
400 }
401 else if(is_std_flux) {
402 cpl_msg_debug(cpl_func,"duplicate FLUX cube tag");
404 ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE, apply_flat_field);
405 eris_ifu_cube_collapse_mean_and_save(ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE,
406 frameset, parlist, recipe_name, /*filenameSpec,*/ apply_flat_field, CPL_FALSE);
407
408 } else if(is_pupil_lamp || is_pupil_sky) {
409 cpl_msg_debug(cpl_func,"duplicate PUPIL cube tag");
411 ERIS_IFU_PRO_JITTER_OBJ_CUBE, apply_flat_field);
412 eris_ifu_cube_collapse_mean_and_save(ERIS_IFU_PRO_JITTER_OBJ_CUBE,
413 frameset, parlist, recipe_name, /*filenameSpec, */apply_flat_field, CPL_TRUE);
414 } else if(is_psf) {
415 cpl_msg_debug(cpl_func,"duplicate PSF cube tag");
417 ERIS_IFU_PRO_JITTER_PSF_CUBE, apply_flat_field);
418 eris_ifu_cube_collapse_mean_and_save(ERIS_IFU_PRO_JITTER_PSF_CUBE,
419 frameset, parlist, recipe_name, /*filenameSpec, */apply_flat_field, CPL_FALSE);
420 }
421 cpl_free(combDoCatg);
422 cpl_free(filenameSpec);
423 }
424
425 if( is_pupil_lamp || is_pupil_sky) {
426// hdrl_imagelist* himl = NULL;
427 cpl_table* qclog_tbl = eris_qclog_init();
428 eris_get_pupil_shift(sof.exposureTable[0].cube, 0, &qclog_tbl);
429 cpl_free(qclog_tbl);
430 }
431
432 /* extract spectra and for STD star computes response and efficiency */
433 if (apply_flat_field == CPL_FALSE) {
434 if (is_std_norm) {
435 obj_type = STD_CUBE_COADD_NOFLAT;
436 } else if (is_std_flux) {
437 obj_type = STD_FLUX_CUBE_COADD_NOFLAT;
438 }
439 }
440 if (params.extractSource && eris_can_extract(frameset)) {
441 eris_print_rec_status(102);
442 cpl_msg_info(cpl_func,"input pro catg: %s obj_type: %d",
443 input_cube_pro_catg, resampled_obj_type);
444
445 eris_ifu_jitter_extract(frameset, parlist, resampled_obj_type,
446 input_cube_pro_catg, stdParams, pipefile_prefix, context);
447 eris_print_rec_status(103);
448 }
449 //cpl_frameset_dump(frameset, stdout);
450 char* param_name = NULL;
451
452 param_name = cpl_sprintf("%s.compute-strehl", context);
453 cpl_boolean compute_strehl = cpl_parameter_get_bool(
454 cpl_parameterlist_find_const(parlist, param_name));
455 cpl_free(param_name);
456
457 param_name = cpl_sprintf("%s.flux-calibrate", context);
458 cpl_boolean flux_calibrate = cpl_parameter_get_bool(
459 cpl_parameterlist_find_const(parlist, param_name));
460 cpl_free(param_name);
461
463 if(obj_type == STD_CUBE || obj_type == STD_CUBE_COADD_NOFLAT ||
464 obj_type == STD_FLUX_CUBE || obj_type == STD_FLUX_CUBE_COADD_NOFLAT||
465 obj_type == DAR_STD_FLUX_CUBE || obj_type == DAR_STD_CUBE_COADD) {
466
467 param_name = cpl_sprintf("%s.compute-efficiency", context);
468 cpl_boolean compute_efficiency = cpl_parameter_get_bool(
469 cpl_parameterlist_find_const(parlist, param_name));
470 cpl_free(param_name);
471
472 param_name = cpl_sprintf("%s.compute-response", context);
473 cpl_boolean compute_response = cpl_parameter_get_bool(
474 cpl_parameterlist_find_const(parlist, param_name));
475 cpl_free(param_name);
476
477 cpl_msg_debug(cpl_func,"compute_response: %d eris_can_compute_response: %d apply_flat_field: %d",
478 compute_response,eris_can_compute_response(frameset),
479 apply_flat_field);
480 if (compute_response && eris_can_compute_response(frameset) &&
481 apply_flat_field == CPL_TRUE) {
482 cpl_msg_info(cpl_func,"Compute response");
483 eris_response_compute(recipe_name, parlist, frameset, frameset);
484 }
485
486 cpl_msg_debug(cpl_func, "compute_efficiency: %d eris_can_compute_efficiency: %d",
487 compute_efficiency,eris_can_compute_efficiency(frameset));
488
489 if (compute_efficiency && apply_flat_field == CPL_FALSE) {
490 if (eris_can_compute_efficiency(frameset)) {
491 cpl_msg_info(cpl_func,"Compute efficiency");
492 cpl_frame * spectrum_frame = NULL;
493 cpl_frame * extcoeff_frame = NULL;
494 cpl_frame * fluxstdcat_frame = NULL;
495
496 spectrum_frame = cpl_frameset_find(frameset,
497 ERIS_IFU_PRO_JITTER_SPECTRUM_NOFLAT);
498 extcoeff_frame = cpl_frameset_find(frameset,
499 ERIS_IFU_CALIB_EXTCOEFF_TABLE);
500 fluxstdcat_frame = cpl_frameset_find(frameset,
501 ERIS_IFU_CALIB_FLUX_STD_CATALOG);
502
503 cpl_table* tab_eff = eris_efficiency_compute(spectrum_frame,
504 fluxstdcat_frame, extcoeff_frame, frameset, parlist,
505 pipefile_prefix);
506
507 cpl_table_delete(tab_eff);
508 }
509 }
510 }
511
512 //cpl_frameset_dump(frameset, stdout);
513 cpl_msg_debug(cpl_func,"flux_calibrate: %d eris_can_flux_calibrate: %d, apply_flat_field:%d",
514 flux_calibrate,eris_can_flux_calibrate(frameset),apply_flat_field);
515 if (flux_calibrate && apply_flat_field == CPL_TRUE) {
516 if (eris_can_flux_calibrate(frameset)) {
517 cpl_msg_info(cpl_func,"Flux calibrate extracted spectrum and combined data cube");
518
519 eris_flux_calibrate_spectra(pipefile_prefix, recipe_name,
520 parlist, frameset, frameset);
521 char* cube_pro_catg = NULL;
522 if (is_std_norm) {
523 cube_pro_catg = cpl_sprintf("%s",ERIS_IFU_PRO_JITTER_STD_CUBE_COADD);
524 } else if (is_std_flux) {
525 cube_pro_catg = cpl_sprintf("%s",ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD);
526 } else {
527 cube_pro_catg = cpl_sprintf("%s",ERIS_IFU_PRO_JITTER_PSF_CUBE_COADD);
528 }
529
530 eris_flux_calibrate_cube2(cube_pro_catg, pipefile_prefix,
531 recipe_name, parlist, /*frameset, */frameset);
532 cpl_free(cube_pro_catg);
533 }
534 }
535
536 //if(compute_strehl && !is_std_flux) {
537 if (compute_strehl && apply_flat_field) {
538 /* for PSF standards we can compute the Strehl */
539 cpl_msg_info(cpl_func,"===============================================");
540 cpl_msg_info(cpl_func,"===========STREHL COMPUTATION==================");
541 cpl_msg_info(cpl_func,"===============================================");
542 eris_ifu_stdstar_strehl_compute(frameset, parlist, context/*, recipe_name*/);
543 }
544 //cpl_frameset_dump(frameset, stdout);
545 } CATCH {
546
547 }
548
549 cpl_free(pipefile_prefix);
551 eris_ifu_free_std_param(&stdParams);
552 eris_check_error_code("eris_stdstar_reduction_common");
553
554 return cpl_error_get_code();
555}
556
#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.
void eris_ifu_free_std_param(struct stdParamStruct *stdParams)
Free memory allocated for stdParamStruct.
cpl_error_code eris_ifu_jitter_processSof(cpl_frameset *frames, struct stdParamStruct stdParams, struct paramStruct params, struct sofStruct *sof)
Process SOF (Set of Frames) file and load all calibration data.
cpl_error_code eris_ifu_jitter_fetch_params(const char *context, const char *recipe_name, const cpl_parameterlist *parlist, struct stdParamStruct *stdParams, struct paramStruct *params)
Fetch and parse jitter recipe parameters from parameter list.
cpl_error_code eris_ifu_jitter_process_cubes(struct sofStruct *sof, struct stdParamStruct stdParams, struct paramStruct params, cpl_frameset *frameset, const cpl_parameterlist *parlist, const char *recipe_name, cubeType *obj_type)
Process and combine data cubes with sky tweaking and DAR correction.
void eris_ifu_jitter_free_sofStruct(struct sofStruct *sof_struct)
Free and clean up SOF structure and all contained data.
cpl_error_code eris_ifu_jitter_extract(cpl_frameset *frameset, const cpl_parameterlist *parlist, cubeType obj_type, const char *pcatg, struct stdParamStruct stdParams, const char *pipefile_prefix, const char *context)
Main spectral extraction function.
cpl_error_code eris_frameset_duplicate_cube_tag(cpl_frameset *frameset, const char *pcatg, cpl_boolean apply_flat)
Duplicate a cube file with different PRODCATG for coadded version.
void eris_ifu_jitter_get_cube_type_string(cubeType type)
Print cube type as string to log.
cpl_error_code eris_ifu_jitter_get_procatg_and_filename(cubeType type, char **proCatg, char **filenamePrefix)
Get the value of the PRO.CATG and the filename as function of the type of cube.
cpl_error_code eris_ifu_jitter_process_exposures(struct sofStruct *sof, struct stdParamStruct stdParams, struct paramStruct params, cpl_frameset *frameset, const cpl_parameterlist *parlist, const char *recipe_name, const char *context)
Process all raw exposures into calibrated 3D data cubes.
int eris_frameset_count_tag(cpl_frameset *sof, const char *tag)
Count frames with specified tag in frameset.
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)
Resample and combine cubes plane-by-plane (2D spatial resampling per wavelength)
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)
-------------------------------------------------------------------------—‍/
cpl_error_code eris_stdstar_reduction_common(cpl_frameset *frameset, const cpl_parameterlist *parlist, cpl_boolean apply_flat_field, const char *context, const char *recipe_name)
Main standard star data reduction pipeline orchestration function.
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)
Convert band enum to string.
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)
Convert instrument enum to string.
const char * eris_ifu_get_preopticsScaleString(ifsPreopticsScale scale)
Convert pre-optics scale enum to string.
cpl_error_code eris_check_error_code(const char *func_id)
handle CPL errors
Definition: eris_utils.c:56