ERIS Pipeline Reference Manual 1.8.10
eris_ifu_utils.c
1/* $Id: eris_ifu_utils.c,v 1.12 2013-03-25 11:46:49 cgarcia Exp $
2 *
3 * This file is part of the ERIS Pipeline
4 * Copyright (C) 2002,2003 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/*
22 * $Author: cgarcia $
23 * $Date: 2013-03-25 11:46:49 $
24 * $Revision: 1.12 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32/*-----------------------------------------------------------------------------
33 Includes
34 -----------------------------------------------------------------------------*/
35
36#include <string.h>
37
38#include "eris_ifu_utils.h"
39#include "eris_ifu_error.h"
40#include "eris_ifu_functions.h"
41#include "eris_utils.h"
42#include "eris_pfits.h"
43/*----------------------------------------------------------------------------*/
48/*----------------------------------------------------------------------------*/
49
78cpl_vector* eris_ifu_idl_where(const cpl_vector *data, double val, int op)
79{
80 cpl_vector *ret_vec = NULL;
81 double *pret_vec = NULL;
82 const double *pdata = NULL;
83 int j = 0,
84 size = 0;
85
86 cpl_ensure(data, CPL_ERROR_NULL_INPUT, NULL);
87
88 TRY
89 {
90 size = cpl_vector_get_size(data);
91
92 // create vector of same size as input data and set default values
93 // to -1.0 (will be shortened at the end)
94 ret_vec = cpl_vector_new(size);
95 pret_vec = cpl_vector_get_data(ret_vec);
96
97 cpl_vector_fill(ret_vec, -1.0);
98
99 // identify valid values in data and copy inidices to temp vector
100 pdata = cpl_vector_get_data_const(data);
101
102 j = 0;
103 for (int i = 0; i < size; i++) {
104 switch (op) {
105 case eq:
106 if (pdata[i] == val)
107 pret_vec[j++] = i;
108 break;
109 case ne:
110 if (fabs(pdata[i]-val) > 0.0001)
111 pret_vec[j++] = i;
112 break;
113 case ge:
114 if (pdata[i] >= val)
115 pret_vec[j++] = i;
116 break;
117 case gt:
118 if (pdata[i] > val)
119 pret_vec[j++] = i;
120 break;
121 case le:
122 if (pdata[i] <= val)
123 pret_vec[j++] = i;
124 break;
125 case lt:
126 if (pdata[i] < val)
127 pret_vec[j++] = i;
128 break;
129 default:
130 SET_ERROR_MSG(CPL_ERROR_ILLEGAL_INPUT,
131 "illegal operator");
132 break;
133 }
134 }
135
136 //cut trailing -1
137 eris_ifu_cut_endings(&ret_vec, NULL, NULL, TRUE);
139 }
140 CATCH
141 {
142 CATCH_MSGS();
143 eris_ifu_free_vector(&ret_vec);
144 }
145 eris_check_error_code("eris_ifu_idl_where");
146 return ret_vec;
147}
148
168cpl_vector* eris_ifu_idl_values_at_indices(const cpl_vector *data,
169 const cpl_vector *indices)
170{
171 cpl_vector* ret_vec = NULL;
172 double *pret_vec = NULL;
173 const double *pdata = NULL,
174 *pindices = NULL;
175 int size = 0;
176
177 cpl_ensure(data, CPL_ERROR_NULL_INPUT, NULL);
178 cpl_ensure(indices, CPL_ERROR_NULL_INPUT, NULL);
179
180 TRY
181 {
182 pdata = cpl_vector_get_data_const(data);
183 pindices = cpl_vector_get_data_const(indices);
184
185 size = cpl_vector_get_size(indices);
186
187 ret_vec = cpl_vector_new(size);
188 pret_vec = cpl_vector_get_data(ret_vec);
189
190 for (int i = 0; i < size; i++) {
191 if ((int)pindices[i] < 0) {
192 SET_ERROR_MSG(CPL_ERROR_ILLEGAL_INPUT,
193 "One of the indices is < 0!");
194 } else {
195 pret_vec[i] = pdata[(int)pindices[i]];
196 }
197 }
198 }
199 CATCH
200 {
201 CATCH_MSGS();
202 eris_ifu_free_vector(&ret_vec);
203 }
204 eris_check_error_code("eris_ifu_idl_values_at_indices");
205 return ret_vec;
206}
207
233cpl_error_code eris_ifu_cut_endings(cpl_vector** vec,
234 int *begin, int *end, int cut)
235{
236 cpl_error_code err = CPL_ERROR_NONE;
237 int min = 0,
238 max = 0;
239 double *pvec = NULL;
240 cpl_vector *tmp_vec = NULL;
241
242 cpl_ensure_code(vec, CPL_ERROR_NULL_INPUT);
243 cpl_ensure_code(*vec, CPL_ERROR_NULL_INPUT);
244
245 TRY
246 {
247 pvec = cpl_vector_get_data(*vec);
248 min = 0; // min_pos
249 max = cpl_vector_get_size(*vec)-1; // max_pos
250
251 // find beginning
252 for (int i = 0; i < cpl_vector_get_size(*vec); i++) {
253 if (pvec[i] == -1) {
254 min = i+1;
255 } else {
256 break;
257 }
258 }
259
260 if (min != cpl_vector_get_size(*vec)) {
261 // find ending
262 for (int i = cpl_vector_get_size(*vec)-1; i >= 0; i--) {
263 if (pvec[i] == -1) {
264 max = i-1;
265 } else {
266 break;
267 }
268 }
269
270 if (cut == TRUE) {
271 // extract appropriate part of vector
272 tmp_vec = cpl_vector_extract(*vec, min, max, 1);
273
274 cpl_vector_delete(*vec); *vec= NULL;
275
276 *vec = tmp_vec;
277 }
278 } else {
279 if (cut == TRUE) {
280 // all values are -1 return NULL
281 cpl_vector_delete(*vec); *vec = NULL;
282 }
283
284 min = 0;
285 max = 0;
286 }
287
288 // set return values if wanted
289 if (begin != NULL) {
290 *begin = min;
291 }
292
293 if (end != NULL) {
294 *end = max;
295 }
296 }
297 CATCH
298 {
299
300 err = cpl_error_get_code();
301// eris_print_rec_status(9);
302// cpl_msg_info(cpl_func,"ok9");
303 if (begin != NULL) {
304 *begin = 0;
305 }
306
307 if (end != NULL) {
308 *end = 0;
309 }
310
312 }
313 eris_check_error_code("eris_ifu_cut_endings");
314 return err;
315}
316
330hdrl_imagelist * eris_ifu_get_hdrlimagelist_by_tag(cpl_frameset *frameset,
331 const char *tag,
332 int exposureCorrectionMode)
333{
334 hdrl_imagelist *hdrl_list = NULL;
335 cpl_frameset *frames = NULL;
336 hdrl_image *tmp_img = NULL;
337 const cpl_frame *fr = NULL;
338 const char *fn = NULL;
339
340 cpl_ensure(frameset, CPL_ERROR_NULL_INPUT, NULL);
341 cpl_ensure(tag, CPL_ERROR_NULL_INPUT, NULL);
342
343 TRY
344 {
345 frames = eris_ifu_get_frameset_by_tag(frameset, tag);
346 hdrl_list = hdrl_imagelist_new();
347
348 /*
349 * Loop through all FLAT_LAMP frames and save on- and off-frames
350 * accordingly in their cpl_imagelists
351 */
352 fr = cpl_frameset_find_const(frames, tag);
353
354 while (fr != NULL) {
355 fn = cpl_frame_get_filename(fr);
356 eris_ifu_file_exists(fn);
357
358 /* If the frame has a tag we process it. Else it is an object and
359 * is ignored */
360 if (cpl_frame_get_tag(fr) != NULL) {
361 tmp_img = eris_ifu_load_exposure_file(fn,
362 exposureCorrectionMode, NULL);
363
364 hdrl_imagelist_set(hdrl_list, tmp_img,
365 hdrl_imagelist_get_size(hdrl_list));
366 } else {
367 /* if (tag == NULL) do nothing */
368 }
369
370 /* next frame */
371 fr = cpl_frameset_find_const(frames, NULL);
372 }
373 }
374 CATCH
375 {
376 CATCH_MSGS();
378 }
379
380 eris_ifu_free_frameset(&frames);
381 eris_check_error_code("eris_ifu_get_hdrlimagelist_by_tag");
382 return hdrl_list;
383}
384
392 const cpl_frameset *frameset,
393 const char *tag)
394{
395 cpl_frameset *frames = NULL;
396 const cpl_frame *curFrame ;
397 cpl_frame *locFrame ;
398 cpl_size frameCnt;
399 int i;
400
401 cpl_ensure(frameset, CPL_ERROR_NULL_INPUT, NULL);
402 cpl_ensure(tag, CPL_ERROR_NULL_INPUT, NULL);
403
404 TRY
405 {
406 /* Check whether there are frames with the requested tag */
407 frameCnt = cpl_frameset_count_tags(frameset, tag);
409 if (frameCnt == 0)
410 {
411 BRK_WITH_ERROR_MSG(CPL_ERROR_DATA_NOT_FOUND,
412 "frameset contains no frames with tag %s", tag);
413 }
414
415 /* Create the output frameset */
416 frames = cpl_frameset_new() ;
417
418 /* Extract frames with proper tag into the output frameset */
419 frameCnt = cpl_frameset_get_size(frameset) ;
420 for (i=0 ; i<frameCnt ; i++) {
421 curFrame = cpl_frameset_get_position_const(frameset, i) ;
422 if (!strcmp(cpl_frame_get_tag(curFrame), tag)) {
423 locFrame = cpl_frame_duplicate(curFrame) ;
424 cpl_frameset_insert(frames, locFrame) ;
425 }
426 }
427 }
428 CATCH
429 {
430 frames = NULL;
431 }
432 eris_check_error_code("eris_ifu_get_frameset_by_tag");
433 return frames;
434}
435
443 cpl_parameterlist *p1,
444 const cpl_parameterlist *p2)
445{
446 cpl_error_code err = CPL_ERROR_NONE;
447 const cpl_parameter *p = NULL;
448
449 cpl_ensure_code(p1, CPL_ERROR_NULL_INPUT);
450 cpl_ensure_code(p2, CPL_ERROR_NULL_INPUT);
451
452 TRY
453 {
454 p = cpl_parameterlist_get_first_const(p2);
455 cpl_parameterlist_append(p1, cpl_parameter_duplicate(p));
456 while ((p = cpl_parameterlist_get_next_const(p2)) != NULL) {
457 cpl_parameterlist_append(p1, cpl_parameter_duplicate(p));
458 }
460 }
461 CATCH
462 {
463 err = cpl_error_get_code();
464 }
465 eris_check_error_code("eris_ifu_parameterlist_append_list");
466 return err;
467}
468
474void eris_ifu_free_hdrl_image(hdrl_image **item) {
475 if ((item != NULL) && (*item != NULL)) {
476 hdrl_image_delete(*item);
477 *item = NULL;
478 }
479}
484void eris_ifu_free_hdrl_imagelist(hdrl_imagelist **item) {
485 if ((item != NULL) && (*item != NULL)) {
487 *item = NULL;
488 }
489}
494void eris_ifu_free_image(cpl_image **item) {
495 if ((item != NULL) && (*item != NULL)) {
496 cpl_image_delete(*item);
497 *item = NULL;
498 }
499}
504void eris_ifu_free_imagelist(cpl_imagelist **item) {
505 if ((item != NULL) && (*item != NULL)) {
506 cpl_imagelist_delete(*item);
507 *item = NULL;
508 }
509}
514void eris_ifu_free_mask(cpl_mask **item) {
515 if ((item != NULL) && (*item != NULL)) {
516 cpl_mask_delete(*item);
517 *item = NULL;
518 }
519}
524void eris_ifu_free_matrix(cpl_matrix **item) {
525 if ((item != NULL) && (*item != NULL)) {
526 cpl_matrix_delete(*item);
527 *item = NULL;
528 }
529}
534void eris_ifu_free_propertylist(cpl_propertylist **item) {
535 if ((item != NULL) && (*item != NULL)) {
536 cpl_propertylist_delete(*item);
537 *item = NULL;
538 }
539}
544void eris_ifu_free_vector(cpl_vector **item) {
545 if ((item != NULL) && (*item != NULL)) {
546 cpl_vector_delete(*item);
547 *item = NULL;
548 }
549}
554void eris_ifu_free_ifu_vector(eris_ifu_vector **item) {
555 if ((item != NULL) && (*item != NULL)) {
557 *item = NULL;
558 }
559}
564void eris_ifu_free_string(char **item) {
565 if ((item != NULL) && (*item != NULL)) {
566 cpl_free(*item);
567 *item = NULL;
568 }
569}
574void eris_ifu_free_frameset(cpl_frameset **item) {
575 if ((item != NULL) && (*item != NULL)) {
576 cpl_frameset_delete(*item);
577 *item = NULL;
578 }
579}
584void eris_ifu_free_frame(cpl_frame **item) {
585 if ((item != NULL) && (*item != NULL)) {
586 cpl_frame_delete(*item);
587 *item = NULL;
588 }
589}
594void eris_ifu_free_hdrl_parameter(hdrl_parameter **item) {
595 if ((item != NULL) && (*item != NULL)) {
597 *item = NULL;
598 }
599}
604void eris_ifu_free_parameter(cpl_parameter **item) {
605 if ((item != NULL) && (*item != NULL)) {
606 cpl_parameter_delete(*item);
607 *item = NULL;
608 }
609}
610
615void eris_ifu_free_parameterlist(cpl_parameterlist **item) {
616 if ((item != NULL) && (*item != NULL)) {
617 cpl_parameterlist_delete(*item);
618 *item = NULL;
619 }
620}
625void eris_ifu_free_table(cpl_table **item) {
626 if ((item != NULL) && (*item != NULL)) {
627 cpl_table_delete(*item);
628 *item = NULL;
629 }
630}
635void eris_ifu_free_double_array(double **item) {
636 if ((item != NULL) && (*item != NULL)) {
637 cpl_free(*item);
638 *item = NULL;
639 }
640}
645void eris_ifu_free_float_array(float **item) {
646 if ((item != NULL) && (*item != NULL)) {
647 cpl_free(*item);
648 *item = NULL;
649 }
650}
655void eris_ifu_free_int_array(int**item) {
656 if ((item != NULL) && (*item != NULL)) {
657 cpl_free(*item);
658 *item = NULL;
659 }
660}
665void eris_ifu_free_polynomial(cpl_polynomial **item) {
666 if ((item != NULL) && (*item != NULL)) {
667 cpl_polynomial_delete(*item);
668 *item = NULL;
669 }
670}
675void eris_ifu_free_bivector(cpl_bivector **item) {
676 if ((item != NULL) && (*item != NULL)) {
677 cpl_bivector_delete(*item);
678 *item = NULL;
679 }
680}
685void eris_ifu_free_apertures(cpl_apertures **item) {
686 if ((item != NULL) && (*item != NULL)) {
687 cpl_apertures_delete(*item);
688 *item = NULL;
689 }
690}
703cpl_error_code eris_ifu_save_image(cpl_frameset *fs,
704 const cpl_propertylist *plist,
705 const cpl_parameterlist *parlist,
706 const char *recipe,
707 const char *procatg,
708 const char *filename,
709 cpl_type type,
710 const cpl_image *image)
711{
712 cpl_error_code err = CPL_ERROR_NONE;
713 char *pckgName = NULL;
714 cpl_propertylist *plistdup = NULL;
715
716 cpl_ensure_code(fs, CPL_ERROR_NULL_INPUT);
717 cpl_ensure_code(plist, CPL_ERROR_NULL_INPUT);
718 cpl_ensure_code(parlist, CPL_ERROR_NULL_INPUT);
719 cpl_ensure_code(recipe, CPL_ERROR_NULL_INPUT);
720 cpl_ensure_code(procatg, CPL_ERROR_NULL_INPUT);
721 cpl_ensure_code(filename, CPL_ERROR_NULL_INPUT);
722 cpl_ensure_code(image, CPL_ERROR_NULL_INPUT);
723
724 TRY
725 {
726 plistdup = cpl_propertylist_duplicate(plist);
727
728 pckgName = cpl_sprintf("%s%s%s", PACKAGE, "/", PACKAGE_VERSION);
729
730 cpl_propertylist_update_string(plistdup, CPL_DFS_PRO_CATG, procatg);
731
732 cpl_dfs_save_image(fs, NULL, parlist, fs, NULL, image, type,
733 recipe, plistdup, "RADECSYS", pckgName, filename);
734
735 cpl_propertylist_delete(plistdup);
736 }
737 CATCH
738 {
739 CATCH_MSGS();
740 err = cpl_error_get_code();
741 }
742
743 eris_ifu_free_string(&pckgName);
744 eris_check_error_code("eris_ifu_save_image");
745 return err;
746}
760cpl_error_code eris_ifu_save_imagelist(cpl_frameset *fs,
761 cpl_frame *inherit,
762 const cpl_propertylist *plist,
763 const cpl_parameterlist *parlist,
764 const char *recipe,
765 const char *procatg,
766 const char *filename,
767 cpl_type type,
768 const cpl_imagelist *imglist)
769{
770 cpl_error_code err = CPL_ERROR_NONE;
771 char *pckgName = NULL;
772 cpl_propertylist *plistdup = NULL;
773
774 cpl_ensure_code(fs, CPL_ERROR_NULL_INPUT);
775 cpl_ensure_code(plist, CPL_ERROR_NULL_INPUT);
776 cpl_ensure_code(parlist, CPL_ERROR_NULL_INPUT);
777 cpl_ensure_code(recipe, CPL_ERROR_NULL_INPUT);
778 cpl_ensure_code(procatg, CPL_ERROR_NULL_INPUT);
779 cpl_ensure_code(filename, CPL_ERROR_NULL_INPUT);
780 cpl_ensure_code(imglist, CPL_ERROR_NULL_INPUT);
781
782 TRY
783 {
784 plistdup = cpl_propertylist_duplicate(plist);
785 pckgName = cpl_sprintf("%s%s%s", PACKAGE, "/", PACKAGE_VERSION);
786 cpl_propertylist_update_string(plistdup, CPL_DFS_PRO_CATG, procatg);
787 // TODO: why adding CPL_DFS_PRO_TYPE, CPL_DFS_PRO_TECH ???
788 cpl_propertylist_update_string(plistdup, CPL_DFS_PRO_TYPE, "CUBE");
789 cpl_propertylist_update_string(plistdup, CPL_DFS_PRO_TECH, "CUBE");
790 //cpl_propertylist_append_string(plist, "PRODCATG", "SCIENCE.CUBE.IFS");
791 cpl_propertylist_erase(plistdup, "RADECSYS");
792 //eris_ifu_plist_erase_wcs(plistdup);
794
795 cpl_dfs_save_imagelist(fs, NULL, parlist, fs, inherit, imglist, type,
796 recipe, plistdup, "RADECSYS", pckgName, filename);
797
798 }
799 CATCH
800 {
801 CATCH_MSGS();
802 err = cpl_error_get_code();
803 }
804
805 eris_ifu_free_string(&pckgName);
806 cpl_propertylist_delete(plistdup);
807 eris_check_error_code("eris_ifu_save_imagelist");
808 return err;
809}
810
824cpl_error_code eris_ifu_hdrl_image_reject_mask(hdrl_image *img,
825 const cpl_mask *mask)
826{
827 cpl_error_code err = CPL_ERROR_NONE;
828 const cpl_binary *pmask = NULL;
829 cpl_mask *img_mask = NULL;
830 cpl_binary *pimg_mask = NULL;
831 cpl_size nRows = 0;
832 cpl_size nCols = 0;
833
834 cpl_ensure_code(img, CPL_ERROR_NULL_INPUT);
835 cpl_ensure_code(mask, CPL_ERROR_NULL_INPUT);
836 cpl_ensure_code(hdrl_image_get_size_x(img)==cpl_mask_get_size_x(mask),
837 CPL_ERROR_ILLEGAL_INPUT);
838 cpl_ensure_code(hdrl_image_get_size_y(img)==cpl_mask_get_size_y(mask),
839 CPL_ERROR_ILLEGAL_INPUT);
840
841 TRY
842 {
843 // reject from image
844 img_mask = hdrl_image_get_mask(img);
845 pimg_mask = cpl_mask_get_data(img_mask);
846 pmask = cpl_mask_get_data_const(mask);
847
848 nCols = hdrl_image_get_size_x(img);
849 nRows = hdrl_image_get_size_y(img);
850 for (cpl_size y = 0; y < nRows; y++) {
851 for (cpl_size x = 0; x < nCols; x++) {
852 if ((pmask[x+y*nCols] == BAD_PIX) &&
853 (pimg_mask[x+y*nCols] == GOOD_PIX))
854 {
855 pimg_mask[x+y*nCols] = BAD_PIX;
856 }
857 }
858 }
859 }
860 CATCH
861 {
862 CATCH_MSGS();
863 err = cpl_error_get_code();
864 }
865 eris_check_error_code("eris_ifu_hdrl_image_reject_mask");
866 return err;
867}
876cpl_error_code eris_ifu_save_vector_dbg(const cpl_vector *vec,
877 const char* filename, int create,
878 const cpl_propertylist *pl)
879{
880 cpl_ensure_code(vec,CPL_ERROR_NULL_INPUT);
881
882 return cpl_vector_save(vec, filename, CPL_TYPE_DOUBLE, pl, create);
883}
891cpl_error_code eris_ifu_save_ifu_vector_dbg(const eris_ifu_vector *vec,
892 const char* filename, int create)
893{
894 return eris_ifu_vector_save(vec, filename, CPL_TYPE_DOUBLE, NULL, create, -10.0);
895}
896
908cpl_error_code eris_ifu_save_bivector_dbg(const cpl_bivector *bivec,
909 const char* filename, int col, int create)
910{
911// int size = cpl_bivector_get_size(bivec);
912// const double *px = cpl_bivector_get_x_data_const(bivec),
913// *py = cpl_bivector_get_y_data_const(bivec);
914 const cpl_vector *x = NULL,
915 *y = NULL;
916
917 if (col == 1) {
918 x = cpl_bivector_get_x_const(bivec);
919 return eris_ifu_save_vector_dbg(x, filename, create, NULL);
920 } else if (col == 2) {
921 y = cpl_bivector_get_x_const(bivec);
922 return eris_ifu_save_vector_dbg(y, filename, create, NULL);
923 } else if (col == 0) {
924 x = cpl_bivector_get_x_const(bivec);
925 y = cpl_bivector_get_y_const(bivec);
926 eris_ifu_save_vector_dbg(x, filename, create, NULL);
927 return eris_ifu_save_vector_dbg(y, filename, CPL_IO_EXTEND, NULL);
928 } else {
929 return CPL_ERROR_ILLEGAL_INPUT;
930 }
931}
940cpl_error_code eris_ifu_save_image_dbg(const cpl_image *img,
941 const char* filename, int create,
942 const cpl_propertylist *pl)
943{
944 cpl_ensure_code(img,CPL_ERROR_NULL_INPUT);
945
946 if (img == NULL) {
947 return cpl_image_save(img, filename,
948 CPL_TYPE_INT, pl, create);
949 } else if (cpl_image_get_type(img) == CPL_TYPE_FLOAT) {
950 return cpl_image_save(img, filename,
951 CPL_TYPE_FLOAT, pl, create);
952 } else if (cpl_image_get_type(img) == CPL_TYPE_DOUBLE) {
953 return cpl_image_save(img, filename,
954 CPL_TYPE_DOUBLE, pl, create);
955 } else if (cpl_image_get_type(img) == CPL_TYPE_INT) {
956 return cpl_image_save(img, filename,
957 CPL_TYPE_INT, pl, create);
958 } else {
959 return CPL_ERROR_ILLEGAL_INPUT;
960 }
961}
969cpl_error_code eris_ifu_save_table_dbg(const cpl_table *tbl,
970 const char* filename, int create)
971{
972 return cpl_table_save(tbl, NULL, NULL, filename, create);
973}
982cpl_error_code eris_ifu_save_mask_dbg(const cpl_mask *mask,
983 const char* filename, int create,
984 const cpl_propertylist *pl)
985{
986 return cpl_mask_save(mask, filename, pl, create);
987}
988
996cpl_error_code eris_ifu_save_imagelist_dbg(const cpl_imagelist *imglist,
997 const char* filename, int create)
998{
999 cpl_ensure_code(imglist, CPL_ERROR_NULL_INPUT);
1000 cpl_ensure_code(cpl_imagelist_get_size(imglist) >= 0,
1001 CPL_ERROR_ILLEGAL_INPUT);
1002
1003 const cpl_image *img = cpl_imagelist_get_const(imglist, 0);
1004 eris_check_error_code("eris_ifu_save_imagelist_dbg");
1005 if (cpl_image_get_type(img) == CPL_TYPE_FLOAT) {
1006 return cpl_imagelist_save(imglist, filename,
1007 CPL_TYPE_FLOAT, NULL, create);
1008 } else if (cpl_image_get_type(img) == CPL_TYPE_DOUBLE) {
1009 return cpl_imagelist_save(imglist, filename,
1010 CPL_TYPE_DOUBLE, NULL, create);
1011 } else {
1012 return CPL_ERROR_ILLEGAL_INPUT;
1013 }
1014}
1023cpl_error_code eris_ifu_save_cpl_image_dbg(const cpl_image *img,
1024 const char* name, int singlefile,
1025 const cpl_propertylist *pl)
1026{
1027 char *fn = NULL;
1028 const cpl_mask *mask = NULL;
1029 cpl_error_code err = CPL_ERROR_NONE;
1030 int create = CPL_IO_CREATE;
1031
1032 TRY
1033 {
1034 if (singlefile) {
1035 fn = cpl_sprintf("%s.fits", name);
1036 } else {
1037 fn = cpl_sprintf("%s_data.fits", name);
1038 }
1039 eris_ifu_save_image_dbg(img, fn, create, pl);
1040 cpl_free(fn); fn = NULL;
1041
1042 if (singlefile) {
1043 fn = cpl_sprintf("%s.fits", name);
1044 create = CPL_IO_EXTEND;
1045 } else {
1046 fn = cpl_sprintf("%s_mask.fits", name);
1047 create = CPL_IO_CREATE;
1048 }
1049 mask = cpl_image_get_bpm_const(img);
1050 eris_ifu_save_mask_dbg(mask, fn, create, pl);
1051 cpl_free(fn); fn = NULL;
1052 }
1053 CATCH
1054 {
1055 CATCH_MSGS();
1056 err = cpl_error_get_code();
1057 }
1058 cpl_free(fn); fn = NULL;
1059 eris_check_error_code("eris_ifu_save_cpl_image_dbg");
1060 return err;
1061}
1068cpl_error_code eris_ifu_save_cpl_imagelist_dbg(const cpl_imagelist *imglist,
1069 const char* name)
1070{
1071 char *fn = NULL;
1072 cpl_error_code err = CPL_ERROR_NONE;
1073
1074 TRY
1075 {
1076 fn = cpl_sprintf("%s.fits", name);
1077 eris_ifu_save_imagelist_dbg(imglist, fn, CPL_IO_CREATE);
1079 }
1080 CATCH
1081 {
1082 CATCH_MSGS();
1083 err = cpl_error_get_code();
1084 }
1085 eris_check_error_code("eris_ifu_save_cpl_imagelist_dbg");
1086 return err;
1087}
1096cpl_error_code eris_ifu_save_hdrl_image_dbg(const hdrl_image *hdrl_img,
1097 const char* filename, int singlefile,
1098 const cpl_propertylist *pl)
1099{
1100 char *fn = NULL;
1101 const cpl_image *img = NULL;
1102 const cpl_mask *mask = NULL;
1103 cpl_error_code err = CPL_ERROR_NONE;
1104 int create = CPL_IO_CREATE;
1105
1106 TRY
1107 {
1108 if (singlefile) {
1109 fn = cpl_sprintf("%s.fits", filename);
1110 } else {
1111 fn = cpl_sprintf("%s_data.fits", filename);
1112 }
1113 img = hdrl_image_get_image_const(hdrl_img);
1114 eris_ifu_save_image_dbg(img, fn, create, pl);
1115 cpl_free(fn); fn = NULL;
1116
1117 if (singlefile) {
1118 fn = cpl_sprintf("%s.fits", filename);
1119 create = CPL_IO_EXTEND;
1120 } else {
1121 fn = cpl_sprintf("%s_err.fits", filename);
1122 create = CPL_IO_CREATE;
1123 }
1124 img = hdrl_image_get_error_const(hdrl_img);
1125 eris_ifu_save_image_dbg(img, fn, create, pl);
1126 cpl_free(fn); fn = NULL;
1127
1128 if (singlefile) {
1129 fn = cpl_sprintf("%s.fits", filename);
1130 create = CPL_IO_EXTEND;
1131 } else {
1132 fn = cpl_sprintf("%s_mask.fits", filename);
1133 create = CPL_IO_CREATE;
1134 }
1135 mask = hdrl_image_get_mask_const(hdrl_img);
1136 if(mask != NULL) {
1137 eris_ifu_save_mask_dbg(mask, fn, create, pl);
1138 }
1139 cpl_free(fn); fn = NULL;
1140 }
1141 CATCH
1142 {
1143 CATCH_MSGS();
1144 err = cpl_error_get_code();
1145 }
1146 eris_check_error_code("eris_ifu_save_hdrl_image_dbg");
1147 return err;
1148}
1157 const hdrl_imagelist *hdrl_img_list,
1158 const char* filename, int singlefile)
1159{
1160 char *fn = NULL;
1161 cpl_imagelist *img_list = NULL;
1162 const hdrl_image *tmp_hdrl_img = NULL;
1163 const cpl_mask *mask = NULL;
1164 const cpl_binary *pmask = NULL;
1165 cpl_image *img = NULL;
1166 cpl_error_code err = CPL_ERROR_NONE;
1167 float *pimg = NULL;
1168 int nx = 0,
1169 ny = 0,
1170 create = CPL_IO_CREATE;
1171
1172 TRY
1173 {
1174 /* save data */
1175 if (singlefile) {
1176 fn = cpl_sprintf("%s.fits", filename);
1177 } else {
1178 fn = cpl_sprintf("%s_data.fits", filename);
1179 }
1180 img_list = eris_ifu_hdrl_get_imagelist(hdrl_img_list,
1181 eris_hdrl_data);
1182 eris_ifu_save_imagelist_dbg(img_list, fn, create);
1183 eris_ifu_free_imagelist(&img_list);
1184 cpl_free(fn); fn = NULL;
1185
1186 /* save error */
1187 if (singlefile) {
1188 fn = cpl_sprintf("%s.fits", filename);
1189 create = CPL_IO_EXTEND;
1190 } else {
1191 fn = cpl_sprintf("%s_err.fits", filename);
1192 create = CPL_IO_CREATE;
1193 }
1194 img_list = eris_ifu_hdrl_get_imagelist(hdrl_img_list,
1195 eris_hdrl_error);
1196 eris_ifu_save_imagelist_dbg(img_list, fn, create);
1197 eris_ifu_free_imagelist(&img_list);
1198 cpl_free(fn); fn = NULL;
1199
1200 /* save bp-mask */
1201 if (singlefile) {
1202 fn = cpl_sprintf("%s.fits", filename);
1203 create = CPL_IO_EXTEND;
1204 } else {
1205 fn = cpl_sprintf("%s_mask.fits", filename);
1206 create = CPL_IO_CREATE;
1207 }
1208 img_list = cpl_imagelist_new();
1209
1210 for (int i = 0; i < hdrl_imagelist_get_size(hdrl_img_list); i++) {
1211 tmp_hdrl_img = hdrl_imagelist_get_const(hdrl_img_list, i);
1212 mask = hdrl_image_get_mask_const(tmp_hdrl_img);
1213
1214 nx = cpl_mask_get_size_x(mask);
1215 ny = cpl_mask_get_size_y(mask);
1216
1217 img = cpl_image_new(nx, ny, CPL_TYPE_FLOAT);
1218 pimg = cpl_image_get_data_float(img);
1219 pmask = cpl_mask_get_data_const(mask);
1220
1221 for (int j = 0; j < nx*ny; j++) {
1222 if (pmask[j] == BAD_PIX) {
1223 pimg[j] = BAD_PIX;
1224 } else {
1225 pimg[j] = GOOD_PIX;
1226 }
1227 }
1228
1229 cpl_imagelist_set(img_list, img, i);
1230 }
1231 eris_ifu_save_imagelist_dbg(img_list, fn, create);
1232 eris_ifu_free_imagelist(&img_list);
1233 cpl_free(fn); fn = NULL;
1234 }
1235 CATCH
1236 {
1237 CATCH_MSGS();
1238 err = cpl_error_get_code();
1239 }
1240 eris_check_error_code("eris_ifu_save_hdrl_imagelist_dbg");
1241 return err;
1242}
1243
1245// @brief Loading image data of a given category.
1246// @param frameset The input set-of-frames.
1247// @param category The category of the image to load. If NULL, the
1248// next frame with same keyword as accessed right before will
1249// be returned
1250// @param ext The number of the extension. 0 for primary HDU
1251// @return The loaded image.
1252// Data type of CPL_TYPE_FLOAT is assumed.
1253//*/
1254//hdrl_image* eris_ifu_load_image_ctg(
1255// cpl_frameset *frameset,
1256// const char *category,
1257// int ext)
1258//{
1259// cpl_frame *frame = NULL; /* must not be deleted at the end */
1260// hdrl_image *imgHdrl = NULL;
1261//
1262// cpl_ensure(frameset, CPL_ERROR_NULL_INPUT, NULL);
1263// cpl_ensure(category, CPL_ERROR_NULL_INPUT, NULL);
1264//
1265// TRY
1266// {
1267// ASSURE(ext >= 0,
1268// CPL_ERROR_ILLEGAL_INPUT,
1269// "ext must be 0 or larger!");
1270//
1271// frame = cpl_frameset_find(frameset, category);
1272// CHECK_ERROR_STATE();
1273//
1274// if (frame != NULL) {
1275// imgHdrl = eris_ifu_load_image(cpl_frame_get_filename(frame),
1276// CPL_TYPE_FLOAT, 0, ext);
1277// }
1278// }
1279// CATCH
1280// {
1281// CATCH_MSG();
1282// eris_ifu_free_hdrl_image(&imgHdrl);
1283// }
1284// return imgHdrl;
1285//}
1286
1297 const cpl_frameset *frameset,
1298 const char *category,
1299 int ext)
1300{
1301 const cpl_frame *frame = NULL; /* must not be deleted at the end */
1302 cpl_mask *bp_mask = NULL;
1303
1304 cpl_ensure(frameset, CPL_ERROR_NULL_INPUT, NULL);
1305 cpl_ensure(category, CPL_ERROR_NULL_INPUT, NULL);
1306
1307 TRY
1308 {
1309 ASSURE(ext >= 0,
1310 CPL_ERROR_ILLEGAL_INPUT,
1311 "ext must be 0 or larger!");
1312
1313 frame = cpl_frameset_find_const(frameset, category);
1315
1316 if (frame != NULL) {
1317 bp_mask = cpl_mask_load(cpl_frame_get_filename(frame), 0, ext);
1318 }
1319 }
1320 CATCH
1321 {
1322 CATCH_MSG();
1323 eris_ifu_free_mask(&bp_mask);
1324 }
1325 eris_check_error_code("eris_ifu_load_badpixel_mask");
1326 return bp_mask;
1327}
1328
1330// @brief
1331// Override for cpl_image_load().
1332
1333// @param filename Name of the file to load from.
1334// @param im_type Type of the created image
1335// @param pnum Plane number in the Data Unit (0 for first)
1336// @param xtnum Extension number in the file (0 for primary HDU)
1337
1338// @return The function returns the newly created image or NULL if an
1339// error occurred.
1340
1341// This is an override for cpl_image_load(), just giving a proper error
1342// message if the input file isn't found and rejecting all infinite values
1343// (NaN, +/-Inf). The errors returned are the same as with @c cpl_image_load
1344//*/
1345//hdrl_image* eris_ifu_load_image(const char *filename,
1346// cpl_type im_type,
1347// int pnum,
1348// int xtnum)
1349//{
1350// hdrl_image *imgHdrl = NULL;
1351// cpl_image *img = NULL;
1352// float *pimg = NULL;
1353// cpl_size nx = 0,
1354// ny = 0;
1355// int ix = 0,
1356// iy = 0;
1357
1358// cpl_ensure(filename, CPL_ERROR_NULL_INPUT, NULL);
1359
1360// TRY
1361// {
1362// /* for the health of any developer:
1363// check if any pre-existing error is set */
1364// if (cpl_error_get_code() != CPL_ERROR_NONE) {
1365// cpl_msg_error("","An already existing error has been detected. "
1366// "Aborting now.");
1367// CHECK_ERROR_STATE();
1368// }
1369
1370// /* load image */
1371// img = cpl_image_load(filename, im_type, pnum, xtnum);
1372// if (cpl_error_get_code() != CPL_ERROR_NONE) {
1373// if (cpl_error_get_code() == CPL_ERROR_FILE_IO) {
1374// cpl_msg_error("", "File not found: %s", filename);
1375// } else {
1376// cpl_msg_debug("", "Problem loading file '%s' (%s --> Code %d)",
1377// filename, cpl_error_get_message(),
1378// cpl_error_get_code());
1379// }
1380// }
1381// CHECK_ERROR_STATE();
1382
1383// /* reject invalid values for internal bad pixel mask */
1384// pimg = cpl_image_get_data(img);
1385// nx = cpl_image_get_size_x(img);
1386// ny = cpl_image_get_size_y(img);
1387// for (iy = 0; iy < ny; iy++) {
1388// for (ix = 0; ix < nx; ix++) {
1389// if (!isfinite(pimg[ix+iy*nx])) {
1390// cpl_image_reject(img, ix+1, iy+1);
1391// }
1392// }
1393// }
1394
1395// /* create noise map*/
1396// imgHdrl = hdrl_image_create(img, NULL);
1397// }
1398// CATCH
1399// {
1400// eris_ifu_free_hdrl_image(&imgHdrl);
1401// }
1402
1403// eris_ifu_free_image(&img);
1404
1405// return imgHdrl;
1406//}
1407
1413cpl_error_code eris_ifu_file_exists(const char *filename)
1414{
1415 cpl_error_code err = CPL_ERROR_NONE;
1416 FILE *fh = NULL;
1417
1418 cpl_ensure_code(filename, CPL_ERROR_NULL_INPUT);
1419
1420 TRY
1421 {
1422 fh = fopen(filename, "r");
1423 }
1424 CATCH
1425 {
1426 err = cpl_error_get_code();
1427 }
1428
1429 if(fh != NULL) {
1430 fclose(fh);
1431 }
1432 eris_check_error_code("eris_ifu_file_exists");
1433 return err;
1434}
1435
1442cpl_imagelist* eris_ifu_hdrl_get_imagelist(const hdrl_imagelist *hdrl_imglist,
1443 enum hdrl_t type)
1444{
1445 cpl_imagelist *data = NULL;
1446 const hdrl_image *tmp_hdrl_img = NULL;
1447 cpl_image *tmp_img = NULL;
1448
1449 cpl_ensure(hdrl_imglist, CPL_ERROR_NULL_INPUT, NULL);
1450
1451 TRY
1452 {
1453 data = cpl_imagelist_new();
1454
1455 for (int i = 0; i < hdrl_imagelist_get_size(hdrl_imglist); i++) {
1456 tmp_hdrl_img = hdrl_imagelist_get(hdrl_imglist, i);
1457
1458 if (type == eris_hdrl_data) {
1459 /* type == data */
1460 tmp_img = cpl_image_duplicate(
1461 hdrl_image_get_image_const(tmp_hdrl_img));
1462 } else if (type == eris_hdrl_error) {
1463 /* type == error */
1464 tmp_img = cpl_image_duplicate(
1465 hdrl_image_get_error_const(tmp_hdrl_img));
1466 } else {
1467 /* type == badpix */
1468
1469 /* doesn't make sense yet */
1470 // tmp_img = cpl_image_duplicate(
1471 // hdrl_image_get_mask(tmp_hdrl_img));
1472 }
1473
1474 cpl_imagelist_set(data, tmp_img, i);
1475 }
1476 }
1477 CATCH
1478 {
1479 CATCH_MSGS();
1481 eris_ifu_free_image(&tmp_img);
1482 }
1483 eris_check_error_code("eris_ifu_hdrl_get_imagelist");
1484 return data;
1485}
1491char* eris_ifu_get_lampString(int lampStatus)
1492{
1493 char *lampString;
1494 const char *arLampString = "";
1495 const char *krLampString = "";
1496 const char *neLampString = "";
1497 const char *xeLampString = "";
1498
1499 if ((lampStatus & AR_LAMP) == AR_LAMP) {arLampString = "Ar";}
1500 if ((lampStatus & KR_LAMP) == KR_LAMP) {krLampString = "Kr";}
1501 if ((lampStatus & NE_LAMP) == NE_LAMP) {neLampString = "Ne";}
1502 if ((lampStatus & XE_LAMP) == XE_LAMP) {xeLampString = "Xe";}
1503 lampString = cpl_sprintf("%s%s%s%s",
1504 arLampString, krLampString, neLampString, xeLampString);
1505 eris_check_error_code("eris_ifu_get_lampString");
1506 return lampString;
1507}
1508
1514const char* eris_ifu_get_bandString(ifsBand band)
1515{
1516 const char *bandString;
1517 switch (band) {
1518 case UNDEFINED_BAND:
1519 bandString = "";
1520 break;
1521 case J_LOW:
1522 bandString = "J_LOW";
1523 break;
1524 case H_LOW:
1525 bandString = "H_LOW";
1526 break;
1527 case K_LOW:
1528 bandString = "K_LOW";
1529 break;
1530 case J_SHORT:
1531 bandString = "J_SHORT";
1532 break;
1533 case J_MIDDLE:
1534 bandString = "J_MIDDLE";
1535 break;
1536 case J_LONG:
1537 bandString = "J_LONG";
1538 break;
1539 case H_SHORT:
1540 bandString = "H_SHORT";
1541 break;
1542 case H_MIDDLE:
1543 bandString = "H_MIDDLE";
1544 break;
1545 case H_LONG:
1546 bandString = "H_LONG";
1547 break;
1548 case K_SHORT:
1549 bandString = "K_SHORT";
1550 break;
1551 case K_MIDDLE:
1552 bandString = "K_MIDDLE";
1553 break;
1554 case K_LONG:
1555 bandString = "K_LONG";
1556 break;
1557 case J_SPIFFI:
1558 bandString = "J_SPIFFI";
1559 break;
1560 case H_SPIFFI:
1561 bandString = "H_SPIFFI";
1562 break;
1563 case K_SPIFFI:
1564 bandString = "K_SPIFFI";
1565 break;
1566 case HK_SPIFFI:
1567 bandString = "HK_SPIFFI";
1568 break;
1569 default:
1570 bandString = "Unknown";
1571 break;
1572 }
1573 eris_check_error_code("eris_ifu_get_bandString");
1574 return bandString;
1575}
1582{
1583 double resolution;
1584 switch (band) {
1585 case UNDEFINED_BAND: resolution = 0; break;
1586 case J_LOW: resolution = 5000; break;
1587 case H_LOW: resolution = 5200; break;
1588 case K_LOW: resolution = 5600; break;
1589 case J_SHORT: resolution = 10000; break;
1590 case J_MIDDLE: resolution = 10000; break;
1591 case J_LONG: resolution = 10000; break;
1592 case H_SHORT: resolution = 10400; break;
1593 case H_MIDDLE: resolution = 10400; break;
1594 case H_LONG: resolution = 10400; break;
1595 case K_SHORT: resolution = 11200; break;
1596 case K_MIDDLE: resolution = 11200; break;
1597 case K_LONG: resolution = 11200; break;
1598 case J_SPIFFI: resolution = 5000; break;
1599 case H_SPIFFI: resolution = 5000; break;
1600 case K_SPIFFI: resolution = 5000; break;
1601 case HK_SPIFFI: resolution = 3000; break;
1602 default: resolution = 0; break;
1603 }
1604 eris_check_error_code("eris_ifu_get_band_resolution");
1605 return resolution;
1606}
1607
1608
1616cpl_error_code
1617eris_ifu_get_plane_cut_min_max(ifsBand band, cpl_size* zmin, cpl_size* zmax)
1618{
1619
1620 cpl_ensure_code(zmin >= 0, CPL_ERROR_ILLEGAL_INPUT);
1621 cpl_ensure_code(zmin <= zmax, CPL_ERROR_ILLEGAL_INPUT);
1622 cpl_ensure_code(zmin != NULL, CPL_ERROR_NULL_INPUT);
1623 cpl_ensure_code(zmax != NULL, CPL_ERROR_NULL_INPUT);
1624
1625 switch (band) {
1626 case UNDEFINED_BAND: break;
1627 case J_LOW: *zmin = 46; *zmax = 2015; break;
1628 case H_LOW: *zmin = 48; *zmax = 2023; break;
1629 case K_LOW: *zmin = 62; *zmax = 2022; break;
1630 case J_SHORT: *zmin = 50; *zmax = 2034; break;
1631 case J_MIDDLE: *zmin = 57; *zmax = 2040; break;
1632 case J_LONG: *zmin = 48; *zmax = 2033; break;
1633 case H_SHORT: *zmin = 52; *zmax = 2034; break;//
1634 case H_MIDDLE: *zmin = 47; *zmax = 2034; break;
1635 case H_LONG: *zmin = 56; *zmax = 2042; break;//
1636 case K_SHORT: *zmin = 54; *zmax = 2036; break;
1637 case K_MIDDLE: *zmin = 49; *zmax = 2029; break;
1638 case K_LONG: *zmin = 50; *zmax = 2034; break;
1639 case J_SPIFFI: *zmin = 32; *zmax = 2058; break;
1640 case H_SPIFFI: *zmin = 32; *zmax = 2058; break;
1641 case K_SPIFFI: *zmin = 32; *zmax = 2058; break;
1642 case HK_SPIFFI: *zmin = 32; *zmax = 2058; break;
1643 default: break;
1644 }
1645 eris_check_error_code("eris_ifu_get_plane_cut_min_max");
1646 return cpl_error_get_code();
1647}
1648
1649
1650
1660//TODO: Why hvalue.data = k * 10.; ?
1661cpl_error_code
1662eris_ifu_cube_set_values(hdrl_imagelist** iml/*, cpl_imagelist** bpm*/) {
1663
1664
1665 cpl_size size = hdrl_imagelist_get_size(*iml);
1666 cpl_msg_info(cpl_func,"org size: %lld", size);
1667 hdrl_image* hima = NULL;
1668// cpl_image* ima = NULL;
1669 hdrl_value hvalue = {0, 0};
1670 for(cpl_size k = 0; k < size; k++) {
1671 hima = hdrl_imagelist_get(*iml, k);
1672 for(cpl_size j = 10; j < 20; j++) {
1673 for(cpl_size i = 10; i < 20; i++) {
1674 hvalue.data = k * 10.; //TODO: why this?
1675 hdrl_image_set_pixel(hima, i, j, hvalue);
1676 }
1677 }
1678 //hdrl_imagelist_unset(*iml, k);
1679 //hdrl_imagelist_set(*iml, k, hima);
1680 //cpl_imagelist_unset(*bpm, k);
1681 }
1682
1683 eris_check_error_code("eris_ifu_cube_set_values");
1684
1685 return cpl_error_get_code();
1686}
1687
1697cpl_error_code
1698eris_ifu_cube_trim_nans(const cpl_size zmin, const cpl_size zmax,
1699 hdrl_imagelist** iml, cpl_imagelist** bpm, cpl_propertylist* header) {
1700
1701 cpl_ensure_code(iml,CPL_ERROR_NULL_INPUT);
1702 cpl_ensure_code(bpm,CPL_ERROR_NULL_INPUT);
1703 cpl_ensure_code(header,CPL_ERROR_NULL_INPUT);
1704 cpl_ensure_code(zmin <= zmax,CPL_ERROR_ILLEGAL_INPUT);
1705 cpl_size size = hdrl_imagelist_get_size(*iml);
1706 cpl_msg_debug(cpl_func,"org size: %lld", size);
1707 /* we peel-off the cube starting from the end thus the index we touch
1708 * is always decreasing (maximum)
1709 */
1710 for(cpl_size i = size-1; i > zmax; i--) {
1711 hdrl_imagelist_unset(*iml, i);
1712 cpl_imagelist_unset(*bpm, i);
1713 }
1714 cpl_msg_debug(cpl_func,"size1: %lld", hdrl_imagelist_get_size(*iml));
1715 /* we peel-off the cube starting from the bottom thus the index we touch
1716 * is always 0 (minimum)
1717 */
1718 for(cpl_size i = 0; i < zmin; i++) {
1719 hdrl_imagelist_unset(*iml, 0);
1720 cpl_imagelist_unset(*bpm, 0);
1721 }
1722 cpl_msg_debug(cpl_func,"size2: %lld", hdrl_imagelist_get_size(*iml));
1723 double crval3 = cpl_propertylist_get_double(header,"CRVAL3");
1724 const double cd3_3 = cpl_propertylist_get_double(header,"CD3_3");
1725 int naxis3 = cpl_propertylist_get_int(header,"NAXIS3");
1726
1727 crval3 += cd3_3 * zmin;
1728 naxis3 = zmax - zmin +1;
1729 cpl_propertylist_set_double(header, "CRVAL3", crval3);
1730 cpl_propertylist_set_int(header, "NAXIS3", naxis3);
1731
1732 eris_check_error_code("eris_ifu_cube_trim_nans");
1733 return cpl_error_get_code();
1734}
1735
1736
1742const char* eris_ifu_get_instrumentString(ifsInstrument instrument)
1743{
1744 const char *instrumentString;
1745 switch (instrument) {
1746 case OTHER_INSTRUMENT: instrumentString = "unknown instrument"; break;
1747 case SPIFFI: instrumentString = "SPIFFI"; break;
1748 case SPIFFIER: instrumentString = "SPIFFIER"; break;
1749 case NIX: instrumentString = "NIX"; break;
1750 case UNSET_INSTRUMENT: instrumentString = "unset instrument"; break;
1751 default: instrumentString = "unset instrument"; break;
1752 }
1753 eris_check_error_code("eris_ifu_get_instrumentString");
1754 return instrumentString;
1755}
1756
1762const char* eris_ifu_get_preopticsScaleString(ifsPreopticsScale scale)
1763{
1764 const char *scaleString;
1765 switch (scale) {
1766 case UNDEFINED_SCALE:
1767 scaleString = "";
1768 break;
1769 case S250MAS:
1770 scaleString = "250mas";
1771 break;
1772 case S100MAS:
1773 scaleString = "100mas";
1774 break;
1775 case S25MAS:
1776 scaleString = "25mas";
1777 break;
1778 case PUPIL:
1779 scaleString = "PUPIL";
1780 break;
1781 default:
1782 scaleString = "Unknown";
1783 break;
1784 }
1785 eris_check_error_code("eris_ifu_get_preopticsScaleString");
1786 return scaleString;
1787}
1788
1789/*
1790 * removes badpixborder around img
1791 * @param img input image
1792 * @return sub-image with removed border
1793 */
1794cpl_image* eris_ifu_image_create_window(const cpl_image* img)
1795{
1796 cpl_size nx = 0,
1797 ny = 0;
1798 double *pimg_window = NULL;
1799 const double *pimg = NULL;
1800 cpl_image *img_window = NULL;
1801 const cpl_mask *mask = NULL;
1802 cpl_mask *mask_window = NULL;
1803 const cpl_binary *pmask = NULL;
1804 cpl_binary *pmask_window = NULL;
1805
1806 cpl_ensure(img, CPL_ERROR_NULL_INPUT, NULL);
1807
1808 TRY
1809 {
1810 nx = cpl_image_get_size_x(img);
1811 ny = cpl_image_get_size_y(img);
1813 img_window = cpl_image_new(nx-2*ERIS_IFU_DETECTOR_BP_BORDER,
1814 ny-2*ERIS_IFU_DETECTOR_BP_BORDER,
1815 cpl_image_get_type(img));
1816
1817 pimg = cpl_image_get_data_const(img);
1818 mask = cpl_image_get_bpm_const(img);
1819 pmask = cpl_mask_get_data_const(mask);
1820 pimg_window = cpl_image_get_data(img_window);
1821 mask_window = cpl_image_get_bpm(img_window);
1822 pmask_window = cpl_mask_get_data(mask_window);
1823
1824 for (int x = 0; x < nx-2*ERIS_IFU_DETECTOR_BP_BORDER; x++) {
1825 for (int y = 0; y < ny-2*ERIS_IFU_DETECTOR_BP_BORDER; y++) {
1826 cpl_size nx_new = nx-2*ERIS_IFU_DETECTOR_BP_BORDER,
1827 x_old = x+ERIS_IFU_DETECTOR_BP_BORDER,
1828 y_old = y+ERIS_IFU_DETECTOR_BP_BORDER;
1829 pimg_window[x+y*nx_new] = pimg[x_old+y_old*nx];
1830 pmask_window[x+y*nx_new] = pmask[x_old+y_old*nx];
1831 }
1832 }
1833 }
1834 CATCH
1835 {
1836 CATCH_MSGS();
1837 eris_ifu_free_image(&img_window);
1838 }
1839 eris_check_error_code("eris_ifu_image_create_window");
1840 return img_window;
1841}
1842
1850cpl_mask* eris_ifu_mask_create_border(const cpl_mask* mask)
1851{
1852 cpl_size nx = 0,
1853 ny = 0;
1854 cpl_binary *pmask_border = NULL;
1855 const cpl_binary *pmask = NULL;
1856 cpl_mask *mask_border = NULL;
1857
1858 cpl_ensure(mask, CPL_ERROR_NULL_INPUT, NULL);
1859
1860 TRY
1861 {
1862 nx = cpl_mask_get_size_x(mask);
1863 ny = cpl_mask_get_size_y(mask);
1865
1866 mask_border = cpl_mask_new(nx+2*ERIS_IFU_DETECTOR_BP_BORDER,
1867 ny+2*ERIS_IFU_DETECTOR_BP_BORDER);
1868
1869 pmask = cpl_mask_get_data_const(mask);
1870 pmask_border = cpl_mask_get_data(mask_border);
1871
1872 for (int x = 0; x < nx; x++) {
1873 for (int y = 0; y < ny; y++) {
1874 cpl_size x_new = x+ERIS_IFU_DETECTOR_BP_BORDER,
1875 y_new = y+ERIS_IFU_DETECTOR_BP_BORDER,
1876 nx_new = nx+2*ERIS_IFU_DETECTOR_BP_BORDER;
1877 pmask_border[x_new+y_new*nx_new] = pmask[x+y*nx];
1878 }
1879 }
1880 }
1881 CATCH
1882 {
1883 CATCH_MSGS();
1884 eris_ifu_free_mask(&mask_border);
1885 }
1886 eris_check_error_code("eris_ifu_mask_create_border");
1887 return mask_border;
1888}
1889
1890/*----------------------------------------------------------------------------*/
1896/*----------------------------------------------------------------------------*/
1897
1898cpl_error_code
1900
1901 double* pdata = NULL;
1902 double* perrs = NULL;
1903 cpl_binary* pbpm = NULL;
1904 cpl_size sx = 0;
1905 cpl_size sy = 0;
1906 cpl_size npoints = 0;
1907 cpl_ensure(hima != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
1908
1909
1910 sx = hdrl_image_get_size_x( *hima );
1911 sy = hdrl_image_get_size_y( *hima );
1912 npoints = sx * sy;
1913
1914 pdata = cpl_image_get_data(hdrl_image_get_image(*hima));
1915 perrs = cpl_image_get_data(hdrl_image_get_error(*hima));
1916 pbpm = cpl_mask_get_data(hdrl_image_get_mask(*hima));
1917
1918 cpl_size nan_pix = 0;
1919 for(cpl_size i = 0; i < npoints; i++) {
1920 //cpl_msg_error(cpl_func,"pdata[%lld]:%g perrs[%lld]:%g",i,pdata[i],i,perrs[i]);
1921 //if(pdata[i] == CPL_VALUE_NOTFINITE || perrs[i] == CPL_VALUE_NOTFINITE ){
1922 if(isnan(pdata[i]) || isnan(perrs[i]) ){
1923 //cpl_msg_info(cpl_func,"found NAN at %lld",i);
1924 pbpm[i] = BAD_PIX;
1925 nan_pix++;
1926 }
1927 }
1928
1929 eris_check_error_code("eris_ifu_mask_nans_in_hdrlimage");
1930 return cpl_error_get_code();
1931}
1932
1933/*----------------------------------------------------------------------------*/
1940/*----------------------------------------------------------------------------*/
1941cpl_error_code eris_ifu_mask_nans_in_cube(cpl_imagelist *cube)
1942{
1943 cpl_error_code retVal = CPL_ERROR_NONE;
1944 cpl_size nx = 0,
1945 ny = 0,
1946 nz = 0,
1947 idx = 0;
1948 cpl_image *tmpImg = NULL;
1949 cpl_mask *mask = NULL;
1950 cpl_binary *maskData = NULL;
1951 const double *imgDataD = NULL;
1952 const float *imgDataF = NULL;
1953 cpl_type imgType = CPL_TYPE_INVALID;
1954
1955 cpl_ensure(cube, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
1956
1957 TRY
1958 {
1959 nz = cpl_imagelist_get_size(cube);
1960 if (nz > 0) {
1961 tmpImg = cpl_imagelist_get(cube,0);
1962 imgType = cpl_image_get_type(tmpImg);
1963 if (! (imgType == CPL_TYPE_FLOAT || imgType == CPL_TYPE_DOUBLE)) {
1964 BRK_WITH_ERROR_MSG(CPL_ERROR_INVALID_TYPE,
1965 "unsupported image type within cube");
1966 }
1967 nx = cpl_image_get_size_x(tmpImg);
1968 ny = cpl_image_get_size_y(tmpImg);
1969 }
1971 for (cpl_size z=0; z < nz; z++) {
1972 tmpImg = cpl_imagelist_get(cube,z);
1973 switch (imgType) {
1974 case CPL_TYPE_FLOAT:
1975 imgDataF = cpl_image_get_data_float_const(tmpImg);
1976 break;
1977 case CPL_TYPE_DOUBLE:
1978 imgDataD = cpl_image_get_data_double_const(tmpImg);
1979 break;
1980 default: break;
1981 }
1982 mask = cpl_image_get_bpm(tmpImg);
1983 maskData = cpl_mask_get_data(mask);
1984 for (cpl_size y=0; y < ny; y++) {
1985 for (cpl_size x=0; x < nx; x++) {
1986 idx = y * nx + x;
1987 switch (imgType) {
1988 case CPL_TYPE_FLOAT:
1989 if (!isfinite(imgDataF[idx])) {
1990 maskData[idx] = BAD_PIX;
1991 }
1992 break;
1993 case CPL_TYPE_DOUBLE:
1994 if (!isfinite(imgDataD[idx])) {
1995 maskData[idx] = BAD_PIX;
1996 }
1997 break;
1998 default: break;
1999 }
2000 }
2001 }
2003
2004 }
2005 }
2006 CATCH {
2007 retVal = cpl_error_get_code();
2008 }
2009 eris_check_error_code("eris_ifu_mask_nans_in_cube");
2010 return retVal;
2011}
2012
2013// /**
2014// * @brief eris_ifu_mask_reset
2015// * @param mask
2016// * @return
2017// */
2018//cpl_error_code eris_ifu_mask_reset(cpl_mask* mask)
2019//{
2020// cpl_error_code err = CPL_ERROR_NONE;
2021// cpl_size nx = 0,
2022// ny = 0;
2023//
2024// cpl_ensure_code(mask, CPL_ERROR_NULL_INPUT);
2025//
2026// TRY
2027// {
2028// nx = cpl_mask_get_size_x(mask);
2029// ny = cpl_mask_get_size_y(mask);
2030// CHECK_ERROR_STATE();
2031//
2032// for (int x = 1; x <= nx; x++) {
2033// for (int y = 1; y <= ny; y++) {
2034// cpl_mask_set(mask, x, y, GOOD_PIX);
2035// }
2036// }
2037// }
2038// CATCH
2039// {
2040// CATCH_MSGS();
2041// err = cpl_error_get_code();
2042// }
2043// return err;
2044//}
2045/*----------------------------------------------------------------------------*/
2046/* TODO: document bit code. Why bit code is double and not integer? */
2054/*----------------------------------------------------------------------------*/
2055cpl_mask* eris_ifu_quality2bp_mask(const cpl_image *qualityMask,
2056 deqQualityType qualityType)
2057{
2058 cpl_mask *bpmMask = NULL;
2059 TRY
2060 {
2061 ASSURE((qualityMask != NULL), CPL_ERROR_NULL_INPUT, NULL);
2062 bpmMask = cpl_mask_threshold_image_create(
2063 qualityMask, .5, 4294967296.5 );
2064 switch(qualityType) {
2065 case maskzero:
2066 cpl_mask_not(bpmMask);
2067 break;
2068 case maskone:
2069 break;
2070 case flag32bit:
2071 break;
2072 case flag16bit:
2073 break;
2074 case unspecified:
2075 cpl_mask_delete(bpmMask);
2076 BRK_WITH_ERROR_MSG(CPL_ERROR_ILLEGAL_INPUT,
2077 "Unspecified DEQ quality type");
2078
2079 break;
2080 default:
2081 BRK_WITH_ERROR_MSG(CPL_ERROR_ILLEGAL_INPUT,
2082 "Unknown DEQ quality type");
2083 }
2084 }
2085 CATCH {
2086 bpmMask = NULL;
2087 }
2088 eris_check_error_code("eris_ifu_quality2bp_mask");
2089 return bpmMask;
2090
2091}
2092/*----------------------------------------------------------------------------*/
2100/*----------------------------------------------------------------------------*/
2101cpl_imagelist* eris_ifu_interpolatedMask_to_maskZero(cpl_imagelist *bpmCube,
2102 double threshold)
2103{
2104 cpl_imagelist *maskOneCube = NULL;
2105 cpl_image *img = NULL;
2106 cpl_image *maskOneImg = NULL;
2107 int *maskOneImgPtr = NULL;
2108 float *floatPtr = NULL;
2109 double *doublePtr = NULL;
2110 float floatThreshold;
2111 cpl_size imgPixelCnt = 0,
2112 nx = 0,
2113 ny = 0;
2114 cpl_type bpmType;
2115
2116 TRY
2117 {
2118 ASSURE(bpmCube != NULL, CPL_ERROR_NULL_INPUT, "bpmCube must not be NULL");
2119
2120 maskOneCube = cpl_imagelist_new();
2121
2122 img = cpl_imagelist_get(bpmCube, 0);
2123 bpmType = cpl_image_get_type(img);
2124 ASSURE(bpmType == CPL_TYPE_FLOAT || bpmType == CPL_TYPE_DOUBLE,
2125 CPL_ERROR_ILLEGAL_INPUT, "bpmCube must be of type float or double");
2126
2127 nx = cpl_image_get_size_x(img);
2128 ny = cpl_image_get_size_y(img);
2129 imgPixelCnt = nx * ny;
2130
2131 floatThreshold = (float) threshold;
2132
2133 for (cpl_size cx=0; cx < cpl_imagelist_get_size(bpmCube); cx++) {
2134 img = cpl_imagelist_get(bpmCube, cx);
2135
2136 maskOneImg = cpl_image_new(nx, ny, CPL_TYPE_INT);
2137 maskOneImgPtr = cpl_image_get_data_int(maskOneImg);
2138
2139 if (bpmType == CPL_TYPE_FLOAT) {
2140 floatPtr = cpl_image_get_data_float(img);
2141 for (cpl_size px=0; px < imgPixelCnt; px++) {
2142 if (floatPtr[px] > floatThreshold) {
2143 maskOneImgPtr[px] = 1;
2144 } else {
2145 maskOneImgPtr[px] = 0;
2146 }
2147 }
2148 } else if (bpmType == CPL_TYPE_DOUBLE) {
2149 doublePtr = cpl_image_get_data_double(img);
2150 for (cpl_size px=0; px < imgPixelCnt; px++) {
2151 if (doublePtr[px] > threshold) {
2152 maskOneImgPtr[px] = 1;
2153 } else {
2154 maskOneImgPtr[px] = 0;
2155 }
2156 }
2157
2158 }
2159
2160 cpl_imagelist_set(maskOneCube, maskOneImg, cx);
2161 }
2162 }
2163 CATCH {
2164 maskOneCube = NULL;
2165 }
2166 eris_check_error_code("eris_ifu_interpolatedMask_to_maskZero");
2167 return maskOneCube;
2168
2169}
2170/*----------------------------------------------------------------------------*/
2180/*----------------------------------------------------------------------------*/
2181cpl_error_code eris_ifu_split_hdrl_imagelist(hdrl_imagelist *cube,
2182 cpl_imagelist *dataCube,
2183 cpl_imagelist *errorCube)
2184{
2185 cpl_error_code retVal = CPL_ERROR_NONE;
2186 hdrl_image *image = NULL;
2187 TRY
2188 {
2189
2190 cpl_ensure(cube != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2191 cpl_ensure(dataCube != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2192 cpl_ensure(errorCube != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2193 for (cpl_size ix=0; ix < hdrl_imagelist_get_size(cube); ix++) {
2194 image = hdrl_imagelist_get(cube, ix);
2195 cpl_imagelist_set(dataCube, cpl_image_duplicate(hdrl_image_get_image(image)), ix);
2196 cpl_imagelist_set(errorCube, cpl_image_duplicate(hdrl_image_get_error(image)), ix);
2197
2198 }
2199 }
2200 CATCH {
2201 }
2202 eris_check_error_code("eris_ifu_split_hdrl_imagelist");
2203 return retVal;
2204
2205}
2206
2207/*----------------------------------------------------------------------------*/
2218/*----------------------------------------------------------------------------*/
2219cpl_error_code eris_ifu_split3_hdrl_imagelist(hdrl_imagelist *cube,
2220 cpl_imagelist *dataCube,
2221 cpl_imagelist *errorCube,
2222 cpl_imagelist *qualCube)
2223{
2224 cpl_error_code retVal = CPL_ERROR_NONE;
2225 hdrl_image *image = NULL;
2226 TRY
2227 {
2228 cpl_ensure(cube != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2229 cpl_ensure(dataCube != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2230 cpl_ensure(errorCube != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2231 cpl_ensure(qualCube != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2232
2233 for (cpl_size ix=0; ix < hdrl_imagelist_get_size(cube); ix++) {
2234 image = hdrl_imagelist_get(cube, ix);
2235 cpl_imagelist_set(dataCube,
2236 hdrl_image_get_image(image), ix);
2237 cpl_imagelist_set(errorCube,
2238 hdrl_image_get_error(image), ix);
2239 cpl_imagelist_set(qualCube,
2240 cpl_image_new_from_mask(hdrl_image_get_mask(image)), ix);
2241
2242 }
2243 }
2244 CATCH {
2245 }
2246 eris_check_error_code("eris_ifu_split3_hdrl_imagelist");
2247 return retVal;
2248
2249}
2250/*----------------------------------------------------------------------------*/
2257/*----------------------------------------------------------------------------*/
2258cpl_table *
2260{
2261
2262 cpl_table *table;
2263
2264 table = cpl_table_new(0);
2265 cpl_table_new_column(table,"key_name", CPL_TYPE_STRING);
2266 cpl_table_new_column(table,"key_type", CPL_TYPE_STRING);
2267 cpl_table_new_column(table,"key_value", CPL_TYPE_STRING);
2268 cpl_table_new_column(table,"key_help", CPL_TYPE_STRING);
2269 eris_check_error_code("eris_qclog_init");
2270 return table;
2271}
2272/*----------------------------------------------------------------------------*/
2283/*----------------------------------------------------------------------------*/
2284cpl_error_code
2285eris_qclog_add_int(cpl_table* table,
2286 const char* key_name,
2287 const int value,
2288 const char* key_help)
2289{
2290
2291 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
2292 cpl_ensure_code(key_name != NULL, CPL_ERROR_NULL_INPUT);
2293 cpl_ensure_code(key_help != NULL, CPL_ERROR_NULL_INPUT);
2294
2295 int sz = cpl_table_get_nrow(table);
2296 int raw = sz;
2297 char* key_value;
2298 char* key_type;
2299
2300 key_value = cpl_sprintf("%d",value);
2301 key_type = cpl_sprintf("%s","CPL_TYPE_INT");
2302
2303 cpl_table_set_size(table,sz+1);
2304
2305 cpl_table_set_string(table,"key_name" ,raw,key_name);
2306 cpl_table_set_string(table,"key_type" ,raw,key_type);
2307 cpl_table_set_string(table,"key_value",raw,key_value);
2308 cpl_table_set_string(table,"key_help" ,raw,key_help);
2309
2310 cpl_free(key_value);
2311 cpl_free(key_type);
2312 eris_check_error_code("eris_qclog_add_int");
2313 return cpl_error_get_code();
2314
2315}
2316
2317/*----------------------------------------------------------------------------*/
2327/*----------------------------------------------------------------------------*/
2328
2329cpl_error_code
2330eris_qclog_add_bool(cpl_table* table,
2331 const char* key_name,
2332 const char* key_help)
2333{
2334 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
2335 cpl_ensure_code(key_name != NULL, CPL_ERROR_NULL_INPUT);
2336 cpl_ensure_code(key_help != NULL, CPL_ERROR_NULL_INPUT);
2337
2338 int sz = cpl_table_get_nrow(table);
2339 int raw = sz;
2340 char* key_value;
2341 char* key_type;
2342
2343 key_value = cpl_sprintf("%s",key_name);
2344 key_type = cpl_sprintf("%s","CPL_TYPE_BOOL");
2345
2346 cpl_table_set_size(table,sz+1);
2347
2348 cpl_table_set_string(table,"key_name" ,raw,key_name);
2349 cpl_table_set_string(table,"key_type" ,raw,key_type);
2350 cpl_table_set_string(table,"key_value",raw,key_value);
2351 cpl_table_set_string(table,"key_help" ,raw,key_help);
2352 cpl_free(key_value);
2353 cpl_free(key_type);
2354 eris_check_error_code("eris_qclog_add_bool");
2355 return cpl_error_get_code();
2356
2357}
2358
2359/*----------------------------------------------------------------------------*/
2370/*----------------------------------------------------------------------------*/
2371cpl_error_code
2372eris_qclog_add_double(cpl_table* table,
2373 const char* key_name,
2374 const double value,
2375 const char* key_help)
2376{
2377 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
2378 cpl_ensure_code(key_name != NULL, CPL_ERROR_NULL_INPUT);
2379 cpl_ensure_code(key_help != NULL, CPL_ERROR_NULL_INPUT);
2380
2381 int sz = cpl_table_get_nrow(table);
2382
2383 int raw = sz;
2384 char* key_value;
2385 char* key_type;
2386
2387 key_value = cpl_sprintf("%g",value);
2388
2389 key_type = cpl_sprintf("%s","CPL_TYPE_DOUBLE");
2390
2391 cpl_table_set_size(table,sz+1);
2392
2393 cpl_table_set_string(table,"key_name" ,raw,key_name);
2394 cpl_table_set_string(table,"key_type" ,raw,key_type);
2395 cpl_table_set_string(table,"key_value",raw,key_value);
2396 cpl_table_set_string(table,"key_help" ,raw,key_help);
2397
2398 cpl_free(key_value);
2399 cpl_free(key_type);
2400 eris_check_error_code("eris_qclog_add_double");
2401 return cpl_error_get_code();
2402
2403}
2404/*----------------------------------------------------------------------------*/
2415/*----------------------------------------------------------------------------*/
2416cpl_error_code
2418 const char* key_name,
2419 const double value,
2420 const char* key_help)
2421{
2422
2423 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
2424 cpl_ensure_code(key_name != NULL, CPL_ERROR_NULL_INPUT);
2425 cpl_ensure_code(key_help != NULL, CPL_ERROR_NULL_INPUT);
2426
2427 int sz = cpl_table_get_nrow(table);
2428 int raw = sz;
2429 char* key_value;
2430 char* key_type;
2431
2432 key_value = cpl_sprintf("%f",value);
2433 key_type = cpl_sprintf("%s","CPL_TYPE_DOUBLE");
2434
2435 cpl_table_set_size(table,sz+1);
2436
2437 cpl_table_set_string(table,"key_name" ,raw,key_name);
2438 cpl_table_set_string(table,"key_type" ,raw,key_type);
2439 cpl_table_set_string(table,"key_value",raw,key_value);
2440 cpl_table_set_string(table,"key_help" ,raw,key_help);
2441 cpl_free(key_value);
2442 cpl_free(key_type);
2443 eris_check_error_code("eris_qclog_add_double_f");
2444 return cpl_error_get_code();
2445
2446}
2447/*----------------------------------------------------------------------------*/
2458/*----------------------------------------------------------------------------*/
2459cpl_error_code
2461 const char* key_name,
2462 const double value,
2463 const char* key_help)
2464{
2465
2466 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
2467 cpl_ensure_code(key_name != NULL, CPL_ERROR_NULL_INPUT);
2468 cpl_ensure_code(key_help != NULL, CPL_ERROR_NULL_INPUT);
2469
2470 int sz = cpl_table_get_nrow(table);
2471 int raw = sz;
2472 char* key_value;
2473 char* key_type;
2474
2475 key_value = cpl_sprintf("%13.6f",value);
2476 key_type = cpl_sprintf("%s","CPL_TYPE_DOUBLE");
2477
2478 cpl_table_set_size(table,sz+1);
2479
2480 cpl_table_set_string(table,"key_name" ,raw,key_name);
2481 cpl_table_set_string(table,"key_type" ,raw,key_type);
2482 cpl_table_set_string(table,"key_value",raw,key_value);
2483 cpl_table_set_string(table,"key_help" ,raw,key_help);
2484 cpl_free(key_value);
2485 cpl_free(key_type);
2486 eris_check_error_code("eris_qclog_add_double_format");
2487 return cpl_error_get_code();
2488
2489}
2490/*----------------------------------------------------------------------------*/
2501/*----------------------------------------------------------------------------*/
2502cpl_error_code
2503eris_qclog_add_string(cpl_table* table,
2504 const char* key_name,
2505 const char* value,
2506 const char* key_help)
2507{
2508
2509 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
2510 cpl_ensure_code(key_name != NULL, CPL_ERROR_NULL_INPUT);
2511 cpl_ensure_code(key_help != NULL, CPL_ERROR_NULL_INPUT);
2512
2513 int sz = cpl_table_get_nrow(table);
2514 int raw = sz;
2515 char* key_value;
2516 char* key_type;
2517
2518 key_value = cpl_sprintf("%s",value);
2519 key_type = cpl_sprintf("%s","CPL_TYPE_STRING");
2520
2521 cpl_table_set_size(table,sz+1);
2522
2523 cpl_table_set_string(table,"key_name" ,raw,key_name);
2524 cpl_table_set_string(table,"key_type" ,raw,key_type);
2525 cpl_table_set_string(table,"key_value",raw,key_value);
2526 cpl_table_set_string(table,"key_help" ,raw,key_help);
2527 cpl_free(key_value);
2528 cpl_free(key_type);
2529 eris_check_error_code("eris_qclog_add_string");
2530 return cpl_error_get_code();
2531
2532}
2533
2534/*----------------------------------------------------------------------------*/
2543/*----------------------------------------------------------------------------*/
2544cpl_error_code
2546 cpl_propertylist * plist,
2547 cpl_table * qclog)
2548{
2549
2550
2551 cpl_ensure_code(plist != NULL, CPL_ERROR_NULL_INPUT);
2552 cpl_ensure_code(qclog != NULL, CPL_ERROR_NULL_INPUT);
2553 char* key_name = NULL;
2554 char* key_value = NULL;
2555 char* key_type = NULL;
2556 char* key_help = NULL;
2557 /*
2558 char key_name[FILE_NAME_SZ];
2559 char key_value[FILE_NAME_SZ];
2560 char key_type[FILE_NAME_SZ];
2561 char key_help[FILE_NAME_SZ] ;
2562 */
2563
2564 int i = 0;
2565 int n = 0;
2566 /* Test entries */
2567 if (plist == NULL) {
2568 cpl_msg_error(cpl_func,"plist=NULL, something strange");
2569 return CPL_ERROR_NULL_INPUT ;
2570 }
2571 /* Parameter Name: PIPEFILE */
2572
2573 //cpl_table_save(qclog,NULL,NULL,"qclog.fits",CPL_IO_CREATE);
2574 n = cpl_table_get_nrow(qclog);
2575 for(i = 0; i < n; i++) {
2576
2577 key_name = cpl_sprintf("ESO %s",cpl_table_get_string(qclog, "key_name", i));
2578 //strcat(key_name, cpl_table_get_string(qclog, "key_name", i));
2579 key_type = cpl_sprintf("%s", cpl_table_get_string(qclog, "key_type", i));
2580 //strcpy(key_type, cpl_table_get_string(qclog, "key_type", i));
2581 key_value = cpl_sprintf("%s", cpl_table_get_string(qclog, "key_value", i));
2582 //strcpy(key_value, cpl_table_get_string(qclog, "key_value", i));
2583 key_help = cpl_sprintf("%s", cpl_table_get_string(qclog, "key_help", i));
2584 //strcpy(key_help, cpl_table_get_string(qclog, "key_help", i));
2585 /*
2586 cpl_msg_info(cpl_func,"raw %i, name=%s type=%s value=%s\n",
2587 i,key_name,key_type,key_value);
2588 */
2589 if( !cpl_propertylist_has(plist, key_name) ) {
2590 if(strcmp(key_type, "CPL_TYPE_STRING") == 0) {
2591 cpl_propertylist_append_string(plist, key_name, key_value) ;
2592 cpl_propertylist_set_comment(plist, key_name, key_help) ;
2593 } else if(strcmp(key_type, "CPL_TYPE_BOOL") == 0) {
2594 cpl_propertylist_append_bool(plist, key_name, atoi(key_value)) ;
2595 cpl_propertylist_set_comment(plist, key_name, key_help) ;
2596 } else if(strcmp(key_type, "CPL_TYPE_INT") == 0) {
2597 cpl_propertylist_append_int(plist, key_name, atoi(key_value)) ;
2598 cpl_propertylist_set_comment(plist, key_name, key_help) ;
2599 } else if(strcmp(key_type, "CPL_TYPE_FLOAT") == 0) {
2600 cpl_propertylist_append_float(plist, key_name, (float) atof(key_value)) ;
2601 cpl_propertylist_set_comment(plist, key_name, key_help) ;
2602 } else if(strcmp(key_type, "CPL_TYPE_DOUBLE") == 0) {
2603 cpl_propertylist_append_double(plist, key_name, atof(key_value)) ;
2604 cpl_propertylist_set_comment(plist, key_name, key_help) ;
2605 }
2606 }
2607 cpl_free(key_name);
2608 cpl_free(key_type);
2609 cpl_free(key_value);
2610 cpl_free(key_help);
2611
2612 }
2613 eris_check_error_code("eris_pfits_put_qc");
2614 return cpl_error_get_code();
2615}
2616/*----------------------------------------------------------------------------*/
2626/*----------------------------------------------------------------------------*/
2627cpl_error_code
2628eris_ifu_get_badpix_qc_from_ima(const cpl_image* image,
2629 cpl_propertylist* qc_list,
2630 const char* prefix)
2631{
2632
2633 cpl_ensure_code(image != NULL, CPL_ERROR_NULL_INPUT);
2634 cpl_ensure_code(qc_list != NULL, CPL_ERROR_NULL_INPUT);
2635 cpl_ensure_code(prefix != NULL, CPL_ERROR_NULL_INPUT);
2636 cpl_size sx = cpl_image_get_size_x(image);
2637 cpl_size sy = cpl_image_get_size_y(image);
2638 cpl_image* ima = cpl_image_duplicate(image);
2639 cpl_image_threshold(ima, 0, 0, 0, 1);
2640 double flux = cpl_image_get_flux(ima);
2641 cpl_image_delete(ima);
2642 cpl_size nBadPix = (cpl_size) flux;
2643
2644 cpl_size npix = sx * sy;
2645 double fracBadPix = flux / npix;
2646 char* kname;
2647 cpl_msg_warning(cpl_func,"nBadPix: %lld",nBadPix);
2648 kname = cpl_sprintf("%s NBADPIX",prefix);
2649 cpl_msg_info(cpl_func,"kname: %s prefix: %s",kname, prefix);
2650 eris_ifu_append_qc_int(qc_list, kname, nBadPix, "Number of bad pixels");
2651 cpl_free(kname);
2652
2653 kname = cpl_sprintf("%s BPIXFRAC",prefix);
2654 eris_ifu_append_qc_double(qc_list, kname, fracBadPix,
2655 "Fraction of bad pixels to total");
2656 cpl_free(kname);
2657 eris_check_error_code("eris_ifu_get_badpix_qc_from_ima");
2658 return cpl_error_get_code();
2659}
2660
2661/*----------------------------------------------------------------------------*/
2671/*----------------------------------------------------------------------------*/
2672cpl_error_code
2673eris_ifu_get_badpix_qc_from_mask(const cpl_mask* bp_mask,
2674 cpl_propertylist* qc_list,
2675 const char* prefix)
2676{
2677 cpl_ensure_code(bp_mask != NULL, CPL_ERROR_NULL_INPUT);
2678 cpl_ensure_code(qc_list != NULL, CPL_ERROR_NULL_INPUT);
2679 cpl_ensure_code(prefix != NULL, CPL_ERROR_NULL_INPUT);
2680 cpl_size sx = cpl_mask_get_size_x(bp_mask);
2681 cpl_size sy = cpl_mask_get_size_y(bp_mask);
2682 cpl_size nBadPix = cpl_mask_count(bp_mask);
2683
2684 cpl_size npix = sx * sy;
2685 double fracBadPix = (double) nBadPix / npix;
2686 char* kname;
2687
2688 kname = cpl_sprintf("%s NBADPIX",prefix);
2689 cpl_msg_info(cpl_func,"kname: %s prefix: %s",kname, prefix);
2690 eris_ifu_append_qc_int(qc_list, kname, nBadPix, "Number of bad pixels");
2691 cpl_free(kname);
2692
2693 kname = cpl_sprintf("%s BPIXFRAC",prefix);
2694 eris_ifu_append_qc_double(qc_list, kname, fracBadPix,
2695 "Fraction of bad pixels to total");
2696 cpl_free(kname);
2697 eris_check_error_code("eris_ifu_get_badpix_qc_from_mask");
2698 return cpl_error_get_code();
2699}
2700
2701/*----------------------------------------------------------------------------*/
2721/*----------------------------------------------------------------------------*/
2722static cpl_error_code eris_apertures_find_max_flux(const cpl_apertures * self,
2723 int * ind, int nfind)
2724{
2725
2726
2727
2728 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2729
2730 const int nsize = cpl_apertures_get_size(self);
2731 int ifind;
2732
2733
2734 cpl_ensure_code(nsize > 0, CPL_ERROR_ILLEGAL_INPUT);
2735 cpl_ensure_code(ind, CPL_ERROR_NULL_INPUT);
2736 cpl_ensure_code(nfind > 0, CPL_ERROR_ILLEGAL_INPUT);
2737 cpl_ensure_code(nfind <= nsize, CPL_ERROR_ILLEGAL_INPUT);
2738
2739 for (ifind=0; ifind < nfind; ifind++) {
2740 double maxflux = -1;
2741 int maxind = -1;
2742 int i;
2743 for (i=1; i <= nsize; i++) {
2744 int k;
2745
2746 /* The flux has to be the highest among those not already found */
2747 for (k=0; k < ifind; k++) if (ind[k] == i) break;
2748
2749 if (k == ifind) {
2750 /* i has not been inserted into ind */
2751 const double flux = cpl_apertures_get_flux(self, i);
2752
2753 if (maxind < 0 || flux > maxflux) {
2754 maxind = i;
2755 maxflux = flux;
2756 }
2757 }
2758 }
2759 ind[ifind] = maxind;
2760 }
2761 eris_check_error_code("eris_apertures_find_max_flux");
2762 return CPL_ERROR_NONE;
2763
2764}
2765
2766/*----------------------------------------------------------------------------*/
2786/*----------------------------------------------------------------------------*/
2787cpl_error_code
2788eris_gaussian_maxpos(const cpl_image * self,
2789 double sigma,
2790 double * pxpos,
2791 double * pypos,
2792 double * ppeak,
2793 double * sigma_x,
2794 double * sigma_y)
2795{
2796 /* copied from irplib_strehl.c r163170 */
2797
2798
2799 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2800 cpl_ensure(sigma > 0, CPL_ERROR_ILLEGAL_INPUT, CPL_ERROR_ILLEGAL_INPUT);
2801
2802
2803
2804 const cpl_size nx = cpl_image_get_size_x(self);
2805 const cpl_size ny = cpl_image_get_size_y(self);
2806 int iretry = 3; /* Number retries with decreasing sigma */
2807 int ifluxapert = 0;
2808 double med_dist;
2809 const double median = cpl_image_get_median_dev(self, &med_dist);
2810 cpl_mask * selection = NULL;
2811 cpl_size nlabels = 0;
2812 cpl_image * labels = NULL;
2813 cpl_apertures * aperts;
2814 cpl_size npixobj;
2815 double objradius;
2816 cpl_size winsize;
2817 cpl_size xposmax, yposmax;
2818 double xposcen, yposcen;
2819 double valmax, valfit = -1.0;
2820 cpl_array * gauss_parameters = NULL;
2821 cpl_errorstate prestate = cpl_errorstate_get();
2822 cpl_error_code code = CPL_ERROR_NONE;
2823
2824
2825 cpl_ensure_code( sigma > 0.0, CPL_ERROR_ILLEGAL_INPUT);
2826
2827 selection = cpl_mask_new(nx, ny);
2828
2829 /* find aperture with signal larger than sigma * median deviation */
2830 for (; iretry > 0 && nlabels == 0; iretry--, sigma *= 0.5) {
2831
2832 /* Compute the threshold */
2833 const double threshold = median + sigma * med_dist;
2834
2835 /* Select the pixel above the threshold */
2836 code = cpl_mask_threshold_image(selection, self, threshold, DBL_MAX,
2837 BAD_PIX);
2838
2839 if (code) break;
2840
2841 /* Labelise the thresholded selection */
2842 cpl_image_delete(labels);
2843 labels = cpl_image_labelise_mask_create(selection, &nlabels);
2844 }
2845 sigma *= 2.0; /* reverse last iteration that found no labels */
2846
2847 cpl_mask_delete(selection);
2848
2849 if (code) {
2850 cpl_image_delete(labels);
2851 return cpl_error_set_where(cpl_func);
2852 } else if (nlabels == 0) {
2853 cpl_image_delete(labels);
2854 return cpl_error_set(cpl_func, CPL_ERROR_DATA_NOT_FOUND);
2855 }
2856
2857 aperts = cpl_apertures_new_from_image(self, labels);
2858
2859 /* Find the aperture with the greatest flux */
2860 code = eris_apertures_find_max_flux(aperts, &ifluxapert, 1);
2861
2862 if (code) {
2863 cpl_apertures_delete(aperts);
2864 cpl_image_delete(labels);
2865 return cpl_error_set(cpl_func, CPL_ERROR_DATA_NOT_FOUND);
2866 }
2867
2868 npixobj = cpl_apertures_get_npix(aperts, ifluxapert);
2869 objradius = sqrt((double)npixobj * CPL_MATH_1_PI);
2870 winsize = CX_MIN(CX_MIN(nx, ny), (3.0 * objradius));
2871
2872 xposmax = cpl_apertures_get_maxpos_x(aperts, ifluxapert);
2873 yposmax = cpl_apertures_get_maxpos_y(aperts, ifluxapert);
2874 xposcen = cpl_apertures_get_centroid_x(aperts, ifluxapert);
2875 yposcen = cpl_apertures_get_centroid_y(aperts, ifluxapert);
2876 valmax = cpl_apertures_get_max(aperts, ifluxapert);
2877
2878 cpl_apertures_delete(aperts);
2879 cpl_image_delete(labels);
2880
2881 cpl_msg_debug(cpl_func, "Object radius at S/R=%g: %g (window-size=%u)",
2882 sigma, objradius, (unsigned)winsize);
2883 cpl_msg_debug(cpl_func, "Object-peak @ (%d, %d) = %g", (int)xposmax,
2884 (int)yposmax, valmax);
2885
2886 /* fit gaussian to get subpixel peak position */
2887
2888 gauss_parameters = cpl_array_new(7, CPL_TYPE_DOUBLE);
2889 cpl_array_set_double(gauss_parameters, 0, median);
2890
2891 code = cpl_fit_image_gaussian(self, NULL, xposmax, yposmax,
2892 winsize, winsize, gauss_parameters,
2893 NULL, NULL, NULL,
2894 NULL, NULL, NULL,
2895 NULL, NULL, NULL);
2896 if (!code) {
2897 const double M_x = cpl_array_get_double(gauss_parameters, 3, NULL);
2898 const double M_y = cpl_array_get_double(gauss_parameters, 4, NULL);
2899 const double SIGMA_x = cpl_array_get_double(gauss_parameters, 5, NULL);
2900 const double SIGMA_y = cpl_array_get_double(gauss_parameters, 6, NULL);
2901 valfit = cpl_gaussian_eval_2d(gauss_parameters, M_x, M_y);
2902 if (!cpl_errorstate_is_equal(prestate)) {
2903 code = cpl_error_get_code();
2904 } else {
2905 *pxpos = M_x;
2906 *pypos = M_y;
2907 *ppeak = valfit;
2908 *sigma_x = SIGMA_x;
2909 *sigma_y = SIGMA_y;
2910
2911 cpl_msg_debug(cpl_func, "Gauss-fit @ (%g, %g) = %g, SIGMA: (%g, %g)",
2912 M_x, M_y, valfit,
2913 SIGMA_x,
2914 SIGMA_y);
2915
2916 }
2917 }
2918 cpl_array_delete(gauss_parameters);
2919
2920 if (code || valfit < valmax) {
2921 cpl_errorstate_set(prestate);
2922 *pxpos = xposcen;
2923 *pypos = yposcen;
2924 *ppeak = valmax;
2925 }
2926 eris_check_error_code("eris_gaussian_maxpos");
2927 return code ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE;
2928}
2929
2930/*----------------------------------------------------------------------------*/
2938/*----------------------------------------------------------------------------*/
2939
2940cpl_propertylist*
2941eris_compute_psf_qc(hdrl_image* hima, const cpl_parameterlist* parlist,
2942 const char* context){
2943
2944 cpl_ensure(hima != NULL, CPL_ERROR_NULL_INPUT, NULL);
2945 cpl_ensure(parlist != NULL, CPL_ERROR_NULL_INPUT, NULL);
2946 cpl_ensure(context != NULL, CPL_ERROR_NULL_INPUT, NULL);
2947
2948 //cpl_errorstate clean_state = cpl_errorstate_get();
2949 cpl_size ima_szx = hdrl_image_get_size_x(hima);
2950 cpl_size ima_szy = hdrl_image_get_size_y(hima);
2951
2952 double peak = 0;
2953 double max_x = 0;
2954 double max_y = 0;
2955 double sigma_x = 0;
2956 double sigma_y = 0;
2957 double FWHM_x = 0;
2958 double FWHM_y = 0;
2959 cpl_image* image = hdrl_image_get_image(hima);
2960 cpl_image* error = hdrl_image_get_image(hima);
2961
2962 cpl_propertylist* qchead = cpl_propertylist_new();
2963 eris_gaussian_maxpos(image, 5, &max_x, &max_y, &peak, &sigma_x, &sigma_y);
2964 FWHM_x = sigma_x * CPL_MATH_FWHM_SIG;
2965 FWHM_y = sigma_y * CPL_MATH_FWHM_SIG;
2966 cpl_msg_info(cpl_func, "max_x: %g max_y: %g FWHM_x:%g FWHM_y: %g",
2967 max_x, max_y, FWHM_x, FWHM_y);
2968
2969 if(cpl_error_get_code() != CPL_ERROR_NONE) {
2970 cpl_msg_error(cpl_func,"Error fitting 2D Gaussian to object for QC. Exit");
2971 cpl_error_reset();
2972 return qchead;
2973 }
2974
2975 int max_ima_x = (int) (max_x + 0.5);
2976 int max_ima_y = (int) (max_y + 0.5);
2977
2978 int psf_sz = 40;
2979 int wllx = ((max_ima_x - psf_sz)>0) ? (max_ima_x - psf_sz) : 1;
2980 int wlly = ((max_ima_y - psf_sz)>0) ? (max_ima_y - psf_sz) : 1;
2981 int wurx = ((max_ima_x + psf_sz)<ima_szx) ? (max_ima_x + psf_sz) : ima_szx ;
2982 int wury = ((max_ima_y + psf_sz)<ima_szy) ? (max_ima_y + psf_sz) : ima_szy ;
2983
2984 cpl_table* qclog_tbl = eris_qclog_init();
2985
2986 /* not used code:
2987 double max_ima_cx = 0;
2988 max_ima_cx = cpl_image_get_centroid_x_window(image, wllx, wlly, wurx, wury);
2989 double max_ima_cy = 0;
2990 max_ima_cy = cpl_image_get_centroid_y_window(image, wllx, wlly, wurx, wury);
2991 */
2992
2993 int llx = 8;
2994 int lly = 8;
2995 int halfbox_x = 16;
2996 int halfbox_y = 16;
2997 eris_qclog_add_int(qclog_tbl,"QC FWHM LLX", llx, "[pix] STD star FWHM LLX");
2998 eris_qclog_add_int(qclog_tbl,"QC FWHM LLY", lly, "[pix] STD star FWHM LLY");
2999 eris_qclog_add_int(qclog_tbl,"QC FWHM HBX", halfbox_x, "[pix] STD star FWHM HBX");
3000 eris_qclog_add_int(qclog_tbl,"QC FWHM HBX", halfbox_y, "[pix] STD star FWHM HBY");
3001
3002
3003 int check1 = 0;
3004 double* pdata = cpl_image_get_data_double(image);
3005 cpl_size npix = cpl_image_get_size_x(image) * cpl_image_get_size_y(image);
3006 cpl_boolean has_nan = CPL_FALSE;
3007 for(cpl_size i =0; i < npix; i++ ) {
3008 if(eris_ifu_is_nan_or_inf(pdata[i])) {
3009 has_nan = CPL_TRUE;
3010 break;
3011 }
3012 }
3013
3014 cpl_bivector * biv = NULL;
3015 if(has_nan == CPL_FALSE) {
3016 cpl_image* fimage = cpl_image_cast(image, CPL_TYPE_FLOAT);
3017 //cpl_image_reject_from_mask(image, mask);
3018 biv = cpl_image_iqe(fimage, wllx, wlly, wurx, wury);
3019 cpl_image_delete(fimage);
3020 }
3021
3022 if( (cpl_error_get_code() == CPL_ERROR_NONE) && (has_nan == CPL_FALSE)) {
3023 const double * x = cpl_bivector_get_x_data_const(biv);
3024 eris_qclog_add_double(qclog_tbl, "QC CENTERX", x[0],
3025 "[pix] STD star X centroid position");
3026 eris_qclog_add_double(qclog_tbl, "QC CENTERY", x[1],
3027 "[pix] STD star Y centroid position");
3028 eris_qclog_add_double(qclog_tbl, "QC FWHM MAJ", x[2],
3029 "[pix] STD star FWHM on major axis");
3030 eris_qclog_add_double(qclog_tbl, "QC FWHM MIN", x[3],
3031 "[pix] STD star FWHM on minor axis");
3032 eris_qclog_add_double(qclog_tbl, "QC THETA", x[4],
3033 "[deg] STD star ellipsis angle theta");
3034 cpl_bivector_delete(biv);
3035 } else {
3036 eris_qclog_add_double(qclog_tbl, "QC CENTERX", max_x,
3037 "[pix] STD star X centroid position");
3038 eris_qclog_add_double(qclog_tbl, "QC CENTERY", max_y,
3039 "[pix] STD star Y centroid position");
3040 eris_qclog_add_double(qclog_tbl, "QC FWHM MAJ", FWHM_x,
3041 "[pix] STD star FWHM on major axis");
3042 eris_qclog_add_double(qclog_tbl, "QC FWHM MIN", FWHM_y,
3043 "[pix] STD star FWHM on minor axis");
3044
3045 cpl_error_reset();
3046 }
3047
3048 double xcen = max_x;
3049 double ycen = max_y;
3050 if (has_nan == CPL_FALSE) {
3051// double norm = 0;
3052
3053// double sig_x = 0;
3054// double sig_y = 0;
3055 double fwhm_x = 0;
3056 double fwhm_y = 0;
3057 //double disp = 0;
3058
3059 double fwhm_factor = 5.0;
3060
3061 char* pname = cpl_sprintf("%s.fwhm-factor",context);
3062 eris_parameters_get_double(parlist, pname, &fwhm_factor);
3063 cpl_free(pname);
3064 double rms = 0;
3065 double red_chisq = 0;
3066 cpl_matrix* covariance = NULL;
3067 double major = 0;
3068 double minor = 0;
3069 double angle = 0;
3070 cpl_array* fit_params = NULL;
3071 cpl_array* gauss2d_fit_params = cpl_array_new(7, CPL_TYPE_DOUBLE);
3072 cpl_array* gauss2d_err_params = cpl_array_new(7, CPL_TYPE_DOUBLE);
3073 cpl_matrix* phys_cov = NULL;
3074 int status = 0;
3075
3076 if(CPL_ERROR_NONE == cpl_fit_image_gaussian(image, error,
3077 max_ima_x, max_ima_y, psf_sz, psf_sz, gauss2d_fit_params,
3078 gauss2d_err_params, fit_params, &rms, &red_chisq, &covariance,
3079 &major, &minor, &angle, &phys_cov) ) {
3080 sigma_x = cpl_array_get(gauss2d_fit_params, 5, &status);
3081 sigma_y = cpl_array_get(gauss2d_fit_params, 6, &status);
3082
3083 fwhm_x = sigma_x * CPL_MATH_FWHM_SIG;
3084 fwhm_y = sigma_y * CPL_MATH_FWHM_SIG;
3085 eris_qclog_add_double_f(qclog_tbl, "QC FWHMX", fwhm_x,
3086 "[pix] STD star FWHM on X");
3087 eris_qclog_add_double_f(qclog_tbl, "QC FWHMY", fwhm_y,
3088 "[pix] STD star FWHM on Y");
3089
3090 halfbox_x = (floor)(0.5 * (fwhm_x + fwhm_y) * fwhm_factor + 0.5);
3091
3092 halfbox_y = (floor)(0.5 * (fwhm_x + fwhm_y) * fwhm_factor + 0.5);
3093
3094 } else {
3095 //TODO remove irplib
3096 //irplib_error_recover(clean_state, "Problem fitting Gaussian");
3097 cpl_array_delete(gauss2d_fit_params);
3098 cpl_array_delete(gauss2d_err_params);
3099 cpl_error_reset();
3100
3101 }
3102 } else {
3103
3104 eris_qclog_add_double_f(qclog_tbl, "QC FWHMX", FWHM_x,
3105 "[pix] STD star FWHM on X");
3106 eris_qclog_add_double_f(qclog_tbl, "QC FWHMY", FWHM_y,
3107 "[pix] STD star FWHM on Y");
3108 }
3109
3110 /* we use a large value of kappa to be sure to flag well the object */
3111 //cpl_mask* obj_mask=NULL;
3112 //int pfx = 3;
3113 //int pfy = 3;
3114 //const char* pfm;
3115 //TODO: maybe use the mask defined elsewhere for extraction
3116 //if(strcmp(extract_method, "optimal") != 0) {
3117 // double kappa = 5.;
3118 // obj_mask = eris_object_mask(image, pfm, pfx, pfy, kappa);
3119 //}
3120
3121
3122 llx = (int)(xcen - halfbox_x);
3123 llx = (llx > 0 ) ? llx : 1;
3124
3125 if((llx + 2 * halfbox_x) >= ima_szx) {
3126 halfbox_x = (int) ((ima_szx - llx - 1) / 2);
3127 check1++;
3128 }
3129
3130 lly = (int)(ycen - halfbox_y);
3131 lly = (lly > 0 ) ? lly : 1;
3132 if((lly + 2 * halfbox_y) >= ima_szy) {
3133 halfbox_y = (int) ((ima_szy - lly - 1) / 2);
3134 check1++;
3135 }
3136 eris_qclog_add_int(qclog_tbl,"QC CHECK1", check1,
3137 "Check on evaluation box");
3138 //cpl_table_save(qclog_tbl,NULL,NULL,"qclog_tbl.fits",CPL_IO_DEFAULT);
3139 eris_pfits_put_qc(qchead, qclog_tbl);
3140 cpl_table_delete(qclog_tbl);
3141 eris_check_error_code("eris_compute_psf_qc");
3142 return qchead;
3143
3144}
3145
3146static cpl_error_code
3147eris_imagelist_reject_value(hdrl_imagelist* iml/*, cpl_value value*/)
3148{
3149
3150 cpl_ensure(iml != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
3151
3152 cpl_size sz = hdrl_imagelist_get_size(iml);
3153
3154 for(cpl_size i = 0; i < sz; i++) {
3155 hdrl_image* hima = hdrl_imagelist_get(iml, i);
3156 hdrl_image_reject_value(hima, CPL_VALUE_NAN);
3157 }
3158 return cpl_error_get_code();
3159}
3160/*----------------------------------------------------------------------------*/
3168/*----------------------------------------------------------------------------*/
3169cpl_mask*
3170eris_ifu_hima_get_obj_mask_percent(hdrl_image* hima, const double percent)
3171{
3172 cpl_mask* mask_obj = NULL;
3173
3174 cpl_size sx = hdrl_image_get_size_x(hima);
3175 cpl_size sy = hdrl_image_get_size_y(hima);
3176
3177 cpl_image* image = hdrl_image_get_image(hima);
3178 cpl_image* ima_tmp = cpl_image_duplicate(image);
3179
3180
3181 cpl_ensure(hima != NULL, CPL_ERROR_NULL_INPUT, NULL);
3182 cpl_ensure(0.25 <= percent && percent <= 0.75, CPL_ERROR_ILLEGAL_INPUT, NULL);
3183 double* data = cpl_image_get_data(ima_tmp);
3184
3185 cpl_size npoints = sx * sy;
3186 cpl_ensure(npoints > 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
3187 cpl_vector* v = cpl_vector_new(npoints);
3188 v = cpl_vector_wrap(npoints, data);
3189
3190 cpl_vector_sort(v, CPL_SORT_ASCENDING);
3191
3192 cpl_size thresh_pos = percent * npoints;
3193 double threshold_max = cpl_vector_get(v, thresh_pos);
3194 //cpl_msg_info(cpl_func,"threshold_max: %g",threshold_max);
3195 cpl_vector_unwrap(v);
3196 cpl_image_delete(ima_tmp);
3197 mask_obj = cpl_mask_threshold_image_create(image, DBL_MIN, threshold_max);
3198 cpl_mask_not(mask_obj);
3199 if (v != NULL) {
3200 cpl_vector_delete(v);
3201 }
3202 return mask_obj;
3203}
3204/*----------------------------------------------------------------------------*/
3213/*----------------------------------------------------------------------------*/
3214cpl_mask*
3215eris_ifu_hima_get_obj_mask(hdrl_image* hima, const cpl_size niter,
3216 const double kappa)
3217{
3218
3219 cpl_mask* mask_tmp = NULL;
3220 cpl_mask* mask_obj = NULL;
3221 hdrl_value median = {0, 0};
3222 double max = 0;
3223 double stdev = 0;
3224
3225 cpl_ensure(hima != NULL, CPL_ERROR_NULL_INPUT, NULL);
3226 cpl_ensure(1 <= niter && niter <= 100, CPL_ERROR_ILLEGAL_INPUT, NULL);
3227 cpl_ensure(kappa > 0., CPL_ERROR_ILLEGAL_INPUT, NULL);
3228
3229 max = cpl_image_get_max(hdrl_image_get_image(hima));
3230
3231 for (cpl_size i = 0; i < niter; i++) {
3232 median = hdrl_image_get_median(hima);
3233 if (!isnan(median.data)) {
3234 stdev = hdrl_image_get_stdev(hima);
3235 double thresh_max = median.data + kappa * stdev;
3236 cpl_msg_info(cpl_func, "median: %g stdev: %g thresh: %g max: %g",
3237 median.data, stdev, thresh_max, max);
3238 thresh_max = (thresh_max < max) ? thresh_max : 0.99 * max;
3239 cpl_msg_info(cpl_func, "median: %g stdev: %g thresh: %g max: %g",
3240 median.data, stdev, thresh_max, max);
3241 if (stdev > 0) {
3242
3243 cpl_image* ima_tmp = hdrl_image_get_image(hima);
3244
3245 mask_tmp = cpl_mask_threshold_image_create(ima_tmp, DBL_MIN, thresh_max);
3246 cpl_mask_not(mask_tmp);
3247
3248 hdrl_image_reject_from_mask(hima, mask_tmp);
3249
3250 if (i == (niter -1)) {
3251 mask_obj = cpl_mask_duplicate(mask_tmp);
3252 }
3253 cpl_mask_delete(mask_tmp);
3254 }
3255 }
3256 }
3257
3258 eris_check_error_code("eris_ifu_hima_get_obj_mask");
3259 return mask_obj;
3260}
3261
3269cpl_error_code
3270eris_get_pupil_shift(hdrl_imagelist* iml, const int n, cpl_table** qclog_tbl)
3271{
3272
3273
3274 cpl_ensure(iml != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
3275 cpl_ensure(qclog_tbl != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
3276 cpl_ensure(*qclog_tbl != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
3277 cpl_ensure(n >= 0, CPL_ERROR_ILLEGAL_INPUT, CPL_ERROR_ILLEGAL_INPUT);
3278
3279 cpl_size max_ima_x = 0;
3280 cpl_size max_ima_y = 0;
3281 int nx = 0;
3282 int ny = 0;
3283
3284 double xshift = 0;
3285 double yshift = 0;
3286
3287 double max_ima_cx = 0;
3288 double max_ima_cy = 0;
3289
3290 hdrl_image* himg = NULL;
3291 cpl_image* img_dup = NULL;
3292 cpl_image* contrib_map = NULL;
3293 char* key_name;
3294
3295 eris_imagelist_reject_value(iml/*, CPL_VALUE_NAN*/);
3296
3297 hdrl_imagelist_collapse_median(iml, &himg, &contrib_map);
3298 nx = hdrl_image_get_size_x(himg);
3299 ny = hdrl_image_get_size_y(himg);
3300
3301 img_dup = hdrl_image_get_image(himg);
3302
3303 cpl_image_get_maxpos(img_dup, &max_ima_x, &max_ima_y);
3304 max_ima_cx = cpl_image_get_centroid_x_window(img_dup, 1, 1, nx, ny);
3305 max_ima_cy = cpl_image_get_centroid_y_window(img_dup, 1, 1, nx, ny);
3306 //cpl_image_delete(img_dup);
3307
3308
3309 xshift = max_ima_cx - (double)nx/2;
3310 yshift = max_ima_cy - (double)ny/2;
3311
3312 key_name = cpl_sprintf("QC PUPIL%d SHIFTX", n);
3313
3314 eris_qclog_add_double_f(*qclog_tbl, key_name, xshift,
3315 "X shift centroid - center image");
3316 cpl_free(key_name);
3317 key_name = cpl_sprintf("QC PUPIL%d SHIFTY", n);
3318 eris_qclog_add_double_f(*qclog_tbl, key_name, yshift,
3319 "Y shift centroid - center image");
3320 cpl_msg_info(cpl_func,"xshift: %g yshift: %g",xshift, yshift);
3321 cpl_free(key_name);
3322 hdrl_image_delete(himg);
3323 cpl_image_delete(contrib_map);
3324 eris_check_error_code("eris_get_pupil_shift");
3325 return cpl_error_get_code();
3326}
3327
3337cpl_mask* eris_ifu_mask_from_image(const cpl_image* img_mask)
3338{
3339 cpl_size nx = 0,
3340 ny = 0;
3341 cpl_mask *mask = NULL;
3342 const double *pimg_mask = NULL;
3343 cpl_binary *pmask = NULL;
3344
3345 cpl_ensure(img_mask != NULL, CPL_ERROR_NULL_INPUT, NULL);
3346
3347 TRY {
3348 nx = cpl_image_get_size_x(img_mask);
3349 ny = cpl_image_get_size_y(img_mask);
3350
3352 mask = cpl_mask_new(nx,ny));
3354 pimg_mask = cpl_image_get_data_double_const(img_mask));
3356 pmask = cpl_mask_get_data(mask));
3357
3358 for (cpl_size x = 0; x < nx; x++) {
3359 for (cpl_size y = 0; y < ny; y++) {
3360 if (pimg_mask[x+nx*y] > 0.5) {
3361 // pimg_mask = 1 -> CPL_BINARY_0
3362 pmask[x+nx*y] = GOOD_PIX;
3363 } else {
3364 // pimg_mask = 0 -> CPL_BINARY_1
3365 pmask[x+nx*y] = BAD_PIX;
3366 }
3367 }
3368 }
3369
3370
3371 } CATCH {
3372 CATCH_MSG();
3373 eris_ifu_free_mask(&mask);
3374 }
3375
3376 return mask;
3377}
3378
cpl_error_code eris_ifu_append_qc_double(cpl_propertylist *pl, const char *name, double val, const char *comment)
Append a QC parameter of type DOUBLE to a property list.
cpl_error_code eris_ifu_append_qc_int(cpl_propertylist *pl, const char *name, int val, const char *comment)
Append a QC parameter of type INT to a property list.
#define ASSURE(condition, error,...)
error handling macro (from fors-pipeline)
#define SET_ERROR_MSG(code, msg)
Set a new error code together with a custom error message.
#define CHECK_ERROR_STATE(void)
Check the CPL error state, and exit the try-block if not CPL_ERROR_NONE.
#define BRK_WITH_ERROR_MSG(code,...)
Set a new CPL error, and exit the try-block.
#define CATCH_MSG()
Displays an error message.
#define TRY
Beginning of a TRY-block.
#define CATCH
End of a TRY-block, beginning of a CATCH-block.
#define BRK_IF_NULL(function)
If function is or returns a NULL pointer, then the try-block is exited.
#define CATCH_MSGS()
Displays an error message stack.
hdrl_image * eris_ifu_load_exposure_file(const char *filename, int exposureCorrectionMode, cpl_image *dqi)
Read a raw detector exposure, perform some correction, add noise data.
void eris_ifu_free_frameset(cpl_frameset **item)
free memory and set pointer to null
cpl_error_code eris_ifu_save_table_dbg(const cpl_table *tbl, const char *filename, int create)
eris_ifu_save_table_dbg
cpl_error_code eris_ifu_save_cpl_image_dbg(const cpl_image *img, const char *name, int singlefile, const cpl_propertylist *pl)
save CPL image for debug purposes
cpl_error_code eris_ifu_save_imagelist(cpl_frameset *fs, cpl_frame *inherit, const cpl_propertylist *plist, const cpl_parameterlist *parlist, const char *recipe, const char *procatg, const char *filename, cpl_type type, const cpl_imagelist *imglist)
save imagelist
cpl_error_code eris_ifu_save_imagelist_dbg(const cpl_imagelist *imglist, const char *filename, int create)
save CPL imagelist for debug purposes
void eris_ifu_free_propertylist(cpl_propertylist **item)
free memory and set pointer to null
cpl_vector * eris_ifu_idl_values_at_indices(const cpl_vector *data, const cpl_vector *indices)
Returns a vector of given indices.
void eris_ifu_free_apertures(cpl_apertures **item)
free memory and set pointer to null
void eris_ifu_free_string(char **item)
free memory and set pointer to null
char * eris_ifu_get_lampString(int lampStatus)
eris_ifu_get_lampString
cpl_error_code eris_ifu_parameterlist_append_list(cpl_parameterlist *p1, const cpl_parameterlist *p2)
Append a parameterlist to another one.
void eris_ifu_free_double_array(double **item)
free memory and set pointer to null
cpl_table * eris_qclog_init(void)
Initialize QC table.
void eris_ifu_free_vector(cpl_vector **item)
free memory and set pointer to null
cpl_error_code eris_ifu_save_vector_dbg(const cpl_vector *vec, const char *filename, int create, const cpl_propertylist *pl)
save vector
cpl_error_code eris_ifu_save_image_dbg(const cpl_image *img, const char *filename, int create, const cpl_propertylist *pl)
eris_ifu_save_image_dbg
void eris_ifu_free_table(cpl_table **item)
free memory and set pointer to null
cpl_error_code eris_ifu_save_ifu_vector_dbg(const eris_ifu_vector *vec, const char *filename, int create)
save vector
cpl_error_code eris_ifu_cut_endings(cpl_vector **vec, int *begin, int *end, int cut)
Cut leading and trailing -1 of a vector.
cpl_error_code eris_ifu_mask_nans_in_hdrlimage(hdrl_image **hima)
Flag NANs in image.
const char * eris_ifu_get_bandString(ifsBand band)
eris_ifu_get_bandString
void eris_ifu_free_ifu_vector(eris_ifu_vector **item)
free memory and set pointer to null
cpl_error_code eris_ifu_split_hdrl_imagelist(hdrl_imagelist *cube, cpl_imagelist *dataCube, cpl_imagelist *errorCube)
extract from hdrl_imagelist the data and error information
cpl_error_code eris_get_pupil_shift(hdrl_imagelist *iml, const int n, cpl_table **qclog_tbl)
Get what object shift.
cpl_mask * eris_ifu_load_badpixel_mask(const cpl_frameset *frameset, const char *category, int ext)
‍**
cpl_error_code eris_ifu_hdrl_image_reject_mask(hdrl_image *img, const cpl_mask *mask)
'Add' the mask to the image
cpl_error_code eris_ifu_get_plane_cut_min_max(ifsBand band, cpl_size *zmin, cpl_size *zmax)
eris_ifu_get_plane_cut_min_max
const char * eris_ifu_get_instrumentString(ifsInstrument instrument)
eris_ifu_get_instrumentString
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_ifu_get_badpix_qc_from_ima(const cpl_image *image, cpl_propertylist *qc_list, const char *prefix)
compute QC keyword with number of bad pixels and fraction to total
void eris_ifu_free_polynomial(cpl_polynomial **item)
free memory and set pointer to null
hdrl_imagelist * eris_ifu_get_hdrlimagelist_by_tag(cpl_frameset *frameset, const char *tag, int exposureCorrectionMode)
Return HDRL imagelist by searching tagged frames in frameset.
void eris_ifu_free_parameter(cpl_parameter **item)
free memory and set pointer to null
cpl_propertylist * eris_compute_psf_qc(hdrl_image *hima, const cpl_parameterlist *parlist, const char *context)
compute QC parameters on a PSF STD image
cpl_error_code eris_ifu_save_bivector_dbg(const cpl_bivector *bivec, const char *filename, int col, int create)
save bivector as a vector (col=1 or col=2) or as a table
cpl_imagelist * eris_ifu_hdrl_get_imagelist(const hdrl_imagelist *hdrl_imglist, enum hdrl_t type)
Extract from a HDRL-imglist a specific CPL-imglist.
cpl_mask * eris_ifu_hima_get_obj_mask_percent(hdrl_image *hima, const double percent)
find mask flagging pixels above percent(%) pixels with lower intensity
cpl_mask * eris_ifu_mask_create_border(const cpl_mask *mask)
eris_ifu_mask_create_border
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
void eris_ifu_free_int_array(int **item)
free memory and set pointer to null
cpl_error_code eris_qclog_add_string(cpl_table *table, const char *key_name, const char *value, const char *key_help)
add QC string info to table
cpl_error_code eris_qclog_add_double(cpl_table *table, const char *key_name, const double value, const char *key_help)
add QC double info to table
cpl_error_code eris_ifu_save_mask_dbg(const cpl_mask *mask, const char *filename, int create, const cpl_propertylist *pl)
eris_ifu_save_mask_dbg
void eris_ifu_free_imagelist(cpl_imagelist **item)
free memory and set pointer to null
cpl_vector * eris_ifu_idl_where(const cpl_vector *data, double val, int op)
Implements the where-function knownm from IDL.
cpl_mask * eris_ifu_quality2bp_mask(const cpl_image *qualityMask, deqQualityType qualityType)
transform input image (quality mask) to output mask with given bit code
cpl_error_code eris_ifu_cube_set_values(hdrl_imagelist **iml)
remove planes from input iml and bpm in the range [0, zmin), (zmax,sz]
void eris_ifu_free_frame(cpl_frame **item)
free memory and set pointer to null
cpl_error_code eris_qclog_add_bool(cpl_table *table, const char *key_name, const char *key_help)
add QC boolean info to table
cpl_error_code eris_ifu_mask_nans_in_cube(cpl_imagelist *cube)
mask NANs in input data cube
void eris_ifu_free_hdrl_imagelist(hdrl_imagelist **item)
free memory and set pointer to null
cpl_error_code eris_qclog_add_int(cpl_table *table, const char *key_name, const int value, const char *key_help)
add QC int info to table
cpl_error_code eris_ifu_save_hdrl_imagelist_dbg(const hdrl_imagelist *hdrl_img_list, const char *filename, int singlefile)
eris_ifu_save_hdrl_imagelist_dbg
cpl_error_code eris_ifu_save_cpl_imagelist_dbg(const cpl_imagelist *imglist, const char *name)
save CPL imagelist for debugging purposes
cpl_error_code eris_ifu_save_hdrl_image_dbg(const hdrl_image *hdrl_img, const char *filename, int singlefile, const cpl_propertylist *pl)
save HDRL imagelist for debugging purposes
cpl_mask * eris_ifu_mask_from_image(const cpl_image *img_mask)
eris_ifu_mask_from_image
void eris_ifu_free_float_array(float **item)
free memory and set pointer to null
void eris_ifu_free_hdrl_image(hdrl_image **item)
free memory and set pointer to null
cpl_error_code eris_ifu_cube_trim_nans(const cpl_size zmin, const cpl_size zmax, hdrl_imagelist **iml, cpl_imagelist **bpm, cpl_propertylist *header)
remove planes from input iml and bpm in the range [0, zmin), (zmax,sz]
cpl_imagelist * eris_ifu_interpolatedMask_to_maskZero(cpl_imagelist *bpmCube, double threshold)
return cube flagging (as 1) pixels above a given threshold
cpl_error_code eris_ifu_get_badpix_qc_from_mask(const cpl_mask *bp_mask, cpl_propertylist *qc_list, const char *prefix)
compute QC keyword with number of bad pixels and fraction to total
void eris_ifu_free_image(cpl_image **item)
free memory and set pointer to null
cpl_error_code eris_qclog_add_double_format(cpl_table *table, const char *key_name, const double value, const char *key_help)
add QC double (with format) info to table
void eris_ifu_free_matrix(cpl_matrix **item)
free memory and set pointer to null
void eris_ifu_free_mask(cpl_mask **item)
free memory and set pointer to null
cpl_frameset * eris_ifu_get_frameset_by_tag(const cpl_frameset *frameset, const char *tag)
Get frames with given tag from frameset.
const char * eris_ifu_get_preopticsScaleString(ifsPreopticsScale scale)
eris_ifu_get_preopticsScaleString
void eris_ifu_free_parameterlist(cpl_parameterlist **item)
free memory and set pointer to null
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
double eris_ifu_get_band_resolution(ifsBand band)
eris_ifu_get_band_resolution
void eris_ifu_free_bivector(cpl_bivector **item)
free memory and set pointer to null
void eris_ifu_free_hdrl_parameter(hdrl_parameter **item)
free memory and set pointer to null
cpl_mask * eris_ifu_hima_get_obj_mask(hdrl_image *hima, const cpl_size niter, const double kappa)
find mask flagging pixels above a threshold set by ks-clip algorithm
int eris_ifu_is_nan_or_inf(double A)
Checks if a value is nan, inf or -inf.
cpl_error_code eris_ifu_vector_save(const eris_ifu_vector *ev, const char *filename, cpl_type_bpp bpp, const cpl_propertylist *pl, unsigned mode, double rej_val)
Override for cpl_vector_save().
void eris_ifu_vector_delete(eris_ifu_vector *ev)
Delete a eris_ifu_vector.
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
Definition: eris_utils.c:765
cpl_error_code eris_check_error_code(const char *func_id)
handle CPL errors
Definition: eris_utils.c:56
cpl_error_code hdrl_image_set_pixel(hdrl_image *self, cpl_size xpos, cpl_size ypos, hdrl_value value)
set pixel values of hdrl_image
Definition: hdrl_image.c:594
cpl_error_code hdrl_image_reject_value(hdrl_image *self, cpl_value mode)
Reject pixels with the specified special value(s)
Definition: hdrl_image.c:477
cpl_error_code hdrl_image_reject_from_mask(hdrl_image *self, const cpl_mask *map)
set bpm of hdrl_image
Definition: hdrl_image.c:407
hdrl_value hdrl_image_get_median(const hdrl_image *self)
computes the median and associated error of an image.
double hdrl_image_get_stdev(const hdrl_image *self)
computes the standard deviation of the data of an image
cpl_mask * hdrl_image_get_mask(hdrl_image *himg)
get cpl bad pixel mask from image
Definition: hdrl_image.c:157
cpl_image * hdrl_image_get_error(hdrl_image *himg)
get error as cpl image
Definition: hdrl_image.c:131
cpl_size hdrl_image_get_size_y(const hdrl_image *self)
return size of Y dimension of image
Definition: hdrl_image.c:540
const cpl_mask * hdrl_image_get_mask_const(const hdrl_image *himg)
get cpl bad pixel mask from image
Definition: hdrl_image.c:175
cpl_size hdrl_image_get_size_x(const hdrl_image *self)
return size of X dimension of image
Definition: hdrl_image.c:525
const cpl_image * hdrl_image_get_error_const(const hdrl_image *himg)
get error as cpl image
Definition: hdrl_image.c:144
cpl_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
Definition: hdrl_image.c:105
const cpl_image * hdrl_image_get_image_const(const hdrl_image *himg)
get data as cpl image
Definition: hdrl_image.c:118
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
Definition: hdrl_image.c:379
hdrl_image * hdrl_imagelist_unset(hdrl_imagelist *himlist, cpl_size pos)
Remove an image from an imagelist.
cpl_error_code hdrl_imagelist_set(hdrl_imagelist *himlist, hdrl_image *himg, cpl_size pos)
Insert an image into an 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_error_code hdrl_imagelist_collapse_median(const hdrl_imagelist *himlist, hdrl_image **out, cpl_image **contrib)
Median collapsing of image list.
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