ERIS Pipeline Reference Manual 1.8.14
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
1622 switch (band) {
1623 case UNDEFINED_BAND: break;
1624 case J_LOW: *zmin = 46; *zmax = 2015; break;
1625 case H_LOW: *zmin = 48; *zmax = 2023; break;
1626 case K_LOW: *zmin = 62; *zmax = 2022; break;
1627 case J_SHORT: *zmin = 50; *zmax = 2034; break;
1628 case J_MIDDLE: *zmin = 57; *zmax = 2040; break;
1629 case J_LONG: *zmin = 48; *zmax = 2033; break;
1630 case H_SHORT: *zmin = 52; *zmax = 2034; break;//
1631 case H_MIDDLE: *zmin = 47; *zmax = 2034; break;
1632 case H_LONG: *zmin = 56; *zmax = 2042; break;//
1633 case K_SHORT: *zmin = 54; *zmax = 2036; break;
1634 case K_MIDDLE: *zmin = 49; *zmax = 2029; break;
1635 case K_LONG: *zmin = 50; *zmax = 2034; break;
1636 case J_SPIFFI: *zmin = 32; *zmax = 2058; break;
1637 case H_SPIFFI: *zmin = 32; *zmax = 2058; break;
1638 case K_SPIFFI: *zmin = 32; *zmax = 2058; break;
1639 case HK_SPIFFI: *zmin = 32; *zmax = 2058; break;
1640 default: break;
1641 }
1642 eris_check_error_code("eris_ifu_get_plane_cut_min_max");
1643 return cpl_error_get_code();
1644}
1645
1646
1647
1657//TODO: Why hvalue.data = k * 10.; ?
1658cpl_error_code
1659eris_ifu_cube_set_values(hdrl_imagelist** iml/*, cpl_imagelist** bpm*/) {
1660
1661
1662 cpl_size size = hdrl_imagelist_get_size(*iml);
1663 cpl_msg_info(cpl_func,"org size: %lld", size);
1664 hdrl_image* hima = NULL;
1665// cpl_image* ima = NULL;
1666 hdrl_value hvalue = {0, 0};
1667 for(cpl_size k = 0; k < size; k++) {
1668 hima = hdrl_imagelist_get(*iml, k);
1669 for(cpl_size j = 10; j < 20; j++) {
1670 for(cpl_size i = 10; i < 20; i++) {
1671 hvalue.data = k * 10.; //TODO: why this?
1672 hdrl_image_set_pixel(hima, i, j, hvalue);
1673 }
1674 }
1675 //hdrl_imagelist_unset(*iml, k);
1676 //hdrl_imagelist_set(*iml, k, hima);
1677 //cpl_imagelist_unset(*bpm, k);
1678 }
1679
1680 eris_check_error_code("eris_ifu_cube_set_values");
1681
1682 return cpl_error_get_code();
1683}
1684
1694cpl_error_code
1695eris_ifu_cube_trim_nans(const cpl_size zmin, const cpl_size zmax,
1696 hdrl_imagelist** iml, cpl_imagelist** bpm, cpl_propertylist* header) {
1697
1698 cpl_ensure_code(iml,CPL_ERROR_NULL_INPUT);
1699 cpl_ensure_code(bpm,CPL_ERROR_NULL_INPUT);
1700 cpl_ensure_code(header,CPL_ERROR_NULL_INPUT);
1701 cpl_ensure_code(zmin <= zmax,CPL_ERROR_ILLEGAL_INPUT);
1702 cpl_size size = hdrl_imagelist_get_size(*iml);
1703 cpl_msg_debug(cpl_func,"org size: %lld", size);
1704 /* we peel-off the cube starting from the end thus the index we touch
1705 * is always decreasing (maximum)
1706 */
1707 for(cpl_size i = size-1; i > zmax; i--) {
1708 hdrl_imagelist_unset(*iml, i);
1709 cpl_imagelist_unset(*bpm, i);
1710 }
1711 cpl_msg_debug(cpl_func,"size1: %lld", hdrl_imagelist_get_size(*iml));
1712 /* we peel-off the cube starting from the bottom thus the index we touch
1713 * is always 0 (minimum)
1714 */
1715 for(cpl_size i = 0; i < zmin; i++) {
1716 hdrl_imagelist_unset(*iml, 0);
1717 cpl_imagelist_unset(*bpm, 0);
1718 }
1719 cpl_msg_debug(cpl_func,"size2: %lld", hdrl_imagelist_get_size(*iml));
1720 double crval3 = cpl_propertylist_get_double(header,"CRVAL3");
1721 const double cd3_3 = cpl_propertylist_get_double(header,"CD3_3");
1722 int naxis3 = cpl_propertylist_get_int(header,"NAXIS3");
1723
1724 crval3 += cd3_3 * zmin;
1725 naxis3 = zmax - zmin +1;
1726 cpl_propertylist_set_double(header, "CRVAL3", crval3);
1727 cpl_propertylist_set_int(header, "NAXIS3", naxis3);
1728
1729 eris_check_error_code("eris_ifu_cube_trim_nans");
1730 return cpl_error_get_code();
1731}
1732
1733
1739const char* eris_ifu_get_instrumentString(ifsInstrument instrument)
1740{
1741 const char *instrumentString;
1742 switch (instrument) {
1743 case OTHER_INSTRUMENT: instrumentString = "unknown instrument"; break;
1744 case SPIFFI: instrumentString = "SPIFFI"; break;
1745 case SPIFFIER: instrumentString = "SPIFFIER"; break;
1746 case NIX: instrumentString = "NIX"; break;
1747 case UNSET_INSTRUMENT: instrumentString = "unset instrument"; break;
1748 default: instrumentString = "unset instrument"; break;
1749 }
1750 eris_check_error_code("eris_ifu_get_instrumentString");
1751 return instrumentString;
1752}
1753
1759const char* eris_ifu_get_preopticsScaleString(ifsPreopticsScale scale)
1760{
1761 const char *scaleString;
1762 switch (scale) {
1763 case UNDEFINED_SCALE:
1764 scaleString = "";
1765 break;
1766 case S250MAS:
1767 scaleString = "250mas";
1768 break;
1769 case S100MAS:
1770 scaleString = "100mas";
1771 break;
1772 case S25MAS:
1773 scaleString = "25mas";
1774 break;
1775 case PUPIL:
1776 scaleString = "PUPIL";
1777 break;
1778 default:
1779 scaleString = "Unknown";
1780 break;
1781 }
1782 eris_check_error_code("eris_ifu_get_preopticsScaleString");
1783 return scaleString;
1784}
1785
1786/*
1787 * removes badpixborder around img
1788 * @param img input image
1789 * @return sub-image with removed border
1790 */
1791cpl_image* eris_ifu_image_create_window(const cpl_image* img)
1792{
1793 cpl_size nx = 0,
1794 ny = 0;
1795 double *pimg_window = NULL;
1796 const double *pimg = NULL;
1797 cpl_image *img_window = NULL;
1798 const cpl_mask *mask = NULL;
1799 cpl_mask *mask_window = NULL;
1800 const cpl_binary *pmask = NULL;
1801 cpl_binary *pmask_window = NULL;
1802
1803 cpl_ensure(img, CPL_ERROR_NULL_INPUT, NULL);
1804
1805 TRY
1806 {
1807 nx = cpl_image_get_size_x(img);
1808 ny = cpl_image_get_size_y(img);
1810 img_window = cpl_image_new(nx-2*ERIS_IFU_DETECTOR_BP_BORDER,
1811 ny-2*ERIS_IFU_DETECTOR_BP_BORDER,
1812 cpl_image_get_type(img));
1813
1814 pimg = cpl_image_get_data_const(img);
1815 mask = cpl_image_get_bpm_const(img);
1816 pmask = cpl_mask_get_data_const(mask);
1817 pimg_window = cpl_image_get_data(img_window);
1818 mask_window = cpl_image_get_bpm(img_window);
1819 pmask_window = cpl_mask_get_data(mask_window);
1820
1821 for (int x = 0; x < nx-2*ERIS_IFU_DETECTOR_BP_BORDER; x++) {
1822 for (int y = 0; y < ny-2*ERIS_IFU_DETECTOR_BP_BORDER; y++) {
1823 cpl_size nx_new = nx-2*ERIS_IFU_DETECTOR_BP_BORDER,
1824 x_old = x+ERIS_IFU_DETECTOR_BP_BORDER,
1825 y_old = y+ERIS_IFU_DETECTOR_BP_BORDER;
1826 pimg_window[x+y*nx_new] = pimg[x_old+y_old*nx];
1827 pmask_window[x+y*nx_new] = pmask[x_old+y_old*nx];
1828 }
1829 }
1830 }
1831 CATCH
1832 {
1833 CATCH_MSGS();
1834 eris_ifu_free_image(&img_window);
1835 }
1836 eris_check_error_code("eris_ifu_image_create_window");
1837 return img_window;
1838}
1839
1847cpl_mask* eris_ifu_mask_create_border(const cpl_mask* mask)
1848{
1849 cpl_size nx = 0,
1850 ny = 0;
1851 cpl_binary *pmask_border = NULL;
1852 const cpl_binary *pmask = NULL;
1853 cpl_mask *mask_border = NULL;
1854
1855 cpl_ensure(mask, CPL_ERROR_NULL_INPUT, NULL);
1856
1857 TRY
1858 {
1859 nx = cpl_mask_get_size_x(mask);
1860 ny = cpl_mask_get_size_y(mask);
1862
1863 mask_border = cpl_mask_new(nx+2*ERIS_IFU_DETECTOR_BP_BORDER,
1864 ny+2*ERIS_IFU_DETECTOR_BP_BORDER);
1865
1866 pmask = cpl_mask_get_data_const(mask);
1867 pmask_border = cpl_mask_get_data(mask_border);
1868
1869 for (int x = 0; x < nx; x++) {
1870 for (int y = 0; y < ny; y++) {
1871 cpl_size x_new = x+ERIS_IFU_DETECTOR_BP_BORDER,
1872 y_new = y+ERIS_IFU_DETECTOR_BP_BORDER,
1873 nx_new = nx+2*ERIS_IFU_DETECTOR_BP_BORDER;
1874 pmask_border[x_new+y_new*nx_new] = pmask[x+y*nx];
1875 }
1876 }
1877 }
1878 CATCH
1879 {
1880 CATCH_MSGS();
1881 eris_ifu_free_mask(&mask_border);
1882 }
1883 eris_check_error_code("eris_ifu_mask_create_border");
1884 return mask_border;
1885}
1886
1887/*----------------------------------------------------------------------------*/
1893/*----------------------------------------------------------------------------*/
1894
1895cpl_error_code
1897
1898 double* pdata = NULL;
1899 double* perrs = NULL;
1900 cpl_binary* pbpm = NULL;
1901 cpl_size sx = 0;
1902 cpl_size sy = 0;
1903 cpl_size npoints = 0;
1904 cpl_ensure(hima != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
1905
1906
1907 sx = hdrl_image_get_size_x( *hima );
1908 sy = hdrl_image_get_size_y( *hima );
1909 npoints = sx * sy;
1910
1911 pdata = cpl_image_get_data(hdrl_image_get_image(*hima));
1912 perrs = cpl_image_get_data(hdrl_image_get_error(*hima));
1913 pbpm = cpl_mask_get_data(hdrl_image_get_mask(*hima));
1914
1915 cpl_size nan_pix = 0;
1916 for(cpl_size i = 0; i < npoints; i++) {
1917 //cpl_msg_error(cpl_func,"pdata[%lld]:%g perrs[%lld]:%g",i,pdata[i],i,perrs[i]);
1918 //if(pdata[i] == CPL_VALUE_NOTFINITE || perrs[i] == CPL_VALUE_NOTFINITE ){
1919 if(isnan(pdata[i]) || isnan(perrs[i]) ){
1920 //cpl_msg_info(cpl_func,"found NAN at %lld",i);
1921 pbpm[i] = BAD_PIX;
1922 nan_pix++;
1923 }
1924 }
1925
1926 eris_check_error_code("eris_ifu_mask_nans_in_hdrlimage");
1927 return cpl_error_get_code();
1928}
1929
1930/*----------------------------------------------------------------------------*/
1937/*----------------------------------------------------------------------------*/
1938cpl_error_code eris_ifu_mask_nans_in_cube(cpl_imagelist *cube)
1939{
1940 cpl_error_code retVal = CPL_ERROR_NONE;
1941 cpl_size nx = 0,
1942 ny = 0,
1943 nz = 0,
1944 idx = 0;
1945 cpl_image *tmpImg = NULL;
1946 cpl_mask *mask = NULL;
1947 cpl_binary *maskData = NULL;
1948 const double *imgDataD = NULL;
1949 const float *imgDataF = NULL;
1950 cpl_type imgType = CPL_TYPE_INVALID;
1951
1952 cpl_ensure(cube, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
1953
1954 TRY
1955 {
1956 nz = cpl_imagelist_get_size(cube);
1957 if (nz > 0) {
1958 tmpImg = cpl_imagelist_get(cube,0);
1959 imgType = cpl_image_get_type(tmpImg);
1960 if (! (imgType == CPL_TYPE_FLOAT || imgType == CPL_TYPE_DOUBLE)) {
1961 BRK_WITH_ERROR_MSG(CPL_ERROR_INVALID_TYPE,
1962 "unsupported image type within cube");
1963 }
1964 nx = cpl_image_get_size_x(tmpImg);
1965 ny = cpl_image_get_size_y(tmpImg);
1966 }
1968 for (cpl_size z=0; z < nz; z++) {
1969 tmpImg = cpl_imagelist_get(cube,z);
1970 switch (imgType) {
1971 case CPL_TYPE_FLOAT:
1972 imgDataF = cpl_image_get_data_float_const(tmpImg);
1973 break;
1974 case CPL_TYPE_DOUBLE:
1975 imgDataD = cpl_image_get_data_double_const(tmpImg);
1976 break;
1977 default: break;
1978 }
1979 mask = cpl_image_get_bpm(tmpImg);
1980 maskData = cpl_mask_get_data(mask);
1981 for (cpl_size y=0; y < ny; y++) {
1982 for (cpl_size x=0; x < nx; x++) {
1983 idx = y * nx + x;
1984 switch (imgType) {
1985 case CPL_TYPE_FLOAT:
1986 if (!isfinite(imgDataF[idx])) {
1987 maskData[idx] = BAD_PIX;
1988 }
1989 break;
1990 case CPL_TYPE_DOUBLE:
1991 if (!isfinite(imgDataD[idx])) {
1992 maskData[idx] = BAD_PIX;
1993 }
1994 break;
1995 default: break;
1996 }
1997 }
1998 }
2000
2001 }
2002 }
2003 CATCH {
2004 retVal = cpl_error_get_code();
2005 }
2006 eris_check_error_code("eris_ifu_mask_nans_in_cube");
2007 return retVal;
2008}
2009
2010// /**
2011// * @brief eris_ifu_mask_reset
2012// * @param mask
2013// * @return
2014// */
2015//cpl_error_code eris_ifu_mask_reset(cpl_mask* mask)
2016//{
2017// cpl_error_code err = CPL_ERROR_NONE;
2018// cpl_size nx = 0,
2019// ny = 0;
2020//
2021// cpl_ensure_code(mask, CPL_ERROR_NULL_INPUT);
2022//
2023// TRY
2024// {
2025// nx = cpl_mask_get_size_x(mask);
2026// ny = cpl_mask_get_size_y(mask);
2027// CHECK_ERROR_STATE();
2028//
2029// for (int x = 1; x <= nx; x++) {
2030// for (int y = 1; y <= ny; y++) {
2031// cpl_mask_set(mask, x, y, GOOD_PIX);
2032// }
2033// }
2034// }
2035// CATCH
2036// {
2037// CATCH_MSGS();
2038// err = cpl_error_get_code();
2039// }
2040// return err;
2041//}
2042/*----------------------------------------------------------------------------*/
2043/* TODO: document bit code. Why bit code is double and not integer? */
2051/*----------------------------------------------------------------------------*/
2052cpl_mask* eris_ifu_quality2bp_mask(const cpl_image *qualityMask,
2053 deqQualityType qualityType)
2054{
2055 cpl_mask *bpmMask = NULL;
2056 TRY
2057 {
2058 ASSURE((qualityMask != NULL), CPL_ERROR_NULL_INPUT, NULL);
2059 bpmMask = cpl_mask_threshold_image_create(
2060 qualityMask, .5, 4294967296.5 );
2061 switch(qualityType) {
2062 case maskzero:
2063 cpl_mask_not(bpmMask);
2064 break;
2065 case maskone:
2066 break;
2067 case flag32bit:
2068 break;
2069 case flag16bit:
2070 break;
2071 case unspecified:
2072 cpl_mask_delete(bpmMask);
2073 BRK_WITH_ERROR_MSG(CPL_ERROR_ILLEGAL_INPUT,
2074 "Unspecified DEQ quality type");
2075
2076 break;
2077 default:
2078 BRK_WITH_ERROR_MSG(CPL_ERROR_ILLEGAL_INPUT,
2079 "Unknown DEQ quality type");
2080 }
2081 }
2082 CATCH {
2083 bpmMask = NULL;
2084 }
2085 eris_check_error_code("eris_ifu_quality2bp_mask");
2086 return bpmMask;
2087
2088}
2089/*----------------------------------------------------------------------------*/
2097/*----------------------------------------------------------------------------*/
2098cpl_imagelist* eris_ifu_interpolatedMask_to_maskZero(cpl_imagelist *bpmCube,
2099 double threshold)
2100{
2101 cpl_imagelist *maskOneCube = NULL;
2102 cpl_image *img = NULL;
2103 cpl_image *maskOneImg = NULL;
2104 int *maskOneImgPtr = NULL;
2105 float *floatPtr = NULL;
2106 double *doublePtr = NULL;
2107 float floatThreshold;
2108 cpl_size imgPixelCnt = 0,
2109 nx = 0,
2110 ny = 0;
2111 cpl_type bpmType;
2112
2113 TRY
2114 {
2115 ASSURE(bpmCube != NULL, CPL_ERROR_NULL_INPUT, "bpmCube must not be NULL");
2116
2117 maskOneCube = cpl_imagelist_new();
2118
2119 img = cpl_imagelist_get(bpmCube, 0);
2120 bpmType = cpl_image_get_type(img);
2121 ASSURE(bpmType == CPL_TYPE_FLOAT || bpmType == CPL_TYPE_DOUBLE,
2122 CPL_ERROR_ILLEGAL_INPUT, "bpmCube must be of type float or double");
2123
2124 nx = cpl_image_get_size_x(img);
2125 ny = cpl_image_get_size_y(img);
2126 imgPixelCnt = nx * ny;
2127
2128 floatThreshold = (float) threshold;
2129
2130 for (cpl_size cx=0; cx < cpl_imagelist_get_size(bpmCube); cx++) {
2131 img = cpl_imagelist_get(bpmCube, cx);
2132
2133 maskOneImg = cpl_image_new(nx, ny, CPL_TYPE_INT);
2134 maskOneImgPtr = cpl_image_get_data_int(maskOneImg);
2135
2136 if (bpmType == CPL_TYPE_FLOAT) {
2137 floatPtr = cpl_image_get_data_float(img);
2138 for (cpl_size px=0; px < imgPixelCnt; px++) {
2139 if (floatPtr[px] > floatThreshold) {
2140 maskOneImgPtr[px] = 1;
2141 } else {
2142 maskOneImgPtr[px] = 0;
2143 }
2144 }
2145 } else if (bpmType == CPL_TYPE_DOUBLE) {
2146 doublePtr = cpl_image_get_data_double(img);
2147 for (cpl_size px=0; px < imgPixelCnt; px++) {
2148 if (doublePtr[px] > threshold) {
2149 maskOneImgPtr[px] = 1;
2150 } else {
2151 maskOneImgPtr[px] = 0;
2152 }
2153 }
2154
2155 }
2156
2157 cpl_imagelist_set(maskOneCube, maskOneImg, cx);
2158 }
2159 }
2160 CATCH {
2161 maskOneCube = NULL;
2162 }
2163 eris_check_error_code("eris_ifu_interpolatedMask_to_maskZero");
2164 return maskOneCube;
2165
2166}
2167/*----------------------------------------------------------------------------*/
2177/*----------------------------------------------------------------------------*/
2178cpl_error_code eris_ifu_split_hdrl_imagelist(hdrl_imagelist *cube,
2179 cpl_imagelist *dataCube,
2180 cpl_imagelist *errorCube)
2181{
2182 cpl_error_code retVal = CPL_ERROR_NONE;
2183 hdrl_image *image = NULL;
2184 TRY
2185 {
2186
2187 cpl_ensure(cube != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2188 cpl_ensure(dataCube != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2189 cpl_ensure(errorCube != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2190 for (cpl_size ix=0; ix < hdrl_imagelist_get_size(cube); ix++) {
2191 image = hdrl_imagelist_get(cube, ix);
2192 cpl_imagelist_set(dataCube, cpl_image_duplicate(hdrl_image_get_image(image)), ix);
2193 cpl_imagelist_set(errorCube, cpl_image_duplicate(hdrl_image_get_error(image)), ix);
2194
2195 }
2196 }
2197 CATCH {
2198 }
2199 eris_check_error_code("eris_ifu_split_hdrl_imagelist");
2200 return retVal;
2201
2202}
2203
2204/*----------------------------------------------------------------------------*/
2215/*----------------------------------------------------------------------------*/
2216cpl_error_code eris_ifu_split3_hdrl_imagelist(hdrl_imagelist *cube,
2217 cpl_imagelist *dataCube,
2218 cpl_imagelist *errorCube,
2219 cpl_imagelist *qualCube)
2220{
2221 cpl_error_code retVal = CPL_ERROR_NONE;
2222 hdrl_image *image = NULL;
2223 TRY
2224 {
2225 cpl_ensure(cube != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2226 cpl_ensure(dataCube != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2227 cpl_ensure(errorCube != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2228 cpl_ensure(qualCube != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2229
2230 for (cpl_size ix=0; ix < hdrl_imagelist_get_size(cube); ix++) {
2231 image = hdrl_imagelist_get(cube, ix);
2232 cpl_imagelist_set(dataCube,
2233 hdrl_image_get_image(image), ix);
2234 cpl_imagelist_set(errorCube,
2235 hdrl_image_get_error(image), ix);
2236 cpl_imagelist_set(qualCube,
2237 cpl_image_new_from_mask(hdrl_image_get_mask(image)), ix);
2238
2239 }
2240 }
2241 CATCH {
2242 }
2243 eris_check_error_code("eris_ifu_split3_hdrl_imagelist");
2244 return retVal;
2245
2246}
2247/*----------------------------------------------------------------------------*/
2254/*----------------------------------------------------------------------------*/
2255cpl_table *
2257{
2258
2259 cpl_table *table;
2260
2261 table = cpl_table_new(0);
2262 cpl_table_new_column(table,"key_name", CPL_TYPE_STRING);
2263 cpl_table_new_column(table,"key_type", CPL_TYPE_STRING);
2264 cpl_table_new_column(table,"key_value", CPL_TYPE_STRING);
2265 cpl_table_new_column(table,"key_help", CPL_TYPE_STRING);
2266 eris_check_error_code("eris_qclog_init");
2267 return table;
2268}
2269/*----------------------------------------------------------------------------*/
2280/*----------------------------------------------------------------------------*/
2281cpl_error_code
2282eris_qclog_add_int(cpl_table* table,
2283 const char* key_name,
2284 const int value,
2285 const char* key_help)
2286{
2287
2288 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
2289 cpl_ensure_code(key_name != NULL, CPL_ERROR_NULL_INPUT);
2290 cpl_ensure_code(key_help != NULL, CPL_ERROR_NULL_INPUT);
2291
2292 int sz = cpl_table_get_nrow(table);
2293 int raw = sz;
2294 char* key_value;
2295 char* key_type;
2296
2297 key_value = cpl_sprintf("%d",value);
2298 key_type = cpl_sprintf("%s","CPL_TYPE_INT");
2299
2300 cpl_table_set_size(table,sz+1);
2301
2302 cpl_table_set_string(table,"key_name" ,raw,key_name);
2303 cpl_table_set_string(table,"key_type" ,raw,key_type);
2304 cpl_table_set_string(table,"key_value",raw,key_value);
2305 cpl_table_set_string(table,"key_help" ,raw,key_help);
2306
2307 cpl_free(key_value);
2308 cpl_free(key_type);
2309 eris_check_error_code("eris_qclog_add_int");
2310 return cpl_error_get_code();
2311
2312}
2313
2314/*----------------------------------------------------------------------------*/
2324/*----------------------------------------------------------------------------*/
2325
2326cpl_error_code
2327eris_qclog_add_bool(cpl_table* table,
2328 const char* key_name,
2329 const char* key_help)
2330{
2331 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
2332 cpl_ensure_code(key_name != NULL, CPL_ERROR_NULL_INPUT);
2333 cpl_ensure_code(key_help != NULL, CPL_ERROR_NULL_INPUT);
2334
2335 int sz = cpl_table_get_nrow(table);
2336 int raw = sz;
2337 char* key_value;
2338 char* key_type;
2339
2340 key_value = cpl_sprintf("%s",key_name);
2341 key_type = cpl_sprintf("%s","CPL_TYPE_BOOL");
2342
2343 cpl_table_set_size(table,sz+1);
2344
2345 cpl_table_set_string(table,"key_name" ,raw,key_name);
2346 cpl_table_set_string(table,"key_type" ,raw,key_type);
2347 cpl_table_set_string(table,"key_value",raw,key_value);
2348 cpl_table_set_string(table,"key_help" ,raw,key_help);
2349 cpl_free(key_value);
2350 cpl_free(key_type);
2351 eris_check_error_code("eris_qclog_add_bool");
2352 return cpl_error_get_code();
2353
2354}
2355
2356/*----------------------------------------------------------------------------*/
2367/*----------------------------------------------------------------------------*/
2368cpl_error_code
2369eris_qclog_add_double(cpl_table* table,
2370 const char* key_name,
2371 const double value,
2372 const char* key_help)
2373{
2374 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
2375 cpl_ensure_code(key_name != NULL, CPL_ERROR_NULL_INPUT);
2376 cpl_ensure_code(key_help != NULL, CPL_ERROR_NULL_INPUT);
2377
2378 int sz = cpl_table_get_nrow(table);
2379
2380 int raw = sz;
2381 char* key_value;
2382 char* key_type;
2383
2384 key_value = cpl_sprintf("%g",value);
2385
2386 key_type = cpl_sprintf("%s","CPL_TYPE_DOUBLE");
2387
2388 cpl_table_set_size(table,sz+1);
2389
2390 cpl_table_set_string(table,"key_name" ,raw,key_name);
2391 cpl_table_set_string(table,"key_type" ,raw,key_type);
2392 cpl_table_set_string(table,"key_value",raw,key_value);
2393 cpl_table_set_string(table,"key_help" ,raw,key_help);
2394
2395 cpl_free(key_value);
2396 cpl_free(key_type);
2397 eris_check_error_code("eris_qclog_add_double");
2398 return cpl_error_get_code();
2399
2400}
2401/*----------------------------------------------------------------------------*/
2412/*----------------------------------------------------------------------------*/
2413cpl_error_code
2415 const char* key_name,
2416 const double value,
2417 const char* key_help)
2418{
2419
2420 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
2421 cpl_ensure_code(key_name != NULL, CPL_ERROR_NULL_INPUT);
2422 cpl_ensure_code(key_help != NULL, CPL_ERROR_NULL_INPUT);
2423
2424 int sz = cpl_table_get_nrow(table);
2425 int raw = sz;
2426 char* key_value;
2427 char* key_type;
2428
2429 key_value = cpl_sprintf("%f",value);
2430 key_type = cpl_sprintf("%s","CPL_TYPE_DOUBLE");
2431
2432 cpl_table_set_size(table,sz+1);
2433
2434 cpl_table_set_string(table,"key_name" ,raw,key_name);
2435 cpl_table_set_string(table,"key_type" ,raw,key_type);
2436 cpl_table_set_string(table,"key_value",raw,key_value);
2437 cpl_table_set_string(table,"key_help" ,raw,key_help);
2438 cpl_free(key_value);
2439 cpl_free(key_type);
2440 eris_check_error_code("eris_qclog_add_double_f");
2441 return cpl_error_get_code();
2442
2443}
2444/*----------------------------------------------------------------------------*/
2455/*----------------------------------------------------------------------------*/
2456cpl_error_code
2458 const char* key_name,
2459 const double value,
2460 const char* key_help)
2461{
2462
2463 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
2464 cpl_ensure_code(key_name != NULL, CPL_ERROR_NULL_INPUT);
2465 cpl_ensure_code(key_help != NULL, CPL_ERROR_NULL_INPUT);
2466
2467 int sz = cpl_table_get_nrow(table);
2468 int raw = sz;
2469 char* key_value;
2470 char* key_type;
2471
2472 key_value = cpl_sprintf("%13.6f",value);
2473 key_type = cpl_sprintf("%s","CPL_TYPE_DOUBLE");
2474
2475 cpl_table_set_size(table,sz+1);
2476
2477 cpl_table_set_string(table,"key_name" ,raw,key_name);
2478 cpl_table_set_string(table,"key_type" ,raw,key_type);
2479 cpl_table_set_string(table,"key_value",raw,key_value);
2480 cpl_table_set_string(table,"key_help" ,raw,key_help);
2481 cpl_free(key_value);
2482 cpl_free(key_type);
2483 eris_check_error_code("eris_qclog_add_double_format");
2484 return cpl_error_get_code();
2485
2486}
2487/*----------------------------------------------------------------------------*/
2498/*----------------------------------------------------------------------------*/
2499cpl_error_code
2500eris_qclog_add_string(cpl_table* table,
2501 const char* key_name,
2502 const char* value,
2503 const char* key_help)
2504{
2505
2506 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
2507 cpl_ensure_code(key_name != NULL, CPL_ERROR_NULL_INPUT);
2508 cpl_ensure_code(key_help != NULL, CPL_ERROR_NULL_INPUT);
2509
2510 int sz = cpl_table_get_nrow(table);
2511 int raw = sz;
2512 char* key_value;
2513 char* key_type;
2514
2515 key_value = cpl_sprintf("%s",value);
2516 key_type = cpl_sprintf("%s","CPL_TYPE_STRING");
2517
2518 cpl_table_set_size(table,sz+1);
2519
2520 cpl_table_set_string(table,"key_name" ,raw,key_name);
2521 cpl_table_set_string(table,"key_type" ,raw,key_type);
2522 cpl_table_set_string(table,"key_value",raw,key_value);
2523 cpl_table_set_string(table,"key_help" ,raw,key_help);
2524 cpl_free(key_value);
2525 cpl_free(key_type);
2526 eris_check_error_code("eris_qclog_add_string");
2527 return cpl_error_get_code();
2528
2529}
2530
2531/*----------------------------------------------------------------------------*/
2540/*----------------------------------------------------------------------------*/
2541cpl_error_code
2543 cpl_propertylist * plist,
2544 cpl_table * qclog)
2545{
2546
2547
2548 cpl_ensure_code(plist != NULL, CPL_ERROR_NULL_INPUT);
2549 cpl_ensure_code(qclog != NULL, CPL_ERROR_NULL_INPUT);
2550 char* key_name = NULL;
2551 char* key_value = NULL;
2552 char* key_type = NULL;
2553 char* key_help = NULL;
2554 /*
2555 char key_name[FILE_NAME_SZ];
2556 char key_value[FILE_NAME_SZ];
2557 char key_type[FILE_NAME_SZ];
2558 char key_help[FILE_NAME_SZ] ;
2559 */
2560
2561 int i = 0;
2562 int n = 0;
2563 /* Test entries */
2564 if (plist == NULL) {
2565 cpl_msg_error(cpl_func,"plist=NULL, something strange");
2566 return CPL_ERROR_NULL_INPUT ;
2567 }
2568 /* Parameter Name: PIPEFILE */
2569
2570 //cpl_table_save(qclog,NULL,NULL,"qclog.fits",CPL_IO_CREATE);
2571 n = cpl_table_get_nrow(qclog);
2572 for(i = 0; i < n; i++) {
2573
2574 key_name = cpl_sprintf("ESO %s",cpl_table_get_string(qclog, "key_name", i));
2575 //strcat(key_name, cpl_table_get_string(qclog, "key_name", i));
2576 key_type = cpl_sprintf("%s", cpl_table_get_string(qclog, "key_type", i));
2577 //strcpy(key_type, cpl_table_get_string(qclog, "key_type", i));
2578 key_value = cpl_sprintf("%s", cpl_table_get_string(qclog, "key_value", i));
2579 //strcpy(key_value, cpl_table_get_string(qclog, "key_value", i));
2580 key_help = cpl_sprintf("%s", cpl_table_get_string(qclog, "key_help", i));
2581 //strcpy(key_help, cpl_table_get_string(qclog, "key_help", i));
2582 /*
2583 cpl_msg_info(cpl_func,"raw %i, name=%s type=%s value=%s\n",
2584 i,key_name,key_type,key_value);
2585 */
2586 if( !cpl_propertylist_has(plist, key_name) ) {
2587 if(strcmp(key_type, "CPL_TYPE_STRING") == 0) {
2588 cpl_propertylist_append_string(plist, key_name, key_value) ;
2589 cpl_propertylist_set_comment(plist, key_name, key_help) ;
2590 } else if(strcmp(key_type, "CPL_TYPE_BOOL") == 0) {
2591 cpl_propertylist_append_bool(plist, key_name, atoi(key_value)) ;
2592 cpl_propertylist_set_comment(plist, key_name, key_help) ;
2593 } else if(strcmp(key_type, "CPL_TYPE_INT") == 0) {
2594 cpl_propertylist_append_int(plist, key_name, atoi(key_value)) ;
2595 cpl_propertylist_set_comment(plist, key_name, key_help) ;
2596 } else if(strcmp(key_type, "CPL_TYPE_FLOAT") == 0) {
2597 cpl_propertylist_append_float(plist, key_name, (float) atof(key_value)) ;
2598 cpl_propertylist_set_comment(plist, key_name, key_help) ;
2599 } else if(strcmp(key_type, "CPL_TYPE_DOUBLE") == 0) {
2600 cpl_propertylist_append_double(plist, key_name, atof(key_value)) ;
2601 cpl_propertylist_set_comment(plist, key_name, key_help) ;
2602 }
2603 }
2604 cpl_free(key_name);
2605 cpl_free(key_type);
2606 cpl_free(key_value);
2607 cpl_free(key_help);
2608
2609 }
2610 eris_check_error_code("eris_pfits_put_qc");
2611 return cpl_error_get_code();
2612}
2613/*----------------------------------------------------------------------------*/
2623/*----------------------------------------------------------------------------*/
2624cpl_error_code
2625eris_ifu_get_badpix_qc_from_ima(const cpl_image* image,
2626 cpl_propertylist* qc_list,
2627 const char* prefix)
2628{
2629
2630 cpl_ensure_code(image != NULL, CPL_ERROR_NULL_INPUT);
2631 cpl_ensure_code(qc_list != NULL, CPL_ERROR_NULL_INPUT);
2632 cpl_ensure_code(prefix != NULL, CPL_ERROR_NULL_INPUT);
2633 cpl_size sx = cpl_image_get_size_x(image);
2634 cpl_size sy = cpl_image_get_size_y(image);
2635 cpl_image* ima = cpl_image_duplicate(image);
2636 cpl_image_threshold(ima, 0, 0, 0, 1);
2637 double flux = cpl_image_get_flux(ima);
2638 cpl_image_delete(ima);
2639 cpl_size nBadPix = (cpl_size) flux;
2640
2641 cpl_size npix = sx * sy;
2642 double fracBadPix = flux / npix;
2643 char* kname;
2644 cpl_msg_warning(cpl_func,"nBadPix: %lld",nBadPix);
2645 kname = cpl_sprintf("%s NBADPIX",prefix);
2646 cpl_msg_info(cpl_func,"kname: %s prefix: %s",kname, prefix);
2647 eris_ifu_append_qc_int(qc_list, kname, nBadPix, "Number of bad pixels");
2648 cpl_free(kname);
2649
2650 kname = cpl_sprintf("%s BPIXFRAC",prefix);
2651 eris_ifu_append_qc_double(qc_list, kname, fracBadPix,
2652 "Fraction of bad pixels to total");
2653 cpl_free(kname);
2654 eris_check_error_code("eris_ifu_get_badpix_qc_from_ima");
2655 return cpl_error_get_code();
2656}
2657
2658/*----------------------------------------------------------------------------*/
2668/*----------------------------------------------------------------------------*/
2669cpl_error_code
2670eris_ifu_get_badpix_qc_from_mask(const cpl_mask* bp_mask,
2671 cpl_propertylist* qc_list,
2672 const char* prefix)
2673{
2674 cpl_ensure_code(bp_mask != NULL, CPL_ERROR_NULL_INPUT);
2675 cpl_ensure_code(qc_list != NULL, CPL_ERROR_NULL_INPUT);
2676 cpl_ensure_code(prefix != NULL, CPL_ERROR_NULL_INPUT);
2677 cpl_size sx = cpl_mask_get_size_x(bp_mask);
2678 cpl_size sy = cpl_mask_get_size_y(bp_mask);
2679 cpl_size nBadPix = cpl_mask_count(bp_mask);
2680
2681 cpl_size npix = sx * sy;
2682 double fracBadPix = (double) nBadPix / npix;
2683 char* kname;
2684
2685 kname = cpl_sprintf("%s NBADPIX",prefix);
2686 cpl_msg_info(cpl_func,"kname: %s prefix: %s",kname, prefix);
2687 eris_ifu_append_qc_int(qc_list, kname, nBadPix, "Number of bad pixels");
2688 cpl_free(kname);
2689
2690 kname = cpl_sprintf("%s BPIXFRAC",prefix);
2691 eris_ifu_append_qc_double(qc_list, kname, fracBadPix,
2692 "Fraction of bad pixels to total");
2693 cpl_free(kname);
2694 eris_check_error_code("eris_ifu_get_badpix_qc_from_mask");
2695 return cpl_error_get_code();
2696}
2697
2698/*----------------------------------------------------------------------------*/
2718/*----------------------------------------------------------------------------*/
2719static cpl_error_code eris_apertures_find_max_flux(const cpl_apertures * self,
2720 int * ind, int nfind)
2721{
2722
2723
2724
2725 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2726
2727 const int nsize = cpl_apertures_get_size(self);
2728 int ifind;
2729
2730
2731 cpl_ensure_code(nsize > 0, CPL_ERROR_ILLEGAL_INPUT);
2732 cpl_ensure_code(ind, CPL_ERROR_NULL_INPUT);
2733 cpl_ensure_code(nfind > 0, CPL_ERROR_ILLEGAL_INPUT);
2734 cpl_ensure_code(nfind <= nsize, CPL_ERROR_ILLEGAL_INPUT);
2735
2736 for (ifind=0; ifind < nfind; ifind++) {
2737 double maxflux = -1;
2738 int maxind = -1;
2739 int i;
2740 for (i=1; i <= nsize; i++) {
2741 int k;
2742
2743 /* The flux has to be the highest among those not already found */
2744 for (k=0; k < ifind; k++) if (ind[k] == i) break;
2745
2746 if (k == ifind) {
2747 /* i has not been inserted into ind */
2748 const double flux = cpl_apertures_get_flux(self, i);
2749
2750 if (maxind < 0 || flux > maxflux) {
2751 maxind = i;
2752 maxflux = flux;
2753 }
2754 }
2755 }
2756 ind[ifind] = maxind;
2757 }
2758 eris_check_error_code("eris_apertures_find_max_flux");
2759 return CPL_ERROR_NONE;
2760
2761}
2762
2763/*----------------------------------------------------------------------------*/
2783/*----------------------------------------------------------------------------*/
2784cpl_error_code
2785eris_gaussian_maxpos(const cpl_image * self,
2786 double sigma,
2787 double * pxpos,
2788 double * pypos,
2789 double * ppeak,
2790 double * sigma_x,
2791 double * sigma_y)
2792{
2793 /* copied from irplib_strehl.c r163170 */
2794
2795
2796 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2797 cpl_ensure(sigma > 0, CPL_ERROR_ILLEGAL_INPUT, CPL_ERROR_ILLEGAL_INPUT);
2798
2799
2800
2801 const cpl_size nx = cpl_image_get_size_x(self);
2802 const cpl_size ny = cpl_image_get_size_y(self);
2803 int iretry = 3; /* Number retries with decreasing sigma */
2804 int ifluxapert = 0;
2805 double med_dist;
2806 const double median = cpl_image_get_median_dev(self, &med_dist);
2807 cpl_mask * selection = NULL;
2808 cpl_size nlabels = 0;
2809 cpl_image * labels = NULL;
2810 cpl_apertures * aperts;
2811 cpl_size npixobj;
2812 double objradius;
2813 cpl_size winsize;
2814 cpl_size xposmax, yposmax;
2815 double xposcen, yposcen;
2816 double valmax, valfit = -1.0;
2817 cpl_array * gauss_parameters = NULL;
2818 cpl_errorstate prestate = cpl_errorstate_get();
2819 cpl_error_code code = CPL_ERROR_NONE;
2820
2821
2822 cpl_ensure_code( sigma > 0.0, CPL_ERROR_ILLEGAL_INPUT);
2823
2824 selection = cpl_mask_new(nx, ny);
2825
2826 /* find aperture with signal larger than sigma * median deviation */
2827 for (; iretry > 0 && nlabels == 0; iretry--, sigma *= 0.5) {
2828
2829 /* Compute the threshold */
2830 const double threshold = median + sigma * med_dist;
2831
2832 /* Select the pixel above the threshold */
2833 code = cpl_mask_threshold_image(selection, self, threshold, DBL_MAX,
2834 BAD_PIX);
2835
2836 if (code) break;
2837
2838 /* Labelise the thresholded selection */
2839 cpl_image_delete(labels);
2840 labels = cpl_image_labelise_mask_create(selection, &nlabels);
2841 }
2842 sigma *= 2.0; /* reverse last iteration that found no labels */
2843
2844 cpl_mask_delete(selection);
2845
2846 if (code) {
2847 cpl_image_delete(labels);
2848 return cpl_error_set_where(cpl_func);
2849 } else if (nlabels == 0) {
2850 cpl_image_delete(labels);
2851 return cpl_error_set(cpl_func, CPL_ERROR_DATA_NOT_FOUND);
2852 }
2853
2854 aperts = cpl_apertures_new_from_image(self, labels);
2855
2856 /* Find the aperture with the greatest flux */
2857 code = eris_apertures_find_max_flux(aperts, &ifluxapert, 1);
2858
2859 if (code) {
2860 cpl_apertures_delete(aperts);
2861 cpl_image_delete(labels);
2862 return cpl_error_set(cpl_func, CPL_ERROR_DATA_NOT_FOUND);
2863 }
2864
2865 npixobj = cpl_apertures_get_npix(aperts, ifluxapert);
2866 objradius = sqrt((double)npixobj * CPL_MATH_1_PI);
2867 winsize = CX_MIN(CX_MIN(nx, ny), (3.0 * objradius));
2868
2869 xposmax = cpl_apertures_get_maxpos_x(aperts, ifluxapert);
2870 yposmax = cpl_apertures_get_maxpos_y(aperts, ifluxapert);
2871 xposcen = cpl_apertures_get_centroid_x(aperts, ifluxapert);
2872 yposcen = cpl_apertures_get_centroid_y(aperts, ifluxapert);
2873 valmax = cpl_apertures_get_max(aperts, ifluxapert);
2874
2875 cpl_apertures_delete(aperts);
2876 cpl_image_delete(labels);
2877
2878 cpl_msg_debug(cpl_func, "Object radius at S/R=%g: %g (window-size=%u)",
2879 sigma, objradius, (unsigned)winsize);
2880 cpl_msg_debug(cpl_func, "Object-peak @ (%d, %d) = %g", (int)xposmax,
2881 (int)yposmax, valmax);
2882
2883 /* fit gaussian to get subpixel peak position */
2884
2885 gauss_parameters = cpl_array_new(7, CPL_TYPE_DOUBLE);
2886 cpl_array_set_double(gauss_parameters, 0, median);
2887
2888 code = cpl_fit_image_gaussian(self, NULL, xposmax, yposmax,
2889 winsize, winsize, gauss_parameters,
2890 NULL, NULL, NULL,
2891 NULL, NULL, NULL,
2892 NULL, NULL, NULL);
2893 if (!code) {
2894 const double M_x = cpl_array_get_double(gauss_parameters, 3, NULL);
2895 const double M_y = cpl_array_get_double(gauss_parameters, 4, NULL);
2896 const double SIGMA_x = cpl_array_get_double(gauss_parameters, 5, NULL);
2897 const double SIGMA_y = cpl_array_get_double(gauss_parameters, 6, NULL);
2898 valfit = cpl_gaussian_eval_2d(gauss_parameters, M_x, M_y);
2899 if (!cpl_errorstate_is_equal(prestate)) {
2900 code = cpl_error_get_code();
2901 } else {
2902 *pxpos = M_x;
2903 *pypos = M_y;
2904 *ppeak = valfit;
2905 *sigma_x = SIGMA_x;
2906 *sigma_y = SIGMA_y;
2907
2908 cpl_msg_debug(cpl_func, "Gauss-fit @ (%g, %g) = %g, SIGMA: (%g, %g)",
2909 M_x, M_y, valfit,
2910 SIGMA_x,
2911 SIGMA_y);
2912
2913 }
2914 }
2915 cpl_array_delete(gauss_parameters);
2916
2917 if (code || valfit < valmax) {
2918 cpl_errorstate_set(prestate);
2919 *pxpos = xposcen;
2920 *pypos = yposcen;
2921 *ppeak = valmax;
2922 }
2923 eris_check_error_code("eris_gaussian_maxpos");
2924 return code ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE;
2925}
2926
2927/*----------------------------------------------------------------------------*/
2935/*----------------------------------------------------------------------------*/
2936
2937cpl_propertylist*
2938eris_compute_psf_qc(hdrl_image* hima, const cpl_parameterlist* parlist,
2939 const char* context){
2940
2941 cpl_ensure(hima != NULL, CPL_ERROR_NULL_INPUT, NULL);
2942 cpl_ensure(parlist != NULL, CPL_ERROR_NULL_INPUT, NULL);
2943 cpl_ensure(context != NULL, CPL_ERROR_NULL_INPUT, NULL);
2944
2945 //cpl_errorstate clean_state = cpl_errorstate_get();
2946 cpl_size ima_szx = hdrl_image_get_size_x(hima);
2947 cpl_size ima_szy = hdrl_image_get_size_y(hima);
2948
2949 double peak = 0;
2950 double max_x = 0;
2951 double max_y = 0;
2952 double sigma_x = 0;
2953 double sigma_y = 0;
2954 double FWHM_x = 0;
2955 double FWHM_y = 0;
2956 cpl_image* image = hdrl_image_get_image(hima);
2957 cpl_image* error = hdrl_image_get_image(hima);
2958
2959 cpl_propertylist* qchead = cpl_propertylist_new();
2960 eris_gaussian_maxpos(image, 5, &max_x, &max_y, &peak, &sigma_x, &sigma_y);
2961 FWHM_x = sigma_x * CPL_MATH_FWHM_SIG;
2962 FWHM_y = sigma_y * CPL_MATH_FWHM_SIG;
2963 cpl_msg_info(cpl_func, "max_x: %g max_y: %g FWHM_x:%g FWHM_y: %g",
2964 max_x, max_y, FWHM_x, FWHM_y);
2965
2966 if(cpl_error_get_code() != CPL_ERROR_NONE) {
2967 cpl_msg_error(cpl_func,"Error fitting 2D Gaussian to object for QC. Exit");
2968 cpl_error_reset();
2969 return qchead;
2970 }
2971
2972 int max_ima_x = (int) (max_x + 0.5);
2973 int max_ima_y = (int) (max_y + 0.5);
2974
2975 int psf_sz = 40;
2976 int wllx = ((max_ima_x - psf_sz)>0) ? (max_ima_x - psf_sz) : 1;
2977 int wlly = ((max_ima_y - psf_sz)>0) ? (max_ima_y - psf_sz) : 1;
2978 int wurx = ((max_ima_x + psf_sz)<ima_szx) ? (max_ima_x + psf_sz) : ima_szx ;
2979 int wury = ((max_ima_y + psf_sz)<ima_szy) ? (max_ima_y + psf_sz) : ima_szy ;
2980
2981 cpl_table* qclog_tbl = eris_qclog_init();
2982
2983 /* not used code:
2984 double max_ima_cx = 0;
2985 max_ima_cx = cpl_image_get_centroid_x_window(image, wllx, wlly, wurx, wury);
2986 double max_ima_cy = 0;
2987 max_ima_cy = cpl_image_get_centroid_y_window(image, wllx, wlly, wurx, wury);
2988 */
2989
2990 int llx = 8;
2991 int lly = 8;
2992 int halfbox_x = 16;
2993 int halfbox_y = 16;
2994 eris_qclog_add_int(qclog_tbl,"QC FWHM LLX", llx, "[pix] STD star FWHM LLX");
2995 eris_qclog_add_int(qclog_tbl,"QC FWHM LLY", lly, "[pix] STD star FWHM LLY");
2996 eris_qclog_add_int(qclog_tbl,"QC FWHM HBX", halfbox_x, "[pix] STD star FWHM HBX");
2997 eris_qclog_add_int(qclog_tbl,"QC FWHM HBX", halfbox_y, "[pix] STD star FWHM HBY");
2998
2999
3000 int check1 = 0;
3001 double* pdata = cpl_image_get_data_double(image);
3002 cpl_size npix = cpl_image_get_size_x(image) * cpl_image_get_size_y(image);
3003 cpl_boolean has_nan = CPL_FALSE;
3004 for(cpl_size i =0; i < npix; i++ ) {
3005 if(eris_ifu_is_nan_or_inf(pdata[i])) {
3006 has_nan = CPL_TRUE;
3007 break;
3008 }
3009 }
3010
3011 cpl_bivector * biv = NULL;
3012 if(has_nan == CPL_FALSE) {
3013 cpl_image* fimage = cpl_image_cast(image, CPL_TYPE_FLOAT);
3014 //cpl_image_reject_from_mask(image, mask);
3015 biv = cpl_image_iqe(fimage, wllx, wlly, wurx, wury);
3016 cpl_image_delete(fimage);
3017 }
3018
3019 if( (cpl_error_get_code() == CPL_ERROR_NONE) && (has_nan == CPL_FALSE)) {
3020 const double * x = cpl_bivector_get_x_data_const(biv);
3021 eris_qclog_add_double(qclog_tbl, "QC CENTERX", x[0],
3022 "[pix] STD star X centroid position");
3023 eris_qclog_add_double(qclog_tbl, "QC CENTERY", x[1],
3024 "[pix] STD star Y centroid position");
3025 eris_qclog_add_double(qclog_tbl, "QC FWHM MAJ", x[2],
3026 "[pix] STD star FWHM on major axis");
3027 eris_qclog_add_double(qclog_tbl, "QC FWHM MIN", x[3],
3028 "[pix] STD star FWHM on minor axis");
3029 eris_qclog_add_double(qclog_tbl, "QC THETA", x[4],
3030 "[deg] STD star ellipsis angle theta");
3031 cpl_bivector_delete(biv);
3032 } else {
3033 eris_qclog_add_double(qclog_tbl, "QC CENTERX", max_x,
3034 "[pix] STD star X centroid position");
3035 eris_qclog_add_double(qclog_tbl, "QC CENTERY", max_y,
3036 "[pix] STD star Y centroid position");
3037 eris_qclog_add_double(qclog_tbl, "QC FWHM MAJ", FWHM_x,
3038 "[pix] STD star FWHM on major axis");
3039 eris_qclog_add_double(qclog_tbl, "QC FWHM MIN", FWHM_y,
3040 "[pix] STD star FWHM on minor axis");
3041
3042 cpl_error_reset();
3043 }
3044
3045 double xcen = max_x;
3046 double ycen = max_y;
3047 if (has_nan == CPL_FALSE) {
3048// double norm = 0;
3049
3050// double sig_x = 0;
3051// double sig_y = 0;
3052 double fwhm_x = 0;
3053 double fwhm_y = 0;
3054 //double disp = 0;
3055
3056 double fwhm_factor = 5.0;
3057
3058 char* pname = cpl_sprintf("%s.fwhm-factor",context);
3059 eris_parameters_get_double(parlist, pname, &fwhm_factor);
3060 cpl_free(pname);
3061 double rms = 0;
3062 double red_chisq = 0;
3063 cpl_matrix* covariance = NULL;
3064 double major = 0;
3065 double minor = 0;
3066 double angle = 0;
3067 cpl_array* fit_params = NULL;
3068 cpl_array* gauss2d_fit_params = cpl_array_new(7, CPL_TYPE_DOUBLE);
3069 cpl_array* gauss2d_err_params = cpl_array_new(7, CPL_TYPE_DOUBLE);
3070 cpl_matrix* phys_cov = NULL;
3071 int status = 0;
3072
3073 if(CPL_ERROR_NONE == cpl_fit_image_gaussian(image, error,
3074 max_ima_x, max_ima_y, psf_sz, psf_sz, gauss2d_fit_params,
3075 gauss2d_err_params, fit_params, &rms, &red_chisq, &covariance,
3076 &major, &minor, &angle, &phys_cov) ) {
3077 sigma_x = cpl_array_get(gauss2d_fit_params, 5, &status);
3078 sigma_y = cpl_array_get(gauss2d_fit_params, 6, &status);
3079
3080 fwhm_x = sigma_x * CPL_MATH_FWHM_SIG;
3081 fwhm_y = sigma_y * CPL_MATH_FWHM_SIG;
3082 eris_qclog_add_double_f(qclog_tbl, "QC FWHMX", fwhm_x,
3083 "[pix] STD star FWHM on X");
3084 eris_qclog_add_double_f(qclog_tbl, "QC FWHMY", fwhm_y,
3085 "[pix] STD star FWHM on Y");
3086
3087 halfbox_x = (floor)(0.5 * (fwhm_x + fwhm_y) * fwhm_factor + 0.5);
3088
3089 halfbox_y = (floor)(0.5 * (fwhm_x + fwhm_y) * fwhm_factor + 0.5);
3090
3091 } else {
3092 //TODO remove irplib
3093 //irplib_error_recover(clean_state, "Problem fitting Gaussian");
3094 cpl_array_delete(gauss2d_fit_params);
3095 cpl_array_delete(gauss2d_err_params);
3096 cpl_error_reset();
3097
3098 }
3099 } else {
3100
3101 eris_qclog_add_double_f(qclog_tbl, "QC FWHMX", FWHM_x,
3102 "[pix] STD star FWHM on X");
3103 eris_qclog_add_double_f(qclog_tbl, "QC FWHMY", FWHM_y,
3104 "[pix] STD star FWHM on Y");
3105 }
3106
3107 /* we use a large value of kappa to be sure to flag well the object */
3108 //cpl_mask* obj_mask=NULL;
3109 //int pfx = 3;
3110 //int pfy = 3;
3111 //const char* pfm;
3112 //TODO: maybe use the mask defined elsewhere for extraction
3113 //if(strcmp(extract_method, "optimal") != 0) {
3114 // double kappa = 5.;
3115 // obj_mask = eris_object_mask(image, pfm, pfx, pfy, kappa);
3116 //}
3117
3118
3119 llx = (int)(xcen - halfbox_x);
3120 llx = (llx > 0 ) ? llx : 1;
3121
3122 if((llx + 2 * halfbox_x) >= ima_szx) {
3123 halfbox_x = (int) ((ima_szx - llx - 1) / 2);
3124 check1++;
3125 }
3126
3127 lly = (int)(ycen - halfbox_y);
3128 lly = (lly > 0 ) ? lly : 1;
3129 if((lly + 2 * halfbox_y) >= ima_szy) {
3130 halfbox_y = (int) ((ima_szy - lly - 1) / 2);
3131 check1++;
3132 }
3133 eris_qclog_add_int(qclog_tbl,"QC CHECK1", check1,
3134 "Check on evaluation box");
3135 //cpl_table_save(qclog_tbl,NULL,NULL,"qclog_tbl.fits",CPL_IO_DEFAULT);
3136 eris_pfits_put_qc(qchead, qclog_tbl);
3137 cpl_table_delete(qclog_tbl);
3138 eris_check_error_code("eris_compute_psf_qc");
3139 return qchead;
3140
3141}
3142
3143static cpl_error_code
3144eris_imagelist_reject_value(hdrl_imagelist* iml/*, cpl_value value*/)
3145{
3146
3147 cpl_ensure(iml != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
3148
3149 cpl_size sz = hdrl_imagelist_get_size(iml);
3150
3151 for(cpl_size i = 0; i < sz; i++) {
3152 hdrl_image* hima = hdrl_imagelist_get(iml, i);
3153 hdrl_image_reject_value(hima, CPL_VALUE_NAN);
3154 }
3155 return cpl_error_get_code();
3156}
3157/*----------------------------------------------------------------------------*/
3165/*----------------------------------------------------------------------------*/
3166cpl_mask*
3167eris_ifu_hima_get_obj_mask_percent(hdrl_image* hima, const double percent)
3168{
3169 cpl_mask* mask_obj = NULL;
3170
3171 cpl_size sx = hdrl_image_get_size_x(hima);
3172 cpl_size sy = hdrl_image_get_size_y(hima);
3173
3174 cpl_image* image = hdrl_image_get_image(hima);
3175 cpl_image* ima_tmp = cpl_image_duplicate(image);
3176
3177
3178 cpl_ensure(hima != NULL, CPL_ERROR_NULL_INPUT, NULL);
3179 cpl_ensure(0.25 <= percent && percent <= 0.75, CPL_ERROR_ILLEGAL_INPUT, NULL);
3180 double* data = cpl_image_get_data(ima_tmp);
3181
3182 cpl_size npoints = sx * sy;
3183 cpl_ensure(npoints > 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
3184 cpl_vector* v = cpl_vector_new(npoints);
3185 v = cpl_vector_wrap(npoints, data);
3186
3187 cpl_vector_sort(v, CPL_SORT_ASCENDING);
3188
3189 cpl_size thresh_pos = percent * npoints;
3190 double threshold_max = cpl_vector_get(v, thresh_pos);
3191 //cpl_msg_info(cpl_func,"threshold_max: %g",threshold_max);
3192 cpl_vector_unwrap(v);
3193 cpl_image_delete(ima_tmp);
3194 mask_obj = cpl_mask_threshold_image_create(image, DBL_MIN, threshold_max);
3195 cpl_mask_not(mask_obj);
3196 if (v != NULL) {
3197 cpl_vector_delete(v);
3198 }
3199 return mask_obj;
3200}
3201/*----------------------------------------------------------------------------*/
3210/*----------------------------------------------------------------------------*/
3211cpl_mask*
3212eris_ifu_hima_get_obj_mask(hdrl_image* hima, const cpl_size niter,
3213 const double kappa)
3214{
3215
3216 cpl_mask* mask_tmp = NULL;
3217 cpl_mask* mask_obj = NULL;
3218 hdrl_value median = {0, 0};
3219 double max = 0;
3220 double stdev = 0;
3221
3222 cpl_ensure(hima != NULL, CPL_ERROR_NULL_INPUT, NULL);
3223 cpl_ensure(1 <= niter && niter <= 100, CPL_ERROR_ILLEGAL_INPUT, NULL);
3224 cpl_ensure(kappa > 0., CPL_ERROR_ILLEGAL_INPUT, NULL);
3225
3226 max = cpl_image_get_max(hdrl_image_get_image(hima));
3227
3228 for (cpl_size i = 0; i < niter; i++) {
3229 median = hdrl_image_get_median(hima);
3230 if (!isnan(median.data)) {
3231 stdev = hdrl_image_get_stdev(hima);
3232 double thresh_max = median.data + kappa * stdev;
3233 cpl_msg_info(cpl_func, "median: %g stdev: %g thresh: %g max: %g",
3234 median.data, stdev, thresh_max, max);
3235 thresh_max = (thresh_max < max) ? thresh_max : 0.99 * max;
3236 cpl_msg_info(cpl_func, "median: %g stdev: %g thresh: %g max: %g",
3237 median.data, stdev, thresh_max, max);
3238 if (stdev > 0) {
3239
3240 cpl_image* ima_tmp = hdrl_image_get_image(hima);
3241
3242 mask_tmp = cpl_mask_threshold_image_create(ima_tmp, DBL_MIN, thresh_max);
3243 cpl_mask_not(mask_tmp);
3244
3245 hdrl_image_reject_from_mask(hima, mask_tmp);
3246
3247 if (i == (niter -1)) {
3248 mask_obj = cpl_mask_duplicate(mask_tmp);
3249 }
3250 cpl_mask_delete(mask_tmp);
3251 }
3252 }
3253 }
3254
3255 eris_check_error_code("eris_ifu_hima_get_obj_mask");
3256 return mask_obj;
3257}
3258
3266cpl_error_code
3267eris_get_pupil_shift(hdrl_imagelist* iml, const int n, cpl_table** qclog_tbl)
3268{
3269
3270
3271 cpl_ensure(iml != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
3272 cpl_ensure(qclog_tbl != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
3273 cpl_ensure(*qclog_tbl != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
3274 cpl_ensure(n >= 0, CPL_ERROR_ILLEGAL_INPUT, CPL_ERROR_ILLEGAL_INPUT);
3275
3276 cpl_size max_ima_x = 0;
3277 cpl_size max_ima_y = 0;
3278 int nx = 0;
3279 int ny = 0;
3280
3281 double xshift = 0;
3282 double yshift = 0;
3283
3284 double max_ima_cx = 0;
3285 double max_ima_cy = 0;
3286
3287 hdrl_image* himg = NULL;
3288 cpl_image* img_dup = NULL;
3289 cpl_image* contrib_map = NULL;
3290 char* key_name;
3291
3292 eris_imagelist_reject_value(iml/*, CPL_VALUE_NAN*/);
3293
3294 hdrl_imagelist_collapse_median(iml, &himg, &contrib_map);
3295 nx = hdrl_image_get_size_x(himg);
3296 ny = hdrl_image_get_size_y(himg);
3297
3298 img_dup = hdrl_image_get_image(himg);
3299
3300 cpl_image_get_maxpos(img_dup, &max_ima_x, &max_ima_y);
3301 max_ima_cx = cpl_image_get_centroid_x_window(img_dup, 1, 1, nx, ny);
3302 max_ima_cy = cpl_image_get_centroid_y_window(img_dup, 1, 1, nx, ny);
3303 //cpl_image_delete(img_dup);
3304
3305
3306 xshift = max_ima_cx - (double)nx/2;
3307 yshift = max_ima_cy - (double)ny/2;
3308
3309 key_name = cpl_sprintf("QC PUPIL%d SHIFTX", n);
3310
3311 eris_qclog_add_double_f(*qclog_tbl, key_name, xshift,
3312 "X shift centroid - center image");
3313 cpl_free(key_name);
3314 key_name = cpl_sprintf("QC PUPIL%d SHIFTY", n);
3315 eris_qclog_add_double_f(*qclog_tbl, key_name, yshift,
3316 "Y shift centroid - center image");
3317 cpl_msg_info(cpl_func,"xshift: %g yshift: %g",xshift, yshift);
3318 cpl_free(key_name);
3319 hdrl_image_delete(himg);
3320 cpl_image_delete(contrib_map);
3321 eris_check_error_code("eris_get_pupil_shift");
3322 return cpl_error_get_code();
3323}
3324
3334cpl_mask* eris_ifu_mask_from_image(const cpl_image* img_mask)
3335{
3336 cpl_size nx = 0,
3337 ny = 0;
3338 cpl_mask *mask = NULL;
3339 const double *pimg_mask = NULL;
3340 cpl_binary *pmask = NULL;
3341
3342 cpl_ensure(img_mask != NULL, CPL_ERROR_NULL_INPUT, NULL);
3343
3344 TRY {
3345 nx = cpl_image_get_size_x(img_mask);
3346 ny = cpl_image_get_size_y(img_mask);
3347
3349 mask = cpl_mask_new(nx,ny));
3351 pimg_mask = cpl_image_get_data_double_const(img_mask));
3353 pmask = cpl_mask_get_data(mask));
3354
3355 for (cpl_size x = 0; x < nx; x++) {
3356 for (cpl_size y = 0; y < ny; y++) {
3357 if (pimg_mask[x+nx*y] > 0.5) {
3358 // pimg_mask = 1 -> CPL_BINARY_0
3359 pmask[x+nx*y] = GOOD_PIX;
3360 } else {
3361 // pimg_mask = 0 -> CPL_BINARY_1
3362 pmask[x+nx*y] = BAD_PIX;
3363 }
3364 }
3365 }
3366
3367
3368 } CATCH {
3369 CATCH_MSG();
3370 eris_ifu_free_mask(&mask);
3371 }
3372
3373 return mask;
3374}
3375
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