ERIS Pipeline Reference Manual 1.9.2
eris_ifu_utils.h
1/* $Id: eris_ifu_utils.h,v 1.15 2013-07-22 13:38:01 jtaylor 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: jtaylor $
23 * $Date: 2013-07-22 13:38:01 $
24 * $Revision: 1.15 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifndef ERIS_IFU_UTILS_H
29#define ERIS_IFU_UTILS_H
30
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35/*-----------------------------------------------------------------------------
36 Includes
37 -----------------------------------------------------------------------------*/
38
39#include <cpl.h>
40#include <hdrl.h>
41#include "eris_ifu_constants.h"
42#include "eris_ifu_vector.h"
43#include "eris_ifu_dfs.h"
44
45#define MAX_STR_SIZE 512
46#define FILE_NAME_SZ 256
47
48enum hdrl_t {
49 eris_hdrl_data,
50 eris_hdrl_error,
51 eris_hdrl_badpix};
52
53/*-----------------------------------------------------------------------------
54 Prototypes
55 -----------------------------------------------------------------------------*/
56
57/* ---------------------- idl-functions ------------------------------------- */
61enum idl_rel_ops {eq, ne, ge, gt, le, lt};
62
63cpl_vector* eris_ifu_idl_where(const cpl_vector *data,
64 double val,
65 int op);
66cpl_vector* eris_ifu_idl_values_at_indices(const cpl_vector *data,
67 const cpl_vector *indices);
68
69cpl_error_code eris_ifu_cut_endings(cpl_vector** vec,
70 int *begin,
71 int *end,
72 int cut);
73
74/* --------- FREE helper functions --------- */
75void eris_ifu_free_hdrl_image(hdrl_image **item);
76void eris_ifu_free_hdrl_imagelist(hdrl_imagelist **item);
77void eris_ifu_free_image(cpl_image **item);
78void eris_ifu_free_imagelist(cpl_imagelist **item);
79void eris_ifu_free_mask(cpl_mask **item);
80void eris_ifu_free_matrix(cpl_matrix **item);
81void eris_ifu_free_propertylist(cpl_propertylist **item);
82void eris_ifu_free_vector(cpl_vector **item);
83void eris_ifu_free_ifu_vector(eris_ifu_vector **item);
84void eris_ifu_free_string(char **item);
85void eris_ifu_free_frame(cpl_frame **item);
86void eris_ifu_free_frameset(cpl_frameset **item);
87void eris_ifu_free_hdrl_parameter(hdrl_parameter **item);
88void eris_ifu_free_parameter(cpl_parameter **item);
89void eris_ifu_free_parameterlist(cpl_parameterlist **item);
90void eris_ifu_free_table(cpl_table **item);
91void eris_ifu_free_double_array(double **item);
92void eris_ifu_free_float_array(float **item);
93void eris_ifu_free_int_array(int **item);
94void eris_ifu_free_polynomial(cpl_polynomial **item);
95void eris_ifu_free_bivector(cpl_bivector **item);
96void eris_ifu_free_apertures(cpl_apertures **item);
97
98/* --------- SAVE helper functions --------- */
99cpl_error_code eris_ifu_save_vector_dbg(const cpl_vector *vec,
100 const char* filename, int create,
101 const cpl_propertylist *pl);
102cpl_error_code eris_ifu_save_ifu_vector_dbg(const eris_ifu_vector *vec,
103 const char* filename, int create);
104cpl_error_code eris_ifu_save_bivector_dbg(const cpl_bivector *bivec,
105 const char* filename, int col, int create);
106cpl_error_code eris_ifu_save_image_dbg(const cpl_image *img,
107 const char* filename, int create, const cpl_propertylist *pl);
108cpl_error_code eris_ifu_save_table_dbg(const cpl_table *tbl,
109 const char* filename, int create);
110cpl_error_code eris_ifu_save_mask_dbg(const cpl_mask *mask,
111 const char* filename, int create, const cpl_propertylist *pl);
112cpl_error_code eris_ifu_save_imagelist_dbg(const cpl_imagelist *imglist,
113 const char* filename, int create);
114cpl_error_code eris_ifu_save_cpl_image_dbg(const cpl_image *img,
115 const char* name, int singlefile,
116 const cpl_propertylist *pl);
117cpl_error_code eris_ifu_save_cpl_imagelist_dbg(const cpl_imagelist *imglist,
118 const char* name);
119cpl_error_code eris_ifu_save_hdrl_image_dbg(const hdrl_image *hdrl_img,
120 const char* filename, int singlefile,
121 const cpl_propertylist *pl);
122cpl_error_code eris_ifu_save_hdrl_imagelist_dbg(const hdrl_imagelist *imgList,
123 const char* filename, int singlefile);
124
125cpl_error_code eris_ifu_save_image(cpl_frameset *fs,
126 const cpl_propertylist *plist,
127 const cpl_parameterlist *parlist,
128 const char *recipe,
129 const char *procatg,
130 const char *filename,
131 cpl_type type,
132 const cpl_image *img);
133
134cpl_error_code eris_ifu_save_imagelist(cpl_frameset *fs,
135 cpl_frame *inherit,
136 const cpl_propertylist *plist,
137 const cpl_parameterlist *parlist,
138 const char *recipe,
139 const char *procatg,
140 const char *filename,
141 cpl_type type,
142 const cpl_imagelist *imglist);
143
144cpl_error_code eris_ifu_hdrl_image_reject_mask(hdrl_image *img,
145 const cpl_mask *mask);
146
147/* --------- LOAD helper functions --------- */
148
149// agudo: commented out, should use eris_ifu_load_exposure_file()/_frame()
150//hdrl_image* eris_ifu_load_image_ctg(cpl_frameset *frameset,
151// const char *category,
152// int ext);
153
154//hdrl_image* eris_ifu_load_image(const char *filename,
155// cpl_type im_type,
156// int pnum,
157// int xtnum);
158
159cpl_mask* eris_ifu_load_badpixel_mask(const cpl_frameset *frameset,
160 const char *category,
161 int ext);
162
163/* --------- OTHER helper functions --------- */
164hdrl_imagelist* eris_ifu_get_hdrlimagelist_by_tag(cpl_frameset *frameset,
165 const char *tag,
166 int exposureCorrectionMode);
167
168cpl_frameset* eris_ifu_get_frameset_by_tag(const cpl_frameset *frameset,
169 const char *tag);
170
171cpl_error_code eris_ifu_parameterlist_append_list(cpl_parameterlist *p1,
172 const cpl_parameterlist *p2);
173
174cpl_error_code eris_ifu_file_exists(const char *filename);
175
176cpl_imagelist* eris_ifu_hdrl_get_imagelist(const hdrl_imagelist *hdrl_imglist,
177 enum hdrl_t type);
178
179char* eris_ifu_get_lampString(int lampStatus);
180
181const char* eris_ifu_get_bandString(ifsBand band);
182
183const char* eris_ifu_get_instrumentString(ifsInstrument instrument);
184
185double eris_ifu_get_band_resolution(ifsBand band);
186
187const char* eris_ifu_get_preopticsScaleString(ifsPreopticsScale scale);
188
189cpl_image* eris_ifu_image_create_window(const cpl_image* img);
190
191cpl_mask* eris_ifu_mask_create_border(const cpl_mask* mask);
192
193cpl_error_code eris_ifu_mask_nans_in_cube(cpl_imagelist *cube);
194cpl_error_code eris_ifu_strehl_flag_nans(hdrl_image** hima);
195//cpl_error_code eris_ifu_mask_reset(cpl_mask *mask);
196
197cpl_mask* eris_ifu_quality2bp_mask(const cpl_image *qualityMask,
198 deqQualityType qualityType);
199
200cpl_imagelist* eris_ifu_interpolatedMask_to_maskZero(cpl_imagelist *bpmCube,
201 double threshold);
202
203cpl_error_code eris_ifu_split_hdrl_imagelist(hdrl_imagelist *cube,
204 cpl_imagelist *dataCube,
205 cpl_imagelist *errorCube);
206
207cpl_error_code eris_ifu_split3_hdrl_imagelist(hdrl_imagelist *cube,
208 cpl_imagelist *dataCube,
209 cpl_imagelist *errorCube,
210 cpl_imagelist *qualCube);
211cpl_table *
212eris_qclog_init(void);
213
214
215cpl_error_code
216eris_qclog_add_int(cpl_table* table,
217 const char* name,
218 const int value,
219 const char* help);
220
221
222cpl_error_code
223eris_qclog_add_bool(cpl_table* table,
224 const char* name,
225 const char* help);
226
227cpl_error_code
228eris_qclog_add_double(cpl_table* table,
229 const char* name,
230 const double value,
231 const char* help);
232
233cpl_error_code
234eris_qclog_add_double_f(cpl_table* table,
235 const char* key_name,
236 const double value,
237 const char* key_help);
238cpl_error_code
239eris_qclog_add_double_format(cpl_table* table,
240 const char* name,
241 const double value,
242 const char* help);
243
244cpl_error_code
245eris_qclog_add_string(cpl_table* table,
246 const char* name,
247 const char* value,
248 const char* help);
249
250cpl_propertylist* eris_qc_init(void);
251
252cpl_error_code
253eris_qc_add_int(cpl_propertylist* table,
254 const char* name,
255 const int value,
256 const char* help,
257 const char* format);
258
259
260cpl_error_code
261eris_qc_add_bool(cpl_propertylist* table,
262 const char* name,
263 const char value,
264 const char* help,
265 const char* format);
266
267
268cpl_error_code
269eris_qc_add_float(cpl_propertylist* table,
270 const char* name,
271 const float value,
272 const char* help,
273 const char* format);
274
275
276cpl_error_code
277eris_qc_add_double(cpl_propertylist* table,
278 const char* name,
279 const double value,
280 const char* help,
281 const char* format);
282
283
284cpl_error_code
285eris_qc_add_string(cpl_propertylist* table,
286 const char* name,
287 const char* value,
288 const char* help,
289 const char* format);
290
291cpl_error_code
292eris_pfits_put_qc(cpl_propertylist *plist,
293 cpl_table *qclog);
294
295cpl_error_code
296eris_ifu_get_badpix_qc_from_mask(const cpl_mask* bp_mask,
297 cpl_propertylist* qc_list,
298 const char* prefix);
299
300cpl_error_code
301eris_ifu_get_badpix_qc_from_ima(const cpl_image* image,
302 cpl_propertylist* qc_list,
303 const char* prefix);
304cpl_propertylist*
305eris_compute_psf_qc(hdrl_image* hima, const cpl_parameterlist* parlist,
306 const char* context);
307
308cpl_error_code
309eris_gaussian_maxpos(const cpl_image * self,
310 double sigma,
311 double * pxpos,
312 double * pypos,
313 double * ppeak,
314 double * sigma_x,
315 double * sigma_y);
316
317cpl_mask*
318eris_ifu_hima_get_obj_mask(hdrl_image* hima, const cpl_size niter,
319 const double kappa);
320
321cpl_error_code
322eris_ifu_mask_nans_in_hdrlimage(hdrl_image** hima);
323
324cpl_error_code
325eris_ifu_get_plane_cut_min_max(ifsBand band, cpl_size* zmin, cpl_size* zmax);
326
327cpl_error_code
328eris_ifu_cube_trim_nans(const cpl_size zmin,
329 const cpl_size zmax,
330 hdrl_imagelist** iml,
331 cpl_imagelist** bpm,
332 cpl_propertylist* header);
333
334cpl_error_code
335eris_ifu_cube_set_values(hdrl_imagelist** iml/*, cpl_imagelist** bpm*/);
336
337cpl_error_code
338eris_get_pupil_shift(hdrl_imagelist* iml, const int n, cpl_table** qclog_tbl);
339
340cpl_mask*
341eris_ifu_hima_get_obj_mask_percent(hdrl_image* hima, const double percent);
342
343cpl_mask* eris_ifu_mask_from_image(const cpl_image *img_mask);
344
345#endif
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)
Save table for debugging (quick, no DFS overhead)
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 with mask for debugging.
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 with DFS compliance.
cpl_error_code eris_ifu_save_imagelist_dbg(const cpl_imagelist *imglist, const char *filename, int create)
Save CPL imagelist for debugging (quick, no DFS overhead)
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)
Convert lamp status bitmask to string.
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 for debugging (quick, no DFS overhead)
cpl_error_code eris_ifu_save_image_dbg(const cpl_image *img, const char *filename, int create, const cpl_propertylist *pl)
Save image for debugging (quick, no DFS overhead)
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 eris_ifu_vector for debugging (quick, no DFS overhead)
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 HDRL image.
const char * eris_ifu_get_bandString(ifsBand band)
Convert band enum to string.
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 mask to HDRL image (reject masked pixels)
cpl_error_code eris_ifu_file_exists(const char *filename)
‍**
cpl_error_code eris_ifu_get_plane_cut_min_max(ifsBand band, cpl_size *zmin, cpl_size *zmax)
Get band-specific plane indices for NaN trimming.
const char * eris_ifu_get_instrumentString(ifsInstrument instrument)
Convert instrument enum to string.
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 for debugging (as vector or table)
cpl_imagelist * eris_ifu_hdrl_get_imagelist(const hdrl_imagelist *hdrl_imglist, enum hdrl_t type)
Extract from an HDRL imagelist a specific CPL imagelist.
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)
Add bad pixel border around mask.
cpl_image * eris_ifu_image_create_window(const cpl_image *img)
Create sub-image by removing bad pixel 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 *name, const char *value, const char *help)
add QC string info to table
cpl_error_code eris_qclog_add_double(cpl_table *table, const char *name, const double value, const char *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)
Save mask for debugging (quick, no DFS overhead)
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 known 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)
Set specific pixel values in HDRL imagelist (debugging utility)
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 *name, const char *help)
add QC boolean info to table
cpl_error_code eris_ifu_mask_nans_in_cube(cpl_imagelist *cube)
Mask NaNs and Infs in CPL imagelist (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 *name, const int value, const char *help)
add QC int info to table
cpl_error_code eris_ifu_save_hdrl_imagelist_dbg(const hdrl_imagelist *imgList, const char *filename, int singlefile)
Save HDRL imagelist for debugging (data + error + mask planes)
cpl_error_code eris_ifu_save_cpl_imagelist_dbg(const cpl_imagelist *imglist, const char *name)
Save CPL imagelist for debugging.
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 image for debugging (data + error + mask)
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)
Trim NaN-dominated planes from cube edges.
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 *name, const double value, const char *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)
Convert pre-optics scale enum to string.
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 *img)
Save image with DFS compliance.
double eris_ifu_get_band_resolution(ifsBand band)
Get nominal spectral resolution for a given band.
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