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"
198 const cpl_parameterlist *parlist,
199 cpl_boolean apply_flat_field,
201 const char *recipe_name)
203 struct stdParamStruct stdParams = stdParamStructInit;
204 struct sofStruct sof;
205 struct paramStruct params;
207 char *pipefile_prefix = NULL;
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);
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);
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");
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;
235 else if (cpl_frameset_find(frameset,
"PUPIL_SKY") != NULL){
236 is_pupil_sky = CPL_TRUE;
238 else if (cpl_frameset_find(frameset,
"PUPIL_LAMP") != NULL) {
239 is_pupil_lamp = CPL_TRUE;
241 else if (cpl_frameset_find(frameset,
"STD_FLUX") != NULL) {
242 is_std_flux = CPL_TRUE;
244 else if (cpl_frameset_find(frameset,
"PSF_CALIBRATOR") != NULL) {
251 }
else if (is_std_flux) {
253 }
else if (is_pupil_lamp) {
255 }
else if (is_pupil_sky) {
261 (void)memset(&sof, 0,
sizeof(sof));
263 cpl_msg_info(cpl_func,
"Reading recipe parameters");
266 &stdParams, ¶ms));
267 cpl_msg_info(cpl_func,
268 "Instrument is %d, requested product level is %d",
269 stdParams.instrument, stdParams.productDepth);
277 cpl_msg_info(cpl_func,
"Instrument %s, band %s, scale %s",
284 frameset, parlist, pipefile_prefix,
287 cubeType obj_type = OBJECT_CUBE;
291 parlist, pipefile_prefix, &obj_type));
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)
297 cpl_msg_info(cpl_func,
"case1");
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;
308 resampled_obj_type = STD_FLUX_CUBE_COADD_NOFLAT;
309 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_NOFLAT;
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;
320 }
else if (cpl_frameset_count_tags(frameset, ERIS_IFU_PRO_JITTER_TWK_CUBE)
322 cpl_msg_info(cpl_func,
"case2");
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;
333 resampled_obj_type = STD_FLUX_CUBE_COADD_NOFLAT;
334 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_NOFLAT;
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;
346 cpl_msg_info(cpl_func,
"case3");
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;
357 resampled_obj_type = STD_FLUX_CUBE_COADD_NOFLAT;
358 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_NOFLAT;
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;
372 cpl_msg_info(cpl_func,
"input cube pro catg: %s",input_cube_pro_catg);
375 if (params.combine && obj_number > 1) {
378 char *combDoCatg = NULL;
379 char *filenameSpec = NULL;
383 cpl_msg_debug(cpl_func,
"GENERATE COMBINED DATA CUBE %s",combDoCatg);
385 NULL, NULL, NULL, recipe_name, pipefile_prefix);
389 }
else if (obj_number == 1) {
390 char *combDoCatg = NULL;
391 char *filenameSpec = NULL;
396 ERIS_IFU_PRO_JITTER_STD_CUBE, apply_flat_field);
398 frameset, parlist, recipe_name, apply_flat_field, CPL_FALSE);
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);
406 frameset, parlist, recipe_name, apply_flat_field, CPL_FALSE);
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);
413 frameset, parlist, recipe_name, apply_flat_field, CPL_TRUE);
415 cpl_msg_debug(cpl_func,
"duplicate PSF cube tag");
417 ERIS_IFU_PRO_JITTER_PSF_CUBE, apply_flat_field);
419 frameset, parlist, recipe_name, apply_flat_field, CPL_FALSE);
421 cpl_free(combDoCatg);
422 cpl_free(filenameSpec);
425 if( is_pupil_lamp || is_pupil_sky) {
433 if (apply_flat_field == CPL_FALSE) {
435 obj_type = STD_CUBE_COADD_NOFLAT;
436 }
else if (is_std_flux) {
437 obj_type = STD_FLUX_CUBE_COADD_NOFLAT;
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);
446 input_cube_pro_catg, stdParams, pipefile_prefix, context);
447 eris_print_rec_status(103);
450 char* param_name = NULL;
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);
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);
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) {
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);
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);
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),
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);
486 cpl_msg_debug(cpl_func,
"compute_efficiency: %d eris_can_compute_efficiency: %d",
487 compute_efficiency,eris_can_compute_efficiency(frameset));
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;
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);
503 cpl_table* tab_eff = eris_efficiency_compute(spectrum_frame,
504 fluxstdcat_frame, extcoeff_frame, frameset, parlist,
507 cpl_table_delete(tab_eff);
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");
519 eris_flux_calibrate_spectra(pipefile_prefix, recipe_name,
520 parlist, frameset, frameset);
521 char* cube_pro_catg = NULL;
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);
527 cube_pro_catg = cpl_sprintf(
"%s",ERIS_IFU_PRO_JITTER_PSF_CUBE_COADD);
530 eris_flux_calibrate_cube2(cube_pro_catg, pipefile_prefix,
531 recipe_name, parlist, frameset);
532 cpl_free(cube_pro_catg);
537 if (compute_strehl && apply_flat_field) {
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);
549 cpl_free(pipefile_prefix);
554 return cpl_error_get_code();
#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