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"
48eris_stdstar_reduction_common(cpl_frameset *frameset,
49 const cpl_parameterlist *parlist,
50 cpl_boolean apply_flat_field,
52 const char *recipe_name)
54 struct stdParamStruct stdParams = stdParamStructInit;
56 struct paramStruct params;
58 char *pipefile_prefix = NULL;
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);
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);
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");
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;
86 else if (cpl_frameset_find(frameset,
"PUPIL_SKY") != NULL){
87 is_pupil_sky = CPL_TRUE;
89 else if (cpl_frameset_find(frameset,
"PUPIL_LAMP") != NULL) {
90 is_pupil_lamp = CPL_TRUE;
92 else if (cpl_frameset_find(frameset,
"STD_FLUX") != NULL) {
93 is_std_flux = CPL_TRUE;
95 else if (cpl_frameset_find(frameset,
"PSF_CALIBRATOR") != NULL) {
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");
109 obj_number = eris_frameset_count_tag(frameset,
"PSF_CALIBRATOR");
112 (void)memset(&sof, 0,
sizeof(sof));
114 cpl_msg_info(cpl_func,
"Reading recipe parameters");
116 eris_ifu_jitter_fetch_params(context, recipe_name, parlist,
117 &stdParams, ¶ms));
118 cpl_msg_info(cpl_func,
119 "Instrument is %d, requested product level is %d",
120 stdParams.instrument, stdParams.productDepth);
123 eris_ifu_jitter_processSof(frameset,
128 cpl_msg_info(cpl_func,
"Instrument %s, band %s, scale %s",
134 eris_ifu_jitter_process_exposures(&sof, stdParams, params,
135 frameset, parlist, pipefile_prefix,
138 cubeType obj_type = OBJECT_CUBE;
141 eris_ifu_jitter_process_cubes(&sof, stdParams, params, frameset,
142 parlist, pipefile_prefix, &obj_type));
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)
148 cpl_msg_info(cpl_func,
"case1");
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;
159 resampled_obj_type = STD_FLUX_CUBE_COADD_NOFLAT;
160 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_NOFLAT;
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;
171 }
else if (cpl_frameset_count_tags(frameset, ERIS_IFU_PRO_JITTER_TWK_CUBE)
173 cpl_msg_info(cpl_func,
"case2");
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;
184 resampled_obj_type = STD_FLUX_CUBE_COADD_NOFLAT;
185 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_NOFLAT;
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;
197 cpl_msg_info(cpl_func,
"case3");
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;
208 resampled_obj_type = STD_FLUX_CUBE_COADD_NOFLAT;
209 input_cube_pro_catg = ERIS_IFU_PRO_JITTER_STD_FLUX_CUBE_COADD_NOFLAT;
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;
223 cpl_msg_info(cpl_func,
"input cube pro catg: %s",input_cube_pro_catg);
226 if (params.combine && obj_number > 1) {
229 char *combDoCatg = NULL;
230 char *filenameSpec = NULL;
231 eris_ifu_jitter_get_procatg_and_filename(obj_type, &combDoCatg,
234 cpl_msg_debug(cpl_func,
"GENERATE COMBINED DATA CUBE %s",combDoCatg);
236 NULL, NULL, NULL, recipe_name, pipefile_prefix);
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,
246 eris_frameset_duplicate_cube_tag(frameset,
247 ERIS_IFU_PRO_JITTER_STD_CUBE, apply_flat_field);
249 frameset, parlist, recipe_name, apply_flat_field, CPL_FALSE);
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);
257 frameset, parlist, recipe_name, apply_flat_field, CPL_FALSE);
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);
264 frameset, parlist, recipe_name, apply_flat_field, CPL_TRUE);
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);
270 frameset, parlist, recipe_name, apply_flat_field, CPL_FALSE);
272 cpl_free(combDoCatg);
273 cpl_free(filenameSpec);
276 if( is_pupil_lamp || is_pupil_sky) {
284 if (apply_flat_field == CPL_FALSE) {
286 obj_type = STD_CUBE_COADD_NOFLAT;
287 }
else if (is_std_flux) {
288 obj_type = STD_FLUX_CUBE_COADD_NOFLAT;
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);
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);
301 char* param_name = NULL;
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);
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);
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) {
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);
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);
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),
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);
337 cpl_msg_debug(cpl_func,
"compute_efficiency: %d eris_can_compute_efficiency: %d",
338 compute_efficiency,eris_can_compute_efficiency(frameset));
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;
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);
354 cpl_table* tab_eff = eris_efficiency_compute(spectrum_frame,
355 fluxstdcat_frame, extcoeff_frame, frameset, parlist,
358 cpl_table_delete(tab_eff);
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");
370 eris_flux_calibrate_spectra(pipefile_prefix, recipe_name,
371 parlist, frameset, frameset);
372 char* cube_pro_catg = NULL;
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);
378 cube_pro_catg = cpl_sprintf(
"%s",ERIS_IFU_PRO_JITTER_PSF_CUBE_COADD);
381 eris_flux_calibrate_cube2(cube_pro_catg, pipefile_prefix,
382 recipe_name, parlist, frameset);
383 cpl_free(cube_pro_catg);
388 if (compute_strehl && apply_flat_field) {
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);
400 cpl_free(pipefile_prefix);
401 eris_ifu_jitter_free_sofStruct(&sof);
402 eris_ifu_free_std_param(&stdParams);
405 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.
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