39#include "eris_nix_dfs.h"
40#include "eris_nix_utils.h"
41#include "eris_pfits.h"
59 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
61 cpl_frame * frame = NULL;
66 cpl_frameset_iterator * fsiter = cpl_frameset_iterator_new(set);
67 frame = cpl_frameset_iterator_get(fsiter);
70 const char * tag = cpl_frame_get_tag(frame);
74 cpl_msg_error(cpl_func,
"Frame %d has no tag", i);
75 }
else if (!strcmp(tag, ERIS_NIX_RAW_DARK_DO_CATG) ||
76 !strcmp(tag, ERIS_NIX_RAW_PERSISTENCE_IMG_DO_CATG) ||
77 !strcmp(tag, ERIS_NIX_RAW_PERSISTENCE_CUBE_DO_CATG) ||
78 !strcmp(tag, ERIS_NIX_RAW_FLAT_LAMP_ON_DO_CATG) ||
79 !strcmp(tag, ERIS_NIX_RAW_FLAT_LAMP_OFF_DO_CATG) ||
80 !strcmp(tag, ERIS_NIX_RAW_FLAT_SKY_DO_CATG) ||
81 !strcmp(tag, ERIS_NIX_RAW_FLAT_SKY_LSS_DO_CATG) ||
82 !strcmp(tag, ERIS_NIX_RAW_FLAT_TWILIGHT_DO_CATG) ||
83 !strcmp(tag, ERIS_NIX_RAW_PUPIL_LAMP_DO_CATG) ||
84 !strcmp(tag, ERIS_NIX_RAW_PUPIL_SKY_DO_CATG) ||
85 !strcmp(tag, ERIS_NIX_RAW_PUPIL_DARK_DO_CATG) ||
86 !strcmp(tag, ERIS_NIX_RAW_PUPIL_BKG_DO_CATG) ||
87 !strcmp(tag, ERIS_NIX_RAW_PUPIL_LAMP_OPEN_DO_CATG) ||
88 !strcmp(tag, ERIS_NIX_RAW_PUPIL_LAMP_MASK_DO_CATG) ||
89 !strcmp(tag, ERIS_NIX_RAW_PUPIL_SKY_OPEN_DO_CATG) ||
90 !strcmp(tag, ERIS_NIX_RAW_PUPIL_SKY_MASK_DO_CATG) ||
91 !strcmp(tag, ERIS_NIX_RAW_PUPIL_DARK_OPEN_DO_CATG) ||
92 !strcmp(tag, ERIS_NIX_RAW_PUPIL_DARK_MASK_DO_CATG) ||
93 !strcmp(tag, ERIS_NIX_RAW_OBJECT_APP_DO_CATG) ||
94 !strcmp(tag, ERIS_NIX_RAW_OBJECT_FPC_DO_CATG) ||
95 !strcmp(tag, ERIS_NIX_RAW_OBJECT_SAM_DO_CATG) ||
96 !strcmp(tag, ERIS_NIX_RAW_OBJECT_JITTER_DO_CATG) ||
97 !strcmp(tag, ERIS_NIX_RAW_SKY_FPC_DO_CATG) ||
98 !strcmp(tag, ERIS_NIX_RAW_SKY_APP_DO_CATG) ||
99 !strcmp(tag, ERIS_NIX_RAW_SKY_JITTER_DO_CATG) ||
100 !strcmp(tag, ERIS_NIX_RAW_STD_JITTER_DO_CATG) ||
101 !strcmp(tag, ERIS_NIX_RAW_OBJECT_LSS_JITTER_DO_CATG) ||
102 !strcmp(tag, ERIS_NIX_RAW_STD_APP_DO_CATG) ||
103 !strcmp(tag, ERIS_NIX_RAW_STD_FPC_DO_CATG) ||
104 !strcmp(tag, ERIS_NIX_RAW_STD_SAM_DO_CATG) ||
105 !strcmp(tag, ERIS_NIX_RAW_SKY_LSS_JITTER_DO_CATG) ||
106 !strcmp(tag, ERIS_NIX_RAW_STD_LSS_JITTER_DO_CATG)) {
108 cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
111 }
else if (!strcmp(tag, ERIS_NIX_COEFFS_CUBE_PRO_CATG) ||
112 !strcmp(tag, ERIS_NIX_DET_LIN_INFO_PRO_CATG) ||
113 !strcmp(tag, ERIS_NIX_GAIN_PRO_CATG) ||
114 !strcmp(tag, ERIS_NIX_MASTER_BPM_LAMP_PRO_CATG) ||
115 !strcmp(tag, ERIS_NIX_MASTER_BPM_LSS_PRO_CATG) ||
116 !strcmp(tag, ERIS_NIX_MASTER_BPM_SKY_PRO_CATG) ||
117 !strcmp(tag, ERIS_NIX_MASTER_DARK_IMG_PRO_CATG) ||
118 !strcmp(tag, ERIS_NIX_MASTER_DARK_IFU_PRO_CATG) ||
119 !strcmp(tag, ERIS_NIX_MASTER_FLAT_LAMP_HIFREQ_PRO_CATG) ||
120 !strcmp(tag, ERIS_NIX_MASTER_FLAT_LAMP_LOFREQ_PRO_CATG) ||
121 !strcmp(tag, ERIS_NIX_MASTER_FLAT_LSS_HIFREQ_PRO_CATG) ||
122 !strcmp(tag, ERIS_NIX_MASTER_FLAT_LSS_LOFREQ_PRO_CATG) ||
123 !strcmp(tag, ERIS_NIX_MASTER_FLAT_SKY_LOFREQ_PRO_CATG) ||
124 !strcmp(tag, ERIS_NIX_MASTER_FLAT_SKY_HIFREQ_PRO_CATG) ||
125 !strcmp(tag, ERIS_NIX_MASTER_FLAT_TWILIGHT_LOFREQ_PRO_CATG)||
126 !strcmp(tag, ERIS_NIX_MASTER_STARTRACE_PRO_CATG)||
127 !strcmp(tag, ERIS_NIX_MASTER_WAVE_PRO_CATG)||
128 !strcmp(tag, ERIS_NIX_NL_BPM_PRO_CATG) ||
129 !strcmp(tag, ERIS_NIX_PHOT_DATA_PRO_CATG) ||
130 !strcmp(tag, ERIS_NIX_WCS_MATCHED_CATALOGUE_PRO_CATG) ||
131 !strcmp(tag, ERIS_NIX_WCS_REFINE_PRO_CATG) ||
132 !strcmp(tag, ERIS_NIX_REFERENCE_DARK_PRO_CATG)) {
134 cpl_frame_set_group(frame, CPL_FRAME_GROUP_CALIB);
137 }
else if (!strcmp(tag, ERIS_NIX_CALIB_OBJECT_JITTER_PRO_CATG) ||
138 !strcmp(tag, ERIS_NIX_CAL_DET_OBJECT_JITTER_PRO_CATG) ||
139 !strcmp(tag, ERIS_NIX_CAL_DET_SKY_JITTER_PRO_CATG) ||
140 !strcmp(tag, ERIS_NIX_CAL_DET_STD_JITTER_PRO_CATG) ||
141 !strcmp(tag, ERIS_NIX_CAL_DET_OBJECT_LSS_JITTER_PRO_CATG) ||
142 !strcmp(tag, ERIS_NIX_CAL_DET_SKY_LSS_JITTER_PRO_CATG) ||
143 !strcmp(tag, ERIS_NIX_CAL_DET_STD_LSS_JITTER_PRO_CATG) ||
144 !strcmp(tag, ERIS_NIX_CAL_PHOT_CATALOGUE_PRO_CATG) ||
145 !strcmp(tag, ERIS_NIX_CAL_PHOT_MATCH_CATALOGUE_PRO_CATG) ||
146 !strcmp(tag, ERIS_NIX_CAL_PHOT_OBJECT_JITTER_PRO_CATG) ||
147 !strcmp(tag, ERIS_NIX_CAL_PHOT_REF_CATALOGUE_PRO_CATG) ||
148 !strcmp(tag, ERIS_NIX_CAL_PHOT_STD_JITTER_PRO_CATG) ||
149 !strcmp(tag, ERIS_NIX_CAL_WCS_CATALOGUE_PRO_CATG) ||
150 !strcmp(tag, ERIS_NIX_CAL_WCS_MATCH_CATALOGUE_PRO_CATG) ||
151 !strcmp(tag, ERIS_NIX_CAL_WCS_OBJECT_JITTER_PRO_CATG) ||
152 !strcmp(tag, ERIS_NIX_CAL_WCS_REF_CATALOGUE_PRO_CATG) ||
153 !strcmp(tag, ERIS_NIX_CAL_WCS_REPORT_PRO_CATG) ||
154 !strcmp(tag, ERIS_NIX_CAL_WCS_STD_JITTER_PRO_CATG) ||
155 !strcmp(tag, ERIS_NIX_CORRECTED_OBJECT_LSS_JITTER_PRO_CATG) ||
156 !strcmp(tag, ERIS_NIX_CORRECTED_STD_LSS_JITTER_PRO_CATG) ||
157 !strcmp(tag, ERIS_NIX_IMG_CATALOGUE_PRO_CATG) ||
158 !strcmp(tag, ERIS_NIX_IMG_OBS_COMBINED_PRO_CATG) ||
159 !strcmp(tag, ERIS_NIX_IMG_STD_COMBINED_PRO_CATG) ||
160 !strcmp(tag, ERIS_NIX_LSS_OBS_COMBINED_PRO_CATG) ||
161 !strcmp(tag, ERIS_NIX_LSS_STD_COMBINED_PRO_CATG) ||
162 !strcmp(tag, ERIS_NIX_SKYSUB_OBJECT_JITTER_PRO_CATG) ||
163 !strcmp(tag, ERIS_NIX_SKYSUB_STD_JITTER_PRO_CATG) ||
164 !strcmp(tag, ERIS_NIX_SKYSUB_OBJECT_LSS_JITTER_PRO_CATG) ||
165 !strcmp(tag, ERIS_NIX_SKYSUB_STD_LSS_JITTER_PRO_CATG)) {
170 cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
173 cpl_frame_set_group(frame, CPL_FRAME_GROUP_NONE);
179 cpl_error_set_message(
"eris_nix_dfs_set_groups",
180 CPL_ERROR_UNSUPPORTED_MODE,
181 "data tag not recognised: %s", tag);
186 cpl_frameset_iterator_advance(fsiter, 1);
187 frame = cpl_frameset_iterator_get(fsiter);
190 enu_check_error_code(
"Could not identify RAW and CALIB frames");
193 cpl_frameset_iterator_delete(fsiter);
195 return cpl_error_get_code();
219 cpl_frameset * allframes,
220 const cpl_parameterlist * parlist,
221 const cpl_frameset * usedframes,
222 const master_bpm * mbad_pix_map,
224 const cpl_propertylist * applist,
225 const char * pipe_id,
226 const char * filename) {
228 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
230 cpl_propertylist * plist = NULL;
232 if (applist == NULL) {
233 plist = cpl_propertylist_new();
235 plist = cpl_propertylist_duplicate(applist);
237 cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG, procat);
238 cpl_dfs_save_image(allframes, NULL, parlist, usedframes, NULL,
239 mbad_pix_map->bpm, CPL_TYPE_INT, recipe, plist, NULL, pipe_id, filename);
240 cpl_ensure_code(!cpl_error_get_code(), cpl_error_get_code());
244 cpl_propertylist_delete(plist);
246 return cpl_error_get_code();
275 const cpl_parameterlist * parlist,
276 const cpl_table * catalogue,
277 const cpl_propertylist * tablelist,
278 const char * cat_name,
280 const char * pipe_id,
281 const char * preface,
282 const char * procat) {
286 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
287 if (!catalogue)
return CPL_ERROR_NONE;
291 cpl_ensure_code(image, CPL_ERROR_NULL_INPUT);
292 cpl_ensure_code(cat_name, CPL_ERROR_NULL_INPUT);
293 cpl_ensure_code(preface, CPL_ERROR_NULL_INPUT);
295 cpl_propertylist * applist = NULL;
296 cpl_propertylist * image_plist = NULL;
297 char * prodname = NULL;
298 cpl_frame * product_frame = NULL;
299 cpl_propertylist * tablelist_copy = NULL;
304 cpl_frameset * provenance = cpl_frameset_new();
305 cpl_frameset_insert(provenance, image);
309 prodname =
enu_repreface(cpl_frame_get_filename(image), preface);
310 product_frame = cpl_frame_new();
311 cpl_frame_set_filename(product_frame, prodname);
312 cpl_frame_set_tag(product_frame, procat);
313 cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_ANY);
314 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT);
315 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL);
319 applist = cpl_propertylist_new();
323 image_plist = cpl_propertylist_load(cpl_frame_get_filename(image), 0);
324 cpl_propertylist_copy_property_regexp(applist,
326 "ORIGIN|TELESCOP|INSTRUME|FILTER|"
327 "OBJECT|RA|DEC|EQUINOX|RADESYS|"
328 "TIMESYS|EXPTIME|TEXPTIME|MJD-OBS|"
329 "MJD-END|PROG_ID|OBID[1-9]([0-9])*|"
330 "NCOMBINE|OBSTECH|PROCSOFT|"
333 enu_check_error_code(
"error copying image HDU info to applist");
349 cpl_propertylist_update_string(applist,
"PRODCATG",
"SCIENCE.SRCTBL");
350 cpl_propertylist_update_string(applist, CPL_DFS_PRO_CATG, procat);
354 if (cpl_frame_get_filename(image)) {
355 char * filename = cpl_strdup(cpl_frame_get_filename(image));
356 cpl_propertylist_update_string(applist,
"PROV1", basename(filename));
362 if (tablelist != NULL) {
363 tablelist_copy = cpl_propertylist_duplicate(tablelist);
365 tablelist_copy = cpl_propertylist_new();
367 cpl_propertylist_update_string(tablelist_copy,
"EXTNAME",
"PHASE3CATALOG");
371 cpl_table_save(catalogue,
377 enu_check_error_code(
"error saving dfs table");
382 cpl_frameset_insert(frameset, cpl_frame_duplicate(product_frame));
386 cpl_propertylist_delete(applist);
387 cpl_propertylist_delete(image_plist);
389 cpl_frame_delete(product_frame);
390 cpl_propertylist_delete(tablelist_copy);
392 return cpl_error_get_code();
422 const cpl_parameterlist * parlist,
423 const cpl_frameset * provenance,
424 const cpl_boolean prov_raw,
425 const hdrl_image * image,
426 const hdrl_imagelist * imagelist,
427 const mef_extension_list* mefs,
429 const cpl_frame * inherit_frame,
430 const cpl_propertylist * applist,
431 const cpl_propertylist * wcs_plist,
432 const char * pipe_id,
433 const char * filename) {
435 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
437 cpl_msg_debug(cpl_func,
"enu_dfs_save_himage entry");
439 cpl_ensure_code(allframes, CPL_ERROR_NULL_INPUT);
440 cpl_ensure_code(parlist, CPL_ERROR_NULL_INPUT);
441 cpl_ensure_code(provenance, CPL_ERROR_NULL_INPUT);
442 cpl_ensure_code(recipe, CPL_ERROR_NULL_INPUT);
443 cpl_ensure_code(applist, CPL_ERROR_NULL_INPUT);
444 cpl_ensure_code(pipe_id, CPL_ERROR_NULL_INPUT);
445 cpl_ensure_code(filename, CPL_ERROR_NULL_INPUT);
447 const cpl_frame * inherit = NULL;
448 cpl_propertylist * inherit_plist = NULL;
449 cpl_frameset * product_frameset = NULL;
450 cpl_propertylist * plist = NULL;
452 int conf = CPL_FALSE;
453 int bkgd = CPL_FALSE;
454 int bkge = CPL_FALSE;
455 int bkgc = CPL_FALSE;
457 cpl_propertylist * dicd = NULL;
462 for (cpl_size i=0; i<mefs->size; i++) {
463 cpl_msg_info(cpl_func,
"%d", (
int)i);
464 cpl_msg_info(cpl_func,
"%s", mefs->mef[i]->name);
465 if (!strcmp(mefs->mef[i]->name,
"CONFIDENCE")) conf = CPL_TRUE;
466 if (!strcmp(mefs->mef[i]->name,
"BKG_DATA")) bkgd = CPL_TRUE;
467 if (!strcmp(mefs->mef[i]->name,
"BKG_ERR")) bkge = CPL_TRUE;
468 if (!strcmp(mefs->mef[i]->name,
"BKG_CONF")) bkgc = CPL_TRUE;
476 const char * procat = cpl_propertylist_get_string(applist,
478 cpl_ensure_code(procat != NULL, cpl_error_get_code());
479 cpl_msg_info(cpl_func,
"Writing MEF product(%s): %s", procat, filename);
483 product_frameset = cpl_frameset_duplicate(provenance);
488 inherit = inherit_frame;
490 cpl_frameset_iterator * frameset_iter = cpl_frameset_iterator_new(
492 inherit = cpl_frameset_iterator_get_const(frameset_iter);
493 cpl_frameset_iterator_delete(frameset_iter);
498 cpl_frame * product_frame = cpl_frame_new();
499 cpl_frame_set_filename(product_frame, filename);
500 cpl_frame_set_tag(product_frame, procat);
501 cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_ANY);
502 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT);
503 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL);
505 cpl_frameset_insert(product_frameset, product_frame);
509 plist = cpl_propertylist_duplicate(applist);
521 cpl_propertylist_update_string(plist,
"ESO PRO REC1 ID", recipe);
523 cpl_propertylist_save(plist, filename, CPL_IO_CREATE);
524 enu_check_error_code(
"error saving header 0");
529 dicd = cpl_propertylist_new();
530 cpl_propertylist_append_string(dicd,
"HDUCLASS",
"ESO");
531 cpl_propertylist_append_string(dicd,
"HDUDOC",
"SDP");
532 cpl_propertylist_append_string(dicd,
"HDUVERS",
"SDP version 8");
533 cpl_propertylist_append_string(dicd,
"SCIDATA",
"DATA");
534 cpl_propertylist_append_string(dicd,
"ERRDATA",
"ERR");
535 cpl_propertylist_append_string(dicd,
"QUALDATA",
"DQ");
537 cpl_propertylist_append_string(dicd,
"CONFDATA",
"CONFIDENCE");
540 cpl_propertylist_append_string(dicd,
"BKGDATA",
"BKG_DATA");
543 cpl_propertylist_append_string(dicd,
"BKGERR",
"BKG_ERR");
546 cpl_propertylist_append_string(dicd,
"BKGCONF",
"BKG_CONF");
548 cpl_size hlist_sz = 0;
549 if (image || imagelist) {
553 cpl_propertylist * header = cpl_propertylist_duplicate(dicd);
554 cpl_propertylist_update_string(header,
"EXTNAME",
"DATA");
555 cpl_propertylist_update_string(header,
"HDUCLAS1",
"IMAGE");
556 cpl_propertylist_update_string(header,
"HDUCLAS2",
"DATA");
557 cpl_propertylist_erase(header,
"SCIDATA");
559 if (wcs_plist) cpl_propertylist_append(header, wcs_plist);
564 const char * data_mandatory[] = {
"BUNIT",
568 const int count_data_mandatory =
sizeof(data_mandatory) /
571 const char * data_mandatory2[] = {
"PHOTSYS",
578 const int count_data_mandatory2 =
sizeof(data_mandatory2) /
582 const char * ins_mode =
"ins_mode";
583 if(cpl_propertylist_has(plist,
"ESO INS1 MODE")) {
584 ins_mode = cpl_propertylist_get_string(plist,
"ESO INS1 MODE");
588 for (
int mandi=0; mandi < count_data_mandatory; mandi++) {
589 if (!cpl_propertylist_has(header, data_mandatory[mandi])) {
590 if (cpl_propertylist_has(applist, data_mandatory[mandi])) {
591 cpl_propertylist_copy_property(header, applist,
592 data_mandatory[mandi]);
597 if(strcmp(ins_mode,
"nixLSS") != 0) {
599 for (
int mandi2=0; mandi2 < count_data_mandatory2; mandi2++) {
600 if (!cpl_propertylist_has(header, data_mandatory2[mandi2])) {
601 if (cpl_propertylist_has(applist, data_mandatory2[mandi2])) {
602 cpl_propertylist_copy_property(header, applist,
603 data_mandatory2[mandi2]);
610 for (
int mandi=0; mandi < count_data_mandatory; mandi++) {
611 if (!cpl_propertylist_has(header, data_mandatory[mandi])) {
612 if (!strcmp(data_mandatory[mandi],
"BUNIT")) {
613 cpl_propertylist_update_string(header,
"BUNIT",
615 }
else if (!strcmp(data_mandatory[mandi],
"CUNIT1")) {
616 cpl_propertylist_update_string(header,
"CUNIT1",
"deg");
617 }
else if (!strcmp(data_mandatory[mandi],
"CUNIT2")) {
618 cpl_propertylist_update_string(header,
"CUNIT2",
"deg");
619 }
else if (!strcmp(data_mandatory[mandi],
"FLUXCAL")) {
620 cpl_propertylist_update_string(header,
"FLUXCAL",
623 cpl_msg_info(cpl_func,
624 "missing extension keyword %s not handled",
625 data_mandatory[mandi]);
630 if(strcmp(ins_mode,
"nixLSS") != 0) {
632 for (
int mandi2=0; mandi2 < count_data_mandatory2; mandi2++) {
633 if (!cpl_propertylist_has(header, data_mandatory2[mandi2])) {
635 if (!strcmp(data_mandatory2[mandi2],
"PHOTSYS")) {
636 cpl_propertylist_update_string(header,
"PHOTSYS",
"VEGA");
637 }
else if (!strcmp(data_mandatory2[mandi2],
"ABMAGLIM")) {
638 cpl_msg_info(cpl_func,
"dummy value for ABMAGLIM");
639 cpl_propertylist_update_double(header,
"ABMAGLIM", 0.0);
640 }
else if (!strcmp(data_mandatory2[mandi2],
"ABMAGSAT")) {
641 cpl_msg_info(cpl_func,
"dummy value for ABMAGSAT");
642 cpl_propertylist_update_double(header,
"ABMAGSAT", 0.0);
643 }
else if (!strcmp(data_mandatory2[mandi2],
"PSF_FWHM")) {
644 cpl_msg_info(cpl_func,
"dummy value for PSF_FWHM");
645 cpl_propertylist_update_double(header,
"PSF_FWHM", -1.0);
646 }
else if (!strcmp(data_mandatory2[mandi2],
"PHOTZP")) {
647 cpl_msg_info(cpl_func,
"PHOTZP not found, set to 0.0");
648 cpl_propertylist_update_double(header,
"PHOTZP", 0.0);
649 cpl_propertylist_set_comment(header,
"PHOTZP",
"Photometric "
650 "zeropoint so that MAG=-2.5*"
651 "log(data)+PHOTZP+APCOR");
652 }
else if (!strcmp(data_mandatory2[mandi2],
"PHOTZPER")) {
653 cpl_msg_info(cpl_func,
"PHOTZPER not found, set to 0.0");
654 cpl_propertylist_update_double(header,
"PHOTZPER", 0.0);
655 cpl_propertylist_set_comment(header,
"PHOTZPER",
"Error on "
657 }
else if (!strcmp(data_mandatory2[mandi2],
"ZPMETHOD")) {
658 cpl_msg_info(cpl_func,
"ZPMETHOD not found");
659 cpl_propertylist_update_string(header,
"ZPMETHOD",
660 "PHOTZP not calculated");
661 cpl_propertylist_set_comment(header,
"ZPMETHOD",
662 "Method of ZP calculation");
664 cpl_msg_info(cpl_func,
665 "missing extension keyword %s not handled",
666 data_mandatory[mandi2]);
684 cpl_imagelist * tlist = cpl_imagelist_new();
687 for (cpl_size i = 0; i < hlist_sz; i++) {
696 cpl_imagelist_set(tlist,
700 cpl_imagelist_save(tlist,
706 cpl_imagelist_unwrap(tlist);
709 eris_ifu_plist_erase_wcs3D(header);
718 cpl_propertylist_delete(header);
719 enu_check_error_code(
"failed to save header 1");
723 header = cpl_propertylist_duplicate(dicd);
724 cpl_propertylist_update_string(header,
"EXTNAME",
"ERR");
725 cpl_propertylist_update_string(header,
"HDUCLAS1",
"IMAGE");
726 cpl_propertylist_update_string(header,
"HDUCLAS2",
"ERROR");
727 cpl_propertylist_update_string(header,
"HDUCLAS3",
"RMSE");
728 cpl_propertylist_erase(header,
"ERRDATA");
729 if (cpl_propertylist_has(applist,
"BUNIT")) {
730 cpl_propertylist_copy_property(header, applist,
"BUNIT");
733 if (wcs_plist) cpl_propertylist_append(header, wcs_plist);
737 HDRL_TYPE_ERROR, header, CPL_IO_EXTEND);
740 cpl_imagelist * tlist = cpl_imagelist_new();
743 for (cpl_size i = 0; i < hlist_sz; i++) {
745 cpl_imagelist_set(tlist,
749 cpl_imagelist_save(tlist,
754 cpl_imagelist_unwrap(tlist);
757 eris_ifu_plist_erase_wcs3D(header);
766 cpl_propertylist_delete(header);
767 enu_check_error_code(
"failed to save header 2");
771 header = cpl_propertylist_duplicate(dicd);
772 cpl_propertylist_update_string(header,
"EXTNAME",
"DQ");
773 cpl_propertylist_update_string(header,
"HDUCLAS1",
"IMAGE");
774 cpl_propertylist_update_string(header,
"HDUCLAS2",
"QUALITY");
775 cpl_propertylist_update_string(header,
"HDUCLAS3",
"MASKZERO");
776 cpl_propertylist_erase(header,
"QUALDATA");
778 if (wcs_plist) cpl_propertylist_append(header, wcs_plist);
785 header, CPL_IO_EXTEND);
790 eris_ifu_plist_erase_wcs3D(header);
793 header, CPL_IO_EXTEND);
796 cpl_propertylist_delete(header);
797 enu_check_error_code(
"failed to save header 3");
803 cpl_msg_info(cpl_func,
"..there are %d mefs", (
int) (mefs->size));
805 for (cpl_size i=0; i<mefs->size; i++) {
806 cpl_propertylist * header = NULL;
807 if (mefs->mef[i]->plist) {
808 header = cpl_propertylist_duplicate(mefs->mef[i]->plist);
810 header = cpl_propertylist_new();
815 cpl_propertylist_copy_property_regexp(header, dicd,
".+",
817 cpl_propertylist_update_string(header,
"EXTNAME",
820 cpl_msg_info(cpl_func,
"..saving mef %s", mefs->mef[i]->name);
821 if (!strcmp(mefs->mef[i]->name,
"CONFIDENCE")) {
822 cpl_propertylist_update_string(header,
"HDUCLAS1",
"IMAGE");
823 cpl_propertylist_update_string(header,
"HDUCLAS2",
"CONF");
824 cpl_propertylist_erase(header,
"CONFDATA");
825 }
else if (!strcmp(mefs->mef[i]->name,
"BKG_DATA")) {
826 cpl_propertylist_update_string(header,
"HDUCLAS1",
"IMAGE");
827 cpl_propertylist_update_string(header,
"HDUCLAS2",
"BKG_DATA");
828 cpl_propertylist_erase(header,
"BKGDATA");
829 if (cpl_propertylist_has(applist,
"BUNIT")) {
830 cpl_propertylist_copy_property(header, applist,
"BUNIT");
832 }
else if (!strcmp(mefs->mef[i]->name,
"BKG_ERR")) {
833 cpl_propertylist_update_string(header,
"HDUCLAS1",
"IMAGE");
834 cpl_propertylist_update_string(header,
"HDUCLAS2",
"BKG_ERROR");
835 cpl_propertylist_update_string(header,
"HDUCLAS3",
"RMSE");
836 cpl_propertylist_erase(header,
"BKGERR");
837 if (cpl_propertylist_has(applist,
"BUNIT")) {
838 cpl_propertylist_copy_property(header, applist,
"BUNIT");
840 }
else if (!strcmp(mefs->mef[i]->name,
"BKG_CONF")) {
841 cpl_propertylist_update_string(header,
"HDUCLAS1",
"IMAGE");
842 cpl_propertylist_update_string(header,
"HDUCLAS2",
"BKG_CONF");
843 cpl_propertylist_erase(header,
"BKGCONF");
844 }
else if (!strcmp(mefs->mef[i]->data_type,
845 MEF_EXTENSION_CONTAINING_IMAGE)) {
846 cpl_propertylist_update_string(header,
"HDUCLAS1",
847 MEF_EXTENSION_CONTAINING_IMAGE);
848 }
else if (!strcmp(mefs->mef[i]->data_type,
849 MEF_EXTENSION_CONTAINING_MASK)) {
850 cpl_propertylist_update_string(header,
"HDUCLAS1",
851 MEF_EXTENSION_CONTAINING_MASK);
852 }
else if (!strcmp(mefs->mef[i]->data_type,
853 MEF_EXTENSION_CONTAINING_TABLE)) {
854 cpl_propertylist_update_string(header,
"HDUCLAS1",
855 MEF_EXTENSION_CONTAINING_TABLE);
860 if (wcs_plist) cpl_propertylist_append(header, wcs_plist);
864 eris_ifu_plist_erase_wcs3D(header);
868 cpl_propertylist_delete(header);
869 enu_check_error_code(
"failed to save MEF extension %d", (
int) i);
876 cpl_frameset_insert(allframes, cpl_frame_duplicate(product_frame));
880 cpl_propertylist_delete(dicd);
881 cpl_propertylist_delete(inherit_plist);
882 cpl_propertylist_delete(plist);
883 cpl_frameset_delete(product_frameset);
885 return cpl_error_get_code();
908 const cpl_parameterlist * parlist,
909 const cpl_frameset * provenance,
910 const cpl_boolean prov_raw,
911 const located_image * limage,
913 const cpl_frame * inherit,
914 cpl_propertylist * applist,
915 const char * pipe_id,
916 const char * filename) {
918 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
920 cpl_msg_debug(cpl_func,
"enu_dfs_save_limage entry");
922 cpl_ensure_code(filename, CPL_ERROR_NULL_INPUT);
923 cpl_ensure_code(limage, CPL_ERROR_NULL_INPUT);
924 cpl_ensure_code(applist, CPL_ERROR_NULL_INPUT);
926 cpl_propertylist * wcs_plist = NULL;
931 if (limage->confidence) nmefs++;
932 if (limage->bkg) nmefs = nmefs + 2;
933 if (limage->bkg_confidence) nmefs++;
935 mef_extension_list * mefs = NULL;
937 cpl_msg_info(cpl_func,
"nmefs %d", nmefs);
940 if (limage->confidence) {
941 cpl_msg_info(cpl_func,
"CONF");
943 limage->confidence, NULL);
947 cpl_msg_info(cpl_func,
"BKG");
952 cpl_msg_info(cpl_func,
"BKG_ERR");
958 if (limage->bkg_confidence) {
959 cpl_msg_info(cpl_func,
"BKG_CONF");
961 limage->bkg_confidence, NULL);
967 wcs_plist = cpl_propertylist_duplicate(limage->plist);
968 cpl_propertylist_erase_regexp(wcs_plist,
969 "CRPIX1|CRPIX2|CRPIX3|"
970 "CRVAL1|CRVAL2|CRVAL3|"
971 "CDELT1|CDELT2|CDELT3|"
975 "CTYPE1|CTYPE2|CTYPE3|"
976 "CUNIT1|CUNIT2|CUNIT3",
982 if (!cpl_propertylist_has(applist,
"BUNIT")) {
983 cpl_propertylist_copy_property(applist, limage->plist,
"BUNIT");
985 if (!cpl_propertylist_has(applist,
"PSF_FWHM")) {
986 if(cpl_propertylist_has(limage->plist,
"PSF_FWHM")) {
987 cpl_propertylist_copy_property(applist, limage->plist,
"PSF_FWHM");
990 if (!cpl_propertylist_has(applist,
"ABMAGLIM")) {
991 if (cpl_propertylist_has(limage->plist,
"ABMAGLIM")) {
992 cpl_propertylist_copy_property(applist, limage->plist,
"ABMAGLIM");
996 cpl_msg_info(cpl_func,
".. writing %s", filename);
1012 cpl_propertylist_delete(wcs_plist);
1014 return cpl_error_get_code();
1036 const cpl_frame * product_frame,
1037 const cpl_frameset * framelist,
1038 const cpl_parameterlist * parlist,
1039 const char * recipe_id,
1040 const char * pipe_id,
1041 const cpl_frame * inherit,
1042 const cpl_frameset * provenance,
1043 cpl_boolean prov_raw) {
1045 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
1047 cpl_ensure_code(header, CPL_ERROR_NULL_INPUT);
1048 cpl_ensure_code(product_frame, CPL_ERROR_NULL_INPUT);
1049 cpl_ensure_code(framelist, CPL_ERROR_NULL_INPUT);
1050 cpl_ensure_code(parlist, CPL_ERROR_NULL_INPUT);
1051 cpl_ensure_code(recipe_id, CPL_ERROR_NULL_INPUT);
1052 cpl_ensure_code(pipe_id, CPL_ERROR_NULL_INPUT);
1053 cpl_ensure_code(inherit, CPL_ERROR_NULL_INPUT);
1054 cpl_ensure_code(provenance, CPL_ERROR_NULL_INPUT);
1056 cpl_propertylist * inherit_plist = NULL;
1057 cpl_propertylist * input_header = NULL;
1062 input_header = cpl_propertylist_duplicate(header);
1063 cpl_dfs_setup_product_header(header,
1071 cpl_propertylist_copy_property_regexp(header,
1075 if (cpl_propertylist_has(header,
"RA")) {
1076 cpl_propertylist_set_comment(header,
"RA",
1077 "[deg] RA (J2000) pointing");
1079 if (cpl_propertylist_has(header,
"DEC")) {
1080 cpl_propertylist_set_comment(header,
"DEC",
1081 "[deg] DEC (J2000) pointing");
1087 cpl_propertylist_erase_regexp(header,
1088 "HDUCLASS|HDUDOC|HDUVERS|SCIDATA|ERRDATA|"
1089 "QUALDATA|CONFDATA|BKGDATA|BKGERR|BKGCONF|"
1090 "CRPIX1|CRPIX2|CRVAL1|CRVAL2|CDELT1|CDELT2|"
1091 "CTYPE1|CTYPE2|CUNIT1|CUNIT2|"
1092 "CD1_1|CD1_2|CD2_1|CD2_2|"
1093 "PHOTSYS|PHOTZP|PHOTZERR|ABMAGSAT|ABMAGLIM|"
1094 "MJD-OBS|PSF_FWHM|BUNIT",
1100 cpl_frameset_iterator * it = cpl_frameset_iterator_new(provenance);
1101 const cpl_frame * frame = cpl_frameset_iterator_get_const(it);
1105 char * filename = cpl_strdup(cpl_frame_get_filename(frame));
1109 pch = strstr(filename,
"ERIS.20");
1116 char * pname = cpl_sprintf(
"PROV%.0i", iprov);
1117 cpl_propertylist_update_string(header, pname, basename(pch));
1120 cpl_frameset_iterator_advance(it, 1);
1121 frame = cpl_frameset_iterator_get(it);
1123 cpl_frameset_iterator_delete(it); it = NULL;
1124 enu_check_error_code(
"error storing PROVenance keywords");
1129 const char * inherit_fname = cpl_frame_get_filename(inherit);
1130 inherit_plist = cpl_propertylist_load(inherit_fname, 0);
1131 enu_check_error_code(
"error reading propertylist from inherit");
1133 const char * mandatory[] = {
"TELESCOP",
1154 const int count_mandatory =
sizeof(mandatory) /
sizeof(
char *);
1155 for (
int mandi=0; mandi < count_mandatory; mandi++) {
1156 if (!cpl_propertylist_has(header, mandatory[mandi])) {
1157 if (cpl_propertylist_has(inherit_plist, mandatory[mandi])) {
1158 cpl_msg_info(cpl_func,
"copying from inherit %s",
1160 cpl_propertylist_copy_property(header, inherit_plist,
1168 for (
int mandi=0; mandi < count_mandatory; mandi++) {
1169 if (!cpl_propertylist_has(header, mandatory[mandi])) {
1170 if (!strcmp(mandatory[mandi],
"FILTER")) {
1171 const char * filter = NULL;
1172 if (inherit_plist) {
1176 cpl_propertylist_update_string(header,
"FILTER",
1179 cpl_propertylist_update_string(header,
"FILTER",
1182 }
else if (!strcmp(mandatory[mandi],
"RADESYS")) {
1183 const char * radesys = NULL;
1184 if (inherit_plist && cpl_propertylist_has(inherit_plist,
1186 radesys = cpl_propertylist_get_string(inherit_plist,
1190 cpl_propertylist_update_string(header,
"RADESYS",
1193 cpl_propertylist_update_string(header,
"RADESYS",
1196 }
else if (!strcmp(mandatory[mandi],
"TIMESYS")) {
1197 cpl_propertylist_update_string(header,
"TIMESYS",
1199 }
else if (!strcmp(mandatory[mandi],
"PROG_ID")) {
1200 const char * prog_id = NULL;
1201 if (inherit_plist && cpl_propertylist_has(inherit_plist,
1202 "ESO OBS PROG ID")) {
1203 prog_id = cpl_propertylist_get_string(inherit_plist,
1207 cpl_propertylist_update_string(header,
"PROG_ID",
1210 cpl_propertylist_update_string(header,
"PROG_ID",
1213 }
else if (!strcmp(mandatory[mandi],
"OBSTECH")) {
1214 const char * obstech = NULL;
1215 if (inherit_plist) {
1216 if (cpl_propertylist_has(inherit_plist,
"ESO DPR TECH")) {
1217 obstech = cpl_propertylist_get_string(
1218 inherit_plist,
"ESO DPR TECH");
1219 }
else if (cpl_propertylist_has(inherit_plist,
"ESO PRO TECH")) {
1220 obstech = cpl_propertylist_get_string(
1221 inherit_plist,
"ESO PRO TECH");
1225 cpl_propertylist_update_string(header,
"OBSTECH",
1228 cpl_propertylist_update_string(header,
"OBSTECH",
1231 }
else if (!strcmp(mandatory[mandi],
"FLUXCAL")) {
1232 cpl_propertylist_update_string(header,
"FLUXCAL",
1234 }
else if (!strcmp(mandatory[mandi],
"PROCSOFT")) {
1235 cpl_propertylist_update_string(header,
"PROCSOFT", pipe_id);
1236 }
else if (!strcmp(mandatory[mandi],
"REFERENC")) {
1237 cpl_propertylist_update_string(header,
"REFERENC",
1239 }
else if (!strcmp(mandatory[mandi],
"OBID1")) {
1241 if (inherit_plist && cpl_propertylist_has(inherit_plist,
1243 obid = cpl_propertylist_get_int(inherit_plist,
"ESO OBS ID");
1245 cpl_propertylist_update_int(header,
"OBID1", obid);
1247 cpl_msg_warning(cpl_func,
"missing %s", mandatory[mandi]);
1253 cpl_propertylist_delete(inherit_plist);
1254 cpl_propertylist_delete(input_header);
1256 return cpl_error_get_code();
cpl_error_code enu_dfs_save_limage(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *provenance, const cpl_boolean prov_raw, const located_image *limage, const char *recipe, const cpl_frame *inherit, cpl_propertylist *applist, const char *pipe_id, const char *filename)
Save a located image structure to a MEF.
cpl_error_code eris_nix_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
cpl_error_code enu_dfs_save_bpm(const char *procat, cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const master_bpm *mbad_pix_map, const char *recipe, const cpl_propertylist *applist, const char *pipe_id, const char *filename)
Save a master_bpm as a DFS-compliant pipeline product.
cpl_error_code enu_dfs_setup_product_header(cpl_propertylist *header, const cpl_frame *product_frame, const cpl_frameset *framelist, const cpl_parameterlist *parlist, const char *recipe_id, const char *pipe_id, const cpl_frame *inherit, const cpl_frameset *provenance, cpl_boolean prov_raw)
Add phase3/IDP keywords to a pipeline product propertyist list.
cpl_error_code enu_dfs_save_catalogue(cpl_frameset *frameset, cpl_frame *image, const cpl_parameterlist *parlist, const cpl_table *catalogue, const cpl_propertylist *tablelist, const char *cat_name, const char *recipe, const char *pipe_id, const char *preface, const char *procat)
Save a catalogue as DFS product.
cpl_error_code enu_dfs_save_himage(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *provenance, const cpl_boolean prov_raw, const hdrl_image *image, const hdrl_imagelist *imagelist, const mef_extension_list *mefs, const char *recipe, const cpl_frame *inherit_frame, const cpl_propertylist *applist, const cpl_propertylist *wcs_plist, const char *pipe_id, const char *filename)
Save an hdrl_image/imagelist as a DFS-compliant MEF pipeline product.
mef_extension * enu_mef_new_image(const char *name, const cpl_image *data, const cpl_propertylist *plist)
Create a mef_extension to hold a cpl_image.
mef_extension_list * enu_mef_extension_list_new(cpl_size size)
Construct a new mef_extension_list.
cpl_error_code enu_mef_extension_save(const mef_extension *mef, const char *filename, const cpl_propertylist *plist, unsigned mode)
Save a mef_extension struct to FITS file.
char * enu_repreface(const char *filename, const char *preface)
Preface a raw filename with a string.
void enu_mef_extension_list_delete(mef_extension_list *list)
Delete a mef_extension_list and its contents.
const char * enu_get_filter(const cpl_propertylist *plist)
Get the filter used in an observation.
cpl_mask * hdrl_image_get_mask(hdrl_image *himg)
get cpl bad pixel mask from image
cpl_image * hdrl_image_get_error(hdrl_image *himg)
get error as cpl image
const cpl_image * hdrl_image_get_error_const(const hdrl_image *himg)
get error as cpl image
cpl_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
const cpl_image * hdrl_image_get_image_const(const hdrl_image *himg)
get data as cpl image
cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *himlist)
Get the number of images in the imagelist.
hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.