MOONS Pipeline Reference Manual 0.13.1
moo_utils.h
1/*
2 * This file is part of the MOONS Pipeline
3 * Copyright (C) 2002-2016 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#ifndef MOO_UTILS_H
21#define MOO_UTILS_H
22
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27
28#include <cpl.h>
29#include <hdrl.h>
30#include <gsl/gsl_errno.h>
31#include <gsl/gsl_spline.h>
32
33#define moo_drand() ((double)rand() / (double)RAND_MAX)
34#define moo_ensure_status(CMD, STATUS) \
35 cpl_error_ensure(((STATUS = CMD), status == CPL_ERROR_NONE), STATUS, \
36 goto moo_try_cleanup, " ")
37
38
39#define moo_try_assure(BOOL, CODE, ...) \
40 cpl_error_ensure(BOOL, CODE, goto moo_try_cleanup, __VA_ARGS__)
41
42#define moo_try_check(CMD, ...) \
43 cpl_error_ensure((CMD, cpl_error_get_code() == CPL_ERROR_NONE), \
44 cpl_error_get_code(), goto moo_try_cleanup, __VA_ARGS__)
45/*-----------------------------------------------------------------------------
46 Prototypes
47 -----------------------------------------------------------------------------*/
48
49typedef struct
50{
51 cpl_polynomial *solution;
52 int degree;
53 double xmin;
54 double xmax;
55 double ymin;
56 double ymax;
57} moo_tcheby_polynomial;
58
59typedef struct
60{
61 cpl_polynomial *solution;
62 int degree_x;
63 int degree_y;
64 double xmin;
65 double xmax;
66 double ymin;
67 double ymax;
68 double lmin;
69 double lmax;
70} moo_tcheby2d_polynomial;
71
72typedef struct
73{
74 gsl_interp_accel *acc;
75 gsl_spline *spline;
76 double min;
77 double max;
78} moo_spline;
79
80typedef struct
81{
82 int year;
83 int month;
84 int day;
85 int hour;
86 int min;
87 float sec;
88} moo_date;
89
90const char *moo_get_license(void);
91
92cpl_image *moo_compute_sigma_map(cpl_imagelist *list,
93 cpl_imagelist *qlist,
94 cpl_image *img);
95
96cpl_mask *moo_kappa_sigma_clipping(cpl_image *sigma_img,
97 int niter,
98 double kappa,
99 double cdiff,
100 double maxfrac);
101
102cpl_error_code
103moo_barycenter_fit(cpl_bivector *points, double *center, double *width);
104cpl_error_code moo_gaussian_fit(cpl_bivector *points,
105 cpl_fit_mode fit_pars,
106 double *center,
107 double *width,
108 double *background,
109 double *area);
110double moo_gaussian_eval(double x,
111 double center,
112 double width,
113 double background,
114 double area);
115cpl_error_code moo_gaussian_eval_inv(double y,
116 double center,
117 double width,
118 double background,
119 double area,
120 double *x1,
121 double *x2);
122
123cpl_error_code moo_find_threshold_limits(cpl_bivector *points,
124 double treshold,
125 double *ymin,
126 double *ymax);
127cpl_error_code moo_tchebychev_fit(cpl_bivector *data,
128 int *cflag,
129 int degree,
130 double xmin,
131 double xmax,
132 double ymin,
133 double ymax);
134
135moo_tcheby_polynomial *moo_tcheby_polynomial_fit(cpl_bivector *data,
136 int degree,
137 double xmin,
138 double xmax);
139moo_tcheby2d_polynomial *moo_tcheby2d_polynomial_fit(cpl_vector *x,
140 int xdegree,
141 double xmin,
142 double xmax,
143 cpl_vector *y,
144 int ydegree,
145 double ymin,
146 double ymax,
147 cpl_vector *l,
148 double lmin,
149 double lmax);
150void moo_tcheby_polynomial_delete(moo_tcheby_polynomial *self);
151void moo_tcheby2d_polynomial_delete(moo_tcheby2d_polynomial *self);
152double moo_tcheby_polynomial_eval(moo_tcheby_polynomial *self, double x);
153double
154moo_tcheby2d_polynomial_eval(moo_tcheby2d_polynomial *self, double x, double y);
155double moo_vector_get_min(const cpl_vector *v, int *flags);
156double moo_vector_get_max(const cpl_vector *v, int *flags);
157double moo_vector_get_dersnr(const cpl_vector *v);
158cpl_vector *moo_hpfilter(cpl_vector *v, double s);
159
160cpl_error_code moo_interpolate_linear(cpl_bivector *fout,
161 cpl_vector *fout_errs,
162 int *fout_qual,
163 const cpl_bivector *fref,
164 const cpl_vector *fref_errs,
165 const int *fref_qual);
166
167double moo_vector_get_percentile(cpl_vector *v, double f);
168
169cpl_vector *moo_vector_filter_nan(cpl_vector *v);
170cpl_bivector *moo_bivector_filter_nan(cpl_bivector *v);
171
172hdrl_image *moo_image_collapse_median_create(hdrl_image *image);
173
174double
175moo_sky_distance(double alpha1, double delta1, double alpha2, double delta2);
176
177moo_spline *moo_spline_create(cpl_bivector *data);
178double moo_spline_eval(moo_spline *self, double data);
179void moo_spline_delete(moo_spline *self);
180
181cpl_error_code moo_fit_mul(const cpl_vector *vx,
182 const cpl_vector *vw,
183 const cpl_vector *vy,
184 const cpl_vector *vy_err,
185 double *c,
186 double *sig_c);
187
188cpl_vector *moo_savgol_filter(cpl_vector *v, int window_length, int poly_order);
189cpl_vector *moo_median_filter(cpl_vector *v, int winhsize);
190
191
192cpl_image *
193moo_imagelist_collapse_bitwiseor(cpl_imagelist *list, hdrl_imagelist *input);
194
195double moo_image_get_ron(cpl_image *image,
196 int llx,
197 int lly,
198 int urx,
199 int ury,
200 int nb_boxes,
201 int box_hsize,
202 double max_error_frac,
203 int max_niter);
204
205cpl_error_code
206moo_image_get_quartile(cpl_image *image, double *qmin, double *qmax);
207
208cpl_error_code moo_hdrl_bpm_fit_compute(const hdrl_parameter *par,
209 const hdrl_imagelist *data,
210 const cpl_vector *sample_pos,
211 cpl_image **out_mask);
212int moo_string_is_strictly_equal(const char *a, const char *b);
213cpl_size moo_table_or_selected_sequal_string(cpl_table *table,
214 const char *name,
215 const char *string);
216cpl_size moo_table_and_selected_sequal_string(cpl_table *table,
217 const char *name,
218 const char *string);
219moo_date moo_get_date_from_string(const char *string);
220#endif
cpl_vector * moo_savgol_filter(cpl_vector *v, int window_length, int poly_order)
Apply a Savitzky-Golay filter to a vector.
Definition: moo_utils.c:1656
double moo_sky_distance(double alpha1, double delta1, double alpha2, double delta2)
Compute sky distance (in rad)
Definition: moo_utils.c:1417
cpl_error_code moo_gaussian_eval_inv(double y, double center, double width, double background, double area, double *x1, double *x2)
Find the x positions of the gaussian at the given y position.
Definition: moo_utils.c:373
cpl_size moo_table_or_selected_sequal_string(cpl_table *table, const char *name, const char *string)
Select from unselected table rows, by comparing column values with a constant.
Definition: moo_utils.c:2285
hdrl_image * moo_image_collapse_median_create(hdrl_image *image)
Collapse row of an image using a median and compute associate error.
Definition: moo_utils.c:1386
double moo_vector_get_min(const cpl_vector *v, int *flags)
Find minimum values in a vector using flags.
Definition: moo_utils.c:979
cpl_bivector * moo_bivector_filter_nan(cpl_bivector *v)
Create new bi vector with nan values filter.
Definition: moo_utils.c:1343
double moo_gaussian_eval(double x, double center, double width, double background, double area)
Evaluate the gaussian at the given x position.
Definition: moo_utils.c:348
moo_tcheby_polynomial * moo_tcheby_polynomial_fit(cpl_bivector *data, int degree, double xmin, double xmax)
Computes Tchebitchev transformation of data.
Definition: moo_utils.c:573
cpl_mask * moo_kappa_sigma_clipping(cpl_image *sigma_img, int niter, double kappa, double cdiff, double maxfrac)
Compute mask of rejected pixels using kappa sigma algorithm.
Definition: moo_utils.c:163
cpl_error_code moo_gaussian_fit(cpl_bivector *points, cpl_fit_mode fit_pars, double *center, double *width, double *background, double *area)
Fit the data with a gaussian.
Definition: moo_utils.c:309
cpl_vector * moo_vector_filter_nan(cpl_vector *v)
Create new vector with nan values filter.
Definition: moo_utils.c:1309
cpl_image * moo_imagelist_collapse_bitwiseor(cpl_imagelist *list, hdrl_imagelist *input)
get the QUAL resulting in a bitwise OR operation on the QUAL list
Definition: moo_utils.c:1791
cpl_size moo_table_and_selected_sequal_string(cpl_table *table, const char *name, const char *string)
Select from unselected table rows, by comparing column values with a constant.
Definition: moo_utils.c:2317
cpl_error_code moo_find_threshold_limits(cpl_bivector *points, double treshold, double *ymin, double *ymax)
Find threshold limits of a 1D signal.
Definition: moo_utils.c:423
moo_tcheby2d_polynomial * moo_tcheby2d_polynomial_fit(cpl_vector *x, int xdegree, double xmin, double xmax, cpl_vector *y, int ydegree, double ymin, double ymax, cpl_vector *l, double lmin, double lmax)
Computes Tchebitchev transformation of data.
Definition: moo_utils.c:667
double moo_image_get_ron(cpl_image *image, int llx, int lly, int urx, int ury, int nb_boxes, int box_hsize, double max_error_frac, int max_niter)
compute ron in a diff image using boxes
Definition: moo_utils.c:1863
double moo_vector_get_max(const cpl_vector *v, int *flags)
Find maximum values in a vector using flags.
Definition: moo_utils.c:1003
const char * moo_get_license(void)
Get the pipeline copyright and license.
Definition: moo_utils.c:81
cpl_error_code moo_fit_mul(const cpl_vector *vx, const cpl_vector *vw, const cpl_vector *vy, const cpl_vector *vy_err, double *c, double *sig_c)
This function computes the best-fit linear regression coefficient c1 of the model Y = c_1 X for the w...
Definition: moo_utils.c:1567
cpl_error_code moo_interpolate_linear(cpl_bivector *fout, cpl_vector *fout_errs, int *fout_qual, const cpl_bivector *fref, const cpl_vector *fref_errs, const int *fref_qual)
Linear interpolation of a 1d-function.
Definition: moo_utils.c:1160
cpl_error_code moo_tchebychev_fit(cpl_bivector *data, int *cflag, int degree, double xmin, double xmax, double ymin, double ymax)
Computes Tchebitchev transformation of data.
Definition: moo_utils.c:880
cpl_vector * moo_median_filter(cpl_vector *v, int winhsize)
Apply a median filter to a vector.
Definition: moo_utils.c:1730
double moo_vector_get_dersnr(const cpl_vector *v)
This function computes the signal to noise ratio DER_SNR following the definition set forth by the Sp...
Definition: moo_utils.c:2189
cpl_error_code moo_image_get_quartile(cpl_image *image, double *qmin, double *qmax)
compute first and last quartile from an image
Definition: moo_utils.c:1906
double moo_vector_get_percentile(cpl_vector *v, double f)
Get percentile of input vector.
Definition: moo_utils.c:1263
cpl_error_code moo_barycenter_fit(cpl_bivector *points, double *center, double *width)
Fit positions using weighted fluxes.
Definition: moo_utils.c:254
int moo_string_is_strictly_equal(const char *a, const char *b)
This function compares to string to see if the two string are stricly equal.
Definition: moo_utils.c:2233
cpl_image * moo_compute_sigma_map(cpl_imagelist *list, cpl_imagelist *qlist, cpl_image *img)
Compute image of sigma variation.
Definition: moo_utils.c:100