ERIS Pipeline Reference Manual 1.9.2
eris_nix_casu_utils.c
1/* $Id$
2 *
3 * This file is part of the ERIS/NIX Pipeline
4 * Copyright (C) 2017 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$
23 * $Date$
24 * $Rev$
25 */
26
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
30
31/*-----------------------------------------------------------------------------
32 Includes
33 -----------------------------------------------------------------------------*/
34
35#include <cpl.h>
36#include <libgen.h>
37#include <math.h>
38#include <string.h>
39#include "eris_nix_casu_utils.h"
40#include <hdrl.h>
41
42/*----------------------------------------------------------------------------*/
46/*----------------------------------------------------------------------------*/
47
50/*----------------------------------------------------------------------------*/
59/*----------------------------------------------------------------------------*/
60
61cpl_error_code encu_limlist_to_casu_fits(located_imagelist * limlist,
62 casu_fits *** indata,
63 casu_fits *** inconf,
64 casu_fits *** invar) {
65
66 if (cpl_error_get_code() != CPL_ERROR_NONE) return cpl_error_get_code();
67 if (!limlist) return CPL_ERROR_NONE;
68
69 cpl_size nimages = limlist->size;
70 *indata = cpl_malloc(nimages * sizeof(casu_fits *));
71 *inconf = cpl_malloc(nimages * sizeof(casu_fits *));
72 *invar = cpl_malloc(nimages * sizeof(casu_fits *));
73
74 for (int i = 0; i < (int)nimages; i++) {
75 enu_check(limlist->limages[i]->himage != NULL,
76 CPL_ERROR_NULL_INPUT,
77 "located image has no himage");
78
79 /* AMO: check Not required */
80 double* pdata = cpl_image_get_data_double(hdrl_image_get_image((limlist->limages[i])->himage));
81 //double* perrs = cpl_image_get_data_double(hdrl_image_get_error((limlist->limages[i])->himage));
82 cpl_size sx = hdrl_image_get_size_x(limlist->limages[i]->himage);
83 cpl_size sy = hdrl_image_get_size_y(limlist->limages[i]->himage);
84 cpl_mask* mask = cpl_image_get_bpm(hdrl_image_get_image(limlist->limages[i]->himage));
85 cpl_mask* mskerr = cpl_image_get_bpm(hdrl_image_get_error(limlist->limages[i]->himage));
86 double* pconf = cpl_image_get_data_double(limlist->limages[i]->confidence);
87 cpl_binary* pbpm_data = cpl_mask_get_data(mask);
88 cpl_binary* pbpm_errs = cpl_mask_get_data(mskerr);
89 for(cpl_size indexj = 0; indexj < sy; indexj++) {
90 for(cpl_size indexi = 0; indexi < sx; indexi++) {
91 if(!isfinite(pdata[indexi+indexj*sx]) ) {
92 pbpm_data[indexi+indexj*sx] = CPL_BINARY_1;
93 pbpm_errs[indexi+indexj*sx] = CPL_BINARY_1;
94 pconf[indexi+indexj*sx] = 0;
95//cpl_msg_warning(cpl_func,"found bad pixel at [%lld,%lld]",indexi,indexj);
96 }
97 }
98 }
99
100
101
102 (*indata)[i] = casu_fits_wrap(cpl_image_cast(hdrl_image_get_image(
103 limlist->limages[i]->himage),
104 CPL_TYPE_FLOAT), NULL,
105 limlist->limages[i]->plist,
106 limlist->limages[i]->plist);
107 (*indata)[i]->fname = cpl_strdup(cpl_frame_get_filename(
108 limlist->limages[i]->frame));
109 (*indata)[i]->nexten = 1;
110 enu_check(limlist->limages[i]->confidence != NULL,
111 CPL_ERROR_NULL_INPUT,
112 "located image has no confidence array");
113 (*inconf)[i] = casu_fits_wrap(cpl_image_cast(
114 limlist->limages[i]->confidence,
115 CPL_TYPE_FLOAT), NULL,
116 limlist->limages[i]->plist, NULL);
117 (*inconf)[i]->fname = cpl_strdup(cpl_frame_get_filename(
118 limlist->limages[i]->frame));
119 (*inconf)[i]->nexten = 4;
120 (*invar)[i] = casu_fits_wrap(cpl_image_cast(hdrl_image_get_error(
121 limlist->limages[i]->himage),
122 CPL_TYPE_FLOAT), NULL,
123 limlist->limages[i]->plist,
124 limlist->limages[i]->plist);
125 (*invar)[i]->fname = cpl_strdup(cpl_frame_get_filename(
126 limlist->limages[i]->frame));
127 (*invar)[i]->nexten = 2;
128 }
129
130 cleanup:
131
132 /* memory cleanup tbd */
133
134 return cpl_error_get_code();;
135}
136
cpl_error_code encu_limlist_to_casu_fits(located_imagelist *limlist, casu_fits ***indata, casu_fits ***inconf, casu_fits ***invar)
Translate a located_imagelist to arrays of casu_fits structs.
cpl_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
cpl_size hdrl_image_get_size_x(const hdrl_image *self)
return size of X dimension of image
Definition: hdrl_image.c:525
cpl_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
Definition: hdrl_image.c:105