29#include "hdrl_bpm_fit.h"
40void test_invalid_parameter(
void)
46 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
49 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
52 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
57 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
60 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
63 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
66 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
70 cpl_test_error(CPL_ERROR_NULL_INPUT);
72 cpl_test_error(CPL_ERROR_NULL_INPUT);
74 cpl_test_error(CPL_ERROR_NULL_INPUT);
77void test_parameter(
void)
108void test_parameterlist(
void)
111 hdrl_parameter * def;
112 cpl_parameterlist * parlist;
119 cpl_test_error(CPL_ERROR_NULL_INPUT);
120 cpl_parameterlist_delete(parlist);
127 cpl_test_error(CPL_ERROR_NULL_INPUT);
128 cpl_parameterlist_delete(parlist);
133 cpl_test_error(CPL_ERROR_NONE);
134 cpl_test_eq(cpl_parameterlist_get_size(parlist), 6);
138 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
141 cpl_test_error(CPL_ERROR_NONE);
142 cpl_test_eq(cpl_parameterlist_get_size(parlist), 6);
146 cpl_parameterlist_delete(parlist);
151 cpl_test_error(CPL_ERROR_NONE);
152 cpl_test_eq(cpl_parameterlist_get_size(parlist), 6);
158 cpl_parameterlist_delete(parlist);
163 cpl_test_error(CPL_ERROR_NONE);
164 cpl_test_eq(cpl_parameterlist_get_size(parlist), 6);
170 cpl_parameterlist_delete(parlist);
173void test_bpm_fit(
void)
177 cpl_vector * sample = cpl_vector_new(10);
178 for (
size_t i = 0; i < 10; i++) {
183 cpl_vector_set(sample, i, i);
187 cpl_image * out_mask;
191 cpl_test_error(CPL_ERROR_NONE);
192 cpl_test_eq(cpl_image_get_flux(out_mask), 0.);
193 cpl_image_delete(out_mask);
198 cpl_test_error(CPL_ERROR_NONE);
199 cpl_test_eq(cpl_image_get(out_mask, 1, 1, &rej), 3);
200 cpl_image_delete(out_mask);
205 (hdrl_value){5.1 , sqrt(5.1)});
207 cpl_test_error(CPL_ERROR_NONE);
208 cpl_test_eq(cpl_image_get_flux(out_mask), 1.);
209 cpl_test_eq(cpl_image_get(out_mask, 1, 1, &rej), 1.);
210 cpl_image_delete(out_mask);
214 cpl_vector_delete(sample);
219 cpl_test_error(CPL_ERROR_NONE);
222 cpl_test(isnan(igamc(-1, 1)));
223 cpl_test(isnan(igamc(1, -1)));
224 cpl_test(isnan(igamc(-1, -1)));
226 cpl_test(!isnan(igamc(1, 1)));
233 double res1 = igamc(a, x);
234 cpl_test_eq(res1, 0.);
236 double res2 = igamc(x, a);
237 cpl_test_eq(res2, 0.);
239 double res3 = igam(a, x);
240 cpl_test_eq(res3, 0.);
242 double res4 = igam(x, a);
243 cpl_test_eq(res4, 0.);
246 double res11 = igamc(0., 0.);
247 cpl_test(res11 != 0.);
249 double res12 = igamc(0., 1.);
250 cpl_test(res12 != 0.);
252 double res13 = igamc(1., 0.);
253 cpl_test(res13 != 0.);
256 double res21 = igamc(0., 1e10);
257 cpl_test(res21 != 0.);
259 double res22 = igamc(1., 1e20);
260 cpl_test_eq(res22, 0.);
262 double res23 = igamc(1e10, 0.);
263 cpl_test_eq(res23, 1.);
265 double res24 = igamc(1e20, 1.);
266 cpl_test_eq(res24, 1.);
269 cpl_test_error(CPL_ERROR_NONE);
280 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
282 test_invalid_parameter();
284 test_parameterlist();
290 return cpl_test_end(0);
hdrl_parameter * hdrl_bpm_fit_parameter_create_rel_coef(int degree, double rel_coef_low, double rel_coef_high)
create bpm_fit parameter with relative coefficient bpm treshold
hdrl_parameter * hdrl_bpm_fit_parameter_parse_parlist(const cpl_parameterlist *parlist, const char *prefix)
Parse a parameterlist to create input parameters for the BPM_FIT.
double hdrl_bpm_fit_parameter_get_rel_chi_high(const hdrl_parameter *p)
get relative chi distribution upper threshold
double hdrl_bpm_fit_parameter_get_rel_coef_high(const hdrl_parameter *p)
get relative fit coefficient distribution upper threshold
int hdrl_bpm_fit_parameter_get_degree(const hdrl_parameter *p)
get degree of polynomial fit of parameter
cpl_parameterlist * hdrl_bpm_fit_parameter_create_parlist(const char *base_context, const char *prefix, const hdrl_parameter *defaults)
Create a parameter list for the BPM_FIT computation.
hdrl_parameter * hdrl_bpm_fit_parameter_create_pval(int degree, double pval)
create bpm_fit parameter with p-value bpm treshold
double hdrl_bpm_fit_parameter_get_pval(const hdrl_parameter *p)
get p-value bpm treshold
double hdrl_bpm_fit_parameter_get_rel_chi_low(const hdrl_parameter *p)
get relative chi distribution lower threshold
hdrl_parameter * hdrl_bpm_fit_parameter_create_rel_chi(int degree, double rel_chi_low, double rel_chi_high)
create bpm_fit parameter with relative chi bpm treshold
cpl_boolean hdrl_bpm_fit_parameter_check(const hdrl_parameter *self)
Check that the parameter is a bpm_fit parameter.
double hdrl_bpm_fit_parameter_get_rel_coef_low(const hdrl_parameter *p)
get relative fit coefficient distribution lower threshold
cpl_error_code hdrl_bpm_fit_compute(const hdrl_parameter *par, const hdrl_imagelist *data, const cpl_vector *sample_pos, cpl_image **out_mask)
compute bad pixel map based on fitting a stack of images
cpl_error_code hdrl_image_set_pixel(hdrl_image *self, cpl_size xpos, cpl_size ypos, hdrl_value value)
set pixel values of hdrl_image
cpl_error_code hdrl_image_add_scalar(hdrl_image *self, hdrl_value value)
Elementwise addition of a scalar to an image.
hdrl_image * hdrl_image_new(cpl_size nx, cpl_size ny)
create new zero filled hdrl image
cpl_error_code hdrl_imagelist_set(hdrl_imagelist *himlist, hdrl_image *himg, cpl_size pos)
Insert an image into an imagelist.
void hdrl_imagelist_delete(hdrl_imagelist *himlist)
Free all memory used by a hdrl_imagelist object including the images.
hdrl_imagelist * hdrl_imagelist_new(void)
Create an empty imagelist.
hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.
void hdrl_parameter_delete(hdrl_parameter *obj)
shallow delete of a parameter