35#include "eris_nix_utils.h"
36#include "eris_utils.h"
37#include "eris_nix_casu_utils.h"
38#include "eris_nix_dfs.h"
39#include "eris_nix_match.h"
42#include <casu_stats.h>
100 const int read_offsets,
101 const cpl_table * refine_wcs,
102 const master_dark * mdark,
103 const gain_linearity * gain_lin,
104 const master_flat * flatfield_1,
105 const master_flat * flatfield_2,
106 const master_bpm * mbad_pix_map,
108 const char * fill_rejected,
109 const double fill_value,
110 const cpl_size x_probe,
111 const cpl_size y_probe) {
113 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
115 if (limage == NULL)
return CPL_ERROR_NONE;
124 if (limage->himage) {
141 enu_check_error_code(
"failure in basic calibration");
143 }
else if (limage->himagelist) {
145 cpl_error_code didfail = CPL_ERROR_NONE;
148 cpl_errorstate cleanstate = cpl_errorstate_get();
150#pragma omp parallel for
152 for (cpl_size plane = 0; plane < nplanes; plane++) {
154 cpl_error_code errori = cpl_error_get_code();
162 if (didfail)
continue;
166 cpl_msg_info(cpl_func,
"basic calibrate cube: plane %d",
189 errori = cpl_error_set_message(cpl_func, cpl_error_get_code(),
190 "Cannot process plane %d/%d",
191 (
int)plane+1, (
int)nplanes);
200 cpl_errorstate_dump(cleanstate, CPL_FALSE, NULL);
201 cpl_errorstate_set(cleanstate);
203#pragma omp critical(enu_basic_calibrate)
208 if (didfail) (void)cpl_error_set_message(cpl_func, didfail,
209 "Cannot process %d plane(s)",
215 return cpl_error_get_code();
258 cpl_image * confidence,
259 cpl_propertylist * plist,
260 const cpl_frame * frame,
261 const int read_offsets,
262 const master_dark * mdark,
263 const gain_linearity * gain_lin,
264 const master_flat * flatfield_1,
265 const master_flat * flatfield_2,
266 const master_bpm * mbad_pix_map,
267 const int set_confidence,
269 const char * fill_rejected,
270 const double fill_value,
271 const cpl_size x_probe,
272 const cpl_size y_probe) {
274 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
276 cpl_ensure_code(himage, CPL_ERROR_NULL_INPUT);
285 cpl_size nx_chip = 0;
286 cpl_size ny_chip = 0;
287 cpl_boolean windowed = 0;
297 enu_check_error_code(
"failed to read detector window information");
299 cpl_msg_info(cpl_func,
"detector is windowed!");
304 const char * instrume = cpl_propertylist_get_string(plist,
"INSTRUME");
305 const cpl_boolean eris = !strcmp(instrume,
"ERIS");
309 int probe = CPL_FALSE;
310 if ((x_probe >= 0) && (y_probe >= 0)) {
311 if (x_probe < nx && y_probe < ny) {
322 cpl_msg_info(cpl_func,
323 "..basic_calibrate probe (%d,%d) entry(v,e,r)=%5.3e %5.3e %d",
324 (
int) x_probe, (
int)y_probe, val.data, val.error,
327 cpl_msg_info(cpl_func,
328 "..basic_calibrate probe (median) entry(v,e)=%5.3e %5.3e",
329 val.data, val.error);
337 cpl_msg_info(cpl_func,
"basic calibrate: correcting wcs for windowed data");
338 const double crpix1 = cpl_propertylist_get_double(plist,
"CRPIX1");
339 cpl_propertylist_update_double(plist,
"CRPIX1",
340 crpix1 - (
double)strx + 1.0);
341 const double crpix2 = cpl_propertylist_get_double(plist,
"CRPIX2");
342 cpl_propertylist_update_double(plist,
"CRPIX2",
343 crpix2 - (
double)stry + 1.0);
344 cpl_msg_info(cpl_func,
"..crpix %f %f -> %f %f", crpix1, crpix2,
345 crpix1 - (
double)strx + 1.0,
346 crpix2 - (
double)stry + 1.0);
351 if (read_offsets && eris) {
352 cpl_msg_info(cpl_func,
"basic calibrate: removing read-offsets and "
355 enu_check_error_code(
"error removing read-offsets");
363 cpl_msg_info(cpl_func,
364 "..basic_calibrate probe (%d,%d) after "
365 "read_offsets(v,e,r)=%5.3e %5.3e %d",
366 (
int) x_probe, (
int)y_probe,
367 val.data, val.error, reject);
369 cpl_msg_info(cpl_func,
370 "..basic_calibrate probe (median) after "
371 "read_offsets(v,e)=%5.3e %5.3e", val.data, val.error);
376 cpl_msg_info(cpl_func,
"basic calibrate: subtracting master dark");
384 "^ESO DET SEQ1 DIT$|"
385 "^ESO DET READ CURNAME$|"
386 "^ESO DET SEQ1 WIN NX$|"
387 "^ESO DET SEQ1 WIN NY$|"
388 "^ESO DET SEQ1 WIN ROT$|"
389 "^ESO DET SEQ1 WIN STRX$|"
390 "^ESO DET SEQ1 WIN STRY$|"
392 "^ESO DET NCORRS NAME$|"
395 "^ESO DET WIN STARTX$|"
396 "^ESO DET WIN STARTY$");
397 const char * filename = NULL;
399 filename = cpl_frame_get_filename(frame);
401 if (filename == NULL) {
402 enu_check(compatible, CPL_ERROR_INCOMPATIBLE_INPUT,
403 "MASTER_DARK does not match frame");
405 enu_check(compatible, CPL_ERROR_INCOMPATIBLE_INPUT,
406 "MASTER_DARK does not match %s", filename);
412 double gain = cpl_propertylist_get_double(mdark->plist,
414 cpl_propertylist_update_double(plist,
"ESO DARK GAIN", gain);
415 cpl_propertylist_set_comment(plist,
"ESO DARK GAIN",
416 "GAIN from master_dark [e-/ADU]");
417 enu_check_error_code(
"error subtracting DARK");
430 cpl_msg_info(cpl_func,
431 "..basic_calibrate probe (%d,%d) after dark_subtract "
432 "dark(v,e,r)=%5.3e %5.3e %d "
433 "data(v,e,r)=%5.3e %5.3e %d",
434 (
int) x_probe, (
int)y_probe,
435 dark.data, dark.error, reject2,
436 val.data, val.error, reject);
439 cpl_msg_info(cpl_func,
440 "..basic_calibrate probe (median) after dark_subtract "
441 "dark(v,e)=%5.3e %5.3e data(v,e)=%5.3e %5.3e",
442 dark.data, dark.error,
443 val.data, val.error);
448 hdrl_image * himage_copy = NULL;
452 cpl_msg_info(cpl_func,
"basic calibrate: linearizing and estimating "
455 himage_copy = end_linearize_and_variance_detmon(gain_lin,
463 enu_check_error_code(
"error estimating variance");
468 cpl_propertylist_update_double(plist,
469 "ESO DETMON SATURATION",
470 gain_lin->saturation_limit);
471 cpl_propertylist_set_comment(plist,
472 "ESO DETMON SATURATION",
473 "saturation level from "
474 "linearisation [ADU]");
479 cpl_propertylist_update_string(plist,
"BUNIT",
"adu/s");
487 cpl_msg_info(cpl_func,
488 "..basic_calibrate probe (%d,%d) "
489 "after linearize/calc_variance "
490 "data(v,e,r)=%5.3e %5.3e %d",
491 (
int) x_probe, (
int)y_probe, val.data, val.error,
494 cpl_msg_info(cpl_func,
495 "..basic_calibrate probe (median) "
496 "after linearize/calc_variance "
497 "data(v,e)=%5.3e %5.3e", val.data, val.error);
502 cpl_msg_info(cpl_func,
"basic calibrate: dividing by flatfield 1");
509 hdrl_image * flat_window = !windowed ? NULL :
514 const hdrl_image * flat_use = !windowed ? flatfield_1->flat
517 enu_check_error_code(
"error extracting window from flatfield 1");
525 if (set_confidence) {
532 cpl_image * flat_conf_window = !windowed ? NULL :
533 cpl_image_extract(flatfield_1->confidence,
537 const cpl_image * flat_conf_use = !windowed ? flatfield_1->confidence
540 enu_check_error_code(
"error extracting window from flatfield 1 "
542 cpl_image_copy(confidence, flat_conf_use, 1, 1);
543 cpl_image_delete(flat_conf_window);
547 cpl_mask * old_mask =
548 cpl_image_set_bpm(confidence,
550 cpl_mask_delete(old_mask);
551 cpl_image_fill_rejected(confidence, 0.0);
552 (void)cpl_image_unset_bpm(confidence);
554 cpl_image_accept_all(confidence);
558 enu_check_error_code(
"error dividing by flatfield 1");
571 cpl_msg_info(cpl_func,
572 "..basic_calibrate probe (%d,%d) after flatfield1 "
573 "flat(v,e,r)=%5.3e %5.3e %d "
574 "data(v,e,r)=%5.3e %5.3e %d",
575 (
int) x_probe, (
int)y_probe,
576 flat.data, flat.error, reject2,
577 val.data, val.error, reject);
580 cpl_msg_info(cpl_func,
581 "..basic_calibrate probe (median) after flatfield1 "
582 "flat(v,e)=%5.3e %5.3e data(v,e)=%5.3e %5.3e",
583 flat.data, flat.error,
584 val.data, val.error);
591 cpl_msg_info(cpl_func,
"basic calibrate: dividing by flatfield 2");
593 hdrl_image * flat_window = !windowed ? NULL :
598 const hdrl_image * flat_use = !windowed ? flatfield_2->flat
601 enu_check_error_code(
"error extracting window from flatfield 2");
605 if (set_confidence) {
606 cpl_image * flat_conf_window = !windowed ? NULL :
607 cpl_image_extract(flatfield_2->confidence,
611 const cpl_image * flat_conf_use = !windowed ? flatfield_2->confidence
614 enu_check_error_code(
"error extracting window from flatfield 1 "
617 cpl_image_copy(confidence, flat_conf_use, 1, 1);
618 cpl_image_delete(flat_conf_window);
622 cpl_mask * old_mask =
623 cpl_image_set_bpm(confidence,
625 cpl_mask_delete(old_mask);
626 cpl_image_fill_rejected(confidence, 0.0);
627 (void)cpl_image_unset_bpm(confidence);
629 cpl_image_accept_all(confidence);
633 enu_check_error_code(
"error dividing by flatfield 2");
646 cpl_msg_info(cpl_func,
647 "..basic_calibrate probe (%d,%d) after flatfield2 "
648 "flat(v,e,r)=%5.3e %5.3e %d "
649 "data(v,e,r)=%5.3e %5.3e %d",
650 (
int) x_probe, (
int)y_probe,
651 flat.data, flat.error, reject2,
652 val.data, val.error, reject);
655 cpl_msg_info(cpl_func,
656 "..basic_calibrate probe (median) after flatfield2 "
657 "flat(v,e)=%5.3e %5.3e data(v,e)=%5.3e %5.3e",
658 flat.data, flat.error,
659 val.data, val.error);
665 cpl_msg_info(cpl_func,
"basic calibrate: associating with master_bpm");
666 cpl_mask * new_mask = en_master_bpm_get_mask(mbad_pix_map, flag_mask);
670 cpl_mask * new_mask_window = !windowed ? NULL :
671 cpl_mask_extract(new_mask,
675 const cpl_mask * new_mask_use = !windowed ? new_mask : new_mask_window;
677 enu_check_error_code(
"error extracting window from bpm mask");
682 cpl_mask_or(current_mask, new_mask_use);
683 enu_check_error_code(
"error setting new mask");
685 if (set_confidence) {
689 double * conf_data = cpl_image_get_data(confidence);
690 cpl_binary * mask_data = cpl_mask_get_data(current_mask);
691 cpl_size nx_mask = cpl_mask_get_size_x(current_mask);
692 cpl_size ny_mask = cpl_mask_get_size_y(current_mask);
693 for (cpl_size i = 0; i < nx_mask * ny_mask; i++) {
694 if (mask_data[i] == CPL_BINARY_1) {
707 double conf = cpl_image_get(confidence, x_probe, y_probe, &ignore);
708 cpl_msg_info(cpl_func,
"..basic_calibrate probe (%d,%d) "
709 "after associate_mask(v,e,r,c)=%5.3e %5.3e %d %5.3e",
710 (
int) x_probe, (
int)y_probe, val.data, val.error,
713 cpl_mask_delete(new_mask);
714 cpl_mask_delete(new_mask_window);
717 if (!strcmp(fill_rejected,
"noop")) {
718 cpl_msg_info(cpl_func,
"not modifying rejected pixels");
721 if (!strcmp(fill_rejected,
"set_NaN")) {
723 cpl_msg_info(cpl_func,
"basic calibrate: setting rejected pixels "
725 }
else if (!strcmp(fill_rejected,
"set_value")) {
727 cpl_msg_info(cpl_func,
"basic calibrate: setting rejected pixels "
730 enu_check(CPL_FALSE, CPL_ERROR_UNSPECIFIED,
731 "bad fill-rejected value: programming error");
735 enu_check_error_code(
"error setting rejected pixels to %f",
745 double conf = cpl_image_get(confidence, x_probe, y_probe, &ignore);
746 cpl_msg_info(cpl_func,
747 "..basic_calibrate probe (%d,%d) after "
748 "fill-rejected(v,e,r,c)=%5.3e %5.3e %d %5.3e",
749 (
int) x_probe, (
int)y_probe, val.data, val.error,
755 return cpl_error_get_code();;
773 const int min_coadds,
774 const hdrl_parameter * collapse_params,
775 const cpl_size filter_size_x,
776 const cpl_size filter_size_y,
777 const hdrl_flat_method method) {
781 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
782 cpl_ensure(himlist, CPL_ERROR_NULL_INPUT, NULL);
783 cpl_ensure(collapse_params, CPL_ERROR_NULL_INPUT, NULL);
785 cpl_image * contribution = NULL;
786 hdrl_parameter * flat_params = NULL;
787 hdrl_image * result = NULL;
792 enu_check(size >= min_coadds, CPL_ERROR_ILLEGAL_INPUT,
793 "insufficient frames for flat (%d<min:%d)",
794 (
int) size, min_coadds);
801 if (method == HDRL_FLAT_FREQ_HIGH) {
802 cpl_msg_info(cpl_func,
"Calculating high freq flatfield");
803 }
else if (method == HDRL_FLAT_FREQ_LOW) {
804 cpl_msg_info(cpl_func,
"Calculating low freq flatfield");
806 cpl_msg_info(cpl_func,
"..smoothing filter sizes %d %d",
807 (
int)filter_size_x, (
int)filter_size_y);
809 flat_params, &result, &contribution);
810 enu_check_error_code(
"error computing flat-field");
813 cpl_image_delete(contribution);
815 if (cpl_error_get_code() != CPL_ERROR_NONE) {
838 const double fwhm_pix,
841 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
842 cpl_ensure_code(limage, CPL_ERROR_NULL_INPUT);
843 cpl_ensure_code(abmaglim, CPL_ERROR_NULL_INPUT);
846 if (fwhm_pix <= 0.0) {
848 return CPL_ERROR_NONE;
854 double histo_min = 10.;
855 double histo_max = 1.;
856 double bin_size = 0.;
857 cpl_size error_niter = 0;
858 hdrl_mode_type mode_method = HDRL_MODE_MEDIAN;
859 hdrl_parameter * mode_parameter = NULL;
868 ((
int) (3.0 * fwhm_pix) / 2) * 2 + 1,
869 ((
int) (3.0 * fwhm_pix) / 2) * 2 + 1,
870 HDRL_IMAGE_EXTEND_MIRROR,
875 return cpl_error_get_code();
893 const cpl_propertylist * wcs_plist) {
895 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
896 cpl_ensure_code(catalogue, CPL_ERROR_NULL_INPUT);
897 cpl_ensure_code(wcs_plist, CPL_ERROR_NULL_INPUT);
899 cpl_array * conv_status = NULL;
900 cpl_matrix * ref_phys = NULL;
901 cpl_matrix * ref_world = NULL;
902 cpl_wcs * wcs = NULL;
914 cpl_size nobj = cpl_table_get_nrow(catalogue);
915 const double * ra = cpl_table_get_data_double_const(catalogue,
"RA");
916 const double * dec = NULL;
920 if (cpl_table_has_column(catalogue,
"DEC")) {
921 dec = cpl_table_get_data_double_const(catalogue,
"DEC");
923 ref_world = cpl_matrix_new(nobj, 2);
924 for (cpl_size iobj = 0; iobj < nobj; iobj++) {
925 cpl_matrix_set(ref_world, iobj, 0, ra[iobj]);
926 cpl_matrix_set(ref_world, iobj, 1, dec[iobj]);
929 wcs = cpl_wcs_new_from_propertylist(wcs_plist);
931 cpl_wcs_convert(wcs, ref_world, &ref_phys, &conv_status,
933 enu_check_error_code(
"failure calculating predicted positions");
938 if (!cpl_table_has_column(catalogue,
"X_coordinate")) {
939 cpl_table_new_column(catalogue,
"X_coordinate", CPL_TYPE_DOUBLE);
941 if (!cpl_table_has_column(catalogue,
"Y_coordinate")) {
942 cpl_table_new_column(catalogue,
"Y_coordinate", CPL_TYPE_DOUBLE);
945 for (cpl_size iobj = 0; iobj < nobj; iobj++) {
946 cpl_table_set_double(catalogue,
"X_coordinate", iobj,
947 cpl_matrix_get(ref_phys, iobj, 0));
948 cpl_table_set_double(catalogue,
"Y_coordinate", iobj,
949 cpl_matrix_get(ref_phys, iobj, 1));
959 cpl_array_delete(conv_status);
960 cpl_matrix_delete(ref_phys);
961 cpl_matrix_delete(ref_world);
964 return cpl_error_get_code();
986 const hdrl_image * himage,
987 const cpl_image * confidence,
989 hdrl_parameter * params) {
991 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
993 cpl_ensure(himage, CPL_ERROR_NULL_INPUT, NULL);
997 cpl_ensure(wcs, CPL_ERROR_NULL_INPUT, NULL);
998 cpl_ensure(params, CPL_ERROR_NULL_INPUT, NULL);
1000 hdrl_catalogue_result * result = NULL;
1008 cpl_ensure(cpl_image_get_max(confidence) > 0.0, CPL_ERROR_ILLEGAL_INPUT,
1013 confidence, wcs, params);
1031 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1041 const char * message = cpl_error_get_message();
1042 cpl_msg_info(cpl_func,
"catalogue %s", message);
1044 if (strstr(message,
"No objects found in image")) {
1045 cpl_msg_warning(cpl_func,
"No objects found in image");
1066 const double timerange,
1067 const located_imagelist * pool,
1070 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
1072 cpl_ensure(target, CPL_ERROR_NULL_INPUT, NULL);
1073 cpl_ensure(timerange > 0.0, CPL_ERROR_ILLEGAL_INPUT, NULL);
1074 cpl_ensure(pool, CPL_ERROR_NULL_INPUT, NULL);
1076 cpl_vector * result = NULL;
1077 cpl_vector * result_diff = NULL;
1079 double target_mjd = cpl_propertylist_get_double(target->plist,
"MJD-OBS");
1081 for (cpl_size j = 0; j < pool->size; j++) {
1082 double mjd_j = cpl_propertylist_get_double((pool->limages[j])->
1084 double diff = (target_mjd - mjd_j) * 3600.0 * 24.0;
1086 if (fabs(diff) < timerange/2.0) {
1087 if (result == NULL) {
1088 result = cpl_vector_new(1);
1089 result_diff = cpl_vector_new(1);
1090 cpl_vector_set(result, 0, (
double)j);
1091 cpl_vector_set(result_diff, 0, diff);
1093 cpl_size size = cpl_vector_get_size(result);
1094 cpl_vector_set_size(result, size + 1);
1095 cpl_vector_set_size(result_diff, size + 1);
1096 cpl_vector_set(result, size, (
double)j);
1097 cpl_vector_set(result_diff, size, diff);
1101 enu_check_error_code(
"error in enu_bracket_skys: %s",
1102 cpl_error_get_message());
1103 enu_check(result && cpl_vector_get_size(result) > 0,
1104 CPL_ERROR_INCOMPATIBLE_INPUT,
1105 "no sky frames found within %f sec of target frame", timerange/2.0);
1108 cpl_size size = cpl_vector_get_size(result);
1110 cpl_msg_info(
" ",
".. enu_bracket_skys: timerange %5.1f", timerange);
1111 cpl_msg_info(
" ",
".. j# diff(sec)");
1113 for (cpl_size i = 0; i < size; i++) {
1114 int j = cpl_vector_get(result, i);
1115 double diff = cpl_vector_get(result_diff, i);
1116 cpl_msg_info(
" ",
".. %3d %7.1f", j, diff);
1121 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1122 cpl_vector_delete(result);
1125 cpl_vector_delete(result_diff);
1142 hdrl_parameter * params) {
1144 cpl_ensure_code(cpl_error_get_code() == CPL_ERROR_NONE,
1145 cpl_error_get_code());
1146 cpl_ensure_code(limlist, CPL_ERROR_NULL_INPUT);
1147 cpl_ensure_code(params, CPL_ERROR_NULL_INPUT);
1149 cpl_size njitters = limlist->size;
1150 cpl_msg_info(cpl_func,
"cataloguing %d images", (
int) njitters);
1152 for (cpl_size i = 0; i < njitters; i++) {
1153 cpl_wcs * wcs = cpl_wcs_new_from_propertylist
1154 (limlist->limages[i]->plist);
1155 cpl_msg_info(cpl_func,
"cataloguing image %d", (
int) i);
1158 limlist->limages[i]->himage,
1159 limlist->limages[i]->confidence,
1162 cpl_wcs_delete(wcs);
1164 if (cpl_error_get_code() != CPL_ERROR_NONE)
break;
1167 return cpl_error_get_code();
1189 const cpl_propertylist * plist2,
1190 const char * regexp) {
1192 if (cpl_error_get_code() != CPL_ERROR_NONE)
return 0;
1196 cpl_ensure(plist1 && plist2 && regexp, CPL_ERROR_NULL_INPUT, 0);
1198 int result = CPL_TRUE;
1199 char * reason = NULL;
1203 cpl_propertylist * subset1 = cpl_propertylist_new();
1204 cpl_propertylist_copy_property_regexp(subset1, plist1, regexp, 0);
1205 cpl_propertylist * subset2 = cpl_propertylist_new();
1206 cpl_propertylist_copy_property_regexp(subset2, plist2, regexp, 0);
1207 enu_check_error_code(
"error deriving subset of propertylist");
1211 cpl_size size1 = cpl_propertylist_get_size(subset1);
1212 cpl_size size2 = cpl_propertylist_get_size(subset2);
1213 if (size1 != size2) {
1215 reason = cpl_sprintf(
"propertylist sizes do not match %s",
" ");
1217 for (cpl_size i=0; i<size1; i++) {
1218 const cpl_property * prop1 = cpl_propertylist_get(subset1, i);
1219 const char * name = cpl_property_get_name(prop1);
1223 if (!cpl_propertylist_has(subset2, name)) {
1225 reason = cpl_sprintf(
"name mismatch: %s", name);
1231 const cpl_property * prop2 = cpl_propertylist_get_property_const(
1234 const cpl_type type1 = cpl_property_get_type(prop1);
1235 const cpl_type type2 = cpl_property_get_type(prop2);
1236 if (type1 != type2) {
1238 reason = cpl_sprintf(
"type mismatch: name %s: types %s and %s",
1240 cpl_type_get_name(cpl_property_get_type(prop1)),
1241 cpl_type_get_name(cpl_property_get_type(prop2)));
1249 const char * sval1 = NULL;
1250 const char * sval2 = NULL;
1254 ival1 = cpl_property_get_int(prop1);
1255 ival2 = cpl_property_get_int(prop2);
1256 if (ival1 != ival2) {
1258 reason = cpl_sprintf(
"value mismatch: name %s: values "
1260 name, ival1, ival2);
1264 case CPL_TYPE_DOUBLE:
1265 dval1 = cpl_property_get_double(prop1);
1266 dval2 = cpl_property_get_double(prop2);
1267 if (dval1 != dval2) {
1269 reason = cpl_sprintf(
"value mismatch: name %s: values "
1271 name, dval1, dval2);
1275 case CPL_TYPE_STRING:
1276 sval1 = cpl_property_get_string(prop1);
1277 sval2 = cpl_property_get_string(prop2);
1278 if (strcmp(sval1, sval2)) {
1280 reason = cpl_sprintf(
"value mismatch: name %s: values "
1281 "%s, %s", name, sval1, sval2);
1285 cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
1286 "name %s, type not handled %s",
1287 name, cpl_type_get_name(
1288 cpl_property_get_type(prop1)));
1291 if (result == CPL_FALSE)
break;
1298 cpl_propertylist_delete(subset1);
1299 cpl_propertylist_delete(subset2);
1304 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1307 if (result == CPL_FALSE) {
1308 cpl_msg_info(cpl_func,
"propertylist match failed: %s", reason);
1332 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
1333 cpl_ensure_code(limage, CPL_ERROR_NULL_INPUT);
1335 cpl_boolean bad = CPL_FALSE;
1337 if (!cpl_propertylist_has(limage->plist,
"CTYPE1")) {
1341 const char * ctype1 = cpl_propertylist_get_string(
1342 limage->plist,
"CTYPE1");
1343 if (strstr(ctype1,
"PIXEL")) {
1349 if (!cpl_propertylist_has(limage->plist,
"CTYPE2")) {
1354 const char * ctype2 = cpl_propertylist_get_string(limage->plist,
1356 if (strstr(ctype2,
"PIXEL")) {
1361 cpl_error_code result = cpl_error_get_code();
1362 if (result == CPL_ERROR_NONE && bad) {
1363 result = cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
1364 "missing or bad WCS keywords in "
1366 cpl_frame_get_filename(limage->frame));
1389 const located_imagelist * limlist,
1390 const char * nameroot,
1391 const char * recipename,
1392 cpl_frameset * frameset,
1393 const cpl_parameterlist * parlist,
1394 const cpl_frameset * used) {
1396 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
1397 if (!debug)
return CPL_ERROR_NONE;
1398 cpl_ensure_code(limlist, CPL_ERROR_NULL_INPUT);
1399 cpl_ensure_code(nameroot, CPL_ERROR_NULL_INPUT);
1400 cpl_ensure_code(recipename, CPL_ERROR_NULL_INPUT);
1401 cpl_ensure_code(frameset, CPL_ERROR_NULL_INPUT);
1402 cpl_ensure_code(parlist, CPL_ERROR_NULL_INPUT);
1403 cpl_ensure_code(used, CPL_ERROR_NULL_INPUT);
1405 char * fname_copy = NULL;
1406 char * out_fname = NULL;
1410 cpl_size nimages = limlist->size;
1411 for (cpl_size j = 0; j < nimages; j++) {
1415 if (limlist->limages[j]->frame) {
1416 const char * fname = cpl_frame_get_filename(
1417 limlist->limages[j]->frame);
1418 fname_copy = cpl_strdup(fname);
1420 const char * fname =
"debug.fits";
1421 fname_copy = cpl_strdup(fname);
1423 out_fname = cpl_sprintf(
"%s_%s", nameroot, basename(fname_copy));
1425 cpl_msg_info(cpl_func,
"..(debug) writing %s", out_fname);
1429 cpl_propertylist * applist = cpl_propertylist_new();
1430 cpl_propertylist_update_string(applist,
1433 cpl_propertylist_update_string(applist,
"PRODCATG",
"ANCILLARY.IMAGE");
1435 cpl_frameset * provenance = cpl_frameset_new();
1436 cpl_frameset_insert(provenance, cpl_frame_duplicate(
1437 limlist->limages[j]->frame));
1443 limlist->limages[j],
1445 limlist->limages[j]->frame,
1450 cpl_frameset_delete(provenance);
1451 cpl_propertylist_delete(applist);
1456 cpl_free(fname_copy);
1457 cpl_free(out_fname);
1459 return cpl_error_get_code();
1479 const hdrl_image * flat,
1480 const cpl_image * confidence,
1481 const cpl_mask * cold_bpm,
1482 cpl_frameset * frameset,
1483 const cpl_parameterlist * parlist,
1484 const char * filename,
1485 const char * recipe_name,
1486 const cpl_propertylist* qclog) {
1490 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
1491 cpl_ensure_code(pro_catg, CPL_ERROR_NULL_INPUT);
1492 cpl_ensure_code(flat, CPL_ERROR_NULL_INPUT);
1493 cpl_ensure_code(frameset, CPL_ERROR_NULL_INPUT);
1494 cpl_ensure_code(parlist, CPL_ERROR_NULL_INPUT);
1495 cpl_ensure_code(filename, CPL_ERROR_NULL_INPUT);
1497 mef_extension_list * mefs = NULL;
1498 cpl_propertylist * plist = NULL;
1502 plist = cpl_propertylist_new();
1503 cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG, pro_catg);
1504 cpl_propertylist_update_string(plist,
"PRODCATG",
"ANCILLARY.IMAGE");
1509 cpl_propertylist_append_double(plist,
"ESO QC FLAT MED",
1510 (
double) flat_median.data);
1511 cpl_propertylist_set_comment(plist,
"ESO QC FLAT MED",
1512 "[ADU] Median flat value");
1514 cpl_propertylist_append_double(plist,
"ESO QC FLAT MEAN",
1515 (
double) flat_mean.data);
1516 cpl_propertylist_set_comment(plist,
"ESO QC FLAT MEAN",
1517 "[ADU] Mean flat value");
1519 cpl_propertylist_append_double(plist,
"ESO QC FLAT RMS", flat_rms);
1520 cpl_propertylist_set_comment(plist,
"ESO QC FLAT RMS",
1521 "[ADU] RMS flat value");
1525 cpl_msg_warning(cpl_func,
"TBD: calculate normalisation value");
1527 cpl_propertylist_append_double(plist,
"ESO QC FLAT NORM", norm);
1528 cpl_propertylist_set_comment(plist,
"ESO QC FLAT NORM",
1529 "Flat normalisation value");
1531 cpl_size ncold = cpl_mask_count(cold_bpm);
1532 cpl_propertylist_append_double(plist,
"ESO QC NUMBER COLD PIXELS",
1534 cpl_propertylist_set_comment(plist,
"ESO QC NUMBER COLD PIXELS",
1535 "Number of cold pixels");
1537 enu_check_error_code(
"error constructing output propertylist");
1550 cpl_propertylist_append(plist, qclog);
1563 PACKAGE
"/" PACKAGE_VERSION,
1568 cpl_propertylist_delete(plist);
1570 return cpl_error_get_code();
1591 if (cpl_error_get_code() != CPL_ERROR_NONE)
return 0;
1593 double airmass = 0.0;
1594 if (cpl_propertylist_has(plist,
"AIRMASS")) {
1596 airmass = cpl_propertylist_get_double(plist,
"AIRMASS");
1597 }
else if (cpl_propertylist_has(plist,
"ESO TEL AIRM START")) {
1599 const double astart = cpl_propertylist_get_double(plist,
1600 "ESO TEL AIRM START");
1601 const double aend = cpl_propertylist_get_double(plist,
1602 "ESO TEL AIRM END");
1603 airmass = (astart + aend) / 2.0;
1606 const double alt = cpl_propertylist_get_double(plist,
1608 double airmass_alt = 1.0 /cos ((90.0 - alt) * CPL_MATH_PI / 180.0);
1609 if (fabs(airmass - airmass_alt) > 1.0e-5) {
1610 cpl_msg_warning(cpl_func,
"discrepency - airmass %f -> %f", airmass,
1612 airmass = airmass_alt;
1615 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
1616 "unable to find airmass information");
1645 const cpl_parameterlist * parlist,
1646 const cpl_propertylist * plist,
1647 double * obj_core_radius,
1648 int * bkg_mesh_size) {
1650 char * param_name = NULL;
1651 const cpl_parameter * p = NULL;
1652 cpl_parameter * par = NULL;
1654 cpl_error_code error_code = CPL_ERROR_NONE;
1656 if (cpl_error_get_code() != CPL_ERROR_NONE)
return CPL_ERROR_NONE;
1657 cpl_ensure_code(context, CPL_ERROR_NULL_INPUT);
1658 cpl_ensure_code(parlist, CPL_ERROR_NULL_INPUT);
1659 cpl_ensure_code(plist, CPL_ERROR_NULL_INPUT);
1660 cpl_ensure_code(obj_core_radius, CPL_ERROR_NULL_INPUT);
1661 cpl_ensure_code(bkg_mesh_size, CPL_ERROR_NULL_INPUT);
1663 *obj_core_radius = -1.0;
1664 *bkg_mesh_size = -1;
1669 param_name = cpl_sprintf(
"%s.catalogue.ao-params", context);
1670 cpl_msg_info(cpl_func,
"%s", param_name);
1671 p = cpl_parameterlist_find_const(parlist, param_name);
1672 const char * ao_params = cpl_parameter_get_string(p);
1673 cpl_free(param_name);
1674 enu_check_error_code(
"failed to read ao-params");
1676 if (!strcmp(ao_params,
"auto") &&
1677 cpl_propertylist_has(plist,
"ESO OBS AOMODE")) {
1678 const char * aomode = cpl_propertylist_get_string(plist,
1680 cpl_msg_info(cpl_func,
"AOMODE: %s", aomode);
1682 if (!strcmp(aomode,
"FULL_AO")) {
1683 *obj_core_radius = 10.0;
1684 *bkg_mesh_size = 64;
1685 if(!strstr(context,
"skysub")) {
1687 param_name = cpl_sprintf(
"%s.catalogue.obj.core-radius", context);
1688 par = (cpl_parameter*) cpl_parameterlist_find_const(parlist, param_name);
1689 cpl_parameter_set_double(par, *obj_core_radius);
1690 cpl_free(param_name);
1694 param_name = cpl_sprintf(
"%s.catalogue.bkg.mesh-size", context);
1695 par = (cpl_parameter*) cpl_parameterlist_find_const(parlist, param_name);
1696 cpl_parameter_set_int(par, *bkg_mesh_size);
1697 cpl_free(param_name);
1699 }
else if (!strcmp(aomode,
"NO_AO")) {
1700 *obj_core_radius = 25.0;
1701 *bkg_mesh_size = 128;
1702 if(!strstr(context,
"skysub")) {
1704 param_name = cpl_sprintf(
"%s.catalogue.obj.core-radius", context);
1705 par = (cpl_parameter*) cpl_parameterlist_find_const(parlist, param_name);
1706 cpl_parameter_set_double(par, *obj_core_radius);
1707 cpl_free(param_name);
1710 param_name = cpl_sprintf(
"%s.catalogue.bkg.mesh-size", context);
1711 par = (cpl_parameter*) cpl_parameterlist_find_const(parlist, param_name);
1712 cpl_parameter_set_int(par, *bkg_mesh_size);
1713 cpl_free(param_name);
1715 error_code = CPL_ERROR_DATA_NOT_FOUND;
1719 if(!strstr(context,
"skysub")) {
1720 param_name = cpl_sprintf(
"%s.catalogue.obj.core-radius", context);
1721 p = cpl_parameterlist_find_const(parlist, param_name);
1722 *obj_core_radius = cpl_parameter_get_double(p);
1723 cpl_free(param_name);
1726 param_name = cpl_sprintf(
"%s.catalogue.bkg.mesh-size", context);
1727 p = cpl_parameterlist_find_const(parlist, param_name);
1728 *bkg_mesh_size = cpl_parameter_get_int(p);
1729 cpl_free(param_name);
1731 cpl_msg_info(cpl_func,
"catalogue AO-related params: %s %f %d",
1732 ao_params, *obj_core_radius, *bkg_mesh_size);
1753 if (cpl_error_get_code() != CPL_ERROR_NONE)
return 0;
1755 double tel_alt = 0.0;
1756 if (cpl_propertylist_has(plist,
"ESO TEL ALT")) {
1758 tel_alt = cpl_propertylist_get_double(plist,
"ESO TEL ALT");
1760 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
1761 "unable to find ESO TEL ALT information");
1783 if (cpl_error_get_code() != CPL_ERROR_NONE)
return 0;
1786 if (cpl_propertylist_has(plist,
"ESO DET DIT")) {
1787 dit = cpl_propertylist_get_double(plist,
"ESO DET DIT");
1788 }
else if (cpl_propertylist_has(plist,
"ESO DET SEQ1 DIT")) {
1789 dit = cpl_propertylist_get_double(plist,
"ESO DET SEQ1 DIT");
1791 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
1792 "no keyword ESO.DET.DIT or ESO.DET.SEQ1.DIT");
1814 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
1816 const char * result = NULL;
1817 if (cpl_propertylist_has(plist,
"ESO DET NCORRS NAME")) {
1818 result = cpl_propertylist_get_string(plist,
"ESO DET NCORRS NAME");
1819 }
else if (cpl_propertylist_has(plist,
"ESO DET READ CURNAME")) {
1820 result = cpl_propertylist_get_string(plist,
"ESO DET READ CURNAME");
1822 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
1823 "no keyword ESO.DET.NCORRS.NAME or "
1824 "ESO.DET.READ.CURNAME");
1850 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
1851 cpl_ensure(plist, CPL_ERROR_NULL_INPUT, NULL);
1853 const char * filter = NULL;
1855 if (cpl_propertylist_has(plist,
"FILTER")) {
1856 filter = cpl_propertylist_get_string(plist,
"FILTER");
1857 }
else if (cpl_propertylist_has(plist,
"INSTRUME")) {
1858 const char * instrume = cpl_propertylist_get_string(plist,
"INSTRUME");
1860 if (!strcmp(instrume,
"NAOS+CONICA")) {
1861 filter = cpl_propertylist_get_string(plist,
"ESO INS OPTI4 NAME");
1862 cpl_msg_info(cpl_func,
"OPTI4 %s", filter);
1863 if (!strcmp(filter,
"clear") || !strcmp(filter,
"empty")) {
1864 filter = cpl_propertylist_get_string(plist,
"ESO INS OPTI5 NAME");
1865 cpl_msg_info(cpl_func,
"OPTI5 %s", filter);
1867 if (!strcmp(filter,
"clear") || !strcmp(filter,
"empty")) {
1868 filter = cpl_propertylist_get_string(plist,
"ESO INS OPTI6 NAME");
1869 cpl_msg_info(cpl_func,
"OPTI6 %s", filter);
1871 }
else if (!strcmp(instrume,
"ERIS")) {
1872 filter = cpl_propertylist_get_string(plist,
"ESO INS2 NXFW NAME");
1874 cpl_error_set(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT);
1901 if (cpl_error_get_code() != CPL_ERROR_NONE)
return -1.0;
1902 cpl_ensure(filter, CPL_ERROR_NULL_INPUT, -1.0);
1904 double lambda = 1.0;
1905 if (!strcmp(filter,
"J")) {
1907 }
else if (!strcmp(filter,
"H")) {
1909 }
else if (!strcmp(filter,
"Ks")) {
1911 }
else if (!strcmp(filter,
"Short-Lp")) {
1913 }
else if (!strcmp(filter,
"L-Broad")) {
1915 }
else if (!strcmp(filter,
"Lp")) {
1917 }
else if (!strcmp(filter,
"Mp")) {
1919 }
else if (!strcmp(filter,
"Pa-b")) {
1921 }
else if (!strcmp(filter,
"Fe-II")) {
1923 }
else if (!strcmp(filter,
"H2-cont")) {
1925 }
else if (!strcmp(filter,
"H2-1-0S")) {
1927 }
else if (!strcmp(filter,
"Br-g")) {
1929 }
else if (!strcmp(filter,
"K-peak")) {
1931 }
else if (!strcmp(filter,
"IB-2.42")) {
1933 }
else if (!strcmp(filter,
"IB-2.48")) {
1935 }
else if (!strcmp(filter,
"Br-a-cont")) {
1937 }
else if (!strcmp(filter,
"Br-a")) {
1940 cpl_msg_warning(cpl_func,
"filter %s not recognized", filter);
1958 const char * eris_nix_license =
1959 "This file is part of the ERIS/NIX Instrument Pipeline\n"
1960 "Copyright (C) 2017 European Southern Observatory\n"
1962 "This program is free software; you can redistribute it and/or modify\n"
1963 "it under the terms of the GNU General Public License as published by\n"
1964 "the Free Software Foundation; either version 2 of the License, or\n"
1965 "(at your option) any later version.\n"
1967 "This program is distributed in the hope that it will be useful,\n"
1968 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1969 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1970 "GNU General Public License for more details.\n"
1972 "You should have received a copy of the GNU General Public License\n"
1973 "along with this program; if not, write to the Free Software\n"
1974 "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, \n"
1975 "MA 02110-1301 USA";
1976 return eris_nix_license;
1991 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
1992 cpl_ensure(wcs, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
1993 cpl_ensure(ra, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
1994 cpl_ensure(dec, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
1998 const cpl_array * dims = cpl_wcs_get_image_dims(wcs);
1999 cpl_matrix * from = cpl_matrix_new(1, 2);
2001 double dim = cpl_array_get(dims, 0, &ignore);
2002 cpl_matrix_set(from, 0, 0, dim / 2.0);
2003 dim = cpl_array_get(dims, 1, &ignore);
2004 cpl_matrix_set(from, 0, 1, dim / 2.0);
2008 cpl_matrix * to = NULL;
2009 cpl_array * status = NULL;
2010 cpl_wcs_convert(wcs, from, &to, &status, CPL_WCS_PHYS2WORLD);
2012 *ra = cpl_matrix_get(to, 0, 0);
2013 *dec = cpl_matrix_get(to, 0, 1);
2017 cpl_matrix_delete(from);
2018 cpl_matrix_delete(to);
2019 cpl_array_delete(status);
2021 return cpl_error_get_code();
2045 cpl_size * strx, cpl_size * stry,
2046 cpl_size * nx_chip, cpl_size * ny_chip,
2047 cpl_boolean * windowed,
2048 const cpl_propertylist * plist) {
2050 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
2052 cpl_ensure_code(plist, CPL_ERROR_NULL_INPUT);
2053 enu_check(cpl_propertylist_has(plist,
"INSTRUME") == 1,
2054 CPL_ERROR_DATA_NOT_FOUND,
2055 "propertylist does not contain INSTRUME keyword");
2059 const char * instrume = cpl_propertylist_get_string(plist,
"INSTRUME");
2067 if (!strcmp(instrume,
"ERIS")) {
2068 nxw = cpl_propertylist_get_int(plist,
"ESO DET SEQ1 WIN NX");
2069 nyw = cpl_propertylist_get_int(plist,
"ESO DET SEQ1 WIN NY");
2070 rotw = cpl_propertylist_get_int(plist,
"ESO DET SEQ1 WIN ROT");
2071 strxw = cpl_propertylist_get_int(plist,
"ESO DET SEQ1 WIN STRX");
2072 stryw = cpl_propertylist_get_int(plist,
"ESO DET SEQ1 WIN STRY");
2076 nxw = cpl_propertylist_get_int(plist,
"ESO DET WIN NX");
2077 nyw = cpl_propertylist_get_int(plist,
"ESO DET WIN NY");
2078 if (cpl_propertylist_get_type(plist,
"ESO DET WIN STARTX") ==
2080 strxw = (int) cpl_propertylist_get_double(plist,
2081 "ESO DET WIN STARTX");
2082 stryw = (int) cpl_propertylist_get_double(plist,
2083 "ESO DET WIN STARTY");
2085 strxw = cpl_propertylist_get_int(plist,
"ESO DET WIN STARTX");
2086 stryw = cpl_propertylist_get_int(plist,
"ESO DET WIN STARTY");
2090 cpl_size nx_chipw = 2048;
2091 cpl_size ny_chipw = 2048;
2093 if(cpl_propertylist_has(plist,
"ESO DET CHIP NX")) {
2094 nx_chipw = cpl_propertylist_get_int(plist,
"ESO DET CHIP NX");
2096 nx_chipw = cpl_propertylist_get_int(plist,
"ESO DET CHIP1 NX");
2099 if(cpl_propertylist_has(plist,
"ESO DET CHIP NY")) {
2100 ny_chipw = cpl_propertylist_get_int(plist,
"ESO DET CHIP NY");
2102 ny_chipw = cpl_propertylist_get_int(plist,
"ESO DET CHIP1 NY");
2105 enu_check_error_code(
"failed to read detector mode information");
2106 enu_check(rotw == 0, CPL_ERROR_UNSUPPORTED_MODE,
2107 "detector window rot must be 0");
2109 cpl_boolean windowedw = (rotw != 0) ||
2112 (nxw != nx_chipw) ||
2114 cpl_msg_info(cpl_func,
"flatfield rot=%d strx=%d stry=%d nx=%d ny=%d",
2115 (
int)rotw, (
int)strxw, (
int)stryw, (
int)nxw, (
int)nyw);
2125 *nx_chip = nx_chipw;
2126 *ny_chip = ny_chipw;
2127 *windowed = windowedw;
2130 return cpl_error_get_code();
2142 const hdrl_catalogue_result * target) {
2143 cpl_ensure(target, CPL_ERROR_NULL_INPUT, NULL);
2145 hdrl_catalogue_result * result = cpl_malloc(
sizeof(hdrl_catalogue_result));
2147 result->catalogue = cpl_table_duplicate(target->catalogue);
2148 result->background = cpl_image_duplicate(target->background);
2149 result->segmentation_map = cpl_image_duplicate(target->segmentation_map);
2150 result->qclist = cpl_propertylist_duplicate(target->qclist);
2170 hdrl_image ** result,
2171 mef_extension_list ** mef_extensions,
2172 cpl_propertylist ** plist) {
2174 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
2176 cpl_propertylist * plist1 = NULL;
2177 cpl_propertylist * plist2 = NULL;
2178 cpl_propertylist * plist3 = NULL;
2179 cpl_image * data = NULL;
2180 cpl_image * error = NULL;
2181 cpl_mask * bpm = NULL;
2182 cpl_mask * old_bpm = NULL;
2186 cpl_ensure_code(filename, CPL_ERROR_NULL_INPUT);
2190 cpl_size size = cpl_fits_count_extensions(filename);
2191 cpl_ensure_code(size >= 3, CPL_ERROR_BAD_FILE_FORMAT);
2195 *plist = cpl_propertylist_load(filename, 0);
2196 enu_check_error_code(
"accessing HDU 0 header");
2200 plist1 = cpl_propertylist_load(filename, 1);
2201 enu_check_error_code(
"accessing HDU 1 header");
2203 const char * extname = cpl_propertylist_get_string(plist1,
"EXTNAME");
2204 const char * hduclass = cpl_propertylist_get_string(plist1,
"HDUCLASS");
2205 const char * hdudoc = cpl_propertylist_get_string(plist1,
"HDUDOC");
2207 const char * hduclas1 = cpl_propertylist_get_string(plist1,
"HDUCLAS1");
2208 const char * hduclas2 = cpl_propertylist_get_string(plist1,
"HDUCLAS2");
2209 enu_check_error_code(
"accessing HDU 1 propertylist");
2210 enu_check(strstr(extname,
"DATA") != NULL &&
2211 strstr(hduclass,
"ESO") != NULL &&
2212 strstr(hdudoc,
"SDP") != NULL &&
2213 strstr(hduclas1,
"IMAGE") != NULL &&
2214 strstr(hduclas2,
"DATA") != NULL,
2215 CPL_ERROR_BAD_FILE_FORMAT,
"bad HD1 format");
2216 data = cpl_image_load(filename, HDRL_TYPE_DATA, 0, 1);
2217 enu_check_error_code(
"accessing HDU 1 data");
2224 const char * wcs_items =
"NAXIS WCSAXES CRPIX1 CRPIX2 "
2225 "CD1_1 CD1_2 CD2_1 CD2_2 CUNIT1 CUNIT2 "
2226 "CTYPE1 CTYPE2 CRVAL1 CRVAL2 LONPOLE "
2227 "LATPOLE CSYER1 CSYER2 EQUINOX MJD-OBS "
2228 "DATE-OBS NAXIS2 NAXIS1";
2229 cpl_size plist1_size = cpl_propertylist_get_size(plist1);
2230 for (cpl_size ip=plist1_size; ip>0; ip--) {
2231 const cpl_property * newprop = cpl_propertylist_get_const(plist1, ip-1);
2232 const char * name = cpl_property_get_name(newprop);
2233 if (strstr(wcs_items, name) != NULL) {
2234 if (cpl_propertylist_has(*plist, name)) {
2235 cpl_propertylist_copy_property(*plist, plist1, name);
2237 cpl_propertylist_insert_after_property(*plist,
"NAXIS",
2245 plist2 = cpl_propertylist_load(filename, 2);
2246 enu_check_error_code(
"accessing HDU 2");
2247 extname = cpl_propertylist_get_string(plist2,
"EXTNAME");
2248 hduclass = cpl_propertylist_get_string(plist2,
"HDUCLASS");
2249 hdudoc = cpl_propertylist_get_string(plist2,
"HDUDOC");
2251 hduclas1 = cpl_propertylist_get_string(plist2,
"HDUCLAS1");
2252 hduclas2 = cpl_propertylist_get_string(plist2,
"HDUCLAS2");
2253 enu_check_error_code(
"accessing HDU 2 propertylist");
2254 enu_check(strstr(extname,
"ERR") != NULL &&
2255 strstr(hduclass,
"ESO") != NULL &&
2256 strstr(hdudoc,
"SDP") != NULL &&
2257 strstr(hduclas1,
"IMAGE") != NULL &&
2258 strstr(hduclas2,
"ERROR") != NULL,
2259 CPL_ERROR_BAD_FILE_FORMAT,
"bad HD2 format");
2260 error = cpl_image_load(filename, HDRL_TYPE_ERROR, 0, 2);
2261 enu_check_error_code(
"accessing HDU 1 data error");
2265 plist3 = cpl_propertylist_load(filename, 3);
2266 enu_check_error_code(
"accessing HDU 3");
2267 extname = cpl_propertylist_get_string(plist3,
"EXTNAME");
2268 hduclass = cpl_propertylist_get_string(plist3,
"HDUCLASS");
2269 hdudoc = cpl_propertylist_get_string(plist3,
"HDUDOC");
2271 hduclas1 = cpl_propertylist_get_string(plist3,
"HDUCLAS1");
2272 hduclas2 = cpl_propertylist_get_string(plist3,
"HDUCLAS2");
2273 enu_check_error_code(
"accessing HDU 3 propertylist");
2274 enu_check(strstr(extname,
"DQ") != NULL &&
2275 strstr(hduclass,
"ESO") != NULL &&
2276 strstr(hdudoc,
"SDP") != NULL &&
2277 strstr(hduclas1,
"IMAGE") != NULL &&
2278 strstr(hduclas2,
"QUALITY") != NULL,
2279 CPL_ERROR_BAD_FILE_FORMAT,
"bad HD3 format");
2283 bpm = cpl_mask_load(filename, 0, 3);
2284 enu_check_error_code(
"accessing HDU 3 data mask");
2285 old_bpm = cpl_image_set_bpm(data, bpm);
2286 cpl_mask_delete(old_bpm); old_bpm = NULL;
2291 int n_ext = size - 3;
2293 for (
int ext=0; ext<n_ext; ext++) {
2297 cpl_propertylist * ext_plist = cpl_propertylist_load(filename, ext+4);
2298 const char * name = cpl_propertylist_get_string(ext_plist,
"EXTNAME");
2299 const char * mef_type = cpl_propertylist_get_string(ext_plist,
2300 "ERIS_NIX_MEF_TYPE");
2304 if (!strcmp(mef_type, MEF_EXTENSION_CONTAINING_MASK)) {
2305 cpl_mask * mask = cpl_mask_load(filename, 0, ext+4);
2307 (*mef_extensions)->mef[ext] =
new;
2308 cpl_mask_delete(mask);
2309 }
else if (!strcmp(mef_type, MEF_EXTENSION_CONTAINING_IMAGE)) {
2310 cpl_image * image = cpl_image_load(filename, HDRL_TYPE_DATA, 0,
2313 (*mef_extensions)->mef[ext] =
new;
2314 cpl_image_delete(image);
2315 }
else if (!strcmp(mef_type, MEF_EXTENSION_CONTAINING_TABLE)) {
2316 cpl_table * table = cpl_table_load(filename, ext+4, 0);
2318 (*mef_extensions)->mef[ext] =
new;
2319 cpl_table_delete(table);
2321 cpl_error_set_message(
"enu_himage_load_from_fits",
2322 CPL_ERROR_UNSUPPORTED_MODE,
2323 "unsupported extension name: %s", name);
2326 cpl_propertylist_delete(ext_plist);
2330 cpl_propertylist_delete(plist1);
2331 cpl_propertylist_delete(plist2);
2332 cpl_propertylist_delete(plist3);
2333 cpl_image_delete(data);
2334 cpl_image_delete(error);
2335 cpl_mask_delete(old_bpm);
2336 if (cpl_error_get_code() != CPL_ERROR_NONE) {
2337 cpl_propertylist_delete(*plist);
2342 *mef_extensions = NULL;
2345 return cpl_error_get_code();
2367 cpl_image ** pcopyconf,
2368 const cpl_boolean collapse_cube) {
2370 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
2372 cpl_ensure(frame, CPL_ERROR_NULL_INPUT, NULL);
2373 cpl_ensure(cpl_frame_get_filename(frame), CPL_ERROR_NULL_INPUT, NULL);
2375 located_image * result = NULL;
2376 mef_extension_list * mefs = NULL;
2377 cpl_image * data = NULL;
2378 cpl_image * err = NULL;
2379 cpl_image * qual = NULL;
2380 cpl_image * conf = NULL;
2381 cpl_image * bkg = NULL;
2382 cpl_image * bkg_err = NULL;
2383 cpl_image * bkg_conf = NULL;
2385 const char * filename = cpl_frame_get_filename(frame);
2386 cpl_msg_info(cpl_func,
"..reading %s", filename);
2392 cpl_size next = cpl_fits_count_extensions(filename);
2394 cpl_propertylist * plist = cpl_propertylist_load(filename, 0);
2397 const char * instrume = cpl_propertylist_get_string(plist,
"INSTRUME");
2398 const cpl_boolean eris = !strcmp(instrume,
"ERIS");
2400 char * first_ext = NULL;
2401 if (eris && (next > 0)) {
2402 cpl_propertylist * plist1 = cpl_propertylist_load(filename, 1);
2403 if (cpl_propertylist_has(plist1,
"EXTNAME")) {
2404 first_ext = cpl_sprintf(
"%s", cpl_propertylist_get_string(plist1,
"EXTNAME"));
2406 cpl_propertylist_delete(plist1);
2410 char * frame_format = NULL;
2411 if (cpl_propertylist_has(plist,
"ESO DET FRAM FORMAT")) {
2412 frame_format = cpl_sprintf(
"%s", cpl_propertylist_get_string(plist,
"ESO DET FRAM FORMAT"));
2413 cpl_msg_info(cpl_func,
"..format %s", frame_format);
2419 cpl_msg_info(cpl_func,
"NACO data");
2424 data = cpl_image_load(filename, HDRL_TYPE_DATA, 0, 0);
2425 enu_check_error_code(
"failed to read file: %s", filename);
2427 cpl_image_delete(data); data = NULL;
2433 cpl_image * confidence;
2434 if (pcopyconf != NULL && *pcopyconf != NULL &&
2435 cpl_image_get_size_x(*pcopyconf) == nx &&
2436 cpl_image_get_size_y(*pcopyconf) == ny) {
2437 confidence = *pcopyconf;
2440 confidence = cpl_image_new(nx, ny, HDRL_TYPE_DATA);
2441 cpl_image_fill_window(confidence, 1, 1, nx, ny, 100.0);
2444 cpl_frame_dump(frame, NULL);
2455 cpl_frame_duplicate(frame));
2458 }
else if ((next == 0) ||
2461 !strcmp(first_ext,
"ASM_DATA"))) {
2468 cpl_table * asm_table = cpl_table_load(filename, 1, CPL_TRUE);
2469 cpl_size nrow = cpl_table_get_nrow(asm_table);
2470 if(cpl_table_has_column(asm_table,
"IA_FWHM")) {
2471 double * ia_fwhm_data = cpl_table_get_data_double(asm_table,
2473 cpl_vector * ia_fwhm = cpl_vector_wrap(nrow, ia_fwhm_data);
2474 double ia_fwhm_mean = cpl_vector_get_mean(ia_fwhm);
2482 double ia_fwhm_corr = ia_fwhm_mean * pow(0.5/lambda, 1./5.);
2484 cpl_propertylist_update_double(plist,
"PSF_FWHM", ia_fwhm_corr);
2485 cpl_propertylist_set_comment(plist,
"PSF_FWHM",
"PSF fwhm derived "
2486 "from AO ASM table [arcsec]");
2488 cpl_vector_unwrap(ia_fwhm);
2490 cpl_msg_warning(cpl_func,
"ASM table miss IA_FWHM column. PSF_FWHM not computed");
2492 cpl_table_delete(asm_table);
2499 if (cpl_propertylist_has(plist,
"ESO TEL AMBI FWHM START") &&
2500 cpl_propertylist_has(plist,
"ESO TEL AMBI FWHM END") &&
2501 cpl_propertylist_has(plist,
"ESO TEL AIRM START") &&
2502 cpl_propertylist_has(plist,
"ESO TEL AIRM END")) {
2504 double dimm1 = cpl_propertylist_get_double(plist,
2505 "ESO TEL AMBI FWHM START");
2506 double dimm2 = cpl_propertylist_get_double(plist,
2507 "ESO TEL AMBI FWHM END");
2508 double airmass1 = cpl_propertylist_get_double(plist,
2509 "ESO TEL AIRM START");
2510 double airmass2 = cpl_propertylist_get_double(plist,
2511 "ESO TEL AIRM END");
2519 pow(0.5/lambda, 1./5.) *
2520 pow(airmass1, 3./5.) *
2522 (pow(lambda/1.e6, 2./5.) *
2523 pow(airmass1, -1./5.) /
2528 pow(0.5/lambda, 1./5.) *
2529 pow(airmass2, 3./5.) *
2531 (pow(lambda/1.e6, 2./5.) *
2532 pow(airmass2, -1./5.) /
2537 cpl_propertylist_update_double(plist,
"PSF_FWHM",
2538 (dimm1 + dimm2) / 2.0);
2539 cpl_propertylist_set_comment(plist,
"PSF_FWHM",
2541 "from DIMM [arcsec]");
2545 if (!strcmp(frame_format,
"single")) {
2549 data = cpl_image_load(filename, HDRL_TYPE_DATA, 0, 0);
2550 enu_check_error_code(
"failed to read file: %s", filename);
2552 cpl_image_delete(data); data = NULL;
2558 cpl_image * confidence;
2559 if (pcopyconf != NULL && *pcopyconf != NULL &&
2560 cpl_image_get_size_x(*pcopyconf) == nx &&
2561 cpl_image_get_size_y(*pcopyconf) == ny) {
2562 confidence = *pcopyconf;
2565 confidence = cpl_image_new(nx, ny, HDRL_TYPE_DATA);
2566 cpl_image_fill_window(confidence, 1, 1, nx, ny, 100.0);
2579 cpl_frame_duplicate(frame));
2582 }
else if (!strcmp(frame_format,
"cube")) {
2586 cpl_imagelist * datalist = cpl_imagelist_load(filename,
2588 enu_check_error_code(
"failed to read file: %s", filename);
2591 cpl_imagelist_delete(datalist); datalist = NULL;
2597 cpl_image * confidence;
2598 if (pcopyconf != NULL && *pcopyconf != NULL &&
2599 cpl_image_get_size_x(*pcopyconf) == nx &&
2600 cpl_image_get_size_y(*pcopyconf) == ny) {
2601 confidence = *pcopyconf;
2604 confidence = cpl_image_new(nx, ny, HDRL_TYPE_DATA);
2605 cpl_image_fill_window(confidence, 1, 1, nx, ny, 100.0);
2609 hdrl_image * himage = NULL;
2610 cpl_image* conf_ima = NULL;
2611 if(collapse_cube == 1) {
2613 }
else if(collapse_cube == 2) {
2615 }
else if(collapse_cube == 3) {
2618 cpl_image_delete(conf_ima);
2629 cpl_frame_duplicate(frame));
2641 cpl_frame_duplicate(frame));
2649 cpl_propertylist_delete(plist);
2652 enu_check_error_code(
"Unable to load components for file");
2656 const char * hduclass = cpl_propertylist_get_string(
2657 mefs->mef[0]->plist,
"HDUCLASS");
2658 const char * hdudoc = cpl_propertylist_get_string(
2659 mefs->mef[0]->plist,
"HDUDOC");
2660 const char * hduvers = cpl_propertylist_get_string(
2661 mefs->mef[0]->plist,
"HDUVERS");
2662 enu_check_error_code(
"Unable to read ESO DPS keywords from header");
2664 enu_check(strstr(hduclass,
"ESO") != NULL &&
2665 strstr(hdudoc,
"SDP") != NULL &&
2666 strstr(hduvers,
"SDP version") != NULL,
2667 CPL_ERROR_BAD_FILE_FORMAT,
"file not in ESO DPS format");
2672 const char * scidata = NULL;
2673 if (mefs->size > 0 &&
2674 cpl_propertylist_has(mefs->mef[1]->plist,
"SCIDATA")){
2675 scidata = cpl_propertylist_get_string(mefs->mef[1]->plist,
2678 const char * errdata = NULL;
2679 if (cpl_propertylist_has(mefs->mef[0]->plist,
"ERRDATA")){
2680 errdata = cpl_propertylist_get_string(mefs->mef[0]->plist,
2683 const char * qualdata = NULL;
2684 if (cpl_propertylist_has(mefs->mef[0]->plist,
"QUALDATA")){
2685 qualdata = cpl_propertylist_get_string(mefs->mef[0]->plist,
2688 const char * confdata = NULL;
2689 if (cpl_propertylist_has(mefs->mef[0]->plist,
"CONFDATA")){
2690 confdata = cpl_propertylist_get_string(mefs->mef[0]->plist,
2693 const char * bkgdata = NULL;
2694 if (cpl_propertylist_has(mefs->mef[0]->plist,
"BKGDATA")){
2695 bkgdata = cpl_propertylist_get_string(mefs->mef[0]->plist,
2698 const char * bkgerr = NULL;
2699 if (cpl_propertylist_has(mefs->mef[0]->plist,
"BKGERR")){
2700 bkgerr = cpl_propertylist_get_string(mefs->mef[0]->plist,
2703 const char * bkgconf = NULL;
2704 if (cpl_propertylist_has(mefs->mef[0]->plist,
"BKGCONF")){
2705 bkgconf = cpl_propertylist_get_string(mefs->mef[0]->plist,
2708 enu_check_error_code(
"accessing DPS standard extensions");
2712 for (cpl_size i=0; i<next; i++) {
2713 const char * extname = cpl_propertylist_get_string(
2714 mefs->mef[i]->plist,
"EXTNAME");
2719 if (scidata && !strcmp(scidata, extname)) {
2722 enu_check_error_code(
"accessing SCIDATA extension");
2727 cpl_propertylist * primary_plist = plist;
2734 plist = cpl_propertylist_duplicate(mefs->mef[i]->plist);
2735 const char * sdp7_items =
" EXTNAME HDUCLAS1 HDUCLAS2"
2737 cpl_size psize = cpl_propertylist_get_size(plist);
2738 for (cpl_size ip = psize; ip > 0; ip--) {
2739 const cpl_property * prop = cpl_propertylist_get_const(
2741 const char * name = cpl_property_get_name(prop);
2747 char * padded_name = cpl_sprintf(
" %s ", name);
2748 if (strstr(sdp7_items, padded_name) != NULL) {
2749 cpl_propertylist_erase(plist, name);
2751 cpl_free(padded_name);
2756 psize = cpl_propertylist_get_size(primary_plist);
2757 for (cpl_size ip = psize; ip > 0; ip--) {
2758 const cpl_property * prop = cpl_propertylist_get_const(
2759 primary_plist, ip-1);
2760 const char * name = cpl_property_get_name(prop);
2761 if (!cpl_propertylist_has(plist, name)) {
2762 cpl_propertylist_copy_property(plist, primary_plist,
2766 cpl_propertylist_delete(primary_plist);
2768 }
else if (errdata && !strcmp(errdata, extname)) {
2771 enu_check_error_code(
"accessing SCIERR extension");
2772 }
else if (qualdata && !strcmp(qualdata, extname)) {
2774 "IMAGE",
"QUALITY");
2775 enu_check_error_code(
"accessing QUALDATA extension");
2776 }
else if (confdata && !strcmp(confdata, extname)) {
2779 enu_check_error_code(
"accessing CONFDATA extension");
2780 }
else if (bkgdata && !strcmp(bkgdata, extname)) {
2782 "IMAGE",
"BKG_DATA");
2783 enu_check_error_code(
"accessing BKGDATA extension");
2784 }
else if (bkgerr && !strcmp(bkgerr, extname)) {
2786 "IMAGE",
"BKG_ERR");
2787 enu_check_error_code(
"accessing BKGERR extension");
2788 }
else if (bkgconf && !strcmp(bkgconf, extname)) {
2790 "IMAGE",
"BKG_CONF");
2791 enu_check_error_code(
"accessing BKGCONF extension");
2797 enu_check(data != NULL, CPL_ERROR_BAD_FILE_FORMAT,
"no data in file");
2798 cpl_mask * bpm = cpl_image_get_bpm(data);
2799 cpl_mask_threshold_image(bpm, qual, 0.9, 1.1, CPL_BINARY_1);
2800 bpm = cpl_image_get_bpm(err);
2801 cpl_mask_threshold_image(bpm, qual, 0.9, 1.1, CPL_BINARY_1);
2803 hdrl_image * hbkg = NULL;
2818 cpl_frame_duplicate(frame));
2821 cpl_image_delete(data);
2822 cpl_image_delete(err);
2823 cpl_image_delete(qual);
2824 cpl_image_delete(bkg);
2825 cpl_image_delete(bkg_err);
2836 cpl_free(frame_format);
2837 cpl_free(first_ext);
2838 cpl_propertylist_delete(plist);
2839 cpl_image_delete(data);
2840 cpl_image_delete(err);
2841 cpl_image_delete(qual);
2842 cpl_image_delete(conf);
2843 cpl_image_delete(bkg);
2844 cpl_image_delete(bkg_err);
2845 cpl_image_delete(bkg_conf);
2847 if (cpl_error_get_code() != CPL_ERROR_NONE) {
2868 cpl_propertylist ** plist) {
2870 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
2872 cpl_ensure(filename, CPL_ERROR_NULL_INPUT, NULL);
2877 cpl_size next = cpl_fits_count_extensions(filename);
2879 mef_extension *
new = NULL;
2880 cpl_propertylist * eplist = NULL;
2884 *plist = cpl_propertylist_load(filename, 0);
2885 enu_check_error_code(
"accessing HDU 0 header");
2889 for (
int i=0; i<next; i++) {
2894 cpl_propertylist_delete(eplist);
2895 eplist = cpl_propertylist_load(filename, hdu);
2896 const char * name = cpl_propertylist_get_string(eplist,
"EXTNAME");
2897 const char * hduclas1 = cpl_propertylist_get_string(eplist,
2899 enu_check_error_code(
"error accessing keywords in HDU %d", hdu);
2903 if (!strcmp(hduclas1, MEF_EXTENSION_CONTAINING_MASK)) {
2904 cpl_mask * mask = cpl_mask_load(filename, 0, hdu);
2906 cpl_mask_delete(mask);
2907 }
else if (!strcmp(hduclas1,
"IMAGE")) {
2908 cpl_image * image = cpl_image_load(filename, HDRL_TYPE_DATA, 0, hdu);
2910 cpl_image_delete(image);
2911 }
else if (!strcmp(hduclas1, MEF_EXTENSION_CONTAINING_TABLE)) {
2912 cpl_table * table = cpl_table_load(filename, hdu, 0);
2914 cpl_table_delete(table);
2916 cpl_error_set_message(
"enu_load_mef_components",
2917 CPL_ERROR_UNSUPPORTED_MODE,
2918 "extension has unsupported HDUCLAS1: %s %s", name, hduclas1);
2920 enu_check_error_code(
"error accessing HDU %d", hdu);
2922 result->mef[i] =
new;
2928 cpl_propertylist_delete(eplist);
2929 if (cpl_error_get_code() != CPL_ERROR_NONE) {
2932 cpl_propertylist_delete(*plist);
2954 cpl_image_delete(limage->confidence);
2956 cpl_image_delete(limage->bkg_confidence);
2957 cpl_propertylist_delete(limage->plist);
2959 cpl_mask_delete(limage->object_mask);
2962 cpl_frame_delete(limage->frame);
2980 cpl_ensure(limage, CPL_ERROR_NULL_INPUT, NULL);
2984 hdrl_image * himage = NULL;
2985 if (limage->himage) {
2988 hdrl_imagelist * himagelist = NULL;
2989 if (limage->himagelist) {
2992 cpl_image * confidence = NULL;
2993 if (limage->confidence) {
2994 confidence = cpl_image_duplicate(limage->confidence);
2996 hdrl_image * bkg = NULL;
3000 cpl_image * bkg_confidence = NULL;
3001 if (limage->bkg_confidence) {
3002 bkg_confidence = cpl_image_duplicate(limage->bkg_confidence);
3004 cpl_propertylist * plist = NULL;
3005 if (limage->plist) {
3006 plist = cpl_propertylist_duplicate(limage->plist);
3008 hdrl_catalogue_result * objects = NULL;
3009 if (limage->objects) {
3012 cpl_mask * object_mask = NULL;
3013 if (limage->object_mask) {
3014 object_mask = cpl_mask_duplicate(limage->object_mask);
3016 hdrl_catalogue_result * matchstd_wcs = NULL;
3017 if (limage->matchstd_wcs) {
3019 limage->matchstd_wcs);
3021 hdrl_catalogue_result * matchstd_phot = NULL;
3022 if (limage->matchstd_phot) {
3024 limage->matchstd_phot);
3026 cpl_frame * frame = NULL;
3027 if (limage->frame) {
3028 frame = cpl_frame_duplicate(limage->frame);
3070 hdrl_imagelist * himagelist,
3071 cpl_image * confidence,
3073 cpl_image * bkg_confidence,
3074 cpl_propertylist * plist,
3075 hdrl_catalogue_result * objects,
3076 cpl_mask * object_mask,
3077 hdrl_catalogue_result * wcs,
3078 hdrl_catalogue_result * photom,
3079 cpl_frame * frame) {
3081 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
3084 cpl_ensure(!(himage && himagelist), CPL_ERROR_ILLEGAL_INPUT, NULL);
3086 located_image * result = cpl_malloc(
sizeof(located_image));
3087 result->himage = himage;
3088 result->himagelist = himagelist;
3089 result->confidence = confidence;
3091 result->bkg_confidence = bkg_confidence;
3092 result->plist = plist;
3093 result->objects = objects;
3094 result->object_mask = object_mask;
3095 result->matchstd_wcs = wcs;
3096 result->matchstd_phot = photom;
3097 result->frame = frame;
3117 cpl_frameset * frameset,
3119 cpl_frameset * used) {
3121 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
3122 cpl_ensure(frameset, CPL_ERROR_NULL_INPUT, NULL);
3123 cpl_ensure(tag, CPL_ERROR_NULL_INPUT, NULL);
3124 cpl_ensure(used, CPL_ERROR_NULL_INPUT, NULL);
3126 located_imagelist * result = NULL;
3127 cpl_frameset_iterator * frameset_iter = NULL;
3128 mef_extension_list * mefs = NULL;
3129 cpl_image * data = NULL;
3130 cpl_image * err = NULL;
3131 cpl_image * qual = NULL;
3132 cpl_image * conf = NULL;
3133 cpl_image * bkg = NULL;
3134 cpl_image * bkg_err = NULL;
3135 cpl_image * bkg_conf = NULL;
3136 cpl_propertylist * plist = NULL;
3140 frameset_iter = cpl_frameset_iterator_new(frameset);
3143 for (cpl_frame * frame = NULL;
3144 (frame = cpl_frameset_iterator_get(frameset_iter)) &&
3145 (cpl_error_get_code() == CPL_ERROR_NONE);
3146 cpl_frameset_iterator_advance(frameset_iter, 1)) {
3148 const char * frametag = cpl_frame_get_tag(frame);
3149 if (!strcmp(tag, frametag)) {
3157 cpl_frameset_iterator_reset(frameset_iter);
3158 cpl_size position = 0;
3159 for (cpl_frame * frame = NULL;
3160 (frame = cpl_frameset_iterator_get(frameset_iter)) &&
3161 (cpl_error_get_code() == CPL_ERROR_NONE);
3162 cpl_frameset_iterator_advance(frameset_iter, 1)) {
3167 const char * frametag = cpl_frame_get_tag(frame);
3169 if (!strcmp(tag, frametag)) {
3412 cpl_frame * dup_frame = cpl_frame_duplicate(frame);
3413 cpl_frameset_insert(used, dup_frame);
3421 cpl_propertylist_delete(plist);
3422 cpl_image_delete(data);
3423 cpl_image_delete(err);
3424 cpl_image_delete(qual);
3425 cpl_image_delete(conf);
3426 cpl_image_delete(bkg);
3427 cpl_image_delete(bkg_err);
3428 cpl_image_delete(bkg_conf);
3430 cpl_frameset_iterator_delete(frameset_iter);
3431 if (cpl_error_get_code() != CPL_ERROR_NONE) {
3455 const char * dps_name,
3456 const char * hduclas1,
3457 const char * hduclas2) {
3459 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
3460 cpl_ensure(mef, CPL_ERROR_NULL_INPUT, NULL);
3461 cpl_ensure(dps_name, CPL_ERROR_NULL_INPUT, NULL);
3462 cpl_ensure(hduclas1, CPL_ERROR_NULL_INPUT, NULL);
3463 cpl_ensure(hduclas2, CPL_ERROR_NULL_INPUT, NULL);
3465 cpl_image * result = NULL;
3467 cpl_propertylist * plist = mef->plist;
3468 const char * hduclass = cpl_propertylist_get_string(plist,
"HDUCLASS");
3469 const char * hdudoc = cpl_propertylist_get_string(plist,
"HDUDOC");
3471 const char * my_hduclas1 = cpl_propertylist_get_string(plist,
"HDUCLAS1");
3472 const char * my_hduclas2 = cpl_propertylist_get_string(plist,
"HDUCLAS2");
3474 enu_check(strstr(hduclass,
"ESO") != NULL &&
3475 strstr(hdudoc,
"SDP") != NULL &&
3477 strstr(my_hduclas1, hduclas1) != NULL &&
3478 strstr(my_hduclas2, hduclas2) != NULL,
3479 CPL_ERROR_BAD_FILE_FORMAT,
"bad %s format", dps_name);
3484 if (cpl_error_get_code() != CPL_ERROR_NONE) {
3487 if (result != NULL) mef->data = NULL;
3506 for (cpl_size i = 0; i < limlist->size; i++) {
3509 cpl_free(limlist->limages);
3526 const located_imagelist * limlist) {
3528 cpl_ensure(limlist, CPL_ERROR_NULL_INPUT, NULL);
3531 for (cpl_size i = 0; i < limlist->size; i++) {
3534 limlist->limages[i]), i);
3555 located_image * limage,
3556 cpl_size position) {
3558 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
3562 cpl_ensure_code(position >= 0 && position < limlist->size,
3563 CPL_ERROR_ACCESS_OUT_OF_RANGE);
3564 limlist->limages[position] = limage;
3566 return cpl_error_get_code();
3583 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
3585 located_imagelist * limlist = cpl_malloc(
sizeof(located_imagelist));
3586 limlist->size = size;
3587 limlist->limages = cpl_calloc(size,
sizeof(located_image));
3588 for (cpl_size i = 0; i < limlist->size; i++) {
3589 limlist->limages[i] = NULL;
3608 if (!strcmp(mef->data_type, MEF_EXTENSION_CONTAINING_IMAGE)) {
3609 cpl_image_delete((cpl_image *) (mef->data));
3610 }
else if (!strcmp(mef->data_type, MEF_EXTENSION_CONTAINING_MASK)) {
3611 cpl_mask_delete((cpl_mask *) mef->data);
3612 }
else if (!strcmp(mef->data_type, MEF_EXTENSION_CONTAINING_TABLE)) {
3613 cpl_table_delete((cpl_table *) mef->data);
3614 }
else if (!strcmp(mef->data_type, MEF_EXTENSION_CONTAINING_VECTOR)) {
3615 cpl_vector_delete((cpl_vector *) mef->data);
3617 cpl_error_set(
"enu_mef_extension_delete",
3618 CPL_ERROR_UNSUPPORTED_MODE);
3620 cpl_propertylist_delete(mef->plist);
3621 cpl_free(mef->name);
3640 for (cpl_size i = 0; i < list->size; i++) {
3643 cpl_free(list->mef);
3662 const char * target) {
3664 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
3666 cpl_ensure(meflist, CPL_ERROR_NULL_INPUT, NULL);
3667 cpl_ensure(target, CPL_ERROR_NULL_INPUT, NULL);
3671 cpl_mask * result = NULL;
3672 for (
int i=0; i<meflist->size; i++) {
3673 if (!strcmp(meflist->mef[i]->name, target)) {
3674 cpl_ensure(!strcmp(meflist->mef[i]->data_type,
3675 MEF_EXTENSION_CONTAINING_MASK),
3676 CPL_ERROR_INCOMPATIBLE_INPUT, NULL);
3677 result = cpl_mask_duplicate((
const cpl_mask *) meflist->mef[i]->data);
3684 cpl_ensure(result, CPL_ERROR_DATA_NOT_FOUND, NULL);
3703 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
3705 mef_extension_list * mef_list = cpl_malloc(
sizeof(mef_extension_list));
3706 mef_list->size = size;
3707 mef_list->mef = cpl_calloc(size,
sizeof(mef_extension));
3708 for (cpl_size i = 0; i < size; i++) {
3709 mef_list->mef[i] = NULL;
3733 const cpl_image * data,
3734 const cpl_propertylist * plist) {
3736 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
3740 cpl_ensure(name && data, CPL_ERROR_NULL_INPUT, NULL);
3742 mef_extension * result = cpl_malloc(
sizeof(mef_extension));
3743 result->name = cpl_strdup(name);
3744 result->data = (
void *) cpl_image_duplicate(data);
3745 result->data_type = MEF_EXTENSION_CONTAINING_IMAGE;
3747 result->plist = cpl_propertylist_duplicate(plist);
3749 result->plist = NULL;
3772 const cpl_mask * data,
3773 const cpl_propertylist * plist) {
3775 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
3779 cpl_ensure(name && data, CPL_ERROR_NULL_INPUT, NULL);
3781 mef_extension * result = cpl_malloc(
sizeof(mef_extension));
3782 result->name = cpl_strdup(name);
3783 result->data = (
void *) cpl_mask_duplicate(data);
3784 result->data_type = MEF_EXTENSION_CONTAINING_MASK;
3786 result->plist = cpl_propertylist_duplicate(plist);
3788 result->plist = NULL;
3811 const cpl_table * table,
3812 const cpl_propertylist * plist) {
3814 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
3815 cpl_ensure(name, CPL_ERROR_NULL_INPUT, NULL);
3816 cpl_ensure(table, CPL_ERROR_NULL_INPUT, NULL);
3818 mef_extension * result = cpl_malloc(
sizeof(mef_extension));
3819 result->name = cpl_strdup(name);
3820 result->data = (
void *) cpl_table_duplicate(table);
3821 result->plist = NULL;
3823 result->plist = cpl_propertylist_duplicate(plist);
3825 result->plist = NULL;
3827 result->data_type = MEF_EXTENSION_CONTAINING_TABLE;
3850 const cpl_vector * vector,
3851 const cpl_propertylist * plist) {
3853 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
3854 cpl_ensure(name, CPL_ERROR_NULL_INPUT, NULL);
3855 cpl_ensure(vector, CPL_ERROR_NULL_INPUT, NULL);
3857 mef_extension * result = cpl_malloc(
sizeof(mef_extension));
3858 result->name = cpl_strdup(name);
3859 result->data = (
void *) cpl_vector_duplicate(vector);
3860 result->plist = NULL;
3862 result->plist = cpl_propertylist_duplicate(plist);
3864 result->plist = NULL;
3866 result->data_type = MEF_EXTENSION_CONTAINING_VECTOR;
3887 const char * filename,
3888 const cpl_propertylist * plist,
3891 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
3893 cpl_msg_debug(cpl_func,
"enu_mef_extension_save entry");
3895 cpl_propertylist * plist_copy = NULL;
3899 cpl_ensure_code(mef, CPL_ERROR_NULL_INPUT);
3900 cpl_ensure_code(filename, CPL_ERROR_NULL_INPUT);
3901 cpl_ensure_code(plist, CPL_ERROR_NULL_INPUT);
3903 plist_copy = cpl_propertylist_duplicate(plist);
3904 cpl_propertylist_update_string(plist_copy,
"ERIS_NIX_MEF_TYPE",
3907 if (!strcmp(mef->data_type, MEF_EXTENSION_CONTAINING_IMAGE)) {
3908 if (cpl_propertylist_has(plist,
"CD3_3")) {
3919 cpl_msg_info(cpl_func,
"..saving data with NDIM=3");
3921 cpl_imagelist * imlist = cpl_imagelist_new();
3922 cpl_imagelist_set(imlist, mef->data, 0);
3923 cpl_imagelist_save(imlist,
3925 CPL_TYPE_UNSPECIFIED,
3929 cpl_imagelist_unset(imlist, 0);
3930 cpl_imagelist_delete(imlist);
3933 cpl_image_save((
const cpl_image *) (mef->data),
3935 CPL_TYPE_UNSPECIFIED,
3939 }
else if (!strcmp(mef->data_type, MEF_EXTENSION_CONTAINING_MASK)) {
3940 cpl_mask_save((
const cpl_mask *) (mef->data),
3944 }
else if (!strcmp(mef->data_type, MEF_EXTENSION_CONTAINING_TABLE)) {
3945 cpl_table_save((
const cpl_table *) (mef->data),
3950 }
else if (!strcmp(mef->data_type, MEF_EXTENSION_CONTAINING_VECTOR)) {
3951 cpl_vector_save((
const cpl_vector *) (mef->data),
3957 cpl_error_set_message(
"enu_mef_extension_save",
3958 CPL_ERROR_UNSUPPORTED_MODE,
3959 "unsupported extension type: %s", mef->data_type);
3962 cpl_propertylist_delete(plist_copy);
3964 return cpl_error_get_code();
3985 const double obj_threshold,
3986 const int bkg_mesh_size,
3987 const double bkg_smooth_fwhm,
3988 located_imagelist * limlist) {
3990 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
3994 cpl_ensure_code(limlist, CPL_ERROR_NULL_INPUT);
3996 casu_fits ** indata = NULL;
3997 casu_fits ** inconf = NULL;
3998 casu_fits ** invar = NULL;
4007 int casu_status = CASU_OK;
4010 cpl_msg_info(cpl_func,
".. calculating object masks");
4011 for (cpl_size j = 0; j < limlist->size; j++) {
4012 casu_opm(indata[j], inconf[j], obj_min_pixels, obj_threshold,
4013 bkg_mesh_size, bkg_smooth_fwhm, niter, &casu_status);
4014 enu_check(casu_status == CASU_OK, CPL_ERROR_UNSPECIFIED,
4015 "CASU error calculating object mask");
4016 limlist->limages[j]->object_mask = cpl_mask_duplicate(
4017 cpl_image_get_bpm(indata[j]->image));
4022 for (cpl_size j = 0; j < limlist->size; j++) {
4023 casu_fits_delete(indata[j]);
4024 casu_fits_delete(inconf[j]);
4025 casu_fits_delete(invar[j]);
4031 return cpl_error_get_code();
4054 const int nsigma_cut) {
4056 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
4057 cpl_ensure_code(limlist, CPL_ERROR_NULL_INPUT);
4059 cpl_msg_info(cpl_func,
"..calculating LSS object pixel mask");
4064 for (cpl_size j = 0; j < limlist->size; j++) {
4067 cpl_image * collapsed = cpl_image_collapse_median_create(
4069 limlist->limages[j]->himage), 0, 0, 0);
4073 double csigma = 0.0;
4074 double cmedian = cpl_image_get_median_dev(collapsed, &csigma);
4075 double maxval = cpl_image_get_max(collapsed);
4076 cpl_mask * collapsed_opm = cpl_mask_threshold_image_create(
4077 collapsed, cmedian + nsigma_cut * csigma,
4082 cpl_mask * kernel = cpl_mask_new(11, 1);
4083 cpl_mask_not(kernel);
4084 cpl_mask * dilated_collapsed_opm = cpl_mask_new(nx, 1);
4085 cpl_mask_filter(dilated_collapsed_opm, collapsed_opm, kernel,
4086 CPL_FILTER_DILATION, CPL_BORDER_NOP);
4087 cpl_mask_delete(kernel);
4091 const cpl_binary * collapsed_opm_data = cpl_mask_get_data_const(
4092 dilated_collapsed_opm);
4093 cpl_mask * opm = cpl_mask_new(nx, ny);
4094 cpl_binary * opm_data = cpl_mask_get_data(opm);
4095 for (cpl_size iy=0; iy < ny; iy++) {
4096 memcpy(opm_data + iy * (nx *
sizeof(*opm_data)),
4098 nx *
sizeof(*opm_data));
4103 cpl_mask_delete(limlist->limages[j]->object_mask);
4104 limlist->limages[j]->object_mask = opm;
4106 cpl_image_delete(collapsed);
4107 cpl_mask_delete(collapsed_opm);
4108 cpl_mask_delete(dilated_collapsed_opm);
4111 return cpl_error_get_code();
4131 const char * wcs_method,
4132 const char * catalogue,
4133 located_image * limage,
4134 const double match_rad,
4135 cpl_table ** matched_stds,
4136 cpl_matrix ** xy_shift) {
4138 cpl_matrix * celestial = NULL;
4139 cpl_array * colnames = NULL;
4140 cpl_array * conv_status = NULL;
4141 cpl_table * refcat_copy = NULL;
4142 cpl_matrix * ref_phys = NULL;
4143 cpl_matrix * ref_world = NULL;
4144 cpl_matrix * xy = NULL;
4145 cpl_wcs * wcs = NULL;
4147 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
4149 cpl_msg_info(cpl_func,
"correcting %s", cpl_frame_get_filename(limage->frame));
4153 cpl_msg_info(cpl_func,
" ..%s", cpl_frame_get_filename(limage->frame));
4157 cpl_size nref = cpl_table_get_nrow(refcat);
4158 const double * ra = cpl_table_get_data_double_const(refcat,
"RA");
4159 const double * dec = NULL;
4160 if (cpl_table_has_column(refcat,
"DEC")) {
4161 dec = cpl_table_get_data_double_const(refcat,
"DEC");
4163 ref_world = cpl_matrix_new(nref, 2);
4164 for (cpl_size iobj = 0; iobj < nref; iobj++) {
4165 cpl_matrix_set(ref_world, iobj, 0, ra[iobj]);
4166 cpl_matrix_set(ref_world, iobj, 1, dec[iobj]);
4168 wcs = cpl_wcs_new_from_propertylist(limage->plist);
4169 cpl_wcs_convert(wcs, ref_world, &ref_phys, &conv_status,
4170 CPL_WCS_WORLD2PHYS);
4171 enu_check_error_code(
"failure calculating predicted positions");
4177 refcat_copy = cpl_table_duplicate(refcat);
4178 colnames = cpl_table_get_column_names(refcat_copy);
4179 cpl_size ncol = cpl_array_get_size(colnames);
4180 for (cpl_size ic = 0; ic < ncol; ic++) {
4181 const char * colname = cpl_array_get_string(colnames, ic);
4182 if (strcmp(colname,
"RA") &&
4183 strcmp(colname,
"DEC") &&
4184 strcmp(colname,
"Aper_flux_3") &&
4185 strcmp(colname,
"Std index")) {
4186 cpl_table_erase_column(refcat_copy, colname);
4192 cpl_table_new_column(refcat_copy,
"xpredict", CPL_TYPE_DOUBLE);
4193 cpl_table_new_column(refcat_copy,
"ypredict", CPL_TYPE_DOUBLE);
4194 for (cpl_size iobj = 0; iobj < nref; iobj++) {
4195 cpl_table_set_double(refcat_copy,
"xpredict", iobj,
4196 cpl_matrix_get(ref_phys, iobj, 0));
4197 cpl_table_set_double(refcat_copy,
"ypredict", iobj,
4198 cpl_matrix_get(ref_phys, iobj, 1));
4200 enu_check_error_code(
"failure while creating predicted positions");
4204 cpl_msg_info(cpl_func,
" ..matching sources");
4206 if (limage->objects && limage->objects->catalogue) {
4207 nobj = cpl_table_get_nrow(limage->objects->catalogue);
4210 if (min(nref, nobj) > 0) {
4212 cpl_msg_info(cpl_func,
" ..calling enm_try_all_associations");
4218 enu_check_error_code(
"enu_correct_wcs failure at "
4219 "try_all_associations");
4226 enu_check_error_code(
"failure to correct wcs");
4229 cpl_msg_info(cpl_func,
" ..no catalogued objects, cannot correct wcs");
4233 cpl_matrix_delete(celestial);
4234 cpl_array_delete(colnames);
4235 cpl_array_delete(conv_status);
4236 cpl_table_delete(refcat_copy);
4237 cpl_matrix_delete(ref_phys);
4238 cpl_matrix_delete(ref_world);
4239 cpl_matrix_delete(xy);
4240 cpl_wcs_delete(wcs);
4242 return cpl_error_get_code();
4259 const cpl_table * refine_wcs) {
4261 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
4262 cpl_ensure_code(limage, CPL_ERROR_NULL_INPUT);
4264 if (!refine_wcs)
return CPL_ERROR_NONE;
4266 const char * camera = cpl_propertylist_get_string(limage->plist,
4267 "ESO INS2 NXCW NAME");
4268 enu_check(camera != NULL,
4269 CPL_ERROR_ILLEGAL_INPUT,
4270 "failed to read NIX camera from ESO.INS2.NXCW.NAME");
4272 cpl_size nrow = cpl_table_get_nrow(refine_wcs);
4273 cpl_boolean match = CPL_FALSE;
4280 for (cpl_size row = 0; row < nrow; row++) {
4281 const char * row_cam = cpl_table_get_string(refine_wcs,
"camera", row);
4283 if (!strcmp(camera, row_cam)) {
4287 cd1_1 = cpl_table_get_double(refine_wcs,
"CD1_1", row, &ignore);
4288 cd1_2 = cpl_table_get_double(refine_wcs,
"CD1_2", row, &ignore);
4289 cd2_1 = cpl_table_get_double(refine_wcs,
"CD2_1", row, &ignore);
4290 cd2_2 = cpl_table_get_double(refine_wcs,
"CD2_2", row, &ignore);
4296 cpl_propertylist_update_double(limage->plist,
"CD1_1", cd1_1);
4297 cpl_propertylist_update_double(limage->plist,
"CD1_2", cd1_2);
4298 cpl_propertylist_update_double(limage->plist,
"CD2_1", cd2_1);
4299 cpl_propertylist_update_double(limage->plist,
"CD2_2", cd2_2);
4304 cpl_error_set_message(cpl_func,
4305 CPL_ERROR_ILLEGAL_INPUT,
4306 "camera name not matched: %s",
4309 cd1_1 = cpl_propertylist_get_double(limage->plist,
"CD1_1");
4310 cd1_2 = cpl_propertylist_get_double(limage->plist,
"CD1_2");
4311 cd2_1 = cpl_propertylist_get_double(limage->plist,
"CD2_1");
4312 cd2_2 = cpl_propertylist_get_double(limage->plist,
"CD2_2");
4313 cpl_msg_info(cpl_func,
"..set CD matrix cd1_1=%10.8e cd1_2=%10.8e "
4314 "cd_2_1=%10.8e cd2_2=%10.8e",
4315 cd1_1, cd1_2, cd2_1, cd2_2);
4320 return cpl_error_get_code();
4338 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
4339 cpl_ensure_code(confidence, CPL_ERROR_NULL_INPUT);
4341 const cpl_size nx = cpl_image_get_size_x(confidence);
4342 const cpl_size ny = cpl_image_get_size_y(confidence);
4343 double * data = cpl_image_get_data_double(confidence);
4345 const cpl_mask * bpm = cpl_image_get_bpm_const(confidence);
4346 cpl_mask * mask = bpm ? cpl_image_get_bpm(confidence) : NULL;
4347 cpl_binary * mask_data = bpm ? cpl_mask_get_data(mask) : NULL;
4352 for (cpl_size i = 0; i < nx*ny; i++) {
4353 if (mask_data != NULL && mask_data[i] == CPL_TRUE) {
4354 mask_data[i] = CPL_FALSE;
4357 if (data[i] < 0.0) data[i] = 0.0;
4359 if (data[i] > 0.0) nonzero++;
4363 cpl_image_multiply_scalar(confidence, 100.0 * (
double)nonzero / sum);
4366 return cpl_error_get_code();
4408 const cpl_propertylist * plist,
4409 cpl_image * confidence,
4410 const int set_confidence) {
4414 double * hdata = cpl_image_get_data_double(himg);
4415 double * edata = cpl_image_get_data_double(eimg);
4416 cpl_binary* hbpm = cpl_mask_get_data(cpl_image_get_bpm(himg));
4417 cpl_binary* ebpm = cpl_mask_get_data(cpl_image_get_bpm(eimg));
4418 const int mx = cpl_image_get_size_x(himg);
4419 cpl_boolean is_fast_uncorr = CPL_FALSE;
4420 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
4423 cpl_ensure_code(hdata != NULL, CPL_ERROR_UNSUPPORTED_MODE);
4424 cpl_ensure_code(edata != NULL, CPL_ERROR_UNSUPPORTED_MODE);
4425 cpl_ensure_code(hbpm != NULL, CPL_ERROR_UNSUPPORTED_MODE);
4426 cpl_ensure_code(ebpm != NULL, CPL_ERROR_UNSUPPORTED_MODE);
4428 cpl_ensure_code(plist, CPL_ERROR_NULL_INPUT);
4437 cpl_size nx_chip = 0;
4438 cpl_size ny_chip = 0;
4439 cpl_boolean windowed = 0;
4449 enu_check_error_code(
"failed to read detector window information");
4455 double mjd = cpl_propertylist_get_double(plist,
"MJD-OBS");
4456 enu_check_error_code(
"failed to read MJD-OBS");
4458 cpl_msg_info(cpl_func,
"PIPE-10417 DITDELAY bug, "
4459 "remove_read_offsets will ignore bottom 4 rows "
4462 const char * curr_name = cpl_propertylist_get_string(plist,
"ESO DET READ CURNAME");
4463 if (strcmp(curr_name,
"FAST_UNCORR") == 0) {
4464 is_fast_uncorr = CPL_TRUE;
4466 cpl_size top_width = 4;
4467 cpl_size bottom_width = 4;
4468 cpl_msg_debug(cpl_func,
4469 "..offsets from %d top rows and %d bottom rows of chip",
4470 (
int) top_width, (
int) bottom_width);
4472 cpl_size nread_chan = nx_chip / 64;
4476 cpl_vector* voff = cpl_vector_new(nread_chan);
4477 double* pvoff = cpl_vector_get_data(voff);
4478 for (cpl_size read_chan = 0; read_chan < nread_chan; read_chan++) {
4482 cpl_array * offset_data = cpl_array_new(0, CPL_TYPE_DOUBLE);
4485 for (cpl_size x = 64 * read_chan; x < 64 * (read_chan+1); x++) {
4490 if (x+1 >= strx && x+1 < strx+nx) {
4492 for (cpl_size y = 0; y < bottom_width; y++) {
4496 if (y+1 >= stry && y+1 < stry+ny) {
4497 const int ipos = x-strx+1 + mx * (y-stry+1);
4501 const double pixval = hdata[ipos];
4505 cpl_array_set_size(offset_data, ndata);
4506 cpl_array_set(offset_data, ndata-1, pixval);
4509 hbpm[ipos] = CPL_BINARY_1;
4510 ebpm[ipos] = CPL_BINARY_1;
4512 if (set_confidence && confidence) {
4513 cpl_image_set(confidence,
4522 for (cpl_size y = ny_chip-top_width; y < ny_chip; y++) {
4523 if (y+1 >= stry && y+1 < stry+ny) {
4524 const int ipos = x-strx+1 + mx * (y-stry+1);
4527 const double pixval = hdata[ipos];
4529 cpl_array_set_size(offset_data, ndata);
4530 cpl_array_set(offset_data, ndata-1, pixval);
4531 hbpm[ipos] = CPL_BINARY_1;
4532 ebpm[ipos] = CPL_BINARY_1;
4533 if (set_confidence && confidence) {
4534 cpl_image_set(confidence,
4547 hdrl_value offset = {0.0, 0.0};
4549 cpl_msg_debug(cpl_func,
"read_chan %d", (
int)read_chan);
4550 cpl_msg_debug(cpl_func,
"ndata %d", (
int)ndata);
4551 cpl_msg_debug(cpl_func,
"median %f", cpl_array_get_median(offset_data));
4552 cpl_msg_debug(cpl_func,
"mean %f", cpl_array_get_mean(offset_data));
4553 cpl_msg_debug(cpl_func,
"std %f", cpl_array_get_stdev(offset_data));
4558 double mean = cpl_array_get_mean(offset_data);
4559 double stdev = cpl_array_get_stdev(offset_data);
4561 for (cpl_size i = 0; i < cpl_array_get_size(offset_data); i++) {
4563 double datum = cpl_array_get_double(offset_data, i, &invalid);
4564 if (!invalid && fabs(datum - mean) > 5 * stdev) {
4565 cpl_array_set_invalid(offset_data, i);
4570 offset.data = cpl_array_get_mean(offset_data);
4571 offset.error = cpl_array_get_stdev(offset_data);
4572 pvoff[read_chan] = offset.data;
4574 cpl_msg_debug(cpl_func,
"..removing offset %f (%f) for read "
4575 "channel %d", offset.data, offset.error,
4578 for (cpl_size x = 64 * read_chan; x < 64 * (read_chan+1); x++) {
4579 for (cpl_size y = 0; y < ny_chip; y++) {
4581 if (x+1 >= strx && x+1 < strx+nx &&
4582 y+1 >= stry && y+1 < stry+ny) {
4583 const int ipos = x-strx+1 + mx * (y-stry+1);
4586 hdata[ipos] -= offset.data;
4587 edata[ipos] = hypot(edata[ipos], offset.error);
4593 cpl_array_delete(offset_data);
4598 if(is_fast_uncorr) {
4599 cpl_image_add_scalar(himg,cpl_vector_get_mean(voff));
4604 for (cpl_size y = 0; y < ny_chip; y++) {
4605 for (cpl_size x = 0; x < 4; x++) {
4607 if (x+1 >= strx && x+1 < strx+nx &&
4608 y+1 >= stry && y+1 < stry+ny) {
4609 const int ipos = x-strx+1 + mx * (y-stry+1);
4611 hbpm[ipos] = CPL_BINARY_1;
4612 ebpm[ipos] = CPL_BINARY_1;
4614 if (set_confidence && confidence) {
4615 cpl_image_set(confidence,
4624 for (cpl_size y = 0; y < ny_chip; y++) {
4625 for (cpl_size x = nx_chip-4; x < nx_chip; x++) {
4627 if (x+1 >= strx && x+1 < strx+nx &&
4628 y+1 >= stry && y+1 < stry+ny) {
4633 if (set_confidence && confidence) {
4634 cpl_image_set(confidence,
4643 cpl_vector_delete(voff);
4646 if (set_confidence && confidence) {
4652 return cpl_error_get_code();
4666 const char * preface) {
4668 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
4670 char * in_name = cpl_strdup(filename);
4673 char * pch = strstr(filename,
"ERIS.20");
4675 pch = strstr(filename,
"NACO.20");
4678 char * outname = cpl_sprintf(
"%s.%s", preface, pch);
4704 const char * select_method,
4705 const double timerange,
4706 const located_imagelist * target_list,
4707 const located_imagelist * sky_list,
4708 const cpl_size x_probe,
4709 const cpl_size y_probe,
4710 hdrl_imagelist ** sky_himagelist,
4711 cpl_imagelist ** sky_confidence_list) {
4713 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
4715 cpl_image * contrib = NULL;
4716 hdrl_imagelist * skylist = NULL;
4717 cpl_image * sky_confidence = NULL;
4718 hdrl_image * sky_himage = NULL;
4719 cpl_vector * sky_indeces = NULL;
4721 cpl_msg_debug(cpl_func,
"enu_sky_backgrounds entry");
4725 cpl_ensure_code(method, CPL_ERROR_NULL_INPUT);
4726 cpl_ensure_code(select_method, CPL_ERROR_NULL_INPUT);
4727 cpl_ensure_code(target_list, CPL_ERROR_NULL_INPUT);
4728 cpl_ensure_code(sky_list, CPL_ERROR_NULL_INPUT);
4729 cpl_ensure_code(!strcmp(select_method,
"bracket") &&
4730 (timerange > 0.0), CPL_ERROR_ILLEGAL_INPUT);
4733 *sky_confidence_list = cpl_imagelist_new();
4737 int debug = CPL_FALSE;
4738 cpl_vector * data = NULL;
4739 cpl_vector * error = NULL;
4740 cpl_vector * reject = NULL;
4741 cpl_vector * confidence = NULL;
4743 cpl_msg_info(cpl_func,
"..calculating skys");
4747 cpl_size njitters = target_list->size;
4748 for (cpl_size j = 0; j < njitters; j++) {
4752 if (strstr(select_method,
"bracket") != NULL) {
4754 sky_list, x_probe > -1);
4756 enu_check_error_code(
"failure in enu_bracket_skys");
4758 cpl_size skysize = cpl_vector_get_size(sky_indeces);
4760 if (x_probe > 0 && skysize > 0) {
4762 sky_list->limages[0]->himage);
4764 sky_list->limages[0]->himage);
4765 if (x_probe > 0 && x_probe <= x_size &&
4766 y_probe > 0 && y_probe <= y_size) {
4769 data = cpl_vector_new(skysize);
4770 error = cpl_vector_new(skysize);
4771 reject = cpl_vector_new(skysize);
4772 confidence = cpl_vector_new(skysize);
4777 if (strstr(method,
"collapse-median") != NULL) {
4784 for (
int k = 0; k < (int)skysize; k++) {
4785 int i = (int)cpl_vector_get(sky_indeces, k);
4787 limages[i]->himage);
4788 cpl_image * confcopy = cpl_image_duplicate(sky_list->
4789 limages[i]->confidence);
4790 if (sky_list->limages[i]->object_mask != NULL) {
4792 sky_list->limages[i]->object_mask);
4793 cpl_mask_or(cpl_image_get_bpm(confcopy),
4794 sky_list->limages[i]->object_mask);
4795 cpl_image_fill_rejected(confcopy, 0.0);
4796 cpl_image_accept_all(confcopy);
4802 x_probe, y_probe, &rejected);
4804 double conf = cpl_image_get(confcopy,
4807 cpl_vector_set(data, k, himval.data);
4808 cpl_vector_set(error, k, himval.error);
4809 cpl_vector_set(reject, k, (
double)rejected);
4810 cpl_vector_set(confidence, k, conf);
4816 if (sky_confidence == NULL) {
4817 sky_confidence = confcopy;
4819 cpl_image_add(sky_confidence, confcopy);
4820 cpl_image_delete(confcopy);
4823 cpl_msg_debug(cpl_func,
"after skylist %s",
4824 cpl_error_get_message());
4830 cpl_image_delete(contrib);
4832 cpl_msg_debug(cpl_func,
"after collapse %s",
4833 cpl_error_get_message());
4841 ".. enu_sky_backgrounds: probe pixel %d,%d",
4842 (
int)x_probe, (
int)y_probe);
4843 cpl_msg_info(
" ",
".. jitter %d" , (
int)j);
4844 cpl_msg_info(
" ",
"... j# q c d (e)");
4846 for (cpl_size k = 0; k < skysize; k++) {
4847 cpl_msg_info(
" ",
"... %3d %3d %3d %8.2f(%4.2f)",
4848 (
int)cpl_vector_get(sky_indeces, k),
4849 (
int)cpl_vector_get(reject, k),
4850 (
int)cpl_vector_get(confidence, k),
4851 cpl_vector_get(data, k),
4852 cpl_vector_get(error, k));
4857 x_probe, y_probe, &rejected);
4858 double cval = cpl_image_get(sky_confidence, x_probe,
4860 cpl_msg_info(
" ",
"... -> %3d %3d %8.2f(%4.2f)",
4861 rejected, (
int)cval, hval.data, hval.error);
4863 cpl_vector_delete(data);
4864 cpl_vector_delete(error);
4865 cpl_vector_delete(reject);
4866 cpl_vector_delete(confidence);
4870 enu_check_error_code(
"failure in collapse-median");
4872 }
else if (strstr(method,
"median-median") != NULL) {
4877 cpl_array * sky_medians = cpl_array_new(0, CPL_TYPE_DOUBLE);
4879 for (
int k = 0; k < (int)skysize; k++) {
4880 int i = (int)cpl_vector_get(sky_indeces, k);
4885 sky_list->limages[i]->himage);
4886 if (sky_list->limages[i]->object_mask != NULL) {
4888 sky_list->limages[i]->object_mask);
4893 cpl_size asize = cpl_array_get_size(sky_medians);
4894 cpl_array_set_size(sky_medians, asize+1);
4895 cpl_array_set_double(sky_medians, asize, bkg.data);
4898 cpl_vector_set(data, k, bkg.data);
4899 cpl_vector_set(error, k, bkg.error);
4900 cpl_vector_set(confidence, k, 100.0);
4901 cpl_vector_set(reject, k, 0.0);
4908 double sky_med_med = cpl_array_get_median(sky_medians);
4909 double sky_med_stdev = cpl_array_get_stdev(sky_medians);
4912 cpl_image * sky_data = cpl_image_new(nx, ny, HDRL_TYPE_DATA);
4913 cpl_image_fill_window(sky_data, 1, 1, nx, ny, sky_med_med);
4914 cpl_image * sky_error = cpl_image_new(nx, ny, HDRL_TYPE_ERROR);
4915 cpl_image_fill_window(sky_error, 1, 1, nx, ny, sky_med_stdev);
4917 cpl_image_delete(sky_data);
4918 cpl_image_delete(sky_error);
4920 sky_confidence = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
4921 cpl_image_fill_window(sky_confidence, 1, 1, nx, ny, 100.0);
4923 cpl_array_delete(sky_medians);
4927 ".. enu_sky_backgrounds: median of images");
4928 cpl_msg_info(
" ",
".. jitter %d" , (
int)j);
4929 cpl_msg_info(
" ",
"... j# c d (e)");
4931 for (cpl_size k = 0; k < skysize; k++) {
4932 cpl_msg_info(
" ",
"... %3d %3d %8.2f(%4.2f)",
4933 (
int)cpl_vector_get(sky_indeces, k),
4934 (
int)cpl_vector_get(confidence, k),
4935 cpl_vector_get(data, k),
4936 cpl_vector_get(error, k));
4942 double cval = cpl_image_get(sky_confidence, 1, 1, &ignore);
4943 cpl_msg_info(
" ",
"... -> %3d %3d %8.2f(%4.2f)",
4944 rejected, (
int)cval, hval.data, hval.error);
4946 cpl_vector_delete(data);
4947 cpl_vector_delete(error);
4948 cpl_vector_delete(confidence);
4950 enu_check_error_code(
"failure in median-median");
4957 cpl_imagelist_set(*sky_confidence_list, sky_confidence,
4958 cpl_imagelist_get_size(*sky_confidence_list));
4959 cpl_vector_delete(sky_indeces); sky_indeces = NULL;
4964 cpl_vector_delete(sky_indeces);
4965 if (cpl_error_get_code() != CPL_ERROR_NONE) {
4967 *sky_himagelist = NULL;
4968 cpl_imagelist_delete(*sky_confidence_list);
4969 *sky_confidence_list = NULL;
4972 return cpl_error_get_code();
4991 const double stk_lthr,
const double stk_hthr,
4992 const char * stk_method,
const int stk_fast,
4993 located_image ** result) {
4995 cpl_ensure_code(cpl_error_get_code() == CPL_ERROR_NONE,
4996 cpl_error_get_code());
4998 casu_fits ** indata = NULL;
4999 casu_fits ** inconf = NULL;
5000 casu_fits ** invar = NULL;
5001 casu_fits * out = NULL;
5002 casu_fits * outc = NULL;
5003 casu_fits * outv = NULL;
5007 cpl_ensure_code(limages, CPL_ERROR_NULL_INPUT);
5008 cpl_ensure_code((stk_fast == 0) || (stk_fast == 1),
5009 CPL_ERROR_ILLEGAL_INPUT);
5013 const int casu_stk_method = (!strcmp(stk_method,
"nearest") ? 0 : 1);
5021 int njitters = (int) limages->size;
5022 int casu_status = CASU_OK;
5023 casu_imstack(indata, inconf, invar, NULL, (
int)njitters, (int)njitters,
5024 stk_lthr, stk_hthr, casu_stk_method, 0, stk_fast, 0,
5025 "ESO DET DIT", &out, &outc, &outv, &casu_status);
5028 cpl_image_duplicate(outc->image),
5031 NULL, NULL, NULL, NULL, NULL);
5036 return cpl_error_get_code();
5056 const char * select_method,
5057 const double timerange,
5058 const located_imagelist * sky_data,
5059 const cpl_size x_probe,
5060 const cpl_size y_probe,
5061 located_imagelist * target_data) {
5063 cpl_ensure_code(cpl_error_get_code() == CPL_ERROR_NONE,
5064 cpl_error_get_code());
5065 cpl_ensure_code(method, CPL_ERROR_NULL_INPUT);
5066 cpl_ensure_code(select_method, CPL_ERROR_NULL_INPUT);
5067 cpl_ensure_code(target_data, CPL_ERROR_NULL_INPUT);
5069 cpl_imagelist * sky_conf_list = NULL;
5070 hdrl_imagelist * sky_himlist = NULL;
5072 cpl_msg_info(cpl_func,
5073 "enu_sky_subtract called: method=%s, sky_selector=%s, "
5075 method, select_method, timerange);
5076 cpl_size njitters = target_data->size;
5077 cpl_msg_info(cpl_func,
"number of jitters to be reduced %d",
5083 sky_data, x_probe, y_probe, &sky_himlist,
5085 enu_check_error_code(
"failure in enu_sky_backgrounds");
5089 hdrl_value before = {0.0, 0.0};
5091 hdrl_value bkg = {0.0, 0.0};
5092 double bkgconf = 0.0;
5093 hdrl_value after = {0.0, 0.0};
5096 int bkgrejected = 1;
5099 int header_printed = CPL_FALSE;
5101 for (cpl_size i = 0; i < njitters; i++) {
5106 target_data->limages[i]->himage);
5108 target_data->limages[i]->himage);
5109 if (x_probe > 0 && x_probe <= x_size &&
5110 y_probe > 0 && y_probe <= y_size) {
5112 x_probe, y_probe, &brejected);
5113 bconf = cpl_image_get(target_data->limages[i]->confidence,
5114 x_probe, y_probe, &ignore);
5123 target_data->limages[i]->bkg_confidence = cpl_image_duplicate(
5124 cpl_imagelist_get(sky_conf_list, i));
5143 cpl_image_fill_rejected(target_data->limages[i]->confidence, 0.0);
5144 cpl_image_accept_all(target_data->limages[i]->confidence);
5149 if (x_probe > 0 && x_probe <= x_size &&
5150 y_probe > 0 && y_probe <= y_size) {
5152 x_probe, y_probe, &arejected);
5153 aconf = cpl_image_get(target_data->limages[i]->confidence,
5154 x_probe, y_probe, &ignore);
5156 x_probe, y_probe, &bkgrejected);
5157 bkgconf = cpl_image_get(target_data->limages[i]->bkg_confidence,
5158 x_probe, y_probe, &ignore);
5160 if (!header_printed) {
5161 header_printed = CPL_TRUE;
5162 cpl_msg_info(
" ",
"..Subtracting sky backgrounds: probe pixel %d,%d",
5163 (
int)x_probe, (
int)y_probe);
5164 cpl_msg_info(
" ",
" j# before sky after");
5165 cpl_msg_info(
" ",
" q c d e q c d e q c d e");
5168 "..%3d %d %3.0f %4.2e(%4.2e)) %d %3.0f %4.2e(%4.2e) %d %3.0f %10.2e(%4.2e)",
5170 brejected, bconf, before.data, before.error,
5171 bkgrejected, bkgconf, bkg.data, bkg.error,
5172 arejected, aconf, after.data, after.error);
5177 cpl_imagelist_delete(sky_conf_list);
5180 return cpl_error_get_code();
5197 cpl_propertylist* qc_list,
5200 cpl_ensure_code(mbad_pix_map != NULL, CPL_ERROR_NULL_INPUT);
5201 cpl_ensure_code(qc_list != NULL, CPL_ERROR_NULL_INPUT);
5202 cpl_ensure_code(prefix != NULL, CPL_ERROR_NULL_INPUT);
5205 cpl_mask * bpm_mask = NULL;
5207 flag_mask = ~flag_mask;
5208 bpm_mask = en_master_bpm_get_mask(mbad_pix_map, flag_mask);
5209 int nbad = cpl_mask_count(bpm_mask);
5210 cpl_propertylist_append_int(qc_list,
"ESO QC NUMBER BAD PIXELS", nbad);
5211 cpl_size sx = cpl_mask_get_size_x(bpm_mask);
5212 cpl_size sy = cpl_mask_get_size_y(bpm_mask);
5213 double fraction = (double) nbad / (sx * sy);
5214 cpl_propertylist_append_double(qc_list,
"ESO QC FRACTION BAD PIXELS",
fraction);
5215 return cpl_error_get_code();
5235 cpl_mask* bp_map_nl_mask,
5236 const cpl_parameterlist* parlist,
5237 const char* context,
5238 const double threshold_pos,
5239 const cpl_boolean verbose,
5240 const cpl_boolean rescale_by_dit){
5242 cpl_ensure(lamp_on_limlist != NULL, CPL_ERROR_NULL_INPUT, NULL);
5243 cpl_ensure(bp_map_nl_mask != NULL, CPL_ERROR_NULL_INPUT, NULL);
5244 cpl_ensure(parlist != NULL, CPL_ERROR_NULL_INPUT, NULL);
5245 cpl_ensure(context != NULL, CPL_ERROR_NULL_INPUT, NULL);
5248 cpl_propertylist* qc;
5257 qc = cpl_propertylist_new();
5258 double threshold_neg = - 4.3e7;
5259 threshold_neg = 300.;
5260 long nthresh_pos = 0;
5261 long nthresh_neg = 0;
5263 const cpl_parameter* param;
5267 pname = cpl_sprintf(
"%s%s",context,
".saturation_neg");
5268 cpl_msg_warning(cpl_func,
"pname: %s",pname);
5269 param = cpl_parameterlist_find_const(parlist,pname);
5270 threshold_neg = cpl_parameter_get_double(param);
5276 double mean_min = DBL_MAX;
5277 double median_min = DBL_MAX;
5279 double mean_max = -DBL_MIN;
5280 double median_max = -DBL_MIN;
5281 double nthresh_pos_max = 0;
5282 double nthresh_neg_max = 0;
5290 cpl_propertylist* plist = NULL;
5291 for(cpl_size i = 0; i < lamp_on_limlist->size; i++) {
5299 cpl_mask_or(mask, bp_map_nl_mask);
5303 plist = lamp_on_limlist->limages[i]->plist;
5304 if(cpl_propertylist_has(plist,
"ESO DET SEQ1 DIT")) {
5305 dit = cpl_propertylist_get_double(plist,
"ESO DET SEQ1 DIT");
5307 nthresh_neg = eris_image_get_threshpix(ima, threshold_neg, CPL_FALSE);
5308 nthresh_pos = eris_image_get_threshpix(ima, threshold_pos, CPL_TRUE);
5310 eris_image_flag_threshpix(&ima, threshold_neg, CPL_FALSE);
5311 mean = cpl_image_get_mean(ima);
5312 median = cpl_image_get_median(ima);
5313 rms = cpl_image_get_stdev(ima);
5318 if(rescale_by_dit) {
5324 key_name = cpl_sprintf(
"ESO QC FLAT_ON%lld NPOSSAT",i);
5325 key_comm = cpl_sprintf(
"Number of flat pixels above threshold");
5326 cpl_propertylist_append_int(qc, key_name, nthresh_pos);
5327 cpl_propertylist_set_comment(qc, key_name, key_comm);
5331 key_name = cpl_sprintf(
"ESO QC FLAT_ON%lld NNEGSAT",i);
5332 key_comm = cpl_sprintf(
"Number of flat pixels below neg threshold");
5333 cpl_propertylist_append_int(qc, key_name, nthresh_neg);
5334 cpl_propertylist_set_comment(qc, key_name, key_comm);
5338 key_name = cpl_sprintf(
"ESO QC FLAT_ON%lld MEAN",i);
5339 key_comm = cpl_sprintf(
"[ADU] Mean of flat");
5340 cpl_propertylist_append_double(qc, key_name, mean);
5341 cpl_propertylist_set_comment(qc,key_name,key_comm);
5345 key_name = cpl_sprintf(
"ESO QC FLAT_ON%lld MEDIAN",i);
5346 key_comm = cpl_sprintf(
"[ADU] Median of flat");
5347 cpl_propertylist_append_double(qc, key_name, median);
5348 cpl_propertylist_set_comment(qc,key_name,key_comm);
5352 key_name = cpl_sprintf(
"ESO QC FLAT_ON%lld STDEV",i);
5353 key_comm = cpl_sprintf(
"[ADU] Stdev of flat");
5354 cpl_propertylist_append_double(qc, key_name, rms);
5355 cpl_propertylist_set_comment(qc,key_name,key_comm);
5360 if(mean > mean_max) {
5363 if(median > median_max) {
5364 median_max = median;
5368 if(mean < mean_min) {
5371 if(median < median_min) {
5372 median_min = median;
5376 if(nthresh_pos > nthresh_pos_max) {
5377 nthresh_pos_max = nthresh_pos;
5379 if(nthresh_neg > nthresh_neg_max) {
5380 nthresh_neg_max = nthresh_neg;
5383 cpl_msg_info(cpl_func,
"mean_min: %g",mean_min);
5384 cpl_msg_info(cpl_func,
"mean_max: %g",mean_max);
5385 cpl_msg_info(cpl_func,
"median_min: %g",median_min);
5386 cpl_msg_info(cpl_func,
"median_max: %g",median_max);
5387 cpl_msg_info(cpl_func,
"f1: %g",mean_min / mean_max);
5388 cpl_msg_info(cpl_func,
"f2: %g",median_min / median_max);
5390 key_name = cpl_sprintf(
"ESO QC FLAT_ON MEAN MIN");
5391 key_comm = cpl_sprintf(
"[ADU] Min of Means of flat");
5392 cpl_propertylist_append_double(qc, key_name, mean_min);
5393 cpl_propertylist_set_comment(qc,key_name,key_comm);
5397 key_name = cpl_sprintf(
"ESO QC FLAT_ON MEDIAN MIN");
5398 key_comm = cpl_sprintf(
"[ADU] Min of Medians of flat");
5399 cpl_propertylist_append_double(qc, key_name, median_min);
5400 cpl_propertylist_set_comment(qc,key_name,key_comm);
5404 key_name = cpl_sprintf(
"ESO QC FLAT_ON MEAN MAX");
5405 key_comm = cpl_sprintf(
"[ADU] Max of Means of flat");
5406 cpl_propertylist_append_double(qc, key_name, mean_max);
5407 cpl_propertylist_set_comment(qc,key_name,key_comm);
5411 key_name = cpl_sprintf(
"ESO QC FLAT_ON MEDIAN MAX");
5412 key_comm = cpl_sprintf(
"[ADU] Max of Medians of flat");
5413 cpl_propertylist_append_double(qc, key_name, median_max);
5414 cpl_propertylist_set_comment(qc,key_name,key_comm);
5419 key_name = cpl_sprintf(
"ESO QC FLAT_ON MEAN FRAC");
5420 key_comm = cpl_sprintf(
"Min/Max of Means of flat");
5421 cpl_propertylist_append_double(qc, key_name, mean_min / mean_max);
5422 cpl_propertylist_set_comment(qc,key_name,key_comm);
5427 key_name = cpl_sprintf(
"ESO QC FLAT_ON MEDIAN FRAC");
5428 key_comm = cpl_sprintf(
"Min/Max of Medians of flat");
5429 cpl_propertylist_append_double(qc, key_name, median_min / median_max);
5430 cpl_propertylist_set_comment(qc,key_name,key_comm);
5436 key_name = cpl_sprintf(
"ESO QC FLAT_ON NPOSSAT MAX");
5437 key_comm = cpl_sprintf(
"Max of Number of flat pixels above threshold");
5438 cpl_propertylist_append_int(qc, key_name, nthresh_pos_max);
5439 cpl_propertylist_set_comment(qc, key_name, key_comm);
5443 key_name = cpl_sprintf(
"ESO QC FLAT_ON NNEGSAT MAX");
5444 key_comm = cpl_sprintf(
"MAX Number of flat pixels below neg threshold");
5445 cpl_propertylist_append_int(qc, key_name, nthresh_neg_max);
5446 cpl_propertylist_set_comment(qc, key_name, key_comm);
cpl_error_code encu_limlist_to_casu_fits(located_imagelist *limlist, casu_fits ***indata, casu_fits ***inconf, casu_fits ***invar)
Translate a located_imagelist to arrays of casu_fits structs.
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 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.
cpl_error_code enm_correct_crpix(const char *wcs_method, const char *catalogue, cpl_table *matched_stds, located_image *limage, cpl_matrix **xy_shift)
Apply median offsets from matched standards table to image.
cpl_error_code enm_try_all_associations(cpl_table *objtab, cpl_table *stdtab, const double match_rad, cpl_table **matchtab)
Match standards with objects by trying all possibilities and selecting best.
located_image * enu_located_image_duplicate(const located_image *limage)
Make a deep copy of a located_image and its contents.
cpl_mask * enu_mef_extension_list_get_mask(mef_extension_list *meflist, const char *target)
Get a cpl_mask from a named mef_extension in a list.
cpl_vector * enu_bracket_skys(const located_image *target, const double timerange, const located_imagelist *pool, const int debug)
Find images taken within a given time of a target image.
cpl_error_code enu_modify_CD_matrix(located_image *limage, const cpl_table *refine_wcs)
Update the CD matrix to reduce image distortion and rotation.
void enu_located_imagelist_delete(located_imagelist *limlist)
Delete a located_imagelist and its contents.
cpl_error_code enu_located_imagelist_insert(located_imagelist *limlist, located_image *limage, cpl_size position)
Insert a located_image at a specified point in a located_imagelist.
void enu_mef_extension_delete(mef_extension *mef)
Delete a mef_extension and its contents.
cpl_error_code eris_nix_get_badpix_qc_from_ima(const master_bpm *mbad_pix_map, cpl_propertylist *qc_list, const char *prefix)
Compute QC on input master bpm.
mef_extension * enu_mef_new_mask(const char *name, const cpl_mask *data, const cpl_propertylist *plist)
Create a mef_extension struct holding a cpl_mask.
cpl_propertylist * enu_raw_flats_qc(located_imagelist *lamp_on_limlist, cpl_mask *bp_map_nl_mask, const cpl_parameterlist *parlist, const char *context, const double threshold_pos, const cpl_boolean verbose, const cpl_boolean rescale_by_dit)
Compute QC on input raw flats.
cpl_error_code enu_flat_save(const char *pro_catg, const hdrl_image *flat, const cpl_image *confidence, const cpl_mask *cold_bpm, cpl_frameset *frameset, const cpl_parameterlist *parlist, const char *filename, const char *recipe_name, const cpl_propertylist *qclog)
Save a flatfield result.
int enu_check_conformance(const cpl_propertylist *plist1, const cpl_propertylist *plist2, const char *regexp)
Check that the specified subset of two propertylists match.
located_image * enu_load_limage_from_frame(const cpl_frame *frame, cpl_image **pcopyconf, const cpl_boolean collapse_cube)
Load components of a located_image from a frame.
hdrl_catalogue_result * enu_hdrl_catalogue_result_duplicate(const hdrl_catalogue_result *target)
Return a deep copy of the given hdrl_catalogue_result object.
located_imagelist * enu_located_imagelist_duplicate(const located_imagelist *limlist)
Make a deep copy of a located_imagelist and its contents.
cpl_error_code enu_calc_maglim(const located_image *limage, const double photzp, const double fwhm_pix, double *abmaglim)
Calculate magnitude limit of image.
cpl_error_code enu_opm_lss_limlist(located_imagelist *limlist, const int nsigma_cut)
Calculate object masks for LSS images in a located_imagelist.
double enu_get_tel_alt(const cpl_propertylist *plist)
Get telescope altitude of an observation.
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.
cpl_error_code enu_get_ra_dec(const cpl_wcs *wcs, double *ra, double *dec)
Get RA and Dec at centre of image with given wcs.
hdrl_image * enu_calc_flat(hdrl_imagelist *himlist, const int min_coadds, const hdrl_parameter *collapse_params, const cpl_size filter_size_x, const cpl_size filter_size_y, const hdrl_flat_method method)
Calculate a flatfield result.
cpl_error_code enu_get_window_info(cpl_size *nx, cpl_size *ny, int *rot, cpl_size *strx, cpl_size *stry, cpl_size *nx_chip, cpl_size *ny_chip, cpl_boolean *windowed, const cpl_propertylist *plist)
Get the detector 'window' information.
cpl_error_code enu_basic_calibrate(located_image *limage, const int read_offsets, const cpl_table *refine_wcs, const master_dark *mdark, const gain_linearity *gain_lin, const master_flat *flatfield_1, const master_flat *flatfield_2, const master_bpm *mbad_pix_map, const int flag_mask, const char *fill_rejected, const double fill_value, const cpl_size x_probe, const cpl_size y_probe)
Do basic calibration of located_image (single or cube)
cpl_error_code enu_catalogue_limlist(located_imagelist *limlist, hdrl_parameter *params)
Calculate object catalogues for a list of images.
cpl_error_code enu_sky_subtract_limlist(const char *method, const char *select_method, const double timerange, const located_imagelist *sky_data, const cpl_size x_probe, const cpl_size y_probe, located_imagelist *target_data)
Estimate and subtract sky backgrounds for a list of target images.
cpl_error_code enu_himage_load_from_fits(const char *filename, hdrl_image **result, mef_extension_list **mef_extensions, cpl_propertylist **plist)
Load an hdrl_image from a multi-extension FITS file.
cpl_error_code enu_debug_limlist_save(const int debug, const located_imagelist *limlist, const char *nameroot, const char *recipename, cpl_frameset *frameset, const cpl_parameterlist *parlist, const cpl_frameset *used)
Save a list of intermediate image results for use in debugging.
mef_extension * enu_mef_new_table(const char *name, const cpl_table *table, const cpl_propertylist *plist)
Create a mef_extension struct holding a cpl_table.
mef_extension_list * enu_mef_extension_list_new(cpl_size size)
Construct a new mef_extension_list.
located_image * enu_located_image_new(hdrl_image *himage, hdrl_imagelist *himagelist, cpl_image *confidence, hdrl_image *bkg, cpl_image *bkg_confidence, cpl_propertylist *plist, hdrl_catalogue_result *objects, cpl_mask *object_mask, hdrl_catalogue_result *wcs, hdrl_catalogue_result *photom, cpl_frame *frame)
Create a located_image structure and initialise the contents.
double enu_get_airmass(const cpl_propertylist *plist)
Get the mean airmass of an observation.
cpl_error_code enu_calc_pixel_coords(cpl_table *catalogue, const cpl_propertylist *wcs_plist)
Calculate predicted positions of catalogue objects for given wcs.
located_imagelist * enu_limlist_load_from_frameset(cpl_frameset *frameset, const char *tag, cpl_frameset *used)
Load tagged data from a frameset into a located_imagelist.
void enu_located_image_delete(located_image *limage)
Delete a located_image and its contents.
mef_extension * enu_mef_new_vector(const char *name, const cpl_vector *vector, const cpl_propertylist *plist)
Create a mef_extension struct holding a cpl_vector.
cpl_error_code enu_remove_read_offsets(hdrl_image *himage, const cpl_propertylist *plist, cpl_image *confidence, const int set_confidence)
Function to remove read offsets from an himage and set blank pixels
cpl_error_code enu_normalise_confidence(cpl_image *confidence)
Normalise confidence array so that mean of good pixels is 100.
cpl_error_code enu_stack(located_imagelist *limages, const double stk_lthr, const double stk_hthr, const char *stk_method, const int stk_fast, located_image **result)
Stack a set of images.
cpl_error_code enu_correct_wcs(const cpl_table *refcat, const char *wcs_method, const char *catalogue, located_image *limage, const double match_rad, cpl_table **matched_stds, cpl_matrix **xy_shift)
Correct the wcs of an image.
cpl_error_code enu_basic_calibrate_himage(hdrl_image *himage, cpl_image *confidence, cpl_propertylist *plist, const cpl_frame *frame, const int read_offsets, const master_dark *mdark, const gain_linearity *gain_lin, const master_flat *flatfield_1, const master_flat *flatfield_2, const master_bpm *mbad_pix_map, const int set_confidence, const int flag_mask, const char *fill_rejected, const double fill_value, const cpl_size x_probe, const cpl_size y_probe)
Do basic calibration of an hdrl_image.
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.
const char * enu_get_license(void)
Get the pipeline copyright and license.
void enu_mef_extension_list_delete(mef_extension_list *list)
Delete a mef_extension_list and its contents.
cpl_image * enu_load_component(mef_extension *mef, const char *dps_name, const char *hduclas1, const char *hduclas2)
Load data from a MEF component of specified type.
const char * enu_get_filter(const cpl_propertylist *plist)
Get the filter used in an observation.
cpl_error_code enu_check_wcs(const located_image *limage)
Check that the image has valid WCS keywords.
cpl_error_code enu_get_rcore_and_mesh_size(const char *context, const cpl_parameterlist *parlist, const cpl_propertylist *plist, double *obj_core_radius, int *bkg_mesh_size)
Get catalogue core-radius and mesh-size appropriate to AO mode.
located_imagelist * enu_located_imagelist_new(cpl_size size)
Return a pointer to a new located_imagelist.
hdrl_catalogue_result * enu_catalogue_compute(const hdrl_image *himage, const cpl_image *confidence, const cpl_wcs *wcs, hdrl_parameter *params)
Wrapper for hdrl_catalogue_compute.
cpl_error_code enu_opm_limlist(const int obj_min_pixels, const double obj_threshold, const int bkg_mesh_size, const double bkg_smooth_fwhm, located_imagelist *limlist)
Calculate object masks for images in a located_imagelist.
const char * enu_get_det_mode(const cpl_propertylist *plist)
Get the detector mode of an integration.
cpl_error_code enu_sky_backgrounds(const char *method, const char *select_method, const double timerange, const located_imagelist *target_list, const located_imagelist *sky_list, const cpl_size x_probe, const cpl_size y_probe, hdrl_imagelist **sky_himagelist, cpl_imagelist **sky_confidence_list)
Get sky backgrounds for a list of target images.
double enu_get_dit(const cpl_propertylist *plist)
Get the DIT of an integration.
double enu_get_filter_wavelength(const char *filter)
Get the effective wavelength of a filter.
mef_extension_list * enu_load_mef_components(const char *filename, cpl_propertylist **plist)
Load components of a multi-extension FITS file.
hdrl_catalogue_result * hdrl_catalogue_compute(const cpl_image *image_, const cpl_image *confidence_map, const cpl_wcs *wcs, hdrl_parameter *param_)
build object catalog
void hdrl_catalogue_result_delete(hdrl_catalogue_result *result)
delete hdrl parameter result object
hdrl_parameter * hdrl_collapse_mode_parameter_create(double histo_min, double histo_max, double bin_size, hdrl_mode_type mode_method, cpl_size error_niter)
create a parameter object for the mode
hdrl_parameter * hdrl_flat_parameter_create(cpl_size filter_size_x, cpl_size filter_size_y, hdrl_flat_method method)
Creates FLAT Parameters object.
cpl_error_code hdrl_flat_compute(hdrl_imagelist *hdrl_data, const cpl_mask *stat_mask, const hdrl_parameter *collapse_params, hdrl_parameter *flat_params, hdrl_image **master, cpl_image **contrib_map)
compute high or low frequency master flat with median filtering
hdrl_value hdrl_image_get_pixel(const hdrl_image *self, cpl_size xpos, cpl_size ypos, int *pis_rejected)
get pixel values of hdrl_image
cpl_error_code hdrl_image_sub_image(hdrl_image *self, const hdrl_image *other)
Subtract two images, store the result in the first image.
cpl_error_code hdrl_image_reject_from_mask(hdrl_image *self, const cpl_mask *map)
set bpm of hdrl_image
hdrl_value hdrl_image_get_median(const hdrl_image *self)
computes the median and associated error of an image.
cpl_error_code hdrl_image_div_image(hdrl_image *self, const hdrl_image *other)
Divide two images, store the result in the first image.
hdrl_image * hdrl_image_duplicate(const hdrl_image *himg)
copy hdrl_image
double hdrl_image_get_stdev(const hdrl_image *self)
computes the standard deviation of the data of an image
cpl_error_code hdrl_image_copy(hdrl_image *dst, const hdrl_image *src, cpl_size xpos, cpl_size ypos)
Copy one image into another.
cpl_mask * hdrl_image_get_mask(hdrl_image *himg)
get cpl bad pixel mask from image
hdrl_image * hdrl_image_extract(const hdrl_image *self, cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury)
extract copy of window from image
cpl_image * hdrl_image_get_error(hdrl_image *himg)
get error as cpl image
hdrl_value hdrl_image_get_mean(const hdrl_image *self)
computes mean pixel value and associated error of an image.
cpl_size hdrl_image_get_size_y(const hdrl_image *self)
return size of Y dimension of image
cpl_size hdrl_image_get_size_x(const hdrl_image *self)
return size of X dimension of image
hdrl_image * hdrl_image_create(const cpl_image *image, const cpl_image *error)
create a new hdrl_image from to existing images by copying them
cpl_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
cpl_error_code hdrl_image_reject(hdrl_image *self, cpl_size xpos, cpl_size ypos)
mark pixel as bad
const cpl_image * hdrl_image_get_image_const(const hdrl_image *himg)
get data as cpl image
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
cpl_error_code hdrl_imagelist_collapse_mean(const hdrl_imagelist *himlist, hdrl_image **out, cpl_image **contrib)
Mean collapsing of image list.
cpl_error_code hdrl_imagelist_set(hdrl_imagelist *himlist, hdrl_image *himg, cpl_size pos)
Insert an image into an imagelist.
cpl_size hdrl_imagelist_get_size_y(const hdrl_imagelist *himlist)
Get number of rows of images in the imagelist.
hdrl_imagelist * hdrl_imagelist_create(cpl_imagelist *imlist, cpl_imagelist *errlist)
Create an hdrl_imagelist out of 2 cpl_imagelist.
void hdrl_imagelist_delete(hdrl_imagelist *himlist)
Free all memory used by a hdrl_imagelist object including the images.
const hdrl_image * hdrl_imagelist_get_const(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.
cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *himlist)
Get the number of images in the imagelist.
cpl_error_code hdrl_imagelist_collapse(const hdrl_imagelist *himlist, const hdrl_parameter *param, hdrl_image **out, cpl_image **contrib)
collapsing of image list
hdrl_imagelist * hdrl_imagelist_new(void)
Create an empty imagelist.
cpl_error_code hdrl_imagelist_collapse_median(const hdrl_imagelist *himlist, hdrl_image **out, cpl_image **contrib)
Median collapsing of image list.
hdrl_imagelist * hdrl_imagelist_duplicate(const hdrl_imagelist *himlist)
Duplicate an image list.
cpl_size hdrl_imagelist_get_size_x(const hdrl_imagelist *himlist)
Get number of colums of images in the imagelist.
cpl_error_code hdrl_imagelist_collapse_weighted_mean(const hdrl_imagelist *himlist, hdrl_image **out, cpl_image **contrib)
Weighted Mean collapsing of image list.
hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.
cpl_error_code hdrl_maglim_compute(const cpl_image *image, const double zeropoint, const double fwhm, const cpl_size kernel_size_x, const cpl_size kernel_size_y, const hdrl_image_extend_method image_extend_method, const hdrl_parameter *mode_parameter, double *limiting_magnitude)
Computes the limiting magnitude of an image.
void hdrl_parameter_delete(hdrl_parameter *obj)
shallow delete of a parameter
double fraction(double x, double y, double r_out)
Fraction of pixel bounded.