39#include "eris_nix_dfs.h"
40#include "eris_nix_utils.h"
41#include "eris_pfits.h"
42#include "eris_utils.h"
60 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
62 cpl_frame * frame = NULL;
67 cpl_frameset_iterator * fsiter = cpl_frameset_iterator_new(set);
68 frame = cpl_frameset_iterator_get(fsiter);
71 const char * tag = cpl_frame_get_tag(frame);
75 cpl_msg_error(cpl_func,
"Frame %d has no tag", i);
76 }
else if (!strcmp(tag, ERIS_NIX_RAW_DARK_DO_CATG) ||
77 !strcmp(tag, ERIS_NIX_RAW_PERSISTENCE_IMG_DO_CATG) ||
78 !strcmp(tag, ERIS_NIX_RAW_PERSISTENCE_CUBE_DO_CATG) ||
79 !strcmp(tag, ERIS_NIX_RAW_FLAT_LAMP_ON_DO_CATG) ||
80 !strcmp(tag, ERIS_NIX_RAW_FLAT_LAMP_OFF_DO_CATG) ||
81 !strcmp(tag, ERIS_NIX_RAW_FLAT_SKY_DO_CATG) ||
82 !strcmp(tag, ERIS_NIX_RAW_FLAT_SKY_LSS_DO_CATG) ||
83 !strcmp(tag, ERIS_NIX_RAW_FLAT_TWILIGHT_DO_CATG) ||
84 !strcmp(tag, ERIS_NIX_RAW_PUPIL_LAMP_DO_CATG) ||
85 !strcmp(tag, ERIS_NIX_RAW_PUPIL_SKY_DO_CATG) ||
86 !strcmp(tag, ERIS_NIX_RAW_PUPIL_DARK_DO_CATG) ||
87 !strcmp(tag, ERIS_NIX_RAW_PUPIL_BKG_DO_CATG) ||
88 !strcmp(tag, ERIS_NIX_RAW_PUPIL_LAMP_OPEN_DO_CATG) ||
89 !strcmp(tag, ERIS_NIX_RAW_PUPIL_LAMP_MASK_DO_CATG) ||
90 !strcmp(tag, ERIS_NIX_RAW_PUPIL_SKY_OPEN_DO_CATG) ||
91 !strcmp(tag, ERIS_NIX_RAW_PUPIL_SKY_MASK_DO_CATG) ||
92 !strcmp(tag, ERIS_NIX_RAW_PUPIL_DARK_OPEN_DO_CATG) ||
93 !strcmp(tag, ERIS_NIX_RAW_PUPIL_DARK_MASK_DO_CATG) ||
94 !strcmp(tag, ERIS_NIX_RAW_OBJECT_APP_DO_CATG) ||
95 !strcmp(tag, ERIS_NIX_RAW_OBJECT_FPC_DO_CATG) ||
96 !strcmp(tag, ERIS_NIX_RAW_OBJECT_SAM_DO_CATG) ||
97 !strcmp(tag, ERIS_NIX_RAW_OBJECT_JITTER_DO_CATG) ||
98 !strcmp(tag, ERIS_NIX_RAW_SKY_FPC_DO_CATG) ||
99 !strcmp(tag, ERIS_NIX_RAW_SKY_APP_DO_CATG) ||
100 !strcmp(tag, ERIS_NIX_RAW_SKY_JITTER_DO_CATG) ||
101 !strcmp(tag, ERIS_NIX_RAW_STD_JITTER_DO_CATG) ||
102 !strcmp(tag, ERIS_NIX_RAW_OBJECT_LSS_JITTER_DO_CATG) ||
103 !strcmp(tag, ERIS_NIX_RAW_STD_APP_DO_CATG) ||
104 !strcmp(tag, ERIS_NIX_RAW_STD_FPC_DO_CATG) ||
105 !strcmp(tag, ERIS_NIX_RAW_STD_SAM_DO_CATG) ||
106 !strcmp(tag, ERIS_NIX_RAW_SKY_LSS_JITTER_DO_CATG) ||
107 !strcmp(tag, ERIS_NIX_RAW_STD_LSS_JITTER_DO_CATG)) {
109 cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
112 }
else if (!strcmp(tag, ERIS_NIX_COEFFS_CUBE_PRO_CATG) ||
113 !strcmp(tag, ERIS_NIX_DET_LIN_INFO_PRO_CATG) ||
114 !strcmp(tag, ERIS_NIX_GAIN_PRO_CATG) ||
115 !strcmp(tag, ERIS_NIX_MASTER_BPM_LAMP_PRO_CATG) ||
116 !strcmp(tag, ERIS_NIX_MASTER_BPM_LSS_PRO_CATG) ||
117 !strcmp(tag, ERIS_NIX_MASTER_BPM_SKY_PRO_CATG) ||
118 !strcmp(tag, ERIS_NIX_MASTER_DARK_IMG_PRO_CATG) ||
119 !strcmp(tag, ERIS_NIX_MASTER_DARK_IFU_PRO_CATG) ||
120 !strcmp(tag, ERIS_NIX_MASTER_FLAT_LAMP_HIFREQ_PRO_CATG) ||
121 !strcmp(tag, ERIS_NIX_MASTER_FLAT_LAMP_LOFREQ_PRO_CATG) ||
122 !strcmp(tag, ERIS_NIX_MASTER_FLAT_LSS_HIFREQ_PRO_CATG) ||
123 !strcmp(tag, ERIS_NIX_MASTER_FLAT_LSS_LOFREQ_PRO_CATG) ||
124 !strcmp(tag, ERIS_NIX_MASTER_FLAT_SKY_LOFREQ_PRO_CATG) ||
125 !strcmp(tag, ERIS_NIX_MASTER_FLAT_SKY_HIFREQ_PRO_CATG) ||
126 !strcmp(tag, ERIS_NIX_MASTER_FLAT_TWILIGHT_LOFREQ_PRO_CATG)||
127 !strcmp(tag, ERIS_NIX_MASTER_STARTRACE_PRO_CATG)||
128 !strcmp(tag, ERIS_NIX_MASTER_WAVE_PRO_CATG)||
129 !strcmp(tag, ERIS_NIX_NL_BPM_PRO_CATG) ||
130 !strcmp(tag, ERIS_NIX_PHOT_DATA_PRO_CATG) ||
131 !strcmp(tag, ERIS_NIX_WCS_MATCHED_CATALOGUE_PRO_CATG) ||
132 !strcmp(tag, ERIS_NIX_WCS_REFINE_PRO_CATG) ||
133 !strcmp(tag, ERIS_NIX_REFERENCE_DARK_PRO_CATG)) {
135 cpl_frame_set_group(frame, CPL_FRAME_GROUP_CALIB);
138 }
else if (!strcmp(tag, ERIS_NIX_CALIB_OBJECT_JITTER_PRO_CATG) ||
139 !strcmp(tag, ERIS_NIX_CAL_DET_OBJECT_JITTER_PRO_CATG) ||
140 !strcmp(tag, ERIS_NIX_CAL_DET_SKY_JITTER_PRO_CATG) ||
141 !strcmp(tag, ERIS_NIX_CAL_DET_STD_JITTER_PRO_CATG) ||
142 !strcmp(tag, ERIS_NIX_CAL_DET_OBJECT_LSS_JITTER_PRO_CATG) ||
143 !strcmp(tag, ERIS_NIX_CAL_DET_SKY_LSS_JITTER_PRO_CATG) ||
144 !strcmp(tag, ERIS_NIX_CAL_DET_STD_LSS_JITTER_PRO_CATG) ||
145 !strcmp(tag, ERIS_NIX_CAL_PHOT_CATALOGUE_PRO_CATG) ||
146 !strcmp(tag, ERIS_NIX_CAL_PHOT_MATCH_CATALOGUE_PRO_CATG) ||
147 !strcmp(tag, ERIS_NIX_CAL_PHOT_OBJECT_JITTER_PRO_CATG) ||
148 !strcmp(tag, ERIS_NIX_CAL_PHOT_REF_CATALOGUE_PRO_CATG) ||
149 !strcmp(tag, ERIS_NIX_CAL_PHOT_STD_JITTER_PRO_CATG) ||
150 !strcmp(tag, ERIS_NIX_CAL_WCS_CATALOGUE_PRO_CATG) ||
151 !strcmp(tag, ERIS_NIX_CAL_WCS_MATCH_CATALOGUE_PRO_CATG) ||
152 !strcmp(tag, ERIS_NIX_CAL_WCS_OBJECT_JITTER_PRO_CATG) ||
153 !strcmp(tag, ERIS_NIX_CAL_WCS_REF_CATALOGUE_PRO_CATG) ||
154 !strcmp(tag, ERIS_NIX_CAL_WCS_REPORT_PRO_CATG) ||
155 !strcmp(tag, ERIS_NIX_CAL_WCS_STD_JITTER_PRO_CATG) ||
156 !strcmp(tag, ERIS_NIX_CORRECTED_OBJECT_LSS_JITTER_PRO_CATG) ||
157 !strcmp(tag, ERIS_NIX_CORRECTED_STD_LSS_JITTER_PRO_CATG) ||
158 !strcmp(tag, ERIS_NIX_IMG_CATALOGUE_PRO_CATG) ||
159 !strcmp(tag, ERIS_NIX_IMG_OBS_COMBINED_PRO_CATG) ||
160 !strcmp(tag, ERIS_NIX_IMG_STD_COMBINED_PRO_CATG) ||
161 !strcmp(tag, ERIS_NIX_LSS_OBS_COMBINED_PRO_CATG) ||
162 !strcmp(tag, ERIS_NIX_LSS_STD_COMBINED_PRO_CATG) ||
163 !strcmp(tag, ERIS_NIX_SKYSUB_OBJECT_JITTER_PRO_CATG) ||
164 !strcmp(tag, ERIS_NIX_SKYSUB_STD_JITTER_PRO_CATG) ||
165 !strcmp(tag, ERIS_NIX_SKYSUB_OBJECT_LSS_JITTER_PRO_CATG) ||
166 !strcmp(tag, ERIS_NIX_SKYSUB_STD_LSS_JITTER_PRO_CATG)) {
171 cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
174 cpl_frame_set_group(frame, CPL_FRAME_GROUP_NONE);
180 cpl_error_set_message(
"eris_nix_dfs_set_groups",
181 CPL_ERROR_UNSUPPORTED_MODE,
182 "data tag not recognised: %s", tag);
187 cpl_frameset_iterator_advance(fsiter, 1);
188 frame = cpl_frameset_iterator_get(fsiter);
191 enu_check_error_code(
"Could not identify RAW and CALIB frames");
194 cpl_frameset_iterator_delete(fsiter);
196 return cpl_error_get_code();
220 cpl_frameset * allframes,
221 const cpl_parameterlist * parlist,
222 const cpl_frameset * usedframes,
223 const master_bpm * mbad_pix_map,
225 const cpl_propertylist * applist,
226 const char * pipe_id,
227 const char * filename) {
229 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
231 cpl_propertylist * plist = NULL;
233 if (applist == NULL) {
234 plist = cpl_propertylist_new();
236 plist = cpl_propertylist_duplicate(applist);
238 cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG, procat);
239 cpl_dfs_save_image(allframes, NULL, parlist, usedframes, NULL,
240 mbad_pix_map->bpm, CPL_TYPE_INT, recipe, plist, NULL, pipe_id, filename);
241 cpl_ensure_code(!cpl_error_get_code(), cpl_error_get_code());
245 cpl_propertylist_delete(plist);
247 return cpl_error_get_code();
276 const cpl_parameterlist * parlist,
277 const cpl_table * catalogue,
278 const cpl_propertylist * tablelist,
279 const char * cat_name,
281 const char * pipe_id,
282 const char * preface,
283 const char * procat) {
287 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
288 if (!catalogue)
return CPL_ERROR_NONE;
292 cpl_ensure_code(image, CPL_ERROR_NULL_INPUT);
293 cpl_ensure_code(cat_name, CPL_ERROR_NULL_INPUT);
294 cpl_ensure_code(preface, CPL_ERROR_NULL_INPUT);
296 cpl_propertylist * applist = NULL;
297 cpl_propertylist * image_plist = NULL;
298 char * prodname = NULL;
299 cpl_frame * product_frame = NULL;
300 cpl_propertylist * tablelist_copy = NULL;
305 cpl_frameset * provenance = cpl_frameset_new();
306 cpl_frameset_insert(provenance, cpl_frame_duplicate(image));
310 prodname =
enu_repreface(cpl_frame_get_filename(image), preface);
311 product_frame = cpl_frame_new();
312 cpl_frame_set_filename(product_frame, prodname);
313 cpl_frame_set_tag(product_frame, procat);
314 cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_ANY);
315 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT);
316 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL);
320 applist = cpl_propertylist_new();
324 image_plist = cpl_propertylist_load(cpl_frame_get_filename(image), 0);
325 cpl_propertylist_copy_property_regexp(applist,
327 "ORIGIN|TELESCOP|INSTRUME|FILTER|"
328 "OBJECT|RA|DEC|EQUINOX|RADESYS|"
329 "TIMESYS|EXPTIME|TEXPTIME|MJD-OBS|"
330 "MJD-END|PROG_ID|OBID[1-9]([0-9])*|"
331 "NCOMBINE|OBSTECH|PROCSOFT|"
334 enu_check_error_code(
"error copying image HDU info to applist");
350 cpl_propertylist_update_string(applist,
"PRODCATG",
"SCIENCE.SRCTBL");
351 cpl_propertylist_update_string(applist, CPL_DFS_PRO_CATG, procat);
355 if (cpl_frame_get_filename(image)) {
356 char * filename = cpl_strdup(cpl_frame_get_filename(image));
357 cpl_propertylist_update_string(applist,
"PROV1", basename(filename));
363 if (tablelist != NULL) {
364 tablelist_copy = cpl_propertylist_duplicate(tablelist);
366 tablelist_copy = cpl_propertylist_new();
368 cpl_propertylist_update_string(tablelist_copy,
"EXTNAME",
"PHASE3CATALOG");
372 cpl_table_save(catalogue,
378 enu_check_error_code(
"error saving dfs table");
383 cpl_frameset_insert(frameset, cpl_frame_duplicate(product_frame));
387 cpl_propertylist_delete(applist);
388 cpl_propertylist_delete(image_plist);
390 cpl_frame_delete(product_frame);
391 cpl_propertylist_delete(tablelist_copy);
392 cpl_frameset_delete(provenance);
394 return cpl_error_get_code();
424 const cpl_parameterlist * parlist,
425 const cpl_frameset * provenance,
426 const cpl_boolean prov_raw,
427 const hdrl_image * image,
428 const hdrl_imagelist * imagelist,
429 const mef_extension_list* mefs,
431 const cpl_frame * inherit_frame,
432 const cpl_propertylist * applist,
433 const cpl_propertylist * wcs_plist,
434 const char * pipe_id,
435 const char * filename) {
437 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
439 cpl_msg_debug(cpl_func,
"enu_dfs_save_himage entry");
441 cpl_ensure_code(allframes, CPL_ERROR_NULL_INPUT);
442 cpl_ensure_code(parlist, CPL_ERROR_NULL_INPUT);
443 cpl_ensure_code(provenance, CPL_ERROR_NULL_INPUT);
444 cpl_ensure_code(recipe, CPL_ERROR_NULL_INPUT);
445 cpl_ensure_code(applist, CPL_ERROR_NULL_INPUT);
446 cpl_ensure_code(pipe_id, CPL_ERROR_NULL_INPUT);
447 cpl_ensure_code(filename, CPL_ERROR_NULL_INPUT);
449 const cpl_frame * inherit = NULL;
450 cpl_propertylist * inherit_plist = NULL;
451 cpl_frameset * product_frameset = NULL;
452 cpl_propertylist * plist = NULL;
454 int conf = CPL_FALSE;
455 int bkgd = CPL_FALSE;
456 int bkge = CPL_FALSE;
457 int bkgc = CPL_FALSE;
459 cpl_propertylist * dicd = NULL;
464 for (cpl_size i=0; i<mefs->size; i++) {
465 cpl_msg_info(cpl_func,
"%d", (
int)i);
466 cpl_msg_info(cpl_func,
"%s", mefs->mef[i]->name);
467 if (!strcmp(mefs->mef[i]->name,
"CONFIDENCE")) conf = CPL_TRUE;
468 if (!strcmp(mefs->mef[i]->name,
"BKG_DATA")) bkgd = CPL_TRUE;
469 if (!strcmp(mefs->mef[i]->name,
"BKG_ERR")) bkge = CPL_TRUE;
470 if (!strcmp(mefs->mef[i]->name,
"BKG_CONF")) bkgc = CPL_TRUE;
478 const char * procat = cpl_propertylist_get_string(applist,
480 cpl_ensure_code(procat != NULL, cpl_error_get_code());
481 cpl_msg_info(cpl_func,
"Writing MEF product(%s): %s", procat, filename);
485 product_frameset = cpl_frameset_duplicate(provenance);
490 inherit = inherit_frame;
492 cpl_frameset_iterator * frameset_iter = cpl_frameset_iterator_new(
494 inherit = cpl_frameset_iterator_get_const(frameset_iter);
495 cpl_frameset_iterator_delete(frameset_iter);
500 cpl_frame * product_frame = cpl_frame_new();
501 cpl_frame_set_filename(product_frame, filename);
502 cpl_frame_set_tag(product_frame, procat);
503 cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_ANY);
504 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT);
505 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL);
507 cpl_frameset_insert(product_frameset, product_frame);
511 plist = cpl_propertylist_duplicate(applist);
523 cpl_propertylist_update_string(plist,
"ESO PRO REC1 ID", recipe);
525 cpl_propertylist_save(plist, filename, CPL_IO_CREATE);
526 enu_check_error_code(
"error saving header 0");
531 dicd = cpl_propertylist_new();
532 cpl_propertylist_append_string(dicd,
"HDUCLASS",
"ESO");
533 cpl_propertylist_append_string(dicd,
"HDUDOC",
"SDP");
534 cpl_propertylist_append_string(dicd,
"HDUVERS",
"SDP version 8");
535 cpl_propertylist_append_string(dicd,
"SCIDATA",
"DATA");
536 cpl_propertylist_append_string(dicd,
"ERRDATA",
"ERR");
537 cpl_propertylist_append_string(dicd,
"QUALDATA",
"DQ");
539 cpl_propertylist_append_string(dicd,
"CONFDATA",
"CONFIDENCE");
542 cpl_propertylist_append_string(dicd,
"BKGDATA",
"BKG_DATA");
545 cpl_propertylist_append_string(dicd,
"BKGERR",
"BKG_ERR");
548 cpl_propertylist_append_string(dicd,
"BKGCONF",
"BKG_CONF");
550 cpl_size hlist_sz = 0;
551 if (image || imagelist) {
555 cpl_propertylist * header = cpl_propertylist_duplicate(dicd);
556 cpl_propertylist_update_string(header,
"EXTNAME",
"DATA");
557 cpl_propertylist_update_string(header,
"HDUCLAS1",
"IMAGE");
558 cpl_propertylist_update_string(header,
"HDUCLAS2",
"DATA");
559 cpl_propertylist_erase(header,
"SCIDATA");
561 if (wcs_plist) cpl_propertylist_append(header, wcs_plist);
566 const char * data_mandatory[] = {
"BUNIT",
570 const int count_data_mandatory =
sizeof(data_mandatory) /
573 const char * data_mandatory2[] = {
"PHOTSYS",
580 const int count_data_mandatory2 =
sizeof(data_mandatory2) /
584 const char * ins_mode =
"ins_mode";
585 if(cpl_propertylist_has(plist,
"ESO INS1 MODE")) {
586 ins_mode = cpl_propertylist_get_string(plist,
"ESO INS1 MODE");
590 for (
int mandi=0; mandi < count_data_mandatory; mandi++) {
591 if (!cpl_propertylist_has(header, data_mandatory[mandi])) {
592 if (cpl_propertylist_has(applist, data_mandatory[mandi])) {
593 cpl_propertylist_copy_property(header, applist,
594 data_mandatory[mandi]);
599 if(strcmp(ins_mode,
"nixLSS") != 0) {
601 for (
int mandi2=0; mandi2 < count_data_mandatory2; mandi2++) {
602 if (!cpl_propertylist_has(header, data_mandatory2[mandi2])) {
603 if (cpl_propertylist_has(applist, data_mandatory2[mandi2])) {
604 cpl_propertylist_copy_property(header, applist,
605 data_mandatory2[mandi2]);
612 for (
int mandi=0; mandi < count_data_mandatory; mandi++) {
613 if (!cpl_propertylist_has(header, data_mandatory[mandi])) {
614 if (!strcmp(data_mandatory[mandi],
"BUNIT")) {
615 cpl_propertylist_update_string(header,
"BUNIT",
617 }
else if (!strcmp(data_mandatory[mandi],
"CUNIT1")) {
618 cpl_propertylist_update_string(header,
"CUNIT1",
"deg");
619 }
else if (!strcmp(data_mandatory[mandi],
"CUNIT2")) {
620 cpl_propertylist_update_string(header,
"CUNIT2",
"deg");
621 }
else if (!strcmp(data_mandatory[mandi],
"FLUXCAL")) {
622 cpl_propertylist_update_string(header,
"FLUXCAL",
625 cpl_msg_info(cpl_func,
626 "missing extension keyword %s not handled",
627 data_mandatory[mandi]);
632 if(strcmp(ins_mode,
"nixLSS") != 0) {
634 for (
int mandi2=0; mandi2 < count_data_mandatory2; mandi2++) {
635 if (!cpl_propertylist_has(header, data_mandatory2[mandi2])) {
637 if (!strcmp(data_mandatory2[mandi2],
"PHOTSYS")) {
638 cpl_propertylist_update_string(header,
"PHOTSYS",
"VEGA");
639 }
else if (!strcmp(data_mandatory2[mandi2],
"ABMAGLIM")) {
640 cpl_msg_info(cpl_func,
"dummy value for ABMAGLIM");
641 cpl_propertylist_update_double(header,
"ABMAGLIM", 0.0);
642 }
else if (!strcmp(data_mandatory2[mandi2],
"ABMAGSAT")) {
643 cpl_msg_info(cpl_func,
"dummy value for ABMAGSAT");
644 cpl_propertylist_update_double(header,
"ABMAGSAT", 0.0);
645 }
else if (!strcmp(data_mandatory2[mandi2],
"PSF_FWHM")) {
646 cpl_msg_info(cpl_func,
"dummy value for PSF_FWHM");
647 cpl_propertylist_update_double(header,
"PSF_FWHM", -1.0);
648 }
else if (!strcmp(data_mandatory2[mandi2],
"PHOTZP")) {
649 cpl_msg_info(cpl_func,
"PHOTZP not found, set to 0.0");
650 cpl_propertylist_update_double(header,
"PHOTZP", 0.0);
651 cpl_propertylist_set_comment(header,
"PHOTZP",
"Photometric "
652 "zeropoint so that MAG=-2.5*"
653 "log(data)+PHOTZP+APCOR");
654 }
else if (!strcmp(data_mandatory2[mandi2],
"PHOTZPER")) {
655 cpl_msg_info(cpl_func,
"PHOTZPER not found, set to 0.0");
656 cpl_propertylist_update_double(header,
"PHOTZPER", 0.0);
657 cpl_propertylist_set_comment(header,
"PHOTZPER",
"Error on "
659 }
else if (!strcmp(data_mandatory2[mandi2],
"ZPMETHOD")) {
660 cpl_msg_info(cpl_func,
"ZPMETHOD not found");
661 cpl_propertylist_update_string(header,
"ZPMETHOD",
662 "PHOTZP not calculated");
663 cpl_propertylist_set_comment(header,
"ZPMETHOD",
664 "Method of ZP calculation");
666 cpl_msg_info(cpl_func,
667 "missing extension keyword %s not handled",
668 data_mandatory[mandi2]);
686 cpl_imagelist * tlist = cpl_imagelist_new();
689 for (cpl_size i = 0; i < hlist_sz; i++) {
698 cpl_imagelist_set(tlist,
702 cpl_imagelist_save(tlist,
708 cpl_imagelist_unwrap(tlist);
711 eris_ifu_plist_erase_wcs3D(header);
720 cpl_propertylist_delete(header);
721 enu_check_error_code(
"failed to save header 1");
725 header = cpl_propertylist_duplicate(dicd);
726 cpl_propertylist_update_string(header,
"EXTNAME",
"ERR");
727 cpl_propertylist_update_string(header,
"HDUCLAS1",
"IMAGE");
728 cpl_propertylist_update_string(header,
"HDUCLAS2",
"ERROR");
729 cpl_propertylist_update_string(header,
"HDUCLAS3",
"RMSE");
730 cpl_propertylist_erase(header,
"ERRDATA");
731 if (cpl_propertylist_has(applist,
"BUNIT")) {
732 cpl_propertylist_copy_property(header, applist,
"BUNIT");
735 if (wcs_plist) cpl_propertylist_append(header, wcs_plist);
739 HDRL_TYPE_ERROR, header, CPL_IO_EXTEND);
742 cpl_imagelist * tlist = cpl_imagelist_new();
745 for (cpl_size i = 0; i < hlist_sz; i++) {
747 cpl_imagelist_set(tlist,
751 cpl_imagelist_save(tlist,
756 cpl_imagelist_unwrap(tlist);
759 eris_ifu_plist_erase_wcs3D(header);
768 cpl_propertylist_delete(header);
769 enu_check_error_code(
"failed to save header 2");
773 header = cpl_propertylist_duplicate(dicd);
774 cpl_propertylist_update_string(header,
"EXTNAME",
"DQ");
775 cpl_propertylist_update_string(header,
"HDUCLAS1",
"IMAGE");
776 cpl_propertylist_update_string(header,
"HDUCLAS2",
"QUALITY");
777 cpl_propertylist_update_string(header,
"HDUCLAS3",
"MASKZERO");
778 cpl_propertylist_erase(header,
"QUALDATA");
780 if (wcs_plist) cpl_propertylist_append(header, wcs_plist);
787 header, CPL_IO_EXTEND);
792 eris_ifu_plist_erase_wcs3D(header);
795 header, CPL_IO_EXTEND);
798 cpl_propertylist_delete(header);
799 enu_check_error_code(
"failed to save header 3");
805 cpl_msg_info(cpl_func,
"..there are %d mefs", (
int) (mefs->size));
807 for (cpl_size i=0; i<mefs->size; i++) {
808 cpl_propertylist * header = NULL;
809 if (mefs->mef[i]->plist) {
810 header = cpl_propertylist_duplicate(mefs->mef[i]->plist);
812 header = cpl_propertylist_new();
817 cpl_propertylist_copy_property_regexp(header, dicd,
".+",
819 cpl_propertylist_update_string(header,
"EXTNAME",
822 cpl_msg_info(cpl_func,
"..saving mef %s", mefs->mef[i]->name);
823 if (!strcmp(mefs->mef[i]->name,
"CONFIDENCE")) {
824 cpl_propertylist_update_string(header,
"HDUCLAS1",
"IMAGE");
825 cpl_propertylist_update_string(header,
"HDUCLAS2",
"CONF");
826 cpl_propertylist_erase(header,
"CONFDATA");
827 }
else if (!strcmp(mefs->mef[i]->name,
"BKG_DATA")) {
828 cpl_propertylist_update_string(header,
"HDUCLAS1",
"IMAGE");
829 cpl_propertylist_update_string(header,
"HDUCLAS2",
"BKG_DATA");
830 cpl_propertylist_erase(header,
"BKGDATA");
831 if (cpl_propertylist_has(applist,
"BUNIT")) {
832 cpl_propertylist_copy_property(header, applist,
"BUNIT");
834 }
else if (!strcmp(mefs->mef[i]->name,
"BKG_ERR")) {
835 cpl_propertylist_update_string(header,
"HDUCLAS1",
"IMAGE");
836 cpl_propertylist_update_string(header,
"HDUCLAS2",
"BKG_ERROR");
837 cpl_propertylist_update_string(header,
"HDUCLAS3",
"RMSE");
838 cpl_propertylist_erase(header,
"BKGERR");
839 if (cpl_propertylist_has(applist,
"BUNIT")) {
840 cpl_propertylist_copy_property(header, applist,
"BUNIT");
842 }
else if (!strcmp(mefs->mef[i]->name,
"BKG_CONF")) {
843 cpl_propertylist_update_string(header,
"HDUCLAS1",
"IMAGE");
844 cpl_propertylist_update_string(header,
"HDUCLAS2",
"BKG_CONF");
845 cpl_propertylist_erase(header,
"BKGCONF");
846 }
else if (!strcmp(mefs->mef[i]->data_type,
847 MEF_EXTENSION_CONTAINING_IMAGE)) {
848 cpl_propertylist_update_string(header,
"HDUCLAS1",
849 MEF_EXTENSION_CONTAINING_IMAGE);
850 }
else if (!strcmp(mefs->mef[i]->data_type,
851 MEF_EXTENSION_CONTAINING_MASK)) {
852 cpl_propertylist_update_string(header,
"HDUCLAS1",
853 MEF_EXTENSION_CONTAINING_MASK);
854 }
else if (!strcmp(mefs->mef[i]->data_type,
855 MEF_EXTENSION_CONTAINING_TABLE)) {
856 cpl_propertylist_update_string(header,
"HDUCLAS1",
857 MEF_EXTENSION_CONTAINING_TABLE);
862 if (wcs_plist) cpl_propertylist_append(header, wcs_plist);
866 eris_ifu_plist_erase_wcs3D(header);
870 cpl_propertylist_delete(header);
871 enu_check_error_code(
"failed to save MEF extension %d", (
int) i);
878 cpl_frameset_insert(allframes, cpl_frame_duplicate(product_frame));
882 cpl_propertylist_delete(dicd);
883 cpl_propertylist_delete(inherit_plist);
884 cpl_propertylist_delete(plist);
885 cpl_frameset_delete(product_frameset);
887 return cpl_error_get_code();
910 const cpl_parameterlist * parlist,
911 const cpl_frameset * provenance,
912 const cpl_boolean prov_raw,
913 const located_image * limage,
915 const cpl_frame * inherit,
916 cpl_propertylist * applist,
917 const char * pipe_id,
918 const char * filename) {
920 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
922 cpl_msg_debug(cpl_func,
"enu_dfs_save_limage entry");
924 cpl_ensure_code(filename, CPL_ERROR_NULL_INPUT);
925 cpl_ensure_code(limage, CPL_ERROR_NULL_INPUT);
926 cpl_ensure_code(applist, CPL_ERROR_NULL_INPUT);
928 cpl_propertylist * wcs_plist = NULL;
933 if (limage->confidence) nmefs++;
934 if (limage->bkg) nmefs = nmefs + 2;
935 if (limage->bkg_confidence) nmefs++;
937 mef_extension_list * mefs = NULL;
939 cpl_msg_info(cpl_func,
"nmefs %d", nmefs);
942 if (limage->confidence) {
943 cpl_msg_info(cpl_func,
"CONF");
945 limage->confidence, NULL);
949 cpl_msg_info(cpl_func,
"BKG");
954 cpl_msg_info(cpl_func,
"BKG_ERR");
960 if (limage->bkg_confidence) {
961 cpl_msg_info(cpl_func,
"BKG_CONF");
963 limage->bkg_confidence, NULL);
969 wcs_plist = cpl_propertylist_duplicate(limage->plist);
970 cpl_propertylist_erase_regexp(wcs_plist,
971 "CRPIX1|CRPIX2|CRPIX3|"
972 "CRVAL1|CRVAL2|CRVAL3|"
973 "CDELT1|CDELT2|CDELT3|"
977 "CTYPE1|CTYPE2|CTYPE3|"
978 "CUNIT1|CUNIT2|CUNIT3",
984 if (!cpl_propertylist_has(applist,
"BUNIT")) {
985 cpl_propertylist_copy_property(applist, limage->plist,
"BUNIT");
987 if (!cpl_propertylist_has(applist,
"PSF_FWHM")) {
988 if(cpl_propertylist_has(limage->plist,
"PSF_FWHM")) {
989 cpl_propertylist_copy_property(applist, limage->plist,
"PSF_FWHM");
992 if (!cpl_propertylist_has(applist,
"ABMAGLIM")) {
993 if (cpl_propertylist_has(limage->plist,
"ABMAGLIM")) {
994 cpl_propertylist_copy_property(applist, limage->plist,
"ABMAGLIM");
998 cpl_msg_info(cpl_func,
".. writing %s", filename);
1014 cpl_propertylist_delete(wcs_plist);
1017 return cpl_error_get_code();
1039 const cpl_frame * product_frame,
1040 const cpl_frameset * framelist,
1041 const cpl_parameterlist * parlist,
1042 const char * recipe_id,
1043 const char * pipe_id,
1044 const cpl_frame * inherit,
1045 const cpl_frameset * provenance,
1046 cpl_boolean prov_raw) {
1048 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
1050 cpl_ensure_code(header, CPL_ERROR_NULL_INPUT);
1051 cpl_ensure_code(product_frame, CPL_ERROR_NULL_INPUT);
1052 cpl_ensure_code(framelist, CPL_ERROR_NULL_INPUT);
1053 cpl_ensure_code(parlist, CPL_ERROR_NULL_INPUT);
1054 cpl_ensure_code(recipe_id, CPL_ERROR_NULL_INPUT);
1055 cpl_ensure_code(pipe_id, CPL_ERROR_NULL_INPUT);
1056 cpl_ensure_code(inherit, CPL_ERROR_NULL_INPUT);
1057 cpl_ensure_code(provenance, CPL_ERROR_NULL_INPUT);
1059 cpl_propertylist * inherit_plist = NULL;
1060 cpl_propertylist * input_header = NULL;
1065 input_header = cpl_propertylist_duplicate(header);
1066 cpl_dfs_setup_product_header(header,
1074 cpl_propertylist_copy_property_regexp(header,
1078 if (cpl_propertylist_has(header,
"RA")) {
1079 cpl_propertylist_set_comment(header,
"RA",
1080 "[deg] RA (J2000) pointing");
1082 if (cpl_propertylist_has(header,
"DEC")) {
1083 cpl_propertylist_set_comment(header,
"DEC",
1084 "[deg] DEC (J2000) pointing");
1090 cpl_propertylist_erase_regexp(header,
1091 "HDUCLASS|HDUDOC|HDUVERS|SCIDATA|ERRDATA|"
1092 "QUALDATA|CONFDATA|BKGDATA|BKGERR|BKGCONF|"
1093 "CRPIX1|CRPIX2|CRVAL1|CRVAL2|CDELT1|CDELT2|"
1094 "CTYPE1|CTYPE2|CUNIT1|CUNIT2|"
1095 "CD1_1|CD1_2|CD2_1|CD2_2|"
1096 "PHOTSYS|PHOTZP|PHOTZERR|ABMAGSAT|ABMAGLIM|"
1097 "MJD-OBS|PSF_FWHM|BUNIT",
1103 cpl_frameset_iterator * it = cpl_frameset_iterator_new(provenance);
1104 const cpl_frame * frame = cpl_frameset_iterator_get_const(it);
1108 char * filename = cpl_strdup(cpl_frame_get_filename(frame));
1112 pch = strstr(filename,
"ERIS.20");
1119 char * pname = cpl_sprintf(
"PROV%.0i", iprov);
1120 cpl_propertylist_update_string(header, pname, basename(pch));
1123 cpl_frameset_iterator_advance(it, 1);
1124 frame = cpl_frameset_iterator_get(it);
1126 cpl_frameset_iterator_delete(it); it = NULL;
1127 enu_check_error_code(
"error storing PROVenance keywords");
1132 const char * inherit_fname = cpl_frame_get_filename(inherit);
1133 inherit_plist = cpl_propertylist_load(inherit_fname, 0);
1134 enu_check_error_code(
"error reading propertylist from inherit");
1136 const char * mandatory[] = {
"TELESCOP",
1157 const int count_mandatory =
sizeof(mandatory) /
sizeof(
char *);
1158 for (
int mandi=0; mandi < count_mandatory; mandi++) {
1159 if (!cpl_propertylist_has(header, mandatory[mandi])) {
1160 if (cpl_propertylist_has(inherit_plist, mandatory[mandi])) {
1161 cpl_msg_info(cpl_func,
"copying from inherit %s",
1163 cpl_propertylist_copy_property(header, inherit_plist,
1171 for (
int mandi=0; mandi < count_mandatory; mandi++) {
1172 if (!cpl_propertylist_has(header, mandatory[mandi])) {
1173 if (!strcmp(mandatory[mandi],
"FILTER")) {
1174 const char * filter = NULL;
1175 if (inherit_plist) {
1179 cpl_propertylist_update_string(header,
"FILTER",
1182 cpl_propertylist_update_string(header,
"FILTER",
1185 }
else if (!strcmp(mandatory[mandi],
"RADESYS")) {
1186 const char * radesys = NULL;
1187 if (inherit_plist && cpl_propertylist_has(inherit_plist,
1189 radesys = cpl_propertylist_get_string(inherit_plist,
1193 cpl_propertylist_update_string(header,
"RADESYS",
1196 cpl_propertylist_update_string(header,
"RADESYS",
1199 }
else if (!strcmp(mandatory[mandi],
"TIMESYS")) {
1200 cpl_propertylist_update_string(header,
"TIMESYS",
1202 }
else if (!strcmp(mandatory[mandi],
"PROG_ID")) {
1203 const char * prog_id = NULL;
1204 if (inherit_plist && cpl_propertylist_has(inherit_plist,
1205 "ESO OBS PROG ID")) {
1206 prog_id = cpl_propertylist_get_string(inherit_plist,
1210 cpl_propertylist_update_string(header,
"PROG_ID",
1213 cpl_propertylist_update_string(header,
"PROG_ID",
1216 }
else if (!strcmp(mandatory[mandi],
"OBSTECH")) {
1217 const char * obstech = NULL;
1218 if (inherit_plist) {
1219 if (cpl_propertylist_has(inherit_plist,
"ESO DPR TECH")) {
1220 obstech = cpl_propertylist_get_string(
1221 inherit_plist,
"ESO DPR TECH");
1222 }
else if (cpl_propertylist_has(inherit_plist,
"ESO PRO TECH")) {
1223 obstech = cpl_propertylist_get_string(
1224 inherit_plist,
"ESO PRO TECH");
1228 cpl_propertylist_update_string(header,
"OBSTECH",
1231 cpl_propertylist_update_string(header,
"OBSTECH",
1234 }
else if (!strcmp(mandatory[mandi],
"FLUXCAL")) {
1235 cpl_propertylist_update_string(header,
"FLUXCAL",
1237 }
else if (!strcmp(mandatory[mandi],
"PROCSOFT")) {
1238 cpl_propertylist_update_string(header,
"PROCSOFT", pipe_id);
1239 }
else if (!strcmp(mandatory[mandi],
"REFERENC")) {
1240 cpl_propertylist_update_string(header,
"REFERENC",
1242 }
else if (!strcmp(mandatory[mandi],
"OBID1")) {
1244 if (inherit_plist && cpl_propertylist_has(inherit_plist,
1246 obid = cpl_propertylist_get_int(inherit_plist,
"ESO OBS ID");
1248 cpl_propertylist_update_int(header,
"OBID1", obid);
1250 cpl_msg_warning(cpl_func,
"missing %s", mandatory[mandi]);
1256 cpl_propertylist_delete(inherit_plist);
1257 cpl_propertylist_delete(input_header);
1259 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_error_code eris_check_error_code(const char *func_id)
handle CPL errors
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.