High-Level Data Reduction Library: hdrl_utils.h Source File

High-Level Data Reduction Library 1.6.0 High-Level data reduction routines for ESO pipelines

Loading...
Searching...
No Matches
hdrl_utils.h
Go to the documentation of this file.
1/* $Id: hdrl_utils.h,v 1.32 2013-10-23 09:13:12 jtaylor Exp $
2 *
3 * This file is part of the HDRL
4 * Copyright (C) 2012,2013 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-10-23 09:13:12 $
24 * $Revision: 1.32 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifndef HDRL_UTILS_H
29#define HDRL_UTILS_H
30
31/*-----------------------------------------------------------------------------
32 Includes
33 -----------------------------------------------------------------------------*/
34
35#include "hdrl_parameter.h"
36#include "hdrl_image.h"
37#include "hdrl_imagelist.h"
38#include <cpl.h>
39
40#include <stdlib.h>
41#include <stdarg.h>
42
43CPL_BEGIN_DECLS
44
45/*-----------------------------------------------------------------------------
46 Define
47 -----------------------------------------------------------------------------*/
48
49/*----------------------------------------------------------------------------*/
54/*----------------------------------------------------------------------------*/
55 typedef enum {
56
58 HDRL_X_AXIS,
60 HDRL_Y_AXIS,
62 HDRL_UNDEFINED_AXIS
63} hdrl_direction;
64
65/*----------------------------------------------------------------------------*/
70/*----------------------------------------------------------------------------*/
71 typedef enum {
72 HDRL_AIRMASS_APPROX_HARDIE = 1, /* Hardie(1962) */
73 HDRL_AIRMASS_APPROX_YOUNG_IRVINE, /* Young & Irvine (1967) */
74 HDRL_AIRMASS_APPROX_YOUNG /* Young(1994) */
75} hdrl_airmass_approx;
76
77 typedef enum {
78 HDRL_IMAGE_EXTEND_NEAREST = 0,
79 HDRL_IMAGE_EXTEND_MIRROR = 1,
80} hdrl_image_extend_method ;
81
82/*-----------------------------------------------------------------------------
83 Functions prototypes
84 -----------------------------------------------------------------------------*/
85
86 const char * hdrl_get_license(void);
87
88cpl_table * hdrl_eop_data_totable(const char * eop_data, cpl_size data_length);
89
90/*----------------------------------------------------------------------------
91 Rect region Parameters
92 ----------------------------------------------------------------------------*/
93 hdrl_parameter * hdrl_rect_region_parameter_create(cpl_size, cpl_size,
94 cpl_size, cpl_size) ;
95cpl_error_code hdrl_rect_region_parameter_update(hdrl_parameter *, cpl_size,
96 cpl_size, cpl_size, cpl_size) ;
97cpl_boolean hdrl_rect_region_parameter_check(const hdrl_parameter *) ;
98cpl_size hdrl_rect_region_get_llx(const hdrl_parameter *) ;
99cpl_size hdrl_rect_region_get_lly(const hdrl_parameter *) ;
100cpl_size hdrl_rect_region_get_urx(const hdrl_parameter *) ;
101cpl_size hdrl_rect_region_get_ury(const hdrl_parameter *) ;
102cpl_error_code hdrl_rect_region_parameter_verify(const hdrl_parameter *,
103 const cpl_size, const cpl_size) ;
104cpl_parameterlist * hdrl_rect_region_parameter_create_parlist(const char *,
105 const char *, const char *, const hdrl_parameter *) ;
106 hdrl_parameter * hdrl_rect_region_parameter_parse_parlist(
107 const cpl_parameterlist *, const char *, const char *) ;
108cpl_boolean hdrl_is_strictly_monotonic_increasing(const double * x, cpl_size l);
109 void hdrl_sort_on_x(double * x, double * y1, double * y2,
110 const cpl_size sample_len, const cpl_boolean sort_decreasing);
111
112/*-----------------------------------------------------------------------------
113 Experimental declarations - can be used, but no guarantees on api stability
114 -----------------------------------------------------------------------------*/
115#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE
116 typedef enum {
117 HDRL_SCALE_ADDITIVE,
118 HDRL_SCALE_MULTIPLICATIVE
119} hdrl_scale_type;
120
121cpl_error_code
122hdrl_normalize_imagelist_by_vector(const cpl_vector * scale,
123 const cpl_vector * scale_e,
124 const hdrl_scale_type scale_type,
125 cpl_imagelist * data,
126 cpl_imagelist * errors);
127
128cpl_error_code
129hdrl_normalize_imagelist_by_imagelist(const cpl_imagelist * scale,
130 const cpl_imagelist * scale_e,
131 const hdrl_scale_type scale_type,
132 cpl_imagelist * data,
133 cpl_imagelist * errors);
134
135 int hdrl_get_tempfile(const char * dir, cpl_boolean unlink);
136 char * hdrl_get_cwd(void);
137cpl_error_code hdrl_rect_region_fix_negatives(hdrl_parameter *, const cpl_size,
138 const cpl_size) ;
139
140cpl_error_code
141hdrl_wcs_convert(const cpl_wcs *wcs, const cpl_matrix *from,
142 cpl_matrix **to, cpl_array **status,
143 cpl_wcs_trans_mode transform);
144#endif
145
146/* --------------- *
147 * Airmass funcion *
148 * --------------- */
149 hdrl_value hdrl_utils_airmass(
150 hdrl_value aRA, hdrl_value aDEC, hdrl_value aLST,
151 hdrl_value aExptime, hdrl_value aLatitude,
152 hdrl_airmass_approx type);
153
154/* must not be followed by a semicolon!
155 * gcc on mac has omp but it doesn't work for nontrivial cases as libc lacks
156 * alloca */
157#if defined (_OPENMP) && !defined( __APPLE__)
158 #define HDRL_OMP(x) _Pragma (#x)
159#else
160 #define HDRL_OMP(x)
161#endif
162
163/*-----------------------------------------------------------------------------
164 Private declarations - must not be used outside of hdrl
165 -----------------------------------------------------------------------------*/
166#ifdef HDRL_USE_PRIVATE
167cpl_matrix *
168hdrl_maglim_kernel_create(const cpl_size kernel_sx, const cpl_size kernel_sy,
169 const double fwhm);
170cpl_image*
171hdrl_extend_image(const cpl_image* image, const cpl_size border_nx,
172 const cpl_size border_ny,
173 const hdrl_image_extend_method image_extend_method);
174
175cpl_image *
176hdrl_image_convolve(const cpl_image * input_image, const cpl_matrix * kernel,
177 const hdrl_image_extend_method image_extend_method);
178
179/* Private functions for airmass calculations */
180 hdrl_value hdrl_get_zenith_distance(
181 hdrl_value aHourAngle, hdrl_value aDelta, hdrl_value aLatitude);
182
183 hdrl_value hdrl_get_airmass_hardie( hdrl_value hvaSecZ);
184 hdrl_value hdrl_get_airmass_youngirvine( hdrl_value hvaSecZ);
185 hdrl_value hdrl_get_airmass_young( hdrl_value hvaCosZt);
186/* ---------------------- */
187
188
189cpl_image *
190hdrl_medianfilter_image_grid(const cpl_image * ima, cpl_matrix * x, cpl_matrix * y,
191 cpl_size filtersize_x, cpl_size filtersize_y);
192
193cpl_matrix * hdrl_matrix_linspace(cpl_size start, cpl_size stop, cpl_size step);
194
195cpl_matrix * hdrl_fit_legendre(cpl_image * img, int order_x, int order_y,
196 cpl_matrix * grid_x, cpl_matrix * grid_y,
197 cpl_size orig_nx, cpl_size orig_ny);
198
199cpl_image * hdrl_legendre_to_image(cpl_matrix * coeffs, int order_x,
200 int order_y, cpl_size nx, cpl_size ny);
201
202 int hdrl_check_maskequality(const cpl_mask * mask1, const cpl_mask * mask2);
203
204 typedef struct hdrl_vector_cache_ hdrl_vector_cache;
205
206hdrl_vector_cache * hdrl_vector_cache_new(cpl_size max_cached_size,
207 cpl_size ncached_entries);
208 void hdrl_vector_cache_delete(hdrl_vector_cache * cache);
209cpl_vector * hdrl_cplvector_new_from_cache(hdrl_vector_cache * cache, cpl_size sz);
210 void hdrl_cplvector_delete_to_cache(hdrl_vector_cache * cache, cpl_vector * v);
211
212/* setup a value parameter and append it into parlist */
213#define hdrl_setup_vparameter(parlist, \
214 prefix, \
215 sep, \
216 name_prefix, \
217 pname, \
218 context, \
219 descr, \
220 type, \
221 pdefault) \
222 do { \
223 char * fname = cpl_sprintf("%s%s", name_prefix, pname); \
224 char * setup_name = hdrl_join_string(sep, 3, context, prefix, fname); \
225 cpl_parameter * setup_p = cpl_parameter_new_value(setup_name, type, \
226 descr, context, pdefault) ; \
227 cpl_free(setup_name); \
228 setup_name = hdrl_join_string(sep, 2, prefix, fname); \
229 cpl_parameter_set_alias(setup_p, CPL_PARAMETER_MODE_CLI, setup_name); \
230 cpl_parameter_disable(setup_p, CPL_PARAMETER_MODE_ENV); \
231 cpl_free(setup_name); \
232 cpl_free(fname); \
233 cpl_parameterlist_append(parlist, setup_p); \
234 } while (0)
235
236cpl_vector * hdrl_image_to_vector(const cpl_image * source, const
237 cpl_mask * bpm);
238cpl_vector * hdrl_imagelist_to_vector(const cpl_imagelist * list,
239 const cpl_size x, const cpl_size y);
240cpl_error_code hdrl_imagelist_to_vector_row(const cpl_imagelist * list,
241 const cpl_size y,
242 cpl_vector ** out,
243 hdrl_vector_cache * cache);
244
245cpl_error_code
246hdrl_imagelist_to_cplwrap(const hdrl_imagelist * list,
247 cpl_imagelist ** data,
248 cpl_imagelist ** errs);
249
250cpl_image *
251hdrl_parallel_filter_image(const cpl_image * img,
252 const cpl_matrix * kernel,
253 const cpl_mask * mask,
254 const cpl_filter_mode mode);
255
256cpl_mask * hcpl_image_set_bpm(cpl_image * self, cpl_mask * bpm) ;
257 double hcpl_vector_get_mad_window(cpl_vector * vec,
258 cpl_size llx,
259 cpl_size urx,
260 double * sigma);
261 double hcpl_gaussian_eval_2d(const cpl_array * self, double x, double y);
262
263 static inline int hdrl_int_is_power_of_two(unsigned long long x)
264{
265 return (x & (x - 1)) == 0;
266}
267
268 static inline size_t hdrl_get_image_npix(const cpl_image * img)
269{
270 return cpl_image_get_size_x(img) * cpl_image_get_size_y(img);
271}
272
273 static inline size_t hdrl_get_image_good_npix(const cpl_image * img)
274{
275 return (cpl_image_get_size_x(img) * cpl_image_get_size_y(img)) -
276 cpl_image_count_rejected(img);
277}
278
279 static inline cpl_mask * hdrl_copy_image_mask(const cpl_image * img)
280{
281 /* always returns a mask even it image has none */
282 const cpl_mask * bpm = cpl_image_get_bpm_const(img);
283
284 if (bpm) {
285 return cpl_mask_duplicate(bpm);
286 }
287 else {
288 return cpl_mask_new(cpl_image_get_size_x(img),
289 cpl_image_get_size_y(img));
290 }
291}
292
293 char * hdrl_join_string(const char * sep_, int n, ...);
294
295 static inline hdrl_data_t * hdrl_get_image_data(cpl_image * image)
296{
297#if HDRL_SIZEOF_DATA == 8
298 return cpl_image_get_data_double(image);
299#else
300 return cpl_image_get_data_float(image);
301#endif
302}
303
304 static inline cpl_error_code
305hdrl_wrap_table(cpl_table * tb, hdrl_data_t * data, const char * name)
306{
307#if HDRL_SIZEOF_DATA == 8
308 return cpl_table_wrap_double(tb, data, name);
309#else
310 return cpl_table_wrap_float(tb, data, name);
311#endif
312}
313
314 static inline hdrl_error_t * hdrl_get_image_error(cpl_image * image)
315{
316#if HDRL_SIZEOF_ERROR == 8
317 return cpl_image_get_data_double(image);
318#else
319 return cpl_image_get_data_float(image);
320#endif
321}
322
323
324 static inline const
325 hdrl_data_t * hdrl_get_image_data_const(const cpl_image * image)
326{
327#if HDRL_SIZEOF_DATA == 8
328 return cpl_image_get_data_double_const(image);
329#else
330 return cpl_image_get_data_float_const(image);
331#endif
332}
333
334 static inline const
335 hdrl_error_t * hdrl_get_image_error_const(const cpl_image * image)
336{
337#if HDRL_SIZEOF_ERROR == 8
338 return cpl_image_get_data_double_const(image);
339#else
340 return cpl_image_get_data_float_const(image);
341#endif
342}
343
344#ifndef HDRL_ATTR_UNUSED
345 #if defined(__GNUC__) || defined(__ICC) || defined(__clang__)
346 #define HDRL_ATTR_UNUSED __attribute__ ((__unused__))
347 #else
348 #define HDRL_ATTR_UNUSED
349 #endif
350#endif
351
352/* Use this to tag a variable as not used. It will remove unused variable
353 * warning and mangle the variable to avoid accidental use */
354#define HDRL_UNUSED(x) (__HDRL_UNUSED_TAGGED ## x) HDRL_ATTR_UNUSED
355
356#endif
357
358
359
360CPL_END_DECLS
361
362#endif
hdrl_error_t
double hdrl_error_t
Definition hdrl_types.h:72
hdrl_data_t
double hdrl_data_t
Definition hdrl_types.h:62
hdrl_image.h
hdrl_imagelist.h
hdrl_image_extend_method
hdrl_image_extend_method
Definition hdrl_utils.h:77
HDRL_IMAGE_EXTEND_NEAREST
@ HDRL_IMAGE_EXTEND_NEAREST
Definition hdrl_utils.h:78
HDRL_IMAGE_EXTEND_MIRROR
@ HDRL_IMAGE_EXTEND_MIRROR
Definition hdrl_utils.h:79
hdrl_airmass_approx
hdrl_airmass_approx
Define the kind of airmass approximation.
Definition hdrl_utils.h:71
HDRL_AIRMASS_APPROX_YOUNG
@ HDRL_AIRMASS_APPROX_YOUNG
Definition hdrl_utils.h:74
HDRL_AIRMASS_APPROX_YOUNG_IRVINE
@ HDRL_AIRMASS_APPROX_YOUNG_IRVINE
Definition hdrl_utils.h:73
HDRL_AIRMASS_APPROX_HARDIE
@ HDRL_AIRMASS_APPROX_HARDIE
Definition hdrl_utils.h:72
hdrl_direction
hdrl_direction
Define an image direction e.g along X or Y.
Definition hdrl_utils.h:55
HDRL_Y_AXIS
@ HDRL_Y_AXIS
Definition hdrl_utils.h:60
HDRL_UNDEFINED_AXIS
@ HDRL_UNDEFINED_AXIS
Definition hdrl_utils.h:62
HDRL_X_AXIS
@ HDRL_X_AXIS
Definition hdrl_utils.h:58
hdrl_parameter.h
hdrl_parameter
struct _hdrl_parameter_ hdrl_parameter
Definition hdrl_parameter.h:27
scale
const hdrl_spectrum1D_wave_scale scale
Definition hdrl_response-test.c:41
hdrl_get_license
const char * hdrl_get_license(void)
Get the pipeline copyright and license.
Definition hdrl_utils.c:68
hdrl_sort_on_x
void hdrl_sort_on_x(double *x, double *y1, double *y2, const cpl_size sample_len, const cpl_boolean sort_decreasing)
sort in increasing or decreasing order x. Keep aligned with y1 and y2.
Definition hdrl_utils.c:765
hdrl_utils_airmass
hdrl_value hdrl_utils_airmass(hdrl_value aRA, hdrl_value aDEC, hdrl_value aLST, hdrl_value aExptime, hdrl_value aLatitude, hdrl_airmass_approx type)
Compute the effective airmass of an observation. Takes in count the error propagation if you enter th...
Definition hdrl_utils.c:2067
hdrl_is_strictly_monotonic_increasing
cpl_boolean hdrl_is_strictly_monotonic_increasing(const double *x, cpl_size l)
returns CPL_TRUE if x is strictly monotonic increasing
Definition hdrl_utils.c:745
hdrl_rect_region_parameter_verify
cpl_error_code hdrl_rect_region_parameter_verify(const hdrl_parameter *, const cpl_size, const cpl_size)
Verify basic correctness of the parameters.
Definition hdrl_utils.c:560
hdrl_eop_data_totable
cpl_table * hdrl_eop_data_totable(const char *eop_data, cpl_size data_length)
Export a raw string buffer containing EOP data to a CPL table.
Definition hdrl_utils.c:112
hdrl_rect_region_parameter_update
cpl_error_code hdrl_rect_region_parameter_update(hdrl_parameter *, cpl_size, cpl_size, cpl_size, cpl_size)
Update Rect Region Parameters object.
Definition hdrl_utils.c:485
hdrl_rect_region_parameter_create_parlist
cpl_parameterlist * hdrl_rect_region_parameter_create_parlist(const char *, const char *, const char *, const hdrl_parameter *)
Create parameter list for hdrl_rect_region.
Definition hdrl_utils.c:615
hdrl_rect_region_fix_negatives
cpl_error_code hdrl_rect_region_fix_negatives(hdrl_parameter *rect_region, const cpl_size nx, const cpl_size ny)
wrap negative or zero coordinates around full image size
Definition hdrl_utils.c:715
hdrl_rect_region_parameter_create
hdrl_parameter * hdrl_rect_region_parameter_create(cpl_size, cpl_size, cpl_size, cpl_size)
Creates Rect Region Parameters object.
Definition hdrl_utils.c:459
hdrl_rect_region_get_llx
cpl_size hdrl_rect_region_get_llx(const hdrl_parameter *)
get lower left x coordinate of rectangual region
Definition hdrl_utils.c:518
hdrl_rect_region_get_urx
cpl_size hdrl_rect_region_get_urx(const hdrl_parameter *)
get upper right x coordinate of rectangular region
Definition hdrl_utils.c:536
hdrl_rect_region_get_lly
cpl_size hdrl_rect_region_get_lly(const hdrl_parameter *)
get lower left y coordinate of rectangual region
Definition hdrl_utils.c:527
hdrl_join_string
char * hdrl_join_string(const char *sep_, int n,...)
join strings together
Definition hdrl_utils.c:810
hdrl_rect_region_get_ury
cpl_size hdrl_rect_region_get_ury(const hdrl_parameter *)
get upper right y coordinate of rectangual region
Definition hdrl_utils.c:545
hdrl_rect_region_parameter_parse_parlist
hdrl_parameter * hdrl_rect_region_parameter_parse_parlist(const cpl_parameterlist *, const char *, const char *)
parse parameterlist for rectangle parameters
Definition hdrl_utils.c:674
hdrl_rect_region_parameter_check
cpl_boolean hdrl_rect_region_parameter_check(const hdrl_parameter *)
Check that the parameter is hdrl_rect_region parameter.
Definition hdrl_utils.c:506
_hdrl_imagelist_
Definition hdrl_imagelist_defs.h:42
hdrl_value
Definition hdrl_types.h:77