34#include <eris_ifu_resample.h>
35#include <eris_ifu_dfs.h>
36#include <eris_ifu_utils.h>
37#include <eris_utils.h>
38#include <eris_pfits.h>
39#include <eris_ifu_sdp.h>
47#define MAX_COMBINE_CUBE_PLANE_DIAGONAL 1000
58eris_ifu_resample_update_table(
const cpl_table* append, cpl_table** storage) {
60 cpl_ensure_code(append, CPL_ERROR_NULL_INPUT);
62 if(*storage == NULL) {
63 *storage = cpl_table_new(0);
64 cpl_table_copy_structure(*storage, append);
65 cpl_table_insert(*storage, append, 0);
67 cpl_size nrow = cpl_table_get_nrow(*storage);
68 cpl_table_insert(*storage, append, nrow);
71 return cpl_error_get_code();
87eris_ifu_resample_tablesave (
const char* recipe_name,
const cpl_parameter *par,
88 const cpl_parameterlist *parlist, cpl_frameset *frameset,
89 cpl_table *tab_final,
const char* pipefile_prefix)
92 char* param_name = cpl_sprintf(
"eris.%s.save-table", recipe_name);
93 par = cpl_parameterlist_find_const (parlist, param_name);
96 const cpl_boolean save_table = cpl_parameter_get_bool (par);
100 cpl_msg_info (cpl_func,
"Saving the table before resampling");
101 cpl_propertylist *applist = cpl_propertylist_new ();
102 cpl_propertylist_update_string (applist, CPL_DFS_PRO_CATG,
104 char* fname = cpl_sprintf(
"%s_resample_table.fits", pipefile_prefix);
105 cpl_dfs_save_table (frameset, NULL, parlist, frameset, NULL, tab_final,
106 NULL, recipe_name, applist, NULL, PACKAGE
"/" PACKAGE_VERSION,
109 cpl_propertylist_delete (applist);
112 return cpl_error_get_code();
129eris_ifu_resample_parameters_get_int(
const cpl_parameterlist* parlist,
130 const char* pname,
int *pvalue)
132 const cpl_parameter* p = cpl_parameterlist_find_const(parlist, pname);
135 if ( cpl_parameter_get_default_flag(p) && p_has_changed != CPL_FALSE) {
136 *pvalue = cpl_parameter_get_int(p);
138 *pvalue = cpl_parameter_get_default_int(p);
141 return cpl_error_get_code();
158set_double_from_parameters(
const cpl_parameterlist* parlist,
160 const double table_value,
165 if (temp_value != -1)
171 *value = table_value;
174 return cpl_error_get_code();
192set_int_from_parameters(
const cpl_parameterlist* parlist,
194 const int table_value,
198 eris_ifu_resample_parameters_get_int (parlist, pname, &temp_value);
199 if (temp_value != -1)
205 *value = table_value;
208 return cpl_error_get_code();
221static hdrl_parameter *
222eris_ifu_resample_set_method (
const cpl_parameterlist *parlist,
225 hdrl_parameter *aParams_method = NULL;
226 const cpl_parameter *p = NULL;
227 cpl_boolean p_has_changed = 0;
228 int loop_distance = 0;
229 double critical_radius_renka = 0.;
230 int kernel_size_lanczos = 0;
231 double pix_frac_drizzle_x = 0.;
232 double pix_frac_drizzle_y= 0.;
233 double pix_frac_drizzle_l= 0.;
234 cpl_boolean use_errorweights = FALSE;
236 const cpl_parameter *par = NULL;
237 char* param_name = NULL;
240 param_name = cpl_sprintf(
"%s.method.use-errorweights",context);
241 par = cpl_parameterlist_find_const (parlist, param_name);
242 use_errorweights = cpl_parameter_get_bool (par);
243 cpl_free(param_name);
246 param_name = cpl_sprintf(
"%s.method.loop-distance",context);
247 p = cpl_parameterlist_find_const (parlist, param_name);
250 if (cpl_parameter_get_default_flag (p) && p_has_changed != CPL_FALSE)
252 loop_distance = cpl_parameter_get_int (p);
256 loop_distance = LOOP_DISTANCE;
258 cpl_free(param_name);
261 param_name = cpl_sprintf(
"%s.method.renka.critical-radius",context);
262 set_double_from_parameters(parlist, param_name,
263 RENKA_CRITICAL_RADIUS, &critical_radius_renka);
264 cpl_free(param_name);
267 param_name = cpl_sprintf(
"%s.method.lanczos.kernel-size",context);
268 set_int_from_parameters(parlist, param_name,
269 LANCZOS_KERNEL_SIZE, &kernel_size_lanczos);
270 cpl_free(param_name);
277 param_name = cpl_sprintf(
"%s.method.drizzle.downscale-x",context);
278 set_double_from_parameters(parlist, param_name, DRIZZLE_DOWN_SCALING_FACTOR_X,
279 &pix_frac_drizzle_x);
280 cpl_free(param_name);
282 param_name = cpl_sprintf(
"%s.method.drizzle.downscale-y",context);
283 set_double_from_parameters(parlist, param_name, DRIZZLE_DOWN_SCALING_FACTOR_Y,
284 &pix_frac_drizzle_y);
285 cpl_free(param_name);
287 param_name = cpl_sprintf(
"%s.method.drizzle.downscale-z",context);
288 set_double_from_parameters(parlist, param_name, DRIZZLE_DOWN_SCALING_FACTOR_Z,
289 &pix_frac_drizzle_l);
290 cpl_free(param_name);
293 param_name = cpl_sprintf(
"%s.method",context);
294 par = cpl_parameterlist_find_const (parlist, param_name);
295 const char *method = cpl_parameter_get_string (par);
297 if (strcmp (method,
"NEAREST") == 0)
301 else if (strcmp (method,
"RENKA") == 0)
305 critical_radius_renka);
307 else if (strcmp (method,
"LINEAR") == 0)
312 else if (strcmp (method,
"QUADRATIC") == 0)
317 else if (strcmp (method,
"DRIZZLE") == 0)
325 else if (strcmp (method,
"LANCZOS") == 0)
329 kernel_size_lanczos);
335 kernel_size_lanczos);
336 cpl_msg_warning (cpl_func,
337 "%s is an unsupported method! Default to LANCZOS",
340 cpl_free(param_name);
343 return aParams_method;
359eris_ifu_resample_get_cdelt123(cpl_wcs *wcs,
double *cdelt1,
double *cdelt2,
362 cpl_ensure_code(wcs, CPL_ERROR_NULL_INPUT);
363 cpl_ensure_code(cdelt1, CPL_ERROR_NULL_INPUT);
364 cpl_ensure_code(cdelt2, CPL_ERROR_NULL_INPUT);
375 const cpl_matrix *cd = cpl_wcs_get_cd(wcs);
376 cd1_1 = cpl_matrix_get(cd, 0, 0);
377 cd1_2 = cpl_matrix_get(cd, 1, 0);
378 cd2_1 = cpl_matrix_get(cd, 0, 1);
379 cd2_2 = cpl_matrix_get(cd, 1, 1);
381 dx = sqrt(pow(cd1_1,2) + pow(cd2_1,2));
382 dy = sqrt(pow(cd1_2,2)+ pow(cd2_2,2));
394 cpl_size cdncol = cpl_matrix_get_ncol(cd);
396 cd3_3= fabs(cpl_matrix_get(cd, 2, 2));
405 cpl_msg_debug(cpl_func,
"cdelt1: %g, cdelt2: %g, cdelt3: %g",
406 *cdelt1, *cdelt2, *cdelt3);
408 return cpl_error_get_code();
422static hdrl_parameter *
423eris_ifu_resample_set_outputgrid (
const char* recipe_name,
424 const cpl_parameterlist *parlist, cpl_table *muse_table, cpl_wcs *wcs)
427 cpl_error_ensure(parlist != NULL, CPL_ERROR_NULL_INPUT,
428 return NULL,
"NULL Input Parameters");
429 cpl_error_ensure(muse_table != NULL, CPL_ERROR_NULL_INPUT,
430 return NULL,
"NULL Input table");
431 cpl_error_ensure(wcs != NULL, CPL_ERROR_NULL_INPUT,
432 return NULL,
"NULL Input wcs");
434 hdrl_parameter *aParams_outputgrid = NULL;
435 char* param_name = NULL;
436 char* context = NULL;
441 double lambda_min = 0.;
442 double lambda_max = 0.;
448 context = cpl_sprintf(
"eris.%s", recipe_name);
452 cpl_table_get_column_min (muse_table, HDRL_RESAMPLE_TABLE_RA);
454 cpl_table_get_column_max (muse_table, HDRL_RESAMPLE_TABLE_RA);
456 cpl_table_get_column_min (muse_table, HDRL_RESAMPLE_TABLE_DEC);
458 cpl_table_get_column_max (muse_table, HDRL_RESAMPLE_TABLE_DEC);
459 double lambda_min_tmp =
460 cpl_table_get_column_min (muse_table, HDRL_RESAMPLE_TABLE_LAMBDA);
461 double lambda_max_tmp =
462 cpl_table_get_column_max (muse_table, HDRL_RESAMPLE_TABLE_LAMBDA);
465 if(ra_max_tmp - ra_min_tmp > 180){
466 const double *ra = cpl_table_get_data_double_const(muse_table,
467 HDRL_RESAMPLE_TABLE_RA);
476 cpl_size nrow = cpl_table_get_nrow(muse_table);
478 for (cpl_size i = 0; i < nrow; i++) {
479 if (ra[i] > ra_min_tmp && ra[i] <= 180.) ra_min_tmp = ra[i];
480 if (ra[i] < ra_max_tmp && ra[i] > 180.) ra_max_tmp = ra[i];
485 cpl_msg_debug (cpl_func,
"min x %10.7f", ra_min_tmp);
486 cpl_msg_debug (cpl_func,
"max x %10.7f", ra_max_tmp);
487 cpl_msg_debug (cpl_func,
"min y %10.7f", dec_min_tmp);
488 cpl_msg_debug (cpl_func,
"max y %10.7f", dec_max_tmp);
489 cpl_msg_debug (cpl_func,
"min lambda %10.7f", lambda_min_tmp);
490 cpl_msg_debug (cpl_func,
"max lambda %10.7f", lambda_max_tmp);
509 dec_min = dec_min_tmp;
516 dec_max = dec_max_tmp;
527 lambda_max = lambda_max_tmp;
531 double cdelt1 = 0., cdelt2 = 0., cdelt3 = 0.;
532 eris_ifu_resample_get_cdelt123 (wcs, &cdelt1, &cdelt2, &cdelt3);
556 const cpl_parameter *par = NULL;
557 param_name = cpl_sprintf(
"%s.fieldmargin", context);
558 par = cpl_parameterlist_find_const (parlist, param_name);
559 cpl_free(param_name);
561 double fieldmargin = 0.;
562 fieldmargin = cpl_parameter_get_double(par);
565 int naxis = cpl_wcs_get_image_naxis(wcs);
581 lambda_min, lambda_max,
585 double dist_x = (ra_max-ra_min)/dx;
586 double dist_y = (dec_max-dec_min)/dy;
588 cpl_msg_debug(cpl_func,
"size1: %g size2: %g",dist_x, dist_y);
589 double dist = sqrt(dist_x * dist_x + dist_y * dist_y);
590 cpl_msg_info(cpl_func,
"Output cube diagonal size: %g", dist);
591 if ( dist > MAX_COMBINE_CUBE_PLANE_DIAGONAL) {
592 cpl_msg_info(cpl_func,
"Internal threshold on max cube plane diagonal size: %d",MAX_COMBINE_CUBE_PLANE_DIAGONAL);
593 cpl_msg_warning(cpl_func,
"Resampled cube plane diagonal greater than threshold. Skip cube combination.");
594 cpl_error_set(cpl_func,CPL_ERROR_INCOMPATIBLE_INPUT);
596 return aParams_outputgrid;
601 return aParams_outputgrid;
614static hdrl_parameter *
615eris_ifu_resample_set_outputgrid2D (
const char* recipe_name,
616 const cpl_parameterlist *parlist, cpl_table *muse_table, cpl_wcs *wcs)
619 cpl_error_ensure(parlist != NULL, CPL_ERROR_NULL_INPUT,
620 return NULL,
"NULL Input Parameters");
621 cpl_error_ensure(muse_table != NULL, CPL_ERROR_NULL_INPUT,
622 return NULL,
"NULL Input table");
623 cpl_error_ensure(wcs != NULL, CPL_ERROR_NULL_INPUT,
624 return NULL,
"NULL Input wcs");
626 hdrl_parameter *aParams_outputgrid = NULL;
627 char* param_name = NULL;
628 char* context = NULL;
637 context = cpl_sprintf(
"eris.%s", recipe_name);
641 cpl_table_get_column_min (muse_table, HDRL_RESAMPLE_TABLE_RA);
643 cpl_table_get_column_max (muse_table, HDRL_RESAMPLE_TABLE_RA);
645 cpl_table_get_column_min (muse_table, HDRL_RESAMPLE_TABLE_DEC);
647 cpl_table_get_column_max (muse_table, HDRL_RESAMPLE_TABLE_DEC);
652 if(ra_max_tmp - ra_min_tmp > 180){
653 const double *ra = cpl_table_get_data_double_const(muse_table,
654 HDRL_RESAMPLE_TABLE_RA);
663 cpl_size nrow = cpl_table_get_nrow(muse_table);
665 for (cpl_size i = 0; i < nrow; i++) {
666 if (ra[i] > ra_min_tmp && ra[i] <= 180.) ra_min_tmp = ra[i];
667 if (ra[i] < ra_max_tmp && ra[i] > 180.) ra_max_tmp = ra[i];
672 cpl_msg_debug (cpl_func,
"min x %10.7f", ra_min_tmp);
673 cpl_msg_debug (cpl_func,
"max x %10.7f", ra_max_tmp);
674 cpl_msg_debug (cpl_func,
"min y %10.7f", dec_min_tmp);
675 cpl_msg_debug (cpl_func,
"max y %10.7f", dec_max_tmp);
694 dec_min = dec_min_tmp;
701 dec_max = dec_max_tmp;
706 double cdelt1 = 0., cdelt2 = 0., cdelt3 = 0.;
707 eris_ifu_resample_get_cdelt123 (wcs, &cdelt1, &cdelt2, &cdelt3);
722 const cpl_parameter *par = NULL;
723 param_name = cpl_sprintf(
"%s.fieldmargin", context);
724 par = cpl_parameterlist_find_const (parlist, param_name);
725 cpl_free(param_name);
727 double fieldmargin = 0.;
728 fieldmargin = cpl_parameter_get_double(par);
740 double dist_x = (ra_max-ra_min)/dx;
741 double dist_y = (dec_max-dec_min)/dy;
743 cpl_msg_debug(cpl_func,
"size1: %g size2: %g",dist_x, dist_y);
744 double dist = sqrt(dist_x * dist_x + dist_y * dist_y);
745 cpl_msg_debug(cpl_func,
"Output cube diagonal size: %g", dist);
746 if ( dist > MAX_COMBINE_CUBE_PLANE_DIAGONAL) {
747 cpl_msg_info(cpl_func,
"Internal threshold on max cube plane diagonal size: %d",MAX_COMBINE_CUBE_PLANE_DIAGONAL);
748 cpl_msg_warning(cpl_func,
"Resampled cube plane diagonal %g greater than threshold. Skip cube combination.", dist);
749 cpl_error_set(cpl_func,CPL_ERROR_INCOMPATIBLE_INPUT);
751 return aParams_outputgrid;
756 return aParams_outputgrid;
779 const char *filename,
780 const cpl_parameterlist *parlist,
781 cpl_frameset *frameset,
782 cpl_boolean gen_phase3)
785 cpl_ensure_code(aCube && aCube->header, CPL_ERROR_NULL_INPUT);
789 cpl_propertylist* dataHeader;
790 cpl_propertylist* errsHeader;
791 cpl_propertylist* qualHeader;
794 deqErrorType errorType = rmse;
795 deqQualityType qualityType = flag16bit;
796 char* pipe_id = cpl_sprintf(
"%s%s%s", PACKAGE,
"/", PACKAGE_VERSION);
799 if(cpl_propertylist_has(aCube->header,
"CDELT3")) {
800 cpl_propertylist_erase(aCube->header,
"CDELT3");
803 if(!cpl_propertylist_has(aCube->header, CUNIT3)) {
804 cpl_propertylist_append_string(aCube->header,
"CUNIT3",
"um");
806 if(!cpl_propertylist_has(aCube->header,
"BUNIT")) {
807 cpl_propertylist_append_string(aCube->header,
"BUNIT", UNIT_ADU);
811 dataHeader = cpl_propertylist_duplicate(aCube->header);
812 errsHeader = cpl_propertylist_duplicate(aCube->header);
813 qualHeader = cpl_propertylist_duplicate(aCube->header);
814 cpl_propertylist_update_string(qualHeader,
"BUNIT",
"");
825 if(cpl_propertylist_has(dataHeader,
"CTYPE1")) {
826 const char* ctype1 = cpl_propertylist_get_string(dataHeader,
"CTYPE1");
827 if (!cpl_propertylist_has(errsHeader,
"CTYPE1"))
828 cpl_propertylist_append_string(errsHeader,
"CTYPE1", ctype1);
829 if (!cpl_propertylist_has(qualHeader,
"CTYPE1"))
830 cpl_propertylist_append_string(qualHeader,
"CTYPE1", ctype1);
832 if(cpl_propertylist_has(dataHeader,
"CTYPE2")) {
833 const char* ctype2 = cpl_propertylist_get_string(dataHeader,
"CTYPE2");
834 if (!cpl_propertylist_has(errsHeader,
"CTYPE2"))
835 cpl_propertylist_append_string(errsHeader,
"CTYPE2",ctype2);
836 if (!cpl_propertylist_has(errsHeader,
"CTYPE2"))
837 cpl_propertylist_append_string(qualHeader,
"CTYPE2", ctype2);
840 cpl_propertylist* applist = cpl_propertylist_duplicate(aCube->header);
848 eris_ifu_sdp_properties * prop = eris_ifu_sdp_properties_collect(aCube,
849 frameset, parlist, recipe);
851 eris_ifu_sdp_properties_update(applist, prop);
853 eris_ifu_sdp_properties_delete(prop);
857 eris_ifu_plist_erase_wcs(applist);
858 eris_pfits_clean_header(dataHeader, CPL_TRUE);
859 eris_pfits_clean_header(errsHeader, CPL_TRUE);
860 eris_pfits_clean_header(qualHeader, CPL_TRUE);
861 cpl_propertylist_append_string(applist,
"PRODCATG",
"SCIENCE.CUBE.IFS");
863 cpl_propertylist_update_string(applist, CPL_DFS_PRO_CATG, procatg);
864 if(cpl_propertylist_has(applist,
"BUNIT")) {
865 cpl_propertylist_erase(applist,
"BUNIT");
867 if(cpl_propertylist_has(applist,
"COMMENT")) {
868 cpl_msg_warning(cpl_func,
"remove comments");
869 cpl_propertylist_erase(applist,
"COMMENT");
871 if(cpl_propertylist_has(dataHeader,
"COMMENT")) {
872 cpl_msg_warning(cpl_func,
"remove comments");
873 cpl_propertylist_erase(dataHeader,
"COMMENT");
875 cpl_dfs_save_propertylist(frameset, NULL, parlist, frameset,
876 NULL, recipe, applist,
"RADECSYS", pipe_id, filename);
878 cpl_imagelist* data = cpl_imagelist_new();
879 cpl_imagelist* errs = cpl_imagelist_new();
880 cpl_imagelist* qual = cpl_imagelist_new();
885 cpl_type data_type = cpl_image_get_type(cpl_imagelist_get(data,0));
887 cpl_imagelist_save(data, filename, data_type, dataHeader, CPL_IO_EXTEND);
888 cpl_imagelist_save(errs, filename, data_type, errsHeader, CPL_IO_EXTEND);
889 cpl_imagelist_save(qual, filename, CPL_TYPE_INT, qualHeader, CPL_IO_EXTEND);
890 cpl_size ix_max = cpl_imagelist_get_size(data);
892 for (cpl_size ix=ix_max-1; ix >= 0; ix--) {
893 cpl_imagelist_unset(data, ix);
894 cpl_imagelist_unset(errs, ix);
895 q=cpl_imagelist_unset(qual, ix);
899 cpl_imagelist_delete(data);
900 cpl_imagelist_delete(errs);
901 cpl_imagelist_delete(qual);
903 cpl_propertylist_delete(applist);
923 return cpl_error_get_code();
941eris_ifu_resample_get_wcs_from_frameset(cpl_frameset* frameset,
942 const char* procatg) {
944 cpl_ensure(frameset, CPL_ERROR_NULL_INPUT, NULL);
947 cpl_frameset* in_set = NULL;
950 cpl_error_set_message(cpl_func, CPL_ERROR_FILE_NOT_FOUND,
"Missing RAW "
955 cpl_frame* frame = cpl_frameset_get_position(in_set, 0);
956 const char* fname = cpl_frame_get_filename(frame);
960 cpl_propertylist* head = NULL;
962 cpl_errorstate prestate = cpl_errorstate_get();
963 head = cpl_propertylist_load(fname, 0);
964 wcs = cpl_wcs_new_from_propertylist(head);
967 cpl_errorstate_set(prestate);
968 cpl_propertylist_delete(head);
970 cpl_propertylist_delete(head);
971 cpl_frameset_delete(in_set);
975 prestate = cpl_errorstate_get();
976 head = cpl_propertylist_load(fname, 1);
977 wcs = cpl_wcs_new_from_propertylist(head);
978 cpl_propertylist_delete(head);
979 cpl_frameset_delete(in_set);
1003eris_ifu_resample_frameset_to_table(
const cpl_frame *data_frm,
1004 const cpl_size data_ext_id,
1005 const cpl_frame *errs_frm,
1006 const cpl_size errs_ext_id,
1007 const cpl_frame *qual_frm,
1008 const cpl_size qual_ext_id,
1009 const cpl_boolean is_variance,
1010 const cpl_boolean subtract_bkg,
1014 cpl_ensure(data_frm, CPL_ERROR_NULL_INPUT, NULL);
1015 cpl_msg_severity level = cpl_msg_get_level();
1016 cpl_msg_set_level(CPL_MSG_INFO);
1017 const char *name = cpl_frame_get_filename(data_frm);
1018 cpl_imagelist *dlist = NULL;
1019 cpl_imagelist *elist = NULL;
1020 cpl_imagelist *qlist = NULL;
1022 cpl_table *tab_ext = NULL;
1024 cpl_errorstate prestate = cpl_errorstate_get();
1026 dlist = cpl_imagelist_load(name, CPL_TYPE_DOUBLE, data_ext_id);
1028 if (dlist == NULL) {
1030 if (!cpl_errorstate_is_equal(prestate)) {
1031 cpl_errorstate_set(prestate);
1036 cpl_propertylist *xheader_data = cpl_propertylist_load(name,
1038 cpl_wcs *wcs = cpl_wcs_new_from_propertylist(xheader_data);
1040 if (errs_frm != NULL) {
1041 name = cpl_frame_get_filename(errs_frm);
1042 elist = cpl_imagelist_load(name, CPL_TYPE_DOUBLE, errs_ext_id);
1045 cpl_imagelist_power(elist, 0.5);
1048 if (qual_frm != NULL) {
1049 name = cpl_frame_get_filename(qual_frm);
1050 qlist = cpl_imagelist_load(name, CPL_TYPE_INT, qual_ext_id);
1053 cpl_size size = cpl_imagelist_get_size(dlist);
1056 if (qual_frm != NULL && size > 0){
1057 for(cpl_size k = 0; k < size; k++) {
1058 cpl_image* data = cpl_imagelist_get(dlist, k);
1059 cpl_image* qual = cpl_imagelist_get(qlist, k);
1063 cpl_mask* mask = cpl_mask_threshold_image_create(qual, 0, INT_MAX);
1065 cpl_image_reject_from_mask(data, mask);
1066 cpl_mask_delete(mask);
1067 cpl_imagelist_set(dlist, data, k);
1074 if(elist != NULL && is_variance){
1075 for(cpl_size k = 0; k < size; k++) {
1076 cpl_image* data = cpl_imagelist_get(dlist, k);
1077 cpl_mask* data_mask = cpl_image_get_bpm(data);
1079 cpl_image* error = cpl_imagelist_get(elist, k);
1080 cpl_mask* error_mask = cpl_image_get_bpm(error);
1082 cpl_mask* merged = cpl_mask_duplicate(data_mask);
1085 cpl_mask_or(merged, error_mask);
1086 cpl_image_reject_from_mask(data, merged);
1087 cpl_image_reject_from_mask(error, merged);
1088 cpl_mask_delete(merged);
1093 hdrl_imagelist* hlist = NULL;
1097 int edge_trim = edgetrim;
1098 if (edge_trim > 0) {
1099 cpl_msg_info(cpl_func,
"Trim input image edges of %d pixels", edge_trim);
1104 if (edge_trim >= 0.5* sx) {
1106 cpl_msg_warning(cpl_func,
"edge-trim must be smaller than half image "
1107 "size. Reset to 0");
1109 if (edge_trim >= 0.5* sy) {
1111 cpl_msg_warning(cpl_func,
"edge-trim must be smaller than half image "
1112 "size. Reset to 0");
1114 for(cpl_size k = 0; k < sz; k++) {
1119 for(cpl_size j = 1; j <= edge_trim; j++) {
1120 for(cpl_size i = 1; i <= sx; i++) {
1125 for(cpl_size j = sy - edge_trim + 1; j <= sy; j++) {
1126 for(cpl_size i = 1; i <= sx; i++) {
1131 for(cpl_size j = 1; j <= sy; j++) {
1132 for(cpl_size i = 1; i <= edge_trim; i++) {
1137 for(cpl_size j = 1; j <= sy; j++) {
1138 for(cpl_size i = sx - edge_trim + 1; i <= sx; i++) {
1147 cpl_imagelist_delete(dlist);
1148 if (qual_frm != NULL)
1149 cpl_imagelist_delete(qlist);
1150 if (errs_frm != NULL)
1151 cpl_imagelist_delete(elist);
1156 cpl_msg_info(cpl_func,
"Reading the image ...");
1160 if(subtract_bkg == CPL_TRUE) {
1161 cpl_msg_info(cpl_func,
"Subtracting the median as requested ...");
1168 cpl_msg_info(cpl_func,
"Converting imagelist to table with hdrl function");
1175 cpl_wcs_delete(wcs);
1176 cpl_propertylist_delete(xheader_data);
1178 cpl_msg_set_level(level);
1192static cpl_error_code
1193eris_ifu_resample_wcs_print(cpl_wcs *wcs)
1195 cpl_ensure_code(wcs, CPL_ERROR_NULL_INPUT);
1197 const cpl_array *crval = cpl_wcs_get_crval(wcs);
1198 const cpl_array *crpix = cpl_wcs_get_crpix(wcs);
1199 const cpl_array *ctype = cpl_wcs_get_ctype(wcs);
1200 const cpl_array *cunit = cpl_wcs_get_cunit(wcs);
1202 const cpl_matrix *cd = cpl_wcs_get_cd(wcs);
1203 const cpl_array *dims = cpl_wcs_get_image_dims(wcs);
1204 cpl_size naxis = cpl_wcs_get_image_naxis(wcs);
1206 cpl_msg_info(cpl_func,
"NAXIS: %lld", naxis);
1209 cpl_msg_indent_more();
1211 for (cpl_size i = 0; i < naxis; i++) {
1212 cpl_msg_info(cpl_func,
"NAXIS%lld: %d", i + 1,
1213 cpl_array_get_int(dims, i, &testerr));
1215 cpl_msg_indent_less();
1217 double cd11 = cpl_matrix_get(cd, 0, 0);
1218 double cd12 = cpl_matrix_get(cd, 0, 1);
1219 double cd21 = cpl_matrix_get(cd, 1, 0);
1220 double cd22 = cpl_matrix_get(cd, 1, 1);
1221 double crpix1 = cpl_array_get_double(crpix, 0, &testerr);
1222 double crpix2 = cpl_array_get_double(crpix, 1, &testerr);
1223 double crval1 = cpl_array_get_double(crval, 0, &testerr);
1224 double crval2 = cpl_array_get_double(crval, 1, &testerr);
1226 cpl_msg_info(cpl_func,
"1st and 2nd dimension");
1227 cpl_msg_indent_more();
1228 cpl_msg_info(cpl_func,
"CD1_1: %g", cd11);
1229 cpl_msg_info(cpl_func,
"CD1_2: %g", cd12);
1230 cpl_msg_info(cpl_func,
"CD2_1: %g", cd21);
1231 cpl_msg_info(cpl_func,
"CD2_2: %g", cd22);
1233 cpl_msg_info(cpl_func,
"CRPIX1: %g", crpix1);
1234 cpl_msg_info(cpl_func,
"CRPIX2: %g", crpix2);
1235 cpl_msg_info(cpl_func,
"CRVAL1: %f", crval1);
1236 cpl_msg_info(cpl_func,
"CRVAL2: %f", crval2);
1238 cpl_msg_info(cpl_func,
"CTYPE1: %s", cpl_array_get_string(ctype, 0));
1239 cpl_msg_info(cpl_func,
"CTYPE2: %s", cpl_array_get_string(ctype, 1));
1243 cpl_msg_info(cpl_func,
"CUNIT1: %s", cpl_array_get_string(cunit, 0));
1244 cpl_msg_info(cpl_func,
"CUNIT2: %s", cpl_array_get_string(cunit, 1));
1246 cpl_msg_indent_less();
1249 cpl_size cdncol = cpl_matrix_get_ncol(cd);
1252 double cd13 = cpl_matrix_get(cd, 0, 2);
1253 double cd23 = cpl_matrix_get(cd, 1, 2);
1254 double cd31 = cpl_matrix_get(cd, 2, 0);
1255 double cd32 = cpl_matrix_get(cd, 2, 1);
1256 double cd33 = cpl_matrix_get(cd, 2, 2);
1257 double crval3 = cpl_array_get_double(crval, 2, &testerr);
1258 double crpix3 = cpl_array_get_double(crpix, 2, &testerr);
1260 cpl_msg_info(cpl_func,
"3rd dimension");
1261 cpl_msg_indent_more();
1262 cpl_msg_info(cpl_func,
"CD1_3: %g", cd13);
1263 cpl_msg_info(cpl_func,
"CD2_3: %g", cd23);
1264 cpl_msg_info(cpl_func,
"CD3_1: %g", cd31);
1265 cpl_msg_info(cpl_func,
"CD3_2: %g", cd32);
1266 cpl_msg_info(cpl_func,
"CD3_3: %g", cd33);
1268 cpl_msg_info(cpl_func,
"CRPIX3: %g", crpix3);
1269 cpl_msg_info(cpl_func,
"CRVAL3: %g", crval3);
1272 cpl_msg_info(cpl_func,
"CTYPE3: %s", cpl_array_get_string(ctype, 2));
1276 cpl_msg_info(cpl_func,
"CUNIT3: %s", cpl_array_get_string(cunit, 2));
1279 cpl_msg_indent_less();
1282 return cpl_error_get_code();
1303eris_ifu_resample_get_table_from_frameset(
const cpl_frame* data_frm,
1304 const cpl_frame* errs_frm,
1305 const cpl_frame* qual_frm,
1306 const cpl_size data_ext_id,
1307 const cpl_size errs_ext_id,
1308 const cpl_size qual_ext_id,
1309 const cpl_boolean is_variance,
1310 const cpl_boolean subtract_bkg,
1311 const int edge_trim) {
1313 cpl_ensure(data_frm, CPL_ERROR_NULL_INPUT, NULL);
1315 cpl_size next = cpl_frame_get_nextensions(data_frm);
1316 cpl_msg_info(cpl_func,
"Analysing and processing file %s",
1317 cpl_frame_get_filename(data_frm));
1325 cpl_msg_indent_more();
1326 cpl_table* table = NULL;
1327 if(data_ext_id != -1) {
1328 cpl_msg_info(cpl_func,
"Extension: %02lld", data_ext_id);
1330 table = eris_ifu_resample_frameset_to_table(data_frm, data_ext_id,
1331 errs_frm, errs_ext_id,
1332 qual_frm, qual_ext_id,
1333 is_variance, subtract_bkg, edge_trim);
1336 for (cpl_size i = 0; i < next + 1; i++ ) {
1337 cpl_table * table_local = NULL;
1338 cpl_msg_info(cpl_func,
"Extension: %02lld", i);
1339 table_local = eris_ifu_resample_frameset_to_table(data_frm, i,
1342 is_variance, subtract_bkg, edge_trim);
1345 if (table_local == NULL) {
1346 cpl_msg_info(cpl_func,
"No siutable data found - continuing");
1352 table = table_local;
1355 cpl_size nrow = cpl_table_get_nrow(table);
1356 cpl_table_insert(table, table_local, nrow);
1357 cpl_table_delete(table_local);
1362 cpl_msg_indent_less();
1588 cpl_frameset* frameset,
1589 const cpl_parameterlist* parlist,
1590 const char* recipe_name,
1592 cpl_boolean apply_flat,
1593 cpl_boolean is_pupil)
1595 hdrl_image* cube_collapsed = NULL;
1596 cpl_image* cube_cmap = NULL;
1598 cpl_frame* frame = cpl_frameset_find(frameset, pro_catg);
1599 const char* cube_fname = cpl_frame_get_filename(frame);
1600 cpl_propertylist* pheader = cpl_propertylist_load(cube_fname, 0);
1601 cpl_propertylist* head_wcs_2d = eris_ifu_plist_extract_wcs2D(pheader);
1602 cpl_propertylist* dheader = cpl_propertylist_load(cube_fname, 1);
1603 cpl_propertylist* eheader = cpl_propertylist_load(cube_fname, 2);
1604 cpl_propertylist* qheader = cpl_propertylist_load(cube_fname, 3);
1606 cpl_imagelist* iml_data = cpl_imagelist_load(cube_fname, CPL_TYPE_DOUBLE, 1);
1607 cpl_imagelist* iml_errs = cpl_imagelist_load(cube_fname, CPL_TYPE_DOUBLE, 2);
1608 cpl_imagelist* iml_qual = cpl_imagelist_load(cube_fname, CPL_TYPE_DOUBLE, 3);
1610 cpl_propertylist_append(dheader, head_wcs_2d);
1611 cpl_propertylist_append(eheader, head_wcs_2d);
1612 cpl_propertylist_append(qheader, head_wcs_2d);
1613 cpl_propertylist_delete(head_wcs_2d);
1616 double exptime = dit * ndit;
1618 cpl_size sz = cpl_imagelist_get_size(iml_data);
1619 cpl_image* data = NULL;
1620 cpl_image* errs = NULL;
1621 cpl_image* qual = NULL;
1622 cpl_mask* bpm_data = NULL;
1623 cpl_mask* bpm_errs = NULL;
1624 cpl_boolean edge_trim = CPL_TRUE;
1625 cpl_size k_center = 0.5 * sz;
1626 for(cpl_size k = 0; k < sz; k++) {
1627 data = cpl_imagelist_get(iml_data, k);
1628 errs = cpl_imagelist_get(iml_errs, k);
1629 qual = cpl_imagelist_get(iml_qual, k);
1630 cpl_image_reject_value(data, CPL_VALUE_NAN);
1631 cpl_image_reject_value(errs, CPL_VALUE_NAN);
1632 bpm_data = cpl_image_get_bpm(data);
1633 bpm_errs = cpl_image_get_bpm(errs);
1634 cpl_mask * bpm_mask = cpl_mask_threshold_image_create(qual, -0.5, 0.5) ;
1635 cpl_mask_not(bpm_mask) ;
1636 cpl_mask_or(bpm_mask,bpm_data);
1637 cpl_mask_or(bpm_mask,bpm_errs);
1638 cpl_image_reject_from_mask(data, bpm_mask);
1639 cpl_image_reject_from_mask(errs, bpm_mask);
1650 cpl_image* ima_time = NULL;
1651 cpl_image* err_time = NULL;
1652 hdrl_image *himg_exptime = NULL;
1653 if(apply_flat && k == k_center) {
1654 ima_time = cpl_image_new(cpl_image_get_size_x(data),
1655 cpl_image_get_size_y(data), CPL_TYPE_DOUBLE);
1656 err_time = cpl_image_new(cpl_image_get_size_x(data),
1657 cpl_image_get_size_y(data), CPL_TYPE_DOUBLE);
1660 cpl_image_add_scalar(ima_time, exptime);
1661 cpl_image_add_scalar(err_time, sqrt(exptime));
1665 if (edge_trim > 0) {
1676 cpl_image_delete(ima_time);
1677 cpl_image_delete(err_time);
1681 cpl_propertylist* phead2D = cpl_propertylist_duplicate(dheader);
1682 char* fname = cpl_sprintf(
"%s_exposure_map.fits", recipe_name);
1683 eris_ifu_plist_erase_wcs3D(phead2D);
1684 eris_ifu_plist_erase_expmap_extra_keys(phead2D);
1685 cpl_propertylist_update_string(phead2D, CPL_DFS_PRO_CATG, ERIS_IFU_PRO_JITTER_EXPOSURE_MAP);
1686 cpl_propertylist_update_string(phead2D,
"PRODCATG", PRODCATG_EXPOSUREMAP);
1688 recipe_name, phead2D,
"RADECSYS", fname,
1692 cpl_propertylist_delete(phead2D);
1698 cpl_mask_delete(bpm_mask) ;
1707 cpl_propertylist* phead2D = cpl_propertylist_duplicate(pheader);
1708 cpl_propertylist_erase_regexp(phead2D,NAXIS3,0);
1709 cpl_propertylist_erase_regexp(phead2D,CTYPE3,0);
1710 cpl_propertylist_erase_regexp(phead2D,CRVAL3,0);
1711 cpl_propertylist_erase_regexp(phead2D,CRPIX3,0);
1712 cpl_propertylist_erase_regexp(phead2D,CUNIT3, 0);
1713 cpl_propertylist_erase_regexp(phead2D,
"CD3_*",0);
1714 cpl_propertylist_erase_regexp(phead2D,CD1_3,0);
1715 cpl_propertylist_erase_regexp(phead2D,CD2_3,0);
1718 char* prefix = NULL;
1719 char* suffix = NULL;
1721 suffix = cpl_sprintf(
"%s",
"");
1723 suffix = cpl_sprintf(
"%s",
"_no_flat");
1725 if(strstr(recipe_name,
"jitter") != NULL ) {
1726 prefix = cpl_sprintf(
"eris_ifu_jitter%s", suffix);
1728 prefix = cpl_sprintf(
"eris_ifu_stdstar%s", suffix);
1731 const char* pcatg = NULL;
1732 if(strstr(pro_catg,
"OBJ") != NULL ) {
1733 fname = cpl_sprintf(
"%s_obj_cube_mean.fits", prefix);
1735 pcatg = ERIS_IFU_PRO_JITTER_OBJ_CUBE_MEAN;
1737 pcatg = ERIS_IFU_PRO_JITTER_OBJ_CUBE_NOFLAT_MEAN;
1739 }
else if(strstr(pro_catg, ERIS_IFU_PRO_JITTER_DAR_CUBE) != NULL ) {
1740 fname = cpl_sprintf(
"%s_dar_cube_mean.fits", prefix);
1742 pcatg = ERIS_IFU_PRO_JITTER_OBJ_DAR_CUBE_MEAN;
1744 pcatg = ERIS_IFU_PRO_JITTER_OBJ_CUBE_NOFLAT_MEAN;
1746 }
else if(strstr(pro_catg, ERIS_IFU_PRO_JITTER_TWK_CUBE) != NULL ) {
1747 fname = cpl_sprintf(
"%s_twk_cube_mean.fits", prefix);
1749 pcatg = ERIS_IFU_PRO_JITTER_TWK_CUBE_MEAN;
1751 pcatg = ERIS_IFU_PRO_JITTER_OBJ_CUBE_NOFLAT_MEAN;
1753 }
else if(strstr(pro_catg,
"STD") != NULL ) {
1754 fname = cpl_sprintf(
"%s_std_cube_mean.fits", prefix);
1756 pcatg = ERIS_IFU_PRO_JITTER_STD_CUBE_MEAN;
1758 pcatg = ERIS_IFU_PRO_JITTER_STD_CUBE_NOFLAT_MEAN;
1760 }
else if(strstr(pro_catg,
"PSF") != NULL ) {
1761 fname = cpl_sprintf(
"%s_psf_cube_mean.fits", prefix);
1763 pcatg = ERIS_IFU_PRO_JITTER_PSF_CUBE_MEAN;
1765 pcatg = ERIS_IFU_PRO_JITTER_PSF_CUBE_NOFLAT_MEAN;
1769 cpl_propertylist_update_string(phead2D, CPL_DFS_PRO_CATG, pcatg);
1780 cpl_size max_ima_x = 0;
1781 cpl_size max_ima_y = 0;
1782 cpl_image_get_maxpos(img, &max_ima_x, &max_ima_y);
1785 double max_ima_cx = cpl_image_get_centroid_x_window(img, 1, 1, sx, sy);
1786 double max_ima_cy = cpl_image_get_centroid_y_window(img, 1, 1, sx, sy);
1787 double xshift = max_ima_cx - (double) sx * 0.5;
1788 double yshift = max_ima_cy - (double) sy * 0.5;
1789 char* key_name = cpl_sprintf(
"QC PUPIL%d SHIFTX", 0);
1792 "[pix] X shift centroid - center image");
1795 key_name = cpl_sprintf(
"QC PUPIL%d SHIFTY", 0);
1797 "[pix] Y shift centroid - center image");
1798 cpl_msg_info(cpl_func,
"xshift: %g yshift: %g", xshift, yshift);
1802 cpl_free(qclog_tbl);
1807 recipe_name, phead2D,
"RADECSYS", fname,
1810 rmse, mask_ima, flag16bit, UNIT_ADU);
1812 cpl_image_delete(mask_ima);
1815 cpl_propertylist_delete(dheader);
1816 cpl_propertylist_delete(eheader);
1817 cpl_propertylist_delete(qheader);
1818 cpl_propertylist_delete(pheader);
1819 cpl_imagelist_delete(iml_data);
1820 cpl_imagelist_delete(iml_errs);
1821 cpl_imagelist_delete(iml_qual);
1823 cpl_image_delete(cube_cmap);
1826 return cpl_error_get_code();
1830eris_ifu_compute_max_cubes_dist(cpl_frameset* cube_set)
1833 double dist_max = -1;
1834 double dist_sqr = -1;
1835 cpl_size ncubes = cpl_frameset_get_size(cube_set);
1836 cpl_vector* vec_ra = cpl_vector_new(ncubes);
1837 cpl_vector* vec_dec = cpl_vector_new(ncubes);
1838 cpl_propertylist* plist = NULL;
1839 const char* name = NULL;
1840 double ra = 0, dec = 0;
1841 double ra1 = 0, dec1 = 0;
1842 double ra2 = 0, dec2 = 0;
1846 double pix_size = 0;
1848 cpl_propertylist* phead = NULL;
1852 cpl_frame* data_frame = NULL;
1854 data_frame = cpl_frameset_get_position(cube_set, 0);
1855 name = cpl_frame_get_filename(data_frame);
1856 plist = cpl_propertylist_load(name, extnum_raw);
1857 phead = cpl_propertylist_load(name, 0);
1864 cpl_propertylist_delete(plist);
1865 cpl_propertylist_delete(phead);
1868 case S250MAS: pix_size = 0.250;
break;
1869 case S100MAS: pix_size = 0.100;
break;
1870 case S25MAS: pix_size = 0.025;
break;
1871 case PUPIL: pix_size = 0.025;
break;
1872 case UNDEFINED_SCALE: pix_size = 0.100;
break;
1881 for (cpl_size i = 0; i < ncubes ; i++) {
1883 data_frame = cpl_frameset_get_position(cube_set, i);
1884 name = cpl_frame_get_filename(data_frame);
1885 plist = cpl_propertylist_load(name, extnum_raw);
1887 ra = cpl_propertylist_get_double(plist,
"RA");
1888 dec = cpl_propertylist_get_double(plist,
"DEC");
1890 cpl_vector_set(vec_ra, i, ra);
1891 cpl_vector_set(vec_dec, i, dec);
1893 cpl_propertylist_delete(plist);
1895 for (cpl_size i = 0; i < ncubes; i++) {
1896 ra1 = cpl_vector_get(vec_ra, i);
1897 dec1 = cpl_vector_get(vec_dec, i);
1898 for (cpl_size j = 0; j < ncubes && i != j; j++) {
1899 ra2 = cpl_vector_get(vec_ra, j);
1900 dec2 = cpl_vector_get(vec_dec, j);
1907 dist = (ra2 - ra1) * (ra2 - ra1) / pix_size / pix_size +
1908 (dec2 - dec1) * (dec2 - dec1) / pix_size / pix_size;
1910 if(dist > dist_sqr) {
1915 cpl_vector_delete(vec_ra);
1916 cpl_vector_delete(vec_dec);
1917 dist_max = sqrt(dist_sqr);
1918 cpl_msg_info(cpl_func,
"Max distance between contributing cubes centers: %g",dist_max);
1969 const cpl_parameterlist * parlist,
1970 const char* recipe_name,
1971 const char* pipefile_prefix)
1973 cpl_size nframes = cpl_frameset_get_size(frameset);
1975 cpl_frameset* cube_set = NULL;
1976 char *proCatg = NULL;
1977 char *filenameSpec = NULL;
1978 cpl_msg_info(cpl_func,
"Combine cubes into a single one, compute mean, median along wavelength axis");
1979 eris_ifu_jitter_get_procatg_and_filename(obj_type, &proCatg, &filenameSpec);
1983 cpl_msg_warning(cpl_func,
"No %s files", proCatg);
1984 cpl_error_set_message(cpl_func, CPL_ERROR_FILE_NOT_FOUND,
"Missing CUBE "
1986 return cpl_error_get_code();
1988 cpl_msg_info(cpl_func,
"%02d file(s) of type %s",
1989 (
int)cpl_frameset_get_size(cube_set), proCatg);
1993 cpl_table* restable = NULL;
1994 cpl_table* tab_tmp = NULL;
1995 const cpl_parameter * par = NULL;
1996 cpl_frame * data_frame = NULL;
1997 cpl_frame * errs_frame = NULL;
1998 cpl_frame * qual_frame = NULL;
2002 cpl_boolean is_variance = CPL_TRUE;
2003 cpl_boolean subtract_bkg = CPL_FALSE;
2006 cpl_size ncubes = cpl_frameset_get_size(cube_set);
2007 char* pname = cpl_sprintf(
"eris.%s.max-cubes-centres-dist",recipe_name);
2008 int max_cubes_dist = 20;
2011 max_cubes_dist = cpl_parameter_get_int(
2012 cpl_parameterlist_find_const(parlist, pname));
2014 if ( max_cubes_dist < eris_ifu_compute_max_cubes_dist(cube_set)) {
2015 cpl_msg_info(cpl_func,
"max-cubes-centres-dist: %d",max_cubes_dist);
2016 cpl_msg_warning(cpl_func,
"max distance between cube centres greater than threshold. Skip cube combination.");
2017 return CPL_ERROR_INCOMPATIBLE_INPUT;
2020 for (cpl_size i = 0; i < ncubes ; i++) {
2022 data_frame = cpl_frameset_get_position(cube_set, i);
2023 errs_frame = data_frame;
2024 qual_frame = data_frame;
2026 tab_tmp = eris_ifu_resample_get_table_from_frameset(data_frame,
2028 qual_frame, extnum_raw,
2029 extnum_err, extnum_bpm,
2030 is_variance, subtract_bkg, edge_trim);
2036 eris_ifu_resample_update_table(tab_tmp, &restable);
2037 cpl_table_delete(tab_tmp);
2042 cpl_ensure_code(restable, CPL_ERROR_NULL_INPUT);
2045 eris_ifu_resample_tablesave (recipe_name, par, parlist, frameset, restable,
2048 cpl_wcs *wcs = eris_ifu_resample_get_wcs_from_frameset(cube_set, proCatg);
2049 cpl_ensure_code(wcs, CPL_ERROR_NULL_INPUT);
2051 cpl_msg_info(cpl_func,
"WCS used for the output grid definition and passed to "
2052 "hdrl_resample_compute():");
2053 cpl_msg_indent_more();
2054 eris_ifu_resample_wcs_print(wcs);
2055 cpl_msg_indent_less();
2057 hdrl_parameter *aParams_method = NULL;
2060 char *context = NULL;
2061 context = cpl_sprintf(
"eris.%s", recipe_name);
2062 aParams_method = eris_ifu_resample_set_method(parlist, context);
2065 cpl_ensure_code(aParams_method, CPL_ERROR_NULL_INPUT);
2068 hdrl_parameter *aParams_outputgrid = NULL;
2070 aParams_outputgrid = eris_ifu_resample_set_outputgrid(recipe_name, parlist,
2072 if(cpl_error_get_code() != CPL_ERROR_NONE) {
2075 return CPL_ERROR_INCOMPATIBLE_INPUT;
2078 cpl_ensure_code(aParams_outputgrid, CPL_ERROR_NULL_INPUT);
2080 hdrl_resample_result *result = NULL;
2085 cpl_msg_severity level = cpl_msg_get_level();
2086 cpl_msg_set_level(CPL_MSG_INFO);
2089 cpl_msg_set_level(level);
2101 cpl_ensure_code(result, CPL_ERROR_NULL_INPUT);
2102 char* pro_catg = NULL;
2103 if(strstr(pipefile_prefix,
"no_flat") != NULL) {
2104 pro_catg = cpl_sprintf(
"%s_%s",proCatg,
"COADD_NOFLAT");
2106 pro_catg = cpl_sprintf(
"%s_%s",proCatg,
"COADD");
2108 char* fname = cpl_sprintf(
"%s_%s_coadd.fits", pipefile_prefix, filenameSpec);
2111 frameset, CPL_FALSE);
2115 hdrl_image* cube_collapsed = NULL;
2116 cpl_image* cube_cmap = NULL;
2120 pro_catg = cpl_sprintf(
"%s_%s",proCatg,
"MEAN");
2121 fname = cpl_sprintf(
"%s_%s_mean.fits", pipefile_prefix, filenameSpec);
2122 cpl_propertylist* phead2D = cpl_propertylist_duplicate(result->header);
2125 cpl_propertylist_append_string(phead2D,
"PRODCATG",PRODCATG_WHITELIGHT);
2130 NULL, CPL_IO_EXTEND);
2132 fname, CPL_TYPE_INT, NULL, CPL_IO_EXTEND);
2140 cpl_image_delete(cube_cmap);
2145 cpl_wcs_delete(wcs);
2146 wcs = cpl_wcs_new_from_propertylist(result->header);
2147 cpl_msg_info(cpl_func,
"Final WCS after resampling: ");
2148 cpl_msg_indent_more();
2149 eris_ifu_resample_wcs_print(wcs);
2150 cpl_msg_indent_less();
2159 cpl_table_delete(restable);
2160 cpl_wcs_delete(wcs);
2161 cpl_frameset_delete(cube_set);
2166 return cpl_error_get_code();
2176static cpl_propertylist* eris_ifu_resample_get_header2D(cpl_propertylist *header3D){
2177 cpl_propertylist *phead2D = cpl_propertylist_duplicate(header3D);
2178 cpl_propertylist_set_int(phead2D,
"NAXIS",2);
2179 cpl_propertylist_erase_regexp(phead2D,
"NAXIS3",0);
2180 cpl_propertylist_erase_regexp(phead2D,
"CTYPE3",0);
2181 cpl_propertylist_erase_regexp(phead2D,
"CRVAL3",0);
2182 cpl_propertylist_erase_regexp(phead2D,
"CRPIX3",0);
2183 cpl_propertylist_erase_regexp(phead2D,
"CUNIT3",0);
2184 cpl_propertylist_erase_regexp(phead2D,
"CDELT3",0);
2185 cpl_propertylist_erase_regexp(phead2D,
"CD3_*",0);
2186 cpl_propertylist_erase_regexp(phead2D,
"CD1_3",0);
2187 cpl_propertylist_erase_regexp(phead2D,
"CD2_3",0);
2201 if (edge_trim > 0) {
2206 if (edge_trim >= 0.5* sx) {
2208 cpl_msg_warning(cpl_func,
"edge-trim must be smaller than half image "
2209 "size. Reset to 0");
2211 if (edge_trim >= 0.5* sy) {
2213 cpl_msg_warning(cpl_func,
"edge-trim must be smaller than half image "
2214 "size. Reset to 0");
2219 for(cpl_size j = 1; j <= edge_trim; j++) {
2220 for(cpl_size i = 1; i <= sx; i++) {
2225 for(cpl_size j = sy - edge_trim + 1; j <= sy; j++) {
2226 for(cpl_size i = 1; i <= sx; i++) {
2231 for(cpl_size j = 1; j <= sy; j++) {
2232 for(cpl_size i = 1; i <= edge_trim; i++) {
2237 for(cpl_size j = 1; j <= sy; j++) {
2238 for(cpl_size i = sx - edge_trim + 1; i <= sx; i++) {
2244 cpl_msg_warning(cpl_func,
"edge-trim is set to 0");
2247 return cpl_error_get_code();
2266 const cpl_parameterlist * parlist,
2267 const char *input_cube_pro_catg,
2268 const char *filenameSpec,
2271 const char* offunit,
2272 const char* recipe_name,
2273 const char* pipefile_prefix){
2275 cpl_frameset* cube_set = NULL;
2276 cpl_msg_info(cpl_func,
"Combine cubes into a single one plane-by-plane, compute mean, median along wavelength axis");
2280 cpl_msg_warning(cpl_func,
"No %s files", input_cube_pro_catg);
2282 cpl_error_set_message(cpl_func, CPL_ERROR_FILE_NOT_FOUND,
2283 "Missing cube files tagged as %s", input_cube_pro_catg);
2284 return cpl_error_get_code();
2286 cpl_msg_info(cpl_func,
"%02d file(s) of type %s",
2287 (
int)cpl_frameset_get_size(cube_set), input_cube_pro_catg);
2292 const cpl_frame * data_frame = NULL;
2293 hdrl_parameter *aParams_outputgrid = NULL;
2294 cpl_propertylist *phead2D = NULL;
2300 cpl_boolean subtract_bkg = CPL_FALSE;
2303 cpl_size ncubes = cpl_frameset_get_size(cube_set);
2305 cpl_error_set_message(cpl_func, CPL_ERROR_FILE_NOT_FOUND,
"Only one CUBE "
2307 return cpl_error_get_code();
2310 char* pname = cpl_sprintf(
"eris.%s.max-cubes-centres-dist",recipe_name);
2311 int max_cubes_dist = 20;
2313 if (offsetx !=NULL && offsety !=NULL)
2314 max_cubes_dist = INT_MAX ;
2316 max_cubes_dist = cpl_parameter_get_int(
2317 cpl_parameterlist_find_const(parlist, pname));
2320 pname = cpl_sprintf(
"eris.%s.subtract-background",recipe_name);
2321 subtract_bkg = cpl_parameter_get_bool(
2322 cpl_parameterlist_find_const(parlist, pname));
2323 if(subtract_bkg == CPL_TRUE)
2324 cpl_msg_info(cpl_func,
"Median of each plane will be subtracted.");
2327 pname = cpl_sprintf(
"eris.%s.edge-trim",recipe_name);
2328 edge_trim = cpl_parameter_get_int(
2329 cpl_parameterlist_find_const(parlist, pname));
2331 cpl_msg_info(cpl_func,
"%d pixel(s) on edges will be trimmed.", edge_trim);
2337 if ( max_cubes_dist < eris_ifu_compute_max_cubes_dist(cube_set)) {
2338 cpl_msg_info(cpl_func,
"max-cubes-centres-dist: %d",max_cubes_dist);
2339 cpl_msg_warning(cpl_func,
"max distance between cube centres greater than threshold. Skip cube combination.");
2340 return CPL_ERROR_INCOMPATIBLE_INPUT;
2343 hdrl_parameter *aParams_method = NULL;
2345 char *context = NULL;
2346 context = cpl_sprintf(
"eris.%s", recipe_name);
2347 aParams_method = eris_ifu_resample_set_method(parlist, context);
2349 cpl_ensure_code(aParams_method, CPL_ERROR_NULL_INPUT);
2352 cpl_wcs *wcs = NULL;
2353 cpl_wcs **tmp_wcs_array = (cpl_wcs **) cpl_calloc(ncubes,
sizeof(wcs));
2354 char const **name_array = (
char const **) cpl_calloc(ncubes,
sizeof(
const char*));
2356 cpl_wcs *wcs3d = NULL;
2371 const char* ctype3 =
"WAVE";
2373 const cpl_matrix *cd = NULL;
2374 cpl_vector* exptime_vec = cpl_vector_new(ncubes);
2378 for (cpl_size i = 0; i < ncubes ; i++) {
2379 data_frame = cpl_frameset_get_position_const(cube_set, i);
2380 const char *name = cpl_frame_get_filename(data_frame);
2381 cpl_propertylist *xheader_data = cpl_propertylist_load(name,
2383 cpl_propertylist* phead = cpl_propertylist_load(name, 0);
2387 cpl_propertylist_delete(phead);
2388 exptime = dit * ndit;
2389 cpl_vector_set(exptime_vec, i, exptime);
2390 cpl_propertylist *header2D = eris_ifu_resample_get_header2D(xheader_data);
2391 cpl_wcs *tmp_wcs = cpl_wcs_new_from_propertylist(header2D);
2392 cpl_propertylist_delete(header2D);
2394 tmp_wcs_array[i] = tmp_wcs;
2395 name_array[i] = name;
2399 cpl_ensure_code(wcs, CPL_ERROR_NULL_INPUT);
2400 cpl_msg_info(cpl_func,
"WCS used for the output grid definition and passed to "
2401 "hdrl_resample_compute():");
2402 cpl_msg_indent_more();
2403 eris_ifu_resample_wcs_print(wcs);
2404 cpl_msg_indent_less();
2405 wcs3d = cpl_wcs_new_from_propertylist(xheader_data);
2406 mjd_obs = cpl_propertylist_get_double(xheader_data,
"MJD-OBS");
2407 crpix3 = cpl_propertylist_get_double(xheader_data,
"CRPIX3");
2408 crval3 = cpl_propertylist_get_double(xheader_data,
"CRVAL3");
2409 naxis3 = cpl_propertylist_get_int(xheader_data,
"NAXIS3");
2425 cd3_3 = cpl_propertylist_get_double(xheader_data,
"CD3_3");
2428 cd = cpl_wcs_get_cd(wcs);
2429 cd1_1 = cpl_matrix_get(cd, 0, 0);
2430 cd1_2 = cpl_matrix_get(cd, 1, 0);
2431 cd2_1 = cpl_matrix_get(cd, 0, 1);
2432 cd2_2 = cpl_matrix_get(cd, 1, 1);
2434 cpl_ensure_code(wcs3d, CPL_ERROR_NULL_INPUT);
2436 cpl_propertylist_delete(xheader_data);
2440 double as2deg = 1.0/3600.0;
2441 double scalex = 1.0;
2442 double scaley = 1.0;
2445 if (offunit != NULL && offsetx !=NULL && offsety !=NULL){
2446 if (strcmp(offunit,
"PIXEL") == 0){
2448 cpl_msg_info(cpl_func,
"User-defined offset unit in PIXEL");
2449 }
else if (strcmp(offunit,
"DEGREE") == 0){
2451 cpl_msg_info(cpl_func,
"User-defined offset unit is DEGREE");
2452 }
else if (strcmp(offunit,
"ARCSEC") == 0){
2454 cpl_msg_info(cpl_func,
"User-defined offset unit is ARCSEC");
2458 cpl_msg_error(cpl_func,
"User-defined offset unit or offset list is not correct.");
2462 const cpl_array *dims = cpl_wcs_get_image_dims(wcs3d);
2463 int nchan = cpl_array_get_int(dims, 2, NULL);
2464 cpl_size ich_center = 0.5 * nchan;
2465 cpl_msg_info(cpl_func,
"Number of planes: %4.4d", nchan);
2470 cpl_msg_severity level = cpl_msg_get_level();
2471 cpl_msg_set_level(CPL_MSG_INFO);
2472 for (cpl_size ich = 0; ich < nchan; ich++){
2473 cpl_table* restable = NULL;
2475 for (cpl_size i = 0; i < ncubes ; i++) {
2476 const char *name = name_array[i];
2477 cpl_image *im = cpl_image_load(name, CPL_TYPE_DOUBLE, ich, extnum_raw);
2478 cpl_image *err = cpl_image_load(name, CPL_TYPE_DOUBLE, ich, extnum_err);
2479 cpl_image* qual = cpl_image_load(name, CPL_TYPE_INT, ich, extnum_bpm);
2480 cpl_mask *mask = cpl_mask_threshold_image_create(qual, 0, INT_MAX);
2481 cpl_image_delete(qual);
2489 cpl_image* ima_time = NULL;
2490 cpl_image* err_time = NULL;
2491 hdrl_image *himg_exptime = NULL;
2492 if(ich == ich_center) {
2493 ima_time = cpl_image_new(cpl_image_get_size_x(im),
2494 cpl_image_get_size_y(im), CPL_TYPE_DOUBLE);
2495 err_time = cpl_image_new(cpl_image_get_size_x(im),
2496 cpl_image_get_size_y(im), CPL_TYPE_DOUBLE);
2498 exptime = cpl_vector_get(exptime_vec, i);
2499 cpl_image_add_scalar(ima_time, exptime);
2500 cpl_image_add_scalar(err_time, sqrt(exptime));
2505 if (edge_trim > 0) {
2509 cpl_image_delete(ima_time);
2510 cpl_image_delete(err_time);
2514 cpl_image_delete(im);
2515 cpl_image_delete(err);
2517 cpl_mask_delete(mask);
2520 if(subtract_bkg == CPL_TRUE) {
2525 if (edge_trim > 0) {
2529 cpl_table *tab_tmp = NULL;
2530 cpl_table *tab_exptime_tmp = NULL;
2531 if (offsetx !=NULL && offsety !=NULL){
2534 cpl_table_subtract_scalar(tab_tmp,
"ra", offsetx[i]*cd1_1+ offsety[i]*cd1_2);
2535 cpl_table_subtract_scalar(tab_tmp,
"dec", offsetx[i]*cd2_1+ offsety[i]*cd2_2);
2537 cpl_msg_info(__func__,
"User-defined offest in RA, DEC (ARCSEC) %g, %g",
2538 (offsetx[i]*cd1_1+ offsety[i]*cd1_2)*3600,
2539 (offsetx[i]*cd2_1+ offsety[i]*cd2_2)*3600);
2541 if(ich == ich_center) {
2544 cpl_table_subtract_scalar(tab_exptime_tmp,
"ra", offsetx[i]*cd1_1+ offsety[i]*cd1_2);
2545 cpl_table_subtract_scalar(tab_exptime_tmp,
"dec", offsetx[i]*cd2_1+ offsety[i]*cd2_2);
2547 }
else if (offcode==1 || offcode==2 ){
2549 cpl_table_subtract_scalar(tab_tmp,
"ra", offsetx[i]*scalex);
2550 cpl_table_subtract_scalar(tab_tmp,
"dec", offsety[i]*scaley);
2552 cpl_msg_info(__func__,
"User-defined offest in RA, DEC (%s) %g, %g",
2557 if(ich == ich_center) {
2559 cpl_table_subtract_scalar(tab_exptime_tmp,
"ra", offsetx[i]*scalex);
2560 cpl_table_subtract_scalar(tab_exptime_tmp,
"dec", offsety[i]*scaley);
2565 if(ich == ich_center) {
2570 eris_ifu_resample_update_table(tab_tmp, &restable);
2572 if(ich == ich_center) {
2576 hdrl_resample_result *himl_exptime_tmp = NULL;
2578 aParams_method, aParams_outputgrid, wcs);
2589 cpl_table_delete(tab_exptime_tmp);
2593 cpl_table_delete(tab_tmp);
2595 cpl_msg_debug(__func__,
"Created table for channel %d cube %d", (
int)ich, (
int)i);
2597 cpl_ensure_code(restable, CPL_ERROR_NULL_INPUT);
2600 cpl_msg_debug(__func__,
"Table of the chanel %d size %lld x %lld", (
int)ich,
2601 cpl_table_get_nrow(restable), cpl_table_get_ncol(restable));
2604 aParams_outputgrid = eris_ifu_resample_set_outputgrid2D(recipe_name, parlist,
2606 if ( cpl_error_get_code() != CPL_ERROR_NONE) {
2608 return CPL_ERROR_NONE;
2610 cpl_ensure_code(aParams_outputgrid, CPL_ERROR_INCOMPATIBLE_INPUT);
2614 cpl_ensure_code(aParams_outputgrid, CPL_ERROR_NULL_INPUT);
2616 hdrl_resample_result *result = NULL;
2628 cpl_ensure_code(result, CPL_ERROR_NULL_INPUT);
2629 cpl_table_delete(restable);
2633 cpl_wcs *res_wcs = cpl_wcs_new_from_propertylist(result->header);
2634 cpl_msg_info(cpl_func,
"Final WCS after resampling: ");
2635 cpl_msg_indent_more();
2636 eris_ifu_resample_wcs_print(res_wcs);
2637 cpl_msg_indent_less();
2638 cpl_wcs_delete(res_wcs);
2639 phead2D = cpl_propertylist_duplicate(result->header);
2647 for (
int i = 0; i < ncubes; i++){
2648 cpl_wcs_delete(tmp_wcs_array[i]);
2650 cpl_free(tmp_wcs_array);
2651 cpl_free(name_array);
2655 cpl_msg_info(__func__,
"Coadding cubes: range [%4.4d,%4.4d] of %d",
2656 (
int)ich,(
int)ich+100, nchan);
2658 cpl_msg_set_level(level);
2660 hdrl_image* hima_exptime_mean = NULL;
2661 cpl_image* contrib_exptime_map = NULL;
2663 &contrib_exptime_map);
2670 cpl_image_multiply_scalar(contrib_exptime_map, cpl_vector_get_median(exptime_vec));
2672 cpl_ensure_code(res_cube, CPL_ERROR_NULL_INPUT);
2673 cpl_vector_delete(exptime_vec);
2681 hdrl_resample_result *result = cpl_calloc(1,
sizeof(hdrl_resample_result));
2682 result->himlist = res_cube;
2683 result->header = phead2D;
2686 cpl_propertylist_append_double(result->header,
"CRPIX3", crpix3);
2687 cpl_propertylist_append_double(result->header,
"CRVAL3", crval3);
2688 cpl_propertylist_append_int(result->header,
"NAXIS3", naxis3);
2690 cpl_propertylist_append_string(result->header,
"CTYPE3", ctype3);
2691 cpl_propertylist_append_double(result->header,
"CD1_3", cd1_3);
2692 cpl_propertylist_append_double(result->header,
"CD2_3", cd2_3);
2693 cpl_propertylist_append_double(result->header,
"CD3_3", cd3_3);
2694 cpl_propertylist_append_double(result->header,
"CD3_1", cd3_1);
2695 cpl_propertylist_append_double(result->header,
"CD3_2", cd3_2);
2696 cpl_propertylist_append_double(result->header,
"MJD-OBS", mjd_obs);
2697 cpl_propertylist* wcs2D = eris_ifu_plist_extract_wcs2D(result->header);
2699 hdrl_image* cube_collapsed = NULL;
2700 cpl_image* cube_cmap = NULL;
2708 char* pro_catg = NULL;
2709 if(strstr(pipefile_prefix,
"no_flat") != NULL) {
2710 pro_catg = cpl_sprintf(
"%s_%s",input_cube_pro_catg,
"COADD_NOFLAT");
2712 pro_catg = cpl_sprintf(
"%s_%s",input_cube_pro_catg,
"COADD");
2714 char* fname = cpl_sprintf(
"%s_%s_coadd.fits", pipefile_prefix, filenameSpec);
2716 if(strcmp(recipe_name,
"eris_ifu_jitter") == 0) {
2718 frameset, CPL_FALSE);
2721 frameset, CPL_FALSE);
2728 pro_catg = cpl_sprintf(
"%s_%s",input_cube_pro_catg,
"MEAN");
2729 fname = cpl_sprintf(
"%s_%s_mean.fits", pipefile_prefix, filenameSpec);
2730 cpl_propertylist_append_string(phead2D,
"PRODCATG", PRODCATG_WHITELIGHT);
2733 cpl_propertylist_update_string(phead2D, CPL_DFS_PRO_CATG, pro_catg);
2736 recipe_name, phead2D,
"RADECSYS", fname,
2739 rmse, mask_ima, flag16bit, UNIT_ADU);
2741 fname = cpl_sprintf(
"%s_%s_exposure_map.fits", pipefile_prefix, filenameSpec);
2743 cpl_propertylist_update_string(phead2D, CPL_DFS_PRO_CATG, ERIS_IFU_PRO_JITTER_EXPOSURE_MAP);
2744 cpl_propertylist_update_string(phead2D,
"PRODCATG", PRODCATG_EXPOSUREMAP);
2746 cpl_propertylist_append(phead2D, wcs2D);
2747 cpl_propertylist_delete(wcs2D);
2749 recipe_name, phead2D,
"RADECSYS", fname, contrib_exptime_map,
2750 CPL_TYPE_DOUBLE, UNIT_TIME);
2753 cpl_image_delete(mask_ima);
2754 cpl_image_delete(contrib_exptime_map);
2758 cpl_image_delete(cube_cmap);
2759 cpl_wcs_delete(wcs3d);
2762 cpl_frameset_delete(cube_set);
2765 return cpl_error_get_code();
ifsPreopticsScale eris_ifu_get_preopticsScale(cpl_propertylist *header)
Return the the pre-optics scaling.
cpl_error_code eris_ifu_heades_add_hduclass_qual(cpl_propertylist *plist, deqQualityType qualityType)
add common quality info properties on errors
cpl_frameset * eris_ifu_extract_frameset(const cpl_frameset *in, const char *tag)
Extract the frames with the given tag from a frameset.
cpl_error_code eris_ifu_save_image_phase3(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const char *recipe, const cpl_propertylist *applist, const char *remregexp, const char *filename, const cpl_image *image, cpl_type type, const char *unit)
Write DFS pipeline product with image, error and data qual.
cpl_error_code eris_ifu_heades_add_hduclass_common(cpl_propertylist *plist, const char *deq_hduclas)
add common properties
cpl_error_code eris_ifu_save_deq_image(cpl_frameset *allframes, cpl_propertylist *header, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_frame *inherit, const char *recipe, const cpl_propertylist *applist, const char *remregexp, const char *filename, const cpl_image *image, const cpl_image *error, deqErrorType errorType, const cpl_image *dataQualityMask, deqQualityType dataQualityType, const char *unit)
Write DFS pipeline product with image, error and data qual.
cpl_error_code eris_ifu_heades_add_hduclass_data(cpl_propertylist *plist)
add common data info properties
cpl_error_code eris_ifu_heades_add_hduclass_errs(cpl_propertylist *plist, deqErrorType errorType)
add common errors info properties
cpl_error_code eris_ifu_combine(cubeType obj_type, cpl_frameset *frameset, const cpl_parameterlist *parlist, const char *recipe_name, const char *pipefile_prefix)
This function resample input cubes using HDRL.
cpl_error_code eris_ifu_combine_pbp(cpl_frameset *frameset, const cpl_parameterlist *parlist, const char *input_cube_pro_catg, const char *filenameSpec, float *offsetx, float *offsety, const char *offunit, const char *recipe_name, const char *pipefile_prefix)
This function resample input cubes plane by plane using HDRL.
cpl_error_code eris_ifu_cube_collapse_mean_and_save(const char *pro_catg, cpl_frameset *frameset, const cpl_parameterlist *parlist, const char *recipe_name, cpl_boolean apply_flat, cpl_boolean is_pupil)
-------------------------------------------------------------------------—/
cpl_error_code eris_ifu_resample_save_cube(hdrl_resample_result *aCube, const char *procatg, const char *recipe, const char *filename, const cpl_parameterlist *parlist, cpl_frameset *frameset, cpl_boolean gen_phase3)
save an cube (imagelist, product of pixel resampling) on a FITS file with proper FITS header
cpl_error_code eris_ifu_resample_trim_edge(hdrl_image *himg, int edge_trim)
Duplicate a 2D header from a 3D header.
void eris_ifu_free_propertylist(cpl_propertylist **item)
free memory and set pointer to null
void eris_ifu_free_string(char **item)
free memory and set pointer to null
cpl_table * eris_qclog_init(void)
Initialize QC table.
cpl_error_code eris_pfits_put_qc(cpl_propertylist *plist, cpl_table *qclog)
convert table with QC parameter information to a propertylist
cpl_error_code eris_qclog_add_double_f(cpl_table *table, const char *key_name, const double value, const char *key_help)
add QC float info to table
cpl_error_code eris_ifu_split3_hdrl_imagelist(hdrl_imagelist *cube, cpl_imagelist *dataCube, cpl_imagelist *errorCube, cpl_imagelist *qualCube)
extract from hdrl_imagelist the data and error information
cpl_error_code eris_ifu_save_image(cpl_frameset *fs, const cpl_propertylist *plist, const cpl_parameterlist *parlist, const char *recipe, const char *procatg, const char *filename, cpl_type type, const cpl_image *image)
save image
int eris_pfits_get_ndit(const cpl_propertylist *plist)
find out the DIT value
double eris_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
cpl_error_code eris_parameters_get_double(const cpl_parameterlist *parlist, const char *pname, double *pvalue)
get double parameter value if changed by the user
cpl_error_code eris_check_error_code(const char *func_id)
handle CPL errors
cpl_boolean eris_param_has_changed(const cpl_parameter *p)
verify if a parameter value has been changed (from command line or or rc file by a user)
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.
hdrl_image * hdrl_image_duplicate(const hdrl_image *himg)
copy hdrl_image
cpl_mask * hdrl_image_get_mask(hdrl_image *himg)
get cpl bad pixel mask from image
cpl_image * hdrl_image_get_error(hdrl_image *himg)
get error as cpl image
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
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
cpl_error_code hdrl_image_sub_scalar(hdrl_image *self, hdrl_value value)
Elementwise subtraction of a scalar from an 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.
hdrl_imagelist * hdrl_imagelist_new(void)
Create an empty imagelist.
cpl_size hdrl_imagelist_get_size_x(const hdrl_imagelist *himlist)
Get number of colums of images in the imagelist.
hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.
void hdrl_parameter_delete(hdrl_parameter *obj)
shallow delete of a parameter
hdrl_parameter * hdrl_resample_parameter_create_nearest(void)
Creates a resample nearest neighbor hdrl parameter object. The algorithm does not use any weighting f...
hdrl_parameter * hdrl_resample_parameter_create_renka(const int loop_distance, cpl_boolean use_errorweights, const double critical_radius)
Creates a resample renka hdrl parameter object. The algorithm uses a modified Shepard-like distance w...
hdrl_parameter * hdrl_resample_parameter_create_lanczos(const int loop_distance, cpl_boolean use_errorweights, const int kernel_size)
Creates a resample Lanczos hdrl parameter object. The algorithm uses a restricted SINC distance weigh...
hdrl_parameter * hdrl_resample_parameter_create_drizzle(const int loop_distance, cpl_boolean use_errorweights, const double pix_frac_x, const double pix_frac_y, const double pix_frac_lambda)
Creates a resample drizzle hdrl parameter object. The algorithm uses a drizzle-like distance weightin...
hdrl_parameter * hdrl_resample_parameter_create_quadratic(const int loop_distance, cpl_boolean use_errorweights)
Creates a resample quadratic hdrl parameter object. The algorithm uses a quadratic inverse distance w...
hdrl_parameter * hdrl_resample_parameter_create_linear(const int loop_distance, cpl_boolean use_errorweights)
Creates a resample linear hdrl parameter object. The algorithm uses a linear inverse distance weighti...
hdrl_parameter * hdrl_resample_parameter_create_outgrid3D_userdef(const double delta_ra, const double delta_dec, const double delta_lambda, const double ra_min, const double ra_max, const double dec_min, const double dec_max, const double lambda_min, const double lambda_max, const double fieldmargin)
Creates a resample_outgrid hdrl parameter object for a 3 dimensional interpolation,...
hdrl_parameter * hdrl_resample_parameter_create_outgrid2D_userdef(const double delta_ra, const double delta_dec, const double ra_min, const double ra_max, const double dec_min, const double dec_max, const double fieldmargin)
Creates a resample_outgrid hdrl parameter object for a 2 dimensional interpolation,...
hdrl_resample_result * hdrl_resample_compute(const cpl_table *ResTable, hdrl_parameter *method, hdrl_parameter *outputgrid, const cpl_wcs *wcs)
High level resampling function.
void hdrl_resample_result_delete(hdrl_resample_result *aCube)
Deallocates the memory associated to a hdrl_resample_result object.
cpl_table * hdrl_resample_image_to_table(const hdrl_image *hima, const cpl_wcs *wcs)
Convert a hdrl image into a cpl table that can be given as input to hdrl_resample_compute()
cpl_table * hdrl_resample_imagelist_to_table(const hdrl_imagelist *himlist, const cpl_wcs *wcs)
Convert a hdrl imagelist into a cpl table that can be given as input to hdrl_resample_compute().