28#include "hdrl_strehl.c"
29#include "hdrl_strehl.h"
38#define ARRAY_LEN(a) sizeof((a))/sizeof((a)[0])
48void hdrl_strehl_test_parlist(
void)
52 0., 0., 0., 0., 0., 0., 0., 0.);
53 hdrl_strehl_parameter_verify(NULL);
54 cpl_test_error(CPL_ERROR_NULL_INPUT);
59 double wavelength = 1.635e-6;
61 double m2 = 5.08/2*0.36;
62 double psx = 0.0331932/2.;
63 double psy = 0.0331932/2.;
70 hdrl_parameter * hpar;
71 hdrl_parameter * strehl_def =
78 cpl_test_error(CPL_ERROR_NONE);
84 cpl_test_error(CPL_ERROR_NULL_INPUT);
86 cpl_test_error(CPL_ERROR_NONE);
89 cpl_test_error(CPL_ERROR_NULL_INPUT);
91 cpl_test_error(CPL_ERROR_NONE);
94 cpl_test_error(CPL_ERROR_NULL_INPUT);
96 cpl_test_error(CPL_ERROR_NONE);
99 cpl_test_error(CPL_ERROR_NULL_INPUT);
101 cpl_test_error(CPL_ERROR_NONE);
104 cpl_test_error(CPL_ERROR_NULL_INPUT);
106 cpl_test_error(CPL_ERROR_NONE);
109 cpl_test_error(CPL_ERROR_NULL_INPUT);
111 cpl_test_error(CPL_ERROR_NONE);
114 cpl_test_error(CPL_ERROR_NULL_INPUT);
116 cpl_test_error(CPL_ERROR_NONE);
119 cpl_test_error(CPL_ERROR_NULL_INPUT);
121 cpl_test_error(CPL_ERROR_NONE);
125 "RECIPE",
"strehl", strehl_def);
128 cpl_test_error(CPL_ERROR_NONE);
130 cpl_test_eq(cpl_parameterlist_get_size(strehl), 8);
134 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
137 cpl_parameterlist_delete(strehl);
138 cpl_test_error(CPL_ERROR_NONE);
159static hdrl_image* hdrl_strehl_test_gauss_create(
void)
167 cpl_image * gauss_data;
168 cpl_image * gauss_error;
170 gauss_data = cpl_image_new(2 * n + 1, 2 * n + 1, CPL_TYPE_DOUBLE);
171 cpl_image_fill_gaussian(gauss_data, n + 1, n + 1, (
double)121.0, sig_x, sig_y);
172 gauss_error = cpl_image_duplicate(gauss_data);
173 cpl_image_multiply_scalar(gauss_error, 0);
174 cpl_image_get_mad(gauss_data, &dmad);
175 cpl_image_add_scalar(gauss_error, (dmad * CPL_MATH_STD_MAD));
178 cpl_image_delete(gauss_data);
179 cpl_image_delete(gauss_error);
191static cpl_error_code hdrl_strehl_test_null_input(
void)
196 double m2 = 5.08/2*0.36;
197 double psx = 0.0331932/2.;
198 double psy = 0.0331932/2.;
203 hdrl_parameter *strehl_param;
204 hdrl_strehl_result strehl_result;
207 hdrl_image *hima = NULL;
212 cpl_test_error(CPL_ERROR_NULL_INPUT);
214 cpl_test(isnan(strehl_result.strehl_value.data));
222 cpl_test_error(CPL_ERROR_NULL_INPUT);
225 cpl_test(isnan(strehl_result.strehl_value.data));
227 return cpl_error_get_code();
236static cpl_error_code hdrl_strehl_test_illegal_input(
void)
240 double m2 = 5.08/2*0.36;
241 double psx = 0.0331932/2.;
242 double psy = 0.0331932/2.;
247 hdrl_image * hima = hdrl_strehl_test_gauss_create();
248 hdrl_parameter * strehl_param;
251 cpl_test_null(strehl_param);
252 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
255 cpl_test_null(strehl_param);
256 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
259 cpl_test_null(strehl_param);
260 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
262 cpl_test_null(strehl_param);
263 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
265 cpl_test_null(strehl_param);
266 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
268 cpl_test_null(strehl_param);
269 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
271 cpl_test_null(strehl_param);
272 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
274 cpl_test_null(strehl_param);
275 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
277 cpl_test_null(strehl_param);
278 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
282 return cpl_error_get_code();
306 double wavelength = 7.7e-6;
307 double pscale_x = 0.075;
308 double pscale_y = 0.075;
311 cpl_image * psf = compute_psf(wavelength, m1, m2, pscale_x, pscale_y,
315 cpl_test_abs(cpl_image_get(psf, hx, hy, &rej), 1., 1e-4);
316 cpl_test_abs(cpl_image_get(psf, hx - 1, hy, &rej), peak, 1e-4);
317 cpl_test_abs(cpl_image_get(psf, hx, hy - 1, &rej), peak, 1e-4);
318 cpl_test_abs(cpl_image_get(psf, hx + 1, hy, &rej), peak, 1e-4);
319 cpl_test_abs(cpl_image_get(psf, hx, hy + 1, &rej), peak, 1e-4);
320 cpl_image_delete(psf);
323 psf = compute_psf(wavelength, m1, m2, pscale_x, pscale_y,
326 cpl_test_abs(cpl_image_get(psf, hx - 1, hy, &rej), 1., 1e-4);
327 cpl_test_abs(cpl_image_get(psf, hx - 2, hy, &rej), peak, 1e-4);
328 cpl_test_abs(cpl_image_get(psf, hx - 1, hy - 1, &rej), peak, 1e-4);
329 cpl_test_abs(cpl_image_get(psf, hx, hy, &rej), peak, 1e-4);
330 cpl_test_abs(cpl_image_get(psf, hx - 1, hy + 1, &rej), peak, 1e-4);
331 cpl_image_delete(psf);
334 psf = compute_psf(wavelength, m1, m2, pscale_x, pscale_y,
338 cpl_test_abs(cpl_image_get(psf, hx, hy, &rej), peak, 1e-4);
339 cpl_test_abs(cpl_image_get(psf, hx - 1, hy - 1, &rej), peak, 1e-4);
340 cpl_test_abs(cpl_image_get(psf, hx, hy - 1, &rej), peak, 1e-4);
341 cpl_test_abs(cpl_image_get(psf, hx - 1, hy, &rej), peak, 1e-4);
342 cpl_image_delete(psf);
345 psf = compute_psf(wavelength, m1, m2, pscale_x, pscale_y,
348 cpl_test_abs(cpl_image_get(psf, hx, hy, &rej), 0.781698, 1e-4);
349 cpl_test_abs(cpl_image_get(psf, hx - 1, hy, &rej), 0.255305, 1e-4);
350 cpl_test_abs(cpl_image_get(psf, hx, hy - 1, &rej), 0.411749, 1e-4);
351 cpl_test_abs(cpl_image_get(psf, hx + 1, hy, &rej), 0.952739, 1e-4);
352 cpl_test_abs(cpl_image_get(psf, hx, hy + 1, &rej), 0.636695, 1e-4);
353 cpl_image_delete(psf);
357 psf = compute_psf(wavelength, m1, m2, pscale_x, 0.025,
361 cpl_test_abs(cpl_image_get(psf, hx, hy, &rej), peak, 1e-4);
362 cpl_test_abs(cpl_image_get(psf, hx - 1, hy - 1, &rej), peak, 1e-4);
363 cpl_test_abs(cpl_image_get(psf, hx, hy - 1, &rej), peak, 1e-4);
364 cpl_test_abs(cpl_image_get(psf, hx - 1, hy, &rej), peak, 1e-4);
367 cpl_test_abs(cpl_image_get(psf, hx + 1, hy, &rej), peak, 1e-4);
368 cpl_test_abs(cpl_image_get(psf, hx + 1, hy - 1, &rej), peak, 1e-4);
369 cpl_test_abs(cpl_image_get(psf, hx - 2, hy, &rej), peak, 1e-4);
370 cpl_test_abs(cpl_image_get(psf, hx - 2, hy - 1, &rej), peak, 1e-4);
373 cpl_test_abs(cpl_image_get(psf, hx, hy + 1, &rej), peak, 1e-4);
374 cpl_test_abs(cpl_image_get(psf, hx - 1, hy + 1, &rej), peak, 1e-4);
375 cpl_test_abs(cpl_image_get(psf, hx, hy - 2, &rej), peak, 1e-4);
376 cpl_test_abs(cpl_image_get(psf, hx - 1, hy - 2, &rej), peak, 1e-4);
377 cpl_image_delete(psf);
382 psf = compute_psf(wavelength, m1, m2, pscale_x / 2., pscale_y / 2.,
386 cpl_test_abs(cpl_image_get(psf, hx, hy, &rej), 1., 1e-4);
387 cpl_test_abs(cpl_image_get(psf, hx - 1, hy, &rej), peak, 1e-4);
388 cpl_test_abs(cpl_image_get(psf, hx, hy - 1, &rej), peak, 1e-4);
389 cpl_test_abs(cpl_image_get(psf, hx + 1, hy, &rej), peak, 1e-4);
390 cpl_test_abs(cpl_image_get(psf, hx, hy + 1, &rej), peak, 1e-4);
391 cpl_image_delete(psf);
398 psf = compute_psf(wavelength, m1, m2, pscale_x, 0.025,
402 cpl_test_abs(cpl_image_get(psf, hx, hy, &rej), peak, 1e-4);
403 cpl_test_abs(cpl_image_get(psf, hx - 1, hy - 1, &rej), peak, 1e-4);
404 cpl_test_abs(cpl_image_get(psf, hx, hy - 1, &rej), peak, 1e-4);
405 cpl_test_abs(cpl_image_get(psf, hx - 1, hy, &rej), peak, 1e-4);
408 cpl_test_abs(cpl_image_get(psf, hx + 1, hy, &rej), peak, 1e-4);
409 cpl_test_abs(cpl_image_get(psf, hx + 1, hy - 1, &rej), peak, 1e-4);
410 cpl_test_abs(cpl_image_get(psf, hx - 2, hy, &rej), peak, 1e-4);
411 cpl_test_abs(cpl_image_get(psf, hx - 2, hy - 1, &rej), peak, 1e-4);
414 cpl_test_abs(cpl_image_get(psf, hx, hy + 1, &rej), peak, 1e-4);
415 cpl_test_abs(cpl_image_get(psf, hx - 1, hy + 1, &rej), peak, 1e-4);
416 cpl_test_abs(cpl_image_get(psf, hx, hy - 2, &rej), peak, 1e-4);
417 cpl_test_abs(cpl_image_get(psf, hx - 1, hy - 2, &rej), peak, 1e-4);
418 cpl_image_delete(psf);
422void test_strehl_with_bkg(
void)
426 hdrl_strehl_result r;
434 double pscale = 0.03;
437 double slope_x = 1. / nx * 100;
439 img = compute_psf(lam, m1, m2, pscale, pscale, nx / 2., ny / 2., nx, ny);
442 cpl_image_multiply_scalar(img, 2000.);
445 cpl_image *bkg = cpl_image_duplicate(img);
446 cpl_image_multiply_scalar(bkg, 0);
447 double *pbkg=cpl_image_get_data_double(bkg);
450 for(
size_t j = 0; j < ny; j++) {
451 for(
size_t i = 0; i < nx; i++) {
452 pbkg[i+nx*j] = i * slope_x;
455 cpl_image_add(img, bkg);
467 r = compute_strehl(himg, lam, m1, m2, pscale, pscale, .5, 2.5, 3.0);
468 cpl_test_abs(r.strehl_value.data, 1.0, rel);
471 cpl_image_delete(img);
472 cpl_image_delete(bkg);
476void test_strehl(
void)
480 hdrl_strehl_result r;
488 double pscale = 0.03;
489 img = compute_psf(lam, m1, m2, pscale, pscale,
490 nx / 2, ny / 2, nx, ny);
497 compute_strehl(himg, lam, m1, m2, pscale, pscale, 1.5, -1, 4.);
498 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
500 compute_strehl(himg, lam, m1, m2, pscale, pscale, 1.5, 4., -1);
501 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
503 compute_strehl(himg, lam, m1, m2, pscale, pscale, 1.5, 5, 5);
504 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
507 compute_strehl(himg, lam, m1, m2, pscale, pscale, 1.5, 5, 6);
508 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
514 r = compute_strehl(himg, lam, m1, m2, pscale, pscale, .5, -1, -1);
515 cpl_test_abs(r.strehl_value.data, 1.0, rel);
516 cpl_test_abs(r.star_x, nx / 2., rel);
517 cpl_test_abs(r.star_y, nx / 2., rel);
521 r = compute_strehl(himg, lam, m1, m2, pscale, pscale, .5, 2, 3);
522 cpl_test_abs(r.strehl_value.data, 1.0, rel);
523 cpl_test_abs(r.star_background.data, 5.0, rel);
524 cpl_test_abs(r.star_background.error, 0., rel);
529 r = compute_strehl(himg, lam, m1, m2, pscale, pscale, .5, 2, 3);
530 cpl_test_abs(r.strehl_value.data, 1.0, rel);
531 cpl_test_abs(r.star_background.data, 5.0, rel);
532 cpl_test_abs(r.star_background.error, 0., rel);
535 compute_strehl(himg, lam, m1, m2, pscale, pscale, .5, 50, 55);
536 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
539 cpl_image_delete(img);
543 for (
size_t i = 0; i < 10; i++) {
544 img = compute_psf(lam, m1, m2, pscale, pscale,
545 nx / 2 + i / 10., ny / 2 + i / 10., nx, ny);
547 r = compute_strehl(himg, lam, m1, m2, pscale, pscale, .5, -1, -1);
548 cpl_test_abs(r.strehl_value.data, 1.0, rel);
550 cpl_image_delete(img);
555 compute_strehl(himg, lam, m1, m2, pscale, pscale, .5, -1, -1);
556 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
628int main(
int argc,
char * argv[])
630 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
632 hdrl_strehl_test_parlist();
633 hdrl_strehl_test_null_input();
634 hdrl_strehl_test_illegal_input();
638 test_strehl_with_bkg();
640 cpl_msg_debug(cpl_func,
"test_strehl_data only for command line "
641 "(argc=%d, argv=%s). If you need to test images images "
642 "via command line uncomment the function.", argc, argv[0]);
646 return cpl_test_end(0);
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_mask * hdrl_image_get_mask(hdrl_image *himg)
get cpl bad pixel mask from 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_create(const cpl_image *image, const cpl_image *error)
create a new hdrl_image from to existing images by copying them
cpl_error_code hdrl_image_reject(hdrl_image *self, cpl_size xpos, cpl_size ypos)
mark pixel as bad
hdrl_image * hdrl_image_new(cpl_size nx, cpl_size ny)
create new zero filled hdrl image
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
void hdrl_parameter_destroy(hdrl_parameter *obj)
deep delete of a parameter
void hdrl_parameter_delete(hdrl_parameter *obj)
shallow delete of a parameter
double hdrl_strehl_parameter_get_m1(const hdrl_parameter *p)
Access the primary mirror radius in the Strehl parameter.
cpl_parameterlist * hdrl_strehl_parameter_create_parlist(const char *base_context, const char *prefix, hdrl_parameter *par)
Create parameter list for the Strehl computation.
hdrl_strehl_result hdrl_strehl_compute(const hdrl_image *himg, hdrl_parameter *params)
This function computes the Strehl ratio.
double hdrl_strehl_parameter_get_flux_radius(const hdrl_parameter *p)
Access the total flux radius in the Strehl parameter.
double hdrl_strehl_parameter_get_wavelength(const hdrl_parameter *p)
Access the wavelength in the Strehl parameter.
double hdrl_strehl_parameter_get_m2(const hdrl_parameter *p)
Access the obstruction radius in the Strehl parameter.
double hdrl_strehl_parameter_get_bkg_radius_high(const hdrl_parameter *p)
Access the background region external radius in the Strehl parameter.
hdrl_parameter * hdrl_strehl_parameter_create(double wavelength, double m1_radius, double m2_radius, double pixel_scale_x, double pixel_scale_y, double flux_radius, double bkg_radius_low, double bkg_radius_high)
Creates Strehl Parameters object.
double hdrl_strehl_parameter_get_pixel_scale_x(const hdrl_parameter *p)
Access the image X pixel scale in the Strehl parameter.
double hdrl_strehl_parameter_get_bkg_radius_low(const hdrl_parameter *p)
Access the background region internal radius in the Strehl parameter.
hdrl_parameter * hdrl_strehl_parameter_parse_parlist(const cpl_parameterlist *parlist, const char *prefix)
Parse parameter list to create input parameters for the Strehl.
cpl_boolean hdrl_strehl_parameter_check(const hdrl_parameter *self)
Check that the parameter is a Strehl parameter.
double hdrl_strehl_parameter_get_pixel_scale_y(const hdrl_parameter *p)
Access the image Y pixel scale in the Strehl parameter.