ERIS Pipeline Reference Manual 1.8.15
eris_ifu_functions.h
1/* $Id$
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#ifndef ERIS_IFU_FUNCTIONS_H
22#define ERIS_IFU_FUNCTIONS_H
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27/*----------------------------------------------------------------------------*/
31/*----------------------------------------------------------------------------*/
32
35/*-----------------------------------------------------------------------------
36 Includes
37 -----------------------------------------------------------------------------*/
38
39#include <gsl/gsl_interp.h>
40#include <gsl/gsl_spline.h>
41#include <gsl/gsl_errno.h>
42#include <cpl.h>
43#include <hdrl.h>
44#include "eris_ifu_constants.h"
45#include "eris_ifu_dfs.h"
46
47/*-----------------------------------------------------------------------------
48 Define
49 -----------------------------------------------------------------------------*/
50#define LINE_EXPOSURE_CORRECTION 1
51#define COLUMN_EXPOSURE_CORRECTION 2
52#define COSMIC_RAY_EXPOSURE_CORRECTION 4
53#define COSMIC_RAY_EXPOSURE_DETECTION 8
54
55#define BAD_PIX CPL_BINARY_1
56#define GOOD_PIX CPL_BINARY_0
57
58#define DBL_ZERO_TOLERANCE 1e-10
59
60typedef enum {
61 PD_SCIENCE, // standard science products
62 PD_AUXILLIARY, // additional intermediate science products
63 PD_ALL, // all science products
64 PD_DEBUG // additional products for pipeline developers
65} productDepthType;
66
67struct stdParamStruct {
68 ifsInstrument instrument;
69 bool line_corr;
70 bool col_corr;
71 bool crh_corr;
72 bool crh_det;
73 int rawImageCorrectionMask;
74 productDepthType productDepth;
75 hdrl_parameter *crh_detection;
76};
77/* Stack allocated object assign by value (copy) only */
78#define stdParamStructInit {0,0,0,0,0,0,0,NULL}
79
80#define GAUSS_PAR_RANGE_MAX 41
81struct gaussParStruct {
82 double x0;
83 double sigma;
84 double area;
85 double offset;
86 double peak;
87 double mse;
88 int errorCode;
89 int range;
90 double xdata[GAUSS_PAR_RANGE_MAX];
91 double ydata[GAUSS_PAR_RANGE_MAX];
92};
93
94/*-----------------------------------------------------------------------------
95 Prototypes
96 -----------------------------------------------------------------------------*/
97ifsInstrument eris_ifu_get_instrument_frame(cpl_frame *frame);
98
99
100hdrl_image * eris_ifu_raw_hdrl_image(const cpl_image *cplImage);
101
102cpl_image* eris_ifu_calc_noise_map(const cpl_image *data,
103 double gain,
104 double readnoise);
105
106cpl_error_code eris_ifu_add_badpix_border(cpl_image *data, cpl_boolean add_ones,
107 cpl_image *dqi);
108
109cpl_error_code eris_ifu_saturation_detection(cpl_image *data, cpl_image *dqi);
110
111cpl_mask* eris_ifu_detect_crh(hdrl_image* image,
112 int exposureCorrectionMode,
113 hdrl_parameter *laCosmicParams,
114 bool maskImage);
115
116hdrl_image* eris_ifu_load_exposure_file(const char *filename,
117 int exposureCorrectionMode,
118 cpl_image *dqi);
119
120hdrl_image* eris_ifu_load_exposure_frame(const cpl_frame *frame,
121 int exposureCorrectionMode,
122 cpl_image *dqi);
123
124hdrl_imagelist* eris_ifu_load_exposure_frameset(const cpl_frameset *frameset,
125 int exposureCorrectionMode);
126
127cpl_error_code eris_ifu_exposure_line_correction(cpl_image *image);
128
129cpl_error_code eris_ifu_exposure_column_correction(cpl_image *image);
130
131cpl_error_code eris_ifu_calc_bpm(const cpl_parameterlist *pl,
132 const char *recipe_name,
133 hdrl_image *master_img,
134 const hdrl_imagelist *imglist_on,
135 cpl_mask **bpm2dMask,
136 cpl_mask **bpm3dMask);
137
138hdrl_image * eris_ifu_warp_polynomial_image(const hdrl_image *inImage,
139 const cpl_polynomial *poly_u,
140 const cpl_polynomial *poly_v);
141
142cpl_error_code eris_ifu_add_std_params(cpl_parameterlist *pl,
143 const char *recipename);
144
145cpl_error_code eris_ifu_fetch_std_param(const cpl_parameterlist *parlist,
146 const char *recipename,
147 struct stdParamStruct *stdParams);
148
149cpl_error_code eris_parlist_config_add_all_recipes(cpl_parameterlist *pl,
150 const char* recname);
151
152cpl_error_code eris_parlist_config_add_bpm(cpl_parameterlist *pl,
153 const char *recname);
154
155cpl_error_code eris_parlist_config_add_flat(cpl_parameterlist *pl,
156 const char *recname);
157
158cpl_vector* eris_ifu_polyfit_1d(const cpl_vector *x,
159 const cpl_vector *y,
160 const int degree);
161
162cpl_polynomial * eris_ifu_1d_polynomial_fit(
163 int nPoints,
164 double *xdata,
165 double *ydata,
166 int degree);
167
168cpl_error_code eris_ifu_1d_interpolation(
169 double *xIn,
170 double *yIn,
171 int nIn,
172 double *xOut,
173 double *yOut,
174 int nOut,
175 const int interType);
176
177void remove_2nans(int size_in, double *xin, double *yin,
178 int *size_out, double **xout, double **yout);
179
180// now in eris_ifu_vector.h/.c
181//double eris_ifu_vector_get_mean(const cpl_vector *vec);
182
183double eris_ifu_image_get_mean(const cpl_image *img);
184
185cpl_error_code eris_ifu_line_gauss_fit(const cpl_vector *yIn,
186 int center,
187 int range,
188 struct gaussParStruct *gaussPar);
189
190cpl_vector* eris_ifu_calc_centers_collapse_chunk(const cpl_image* img,
191 int chunk_center,
192 int height);
193
194cpl_vector* eris_ifu_image_collapse(const cpl_image* img);
195
196cpl_error_code eris_ifu_slitpos_gauss(const cpl_image *profile_x,
197 double *left_edge_pos,
198 double *right_edge_pos,
199 int llx,
200 int productDepth);
201void eris_ifu_free_std_param(struct stdParamStruct * stdParams) ;
202
203cpl_error_code eris_ifu_bpm_correction(hdrl_image *himg,
204 hdrl_image *badPixelMaskImg);
205
206double eris_ifu_auto_derot_corr(double alt, double rot);
207#endif
cpl_error_code eris_ifu_exposure_line_correction(cpl_image *image)
Perform line/row correction on raw detector image.
cpl_polynomial * eris_ifu_1d_polynomial_fit(int nPoints, double *xdata, double *ydata, int degree)
Fit a 1D polynomial to arrays of data points.
cpl_error_code eris_ifu_slitpos_gauss(const cpl_image *profile_x, double *left_edge_pos, double *right_edge_pos, int llx, int productDepth)
eris_ifu_dist_slitpos_gauss
cpl_error_code eris_ifu_1d_interpolation(double *xIn, double *yIn, int nIn, double *xOut, double *yOut, int nOut, const int interType)
Perform 1D interpolation using GSL routines.
cpl_error_code eris_ifu_bpm_correction(hdrl_image *himg, hdrl_image *badPixelMaskImg)
eris_ifu_bpm_correction
cpl_error_code eris_parlist_config_add_flat(cpl_parameterlist *pl, const char *recname)
Add flat field configuration parameters to parameter list.
cpl_error_code eris_parlist_config_add_all_recipes(cpl_parameterlist *pl, const char *recname)
Add common configuration parameters for all recipes.
cpl_vector * eris_ifu_calc_centers_collapse_chunk(const cpl_image *img, int chunk_center, int height)
hdrl_image * eris_ifu_load_exposure_frame(const cpl_frame *frame, int exposureCorrectionMode, cpl_image *dqi)
Load a raw detector exposure from a frame with optional corrections.
cpl_error_code eris_ifu_fetch_std_param(const cpl_parameterlist *parlist, const char *recipename, struct stdParamStruct *stdParams)
Fetch standard parameters from parameter list into structure.
void eris_ifu_free_std_param(struct stdParamStruct *stdParams)
Free memory allocated for stdParamStruct.
cpl_vector * eris_ifu_image_collapse(const cpl_image *img)
cpl_error_code eris_ifu_calc_bpm(const cpl_parameterlist *pl, const char *recipe_name, hdrl_image *master_img, const hdrl_imagelist *imglist_on, cpl_mask **bpm2dMask, cpl_mask **bpm3dMask)
Create 2D and/or 3D bad pixel masks using HDRL algorithms.
cpl_error_code eris_ifu_add_badpix_border(cpl_image *data, cpl_boolean add_ones, cpl_image *dqi)
Flag detector border pixels as bad in image and optionally set to 1.
cpl_error_code eris_ifu_add_std_params(cpl_parameterlist *pl, const char *recipename)
Add standard recipe parameters to a parameter list.
cpl_error_code eris_ifu_exposure_column_correction(cpl_image *image)
Perform column correction on raw detector image.
cpl_vector * eris_ifu_polyfit_1d(const cpl_vector *x, const cpl_vector *y, const int degree)
Fit a 1D polynomial to vector data.
cpl_mask * eris_ifu_detect_crh(hdrl_image *image, int exposureCorrectionMode, hdrl_parameter *laCosmicParams, bool maskImage)
Detect cosmic ray hits using LA-cosmic algorithm.
cpl_error_code eris_parlist_config_add_bpm(cpl_parameterlist *pl, const char *recname)
Add bad pixel mask configuration parameters to parameter list.
cpl_image * eris_ifu_calc_noise_map(const cpl_image *data, double gain, double readnoise)
Calculate a noise map for detector data.
cpl_error_code eris_ifu_saturation_detection(cpl_image *image, cpl_image *dqi)
Detect saturated pixels and flag them as bad.
hdrl_image * eris_ifu_load_exposure_file(const char *filename, int exposureCorrectionMode, cpl_image *dqi)
Load a raw detector exposure from file with corrections and noise.
hdrl_imagelist * eris_ifu_load_exposure_frameset(const cpl_frameset *frameset, int exposureCorrectionMode)
Load raw exposures from a frameset with optional corrections.
ifsInstrument eris_ifu_get_instrument_frame(cpl_frame *frame)
Get instrument identifier from a CPL frame.
double eris_ifu_image_get_mean(const cpl_image *image)
‍**
hdrl_image * eris_ifu_raw_hdrl_image(const cpl_image *cplImage)
Create an HDRL image from a CPL image with calculated noise.
hdrl_image * eris_ifu_warp_polynomial_image(const hdrl_image *hdrlInImg, const cpl_polynomial *poly_u, const cpl_polynomial *poly_v)
Warp an HDRL image using 2D polynomial transformations.