NACO Pipeline Reference Manual  4.4.0
irplib_strehl-test.c
1 /* $Id: irplib_strehl-test.c,v 1.10 2013-01-29 08:43:33 jtaylor Exp $
2  *
3  * This file is part of the ESO Common Pipeline Library
4  * Copyright (C) 2001-2008 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 02111-1307 USA
19  */
20 
21 /*
22  * $Author: jtaylor $
23  * $Date: 2013-01-29 08:43:33 $
24  * $Revision: 1.10 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 /*-----------------------------------------------------------------------------
29  Includes
30  -----------------------------------------------------------------------------*/
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
34 
35 #include "irplib_strehl.h"
36 #include "irplib_utils.h"
37 
38 #include <string.h>
39 
40 /*-----------------------------------------------------------------------------
41  Defines
42  -----------------------------------------------------------------------------*/
43 
44 #ifndef IMAGESZ
45 #define IMAGESZ 1024
46 #endif
47 
48 #ifndef CWLEN
49 #define CWLEN 1.6
50 #endif
51 
52 #ifndef DWLEN
53 #define DWLEN 0.05
54 #endif
55 
56 #ifndef PIXSCALE
57 #define PIXSCALE 12.25e-3
58 #endif
59 
60 /*-----------------------------------------------------------------------------
61  Static functions
62  -----------------------------------------------------------------------------*/
63 static void irplib_strehl_test_one(void);
64 static void irplib_psf_test_one(int);
65 static void irplib_psf_test(void);
66 static cpl_image * irplib_strehl_create(cpl_size, cpl_size, cpl_type,
67  double, double, double);
68 static void irplib_strehl_test(const cpl_image *, double, double,
69  double, double, double, double, double,
70  const char *);
71 
72 static void irplib_strehl_test_fits(const char *, double, double, double,
73  double, double, cpl_size);
74 
75 static const char * irplib_get_base_name(const char *);
76 
77 struct fitsinfo {
78  const char *bname; /* filename with extension, but without path */
79  double pixscale; /* Arcseconds per pixel */
80  double cwlen; /* micron */
81  double dwlen; /* micron */
82  double m1; /* The diameter of the primary mirror [m] */
83  double m2; /* The diameter of the secondary mirror [m] */
84  cpl_size iplane;
85 };
86 
87 /*-----------------------------------------------------------------------------
88  Main
89  -----------------------------------------------------------------------------*/
90 /*----------------------------------------------------------------------------*/
98 /*----------------------------------------------------------------------------*/
99 int main (int argc, char * argv[])
100 {
101  /* Support the Strehl-method evaluation effort by Enrico Marchetti */
102  const struct fitsinfo suite[] = {
103  {"Berlin.fits", 12.25e-3, 1.6, 0.060, IRPLIB_STREHL_M1,
104  IRPLIB_STREHL_M2, 0},
105  {"Frankfurt.fits", 12.25e-3, 1.6, 0.060, IRPLIB_STREHL_M1,
106  IRPLIB_STREHL_M2, 0},
107  {"Hamburg.fits", 12.25e-3, 1.6, 0.060, IRPLIB_STREHL_M1,
108  IRPLIB_STREHL_M2, 0},
109  {"Koeln.fits", 12.25e-3, 1.6, 0.060, IRPLIB_STREHL_M1,
110  IRPLIB_STREHL_M2, 0},
111  {"Muenchen.fits", 12.25e-3, 1.6, 0.060, IRPLIB_STREHL_M1,
112  IRPLIB_STREHL_M2, 0},
113  {"Stuttgart.fits", 12.25e-3, 1.6, 0.060, IRPLIB_STREHL_M1,
114  IRPLIB_STREHL_M2, 0},
115 
116  {"Torino_2.fits", 0.0331932, 1.635, 0.0001, 5.0800, 1.8288, 0},
117  {"Trieste_2.fits", 0.0331932, 1.635, 0.0001, 5.0800, 1.8288, 0},
118  {"Bologna_2.fits", 0.0331932, 1.635, 0.0001, 5.0800, 1.8288, 0},
119  {"Cagliari_2.fits", 0.0331932, 1.635, 0.0001, 5.0800, 1.8288, 0},
120  {"Catania_2.fits", 0.0331932, 1.635, 0.0001, 5.0800, 1.8288, 0},
121  {"Firenze_2.fits", 0.0331932, 1.635, 0.0001, 5.0800, 1.8288, 0},
122  {"Lapalma_2.fits", 0.0331932, 1.635, 0.0001, 5.0800, 1.8288, 0},
123  {"Milano_2.fits", 0.0331932, 1.635, 0.0001, 5.0800, 1.8288, 0},
124  {"Napoli_2.fits", 0.0331932, 1.635, 0.0001, 5.0800, 1.8288, 0},
125  {"Padova_2.fits", 0.0331932, 1.635, 0.0001, 5.0800, 1.8288, 0},
126  {"Palermo_2.fits", 0.0331932, 1.635, 0.0001, 5.0800, 1.8288, 0},
127  {"Roma_2.fits", 0.0331932, 1.635, 0.0001, 5.0800, 1.8288, 0},
128  {"Teramo_2.fits", 0.0331932, 1.635, 0.0001, 5.0800, 1.8288, 0},
129 
130  {"Bologna_4.fits", 0.0165966, 1.635, 0.0001, 5.0800, 1.8288, 0},
131  {"Cagliari_4.fits", 0.0165966, 1.635, 0.0001, 5.0800, 1.8288, 0},
132  {"Catania_4.fits", 0.0165966, 1.635, 0.0001, 5.0800, 1.8288, 0},
133  {"Firenze_4.fits", 0.0165966, 1.635, 0.0001, 5.0800, 1.8288, 0},
134  {"Lapalma.fits", 0.0165966, 1.635, 0.0001, 5.0800, 1.8288, 0},
135  {"Milano_4.fits", 0.0165966, 1.635, 0.0001, 5.0800, 1.8288, 0},
136  {"Naoli_4.fits", 0.0165966, 1.635, 0.0001, 5.0800, 1.8288, 0},
137  {"Padova_4.fits", 0.0165966, 1.635, 0.0001, 5.0800, 1.8288, 0},
138  {"Palermo_4.fits", 0.0165966, 1.635, 0.0001, 5.0800, 1.8288, 0},
139  {"Roma_4.fits", 0.0165966, 1.635, 0.0001, 5.0800, 1.8288, 0},
140  {"Teramo_4.fits", 0.0165966, 1.635, 0.0001, 5.0800, 1.8288, 0},
141  {"Torino_4.fits", 0.0165966, 1.635, 0.0001, 5.0800, 1.8288, 0},
142  {"Trieste_4.fits", 0.0165966, 1.635, 0.0001, 5.0800, 1.8288, 0},
143 
144  {"Antofagasta.fits", 0.17678, 2.2 , 0.05, IRPLIB_STREHL_M1,
145  IRPLIB_STREHL_M2, 0},
146  {"Bordeaux.fits", 0.01327, 2.166, 0.05, IRPLIB_STREHL_M1,
147  IRPLIB_STREHL_M2, 0},
148  {"Concepcion.fits", 0.01768, 2.2 , 0.05, IRPLIB_STREHL_M1,
149  IRPLIB_STREHL_M2, 0},
150  {"Grenoble.fits", 0.02715, 2.15 , 0.05, IRPLIB_STREHL_M1,
151  IRPLIB_STREHL_M2, 0},
152  {"LeHavre.fits", 0.01327, 1.65 , 0.05, IRPLIB_STREHL_M1,
153  IRPLIB_STREHL_M2, 0},
154  {"Lille.fits", 0.01327, 1.04 , 0.05, IRPLIB_STREHL_M1,
155  IRPLIB_STREHL_M2, 8},
156  {"Lyon.fits", 0.01327, 2.15 , 0.05, IRPLIB_STREHL_M1,
157  IRPLIB_STREHL_M2, 0},
158  {"Marseille.fits", 0.02715, 4.05 , 0.05, IRPLIB_STREHL_M1,
159  IRPLIB_STREHL_M2, 0},
160  {"Nantes.fits", 0.0546 , 2.15 , 0.05, IRPLIB_STREHL_M1,
161  IRPLIB_STREHL_M2, 0},
162  {"Nice.fits", 0.02715, 4.78 , 0.05, IRPLIB_STREHL_M1,
163  IRPLIB_STREHL_M2, 0},
164  {"Paris.fits", 0.0033 , 2.18 , 0.05, IRPLIB_STREHL_M1,
165  IRPLIB_STREHL_M2, 0},
166  {"Santiago.fits", 0.01768, 2.2 , 0.05, IRPLIB_STREHL_M1,
167  IRPLIB_STREHL_M2, 0},
168  {"Strasbourg.fits", 0.01327, 2.166, 0.05, IRPLIB_STREHL_M1,
169  IRPLIB_STREHL_M2, 0},
170  {"Toulouse.fits", 0.02715, 2.15 , 0.05, IRPLIB_STREHL_M1,
171  IRPLIB_STREHL_M2, 0},
172  {"Valdivia.fits", 0.07071, 2.2 , 0.05, IRPLIB_STREHL_M1,
173  IRPLIB_STREHL_M2, 0}};
174 
175  const size_t suitesz = sizeof(suite) / sizeof(*suite);
176  int iarg;
177 
178  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
179 
180  cpl_msg_info("Strehl-testing with star with ",
181  IRPLIB_XSTRINGIFY(IRPLIB_STREHL_STAR_RADIUS) " = "
182  IRPLIB_STRINGIFY(IRPLIB_STREHL_STAR_RADIUS) ". "
183  IRPLIB_XSTRINGIFY(IRPLIB_STREHL_BACKGROUND_R1) " = "
184  IRPLIB_STRINGIFY(IRPLIB_STREHL_BACKGROUND_R1) ". "
185  IRPLIB_XSTRINGIFY(IRPLIB_STREHL_BACKGROUND_R2) " = "
186  IRPLIB_STRINGIFY(IRPLIB_STREHL_BACKGROUND_R2) ".");
187 
188  irplib_strehl_test_one();
189 
190  for (iarg = 1; iarg < argc; iarg++) {
191  const char * basename = irplib_get_base_name(argv[iarg]);
192  double pixscale = PIXSCALE;
193  double cwlen = CWLEN;
194  double dwlen = DWLEN;
195  double m1 = IRPLIB_STREHL_M1;
196  double m2 = IRPLIB_STREHL_M2;
197  cpl_size iplane = 0;
198  size_t i;
199 
200  cpl_test_assert(basename != NULL);
201 
202  for (i = 0; i < suitesz; i++) {
203  if (!strcmp(basename, suite[i].bname)) {
204  pixscale = suite[i].pixscale;
205  cwlen = suite[i].cwlen;
206  dwlen = suite[i].dwlen;
207  m1 = suite[i].m1;
208  m2 = suite[i].m2;
209  iplane = suite[i].iplane;
210  break;
211  }
212  }
213 
214  irplib_strehl_test_fits(argv[iarg], pixscale, cwlen, dwlen, m1, m2,
215  iplane);
216  }
217 
218  irplib_psf_test();
219 
220  return cpl_test_end(0);
221 }
222 
223 
224 /*----------------------------------------------------------------------------*/
237 /*----------------------------------------------------------------------------*/
238 static void irplib_strehl_test_fits(const char * file, double pixscale,
239  double lam, double dlam, double m1,
240  double m2, cpl_size iplane)
241 {
242 
243  cpl_type type = CPL_TYPE_DOUBLE;
244  int i;
245 
246  for (i = 0; i < 1; i++, type = CPL_TYPE_FLOAT) {
247 
248  cpl_image * img = cpl_image_load(file, type, iplane, 0);
249 
250  cpl_test_error(CPL_ERROR_NONE);
251  cpl_test_nonnull(img);
252 
253  irplib_strehl_test(img, 0.0, 10.0, pixscale, lam, dlam, m1, m2, file);
254 
255  cpl_image_delete(img);
256  }
257 }
258 
259 
260 /*----------------------------------------------------------------------------*/
266 /*----------------------------------------------------------------------------*/
267 static void irplib_psf_test(void)
268 {
269 
270  const int is_bench = cpl_msg_get_level() <= CPL_MSG_INFO
271  ? CPL_TRUE : CPL_FALSE;
272 
273  double tstop;
274  const double tstart = cpl_test_get_cputime();
275 
276  int szstart = 4;
277  int szstop = is_bench ? IMAGESZ : IRPLIB_STREHL_BOX_SIZE * 2;
278 
279  int isz, irep;
280 
281  for (irep = 0; irep < (is_bench ? 3 : 1); irep++) {
282 
283  for (isz = szstart; isz <= szstop; isz *= 2) {
284  irplib_psf_test_one(isz);
285  }
286  }
287 
288  tstop = cpl_test_get_cputime() - tstart;
289 
290  cpl_msg_info(cpl_func, "Time to generate %d set(s) of PSFs up to size "
291  "%d X %d [s]: %g", irep, szstop, szstop, tstop);
292 }
293 
294 /*----------------------------------------------------------------------------*/
300 /*----------------------------------------------------------------------------*/
301 static void irplib_psf_test_one(int size)
302 {
303  cpl_image * imgpsf = irplib_strehl_generate_psf(IRPLIB_STREHL_M1,
305  CWLEN, DWLEN, PIXSCALE,
306  size);
307  cpl_test_error(CPL_ERROR_NONE);
308  cpl_test_nonnull(imgpsf);
309  cpl_test_eq(cpl_image_get_size_x(imgpsf),
310  cpl_image_get_size_y(imgpsf));
311 
312  cpl_test_eq(cpl_image_get_size_x(imgpsf), size);
313 
314  cpl_image_delete(imgpsf);
315 }
316 
317 /*----------------------------------------------------------------------------*/
323 /*----------------------------------------------------------------------------*/
324 static void irplib_strehl_test_one(void)
325 {
326  cpl_type type = CPL_TYPE_DOUBLE;
327  int i;
328 
329  for (i = 0; i < 2; i++, type = CPL_TYPE_FLOAT) {
330 
331  cpl_image * img = irplib_strehl_create(IMAGESZ, IMAGESZ, type,
332  1000.0, 1.0, 1.0);
333 
334  irplib_strehl_test(img, 1000.0, 1.0, 0.03,
335  2.18, 0.35, IRPLIB_STREHL_M1, IRPLIB_STREHL_M2,
336  "Synthetic image"); /* NACO values */
337 
338  cpl_image_delete(img);
339  }
340 }
341 
342 /*----------------------------------------------------------------------------*/
355 /*----------------------------------------------------------------------------*/
356 static cpl_image * irplib_strehl_create(cpl_size nx, cpl_size ny,
357  cpl_type type,
358  double norm,
359  double sig_x,
360  double sig_y)
361 {
362 
363  const double noise = FLT_EPSILON;
364  cpl_size mx, my;
365  cpl_image * im1 = cpl_image_new(nx, ny, type);
366  cpl_error_code code;
367 
368  code = cpl_image_fill_gaussian(im1, nx/2, ny/2, norm, sig_x, sig_y);
369  cpl_test_eq_error(code, CPL_ERROR_NONE);
370 
371  if (noise != 0.0) {
372  cpl_image * im0 = cpl_image_new(nx, ny, CPL_TYPE_FLOAT);
373  code = cpl_image_fill_noise_uniform(im0, -noise, noise);
374  cpl_test_eq_error(code, CPL_ERROR_NONE);
375  code = cpl_image_subtract(im1, im0);
376  cpl_test_eq_error(code, CPL_ERROR_NONE);
377  cpl_image_delete(im0);
378  }
379 
380  code = cpl_image_get_maxpos(im1, &mx, &my);
381  cpl_test_eq_error(code, CPL_ERROR_NONE);
382  cpl_test_eq(mx, nx/2);
383  cpl_test_eq(my, ny/2);
384 
385  return im1;
386 }
387 
388 /*----------------------------------------------------------------------------*/
403 /*----------------------------------------------------------------------------*/
404 static void irplib_strehl_test(const cpl_image * im1, double norm,
405  double sigma,
406  double pixscale, double lam, double dlam,
407  double m1, double m2,
408  const char * label)
409 {
410 
411  const cpl_size nx = cpl_image_get_size_x(im1);
412  const cpl_size ny = cpl_image_get_size_y(im1);
413  cpl_error_code code;
414 
415  /* Sigma-levels for detection of a bright star, copied from NACO */
416  const double psigmas[] = {sigma, sigma/2.0, sigma/4.0};
417  const size_t nsigmas = sizeof(psigmas)/sizeof(*psigmas);
418  cpl_size isigma;
419  cpl_vector * sigmas = cpl_vector_wrap(nsigmas, (double*)psigmas);
420  cpl_apertures * apert = NULL;
421  double fwhm_x, fwhm_y;
422  cpl_size mx, my;
423  cpl_image * imgpsf;
424 
425  double strehl = 0.0, strehl_err = 0.0;
426  double star_bg = 0.0, star_peak = 0.0, star_flux = 0.0;
427  double psf_peak = 0.0, psf_flux = 0.0, bg_noise = 0.0;
428 
429  const double star_radius = IRPLIB_STREHL_STAR_RADIUS;
430  const double background_1 = IRPLIB_STREHL_BACKGROUND_R1;
431  const double background_2 = IRPLIB_STREHL_BACKGROUND_R2;
432 
433  code = cpl_image_get_maxpos(im1, &mx, &my);
434  cpl_test_eq_error(code, CPL_ERROR_NONE);
435  cpl_test_leq(mx - nx/4, mx);
436  cpl_test_leq(my - ny/4, my);
437  cpl_test_leq(mx, mx + nx/4);
438  cpl_test_leq(my, my + ny/4);
439 
440  apert = cpl_apertures_extract_window(im1, sigmas,
441  mx - nx/4, my - ny/4,
442  mx + nx/4, my + ny/4,
443  &isigma);
444  cpl_test_error(CPL_ERROR_NONE);
445  cpl_test_nonnull(apert);
446  cpl_test_zero(isigma);
447 
448  cpl_apertures_delete(apert);
449  cpl_test_eq_ptr(cpl_vector_unwrap(sigmas), psigmas);
450 
451  cpl_test_lt(0.0, pixscale);
452 
453  code = cpl_image_get_fwhm(im1, mx, my, &fwhm_x, &fwhm_y);
454  cpl_test_eq_error(code, CPL_ERROR_NONE);
455 
456  cpl_msg_info(cpl_func, "Expected star-radius vs. actual FWHM [pixel]: "
457  "%g <=> (%g, %g)", star_radius / pixscale,
458  fwhm_x, fwhm_y);
459 
460  cpl_msg_debug(cpl_func, "Inner and outer radius of ring-zone for noise "
461  "estimate [pixel]: %g < %g", background_1 / pixscale,
462  background_2 / pixscale);
463 
464 
465  imgpsf = irplib_strehl_generate_psf(m1, m2,
466  lam, dlam, pixscale,
468  cpl_test_error(CPL_ERROR_NONE);
469  cpl_test_nonnull(imgpsf);
470  cpl_test_eq(cpl_image_get_size_x(imgpsf),
471  cpl_image_get_size_y(imgpsf));
472 
473  cpl_test_eq(cpl_image_get_size_x(imgpsf),
475 
476  if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
477  cpl_plot_image("", "", "", imgpsf);
478  }
479  cpl_image_delete(imgpsf);
480 
481  code = irplib_strehl_compute(im1, m1, m2,
482  lam, dlam, pixscale,
484  mx, my,
485  star_radius,
486  background_1,
487  background_2,
488  -1, -1,
489  &strehl,
490  &strehl_err,
491  &star_bg,
492  &star_peak,
493  &star_flux,
494  &psf_peak,
495  &psf_flux,
496  &bg_noise);
497  cpl_test_eq_error(code, CPL_ERROR_NONE);
498  cpl_test_leq(0.0, strehl);
499  cpl_test_leq(strehl, 1.0);
500  cpl_test_leq(0.0, strehl_err);
501  if (norm > 0.0) {
502  cpl_test_rel(norm, star_flux, 0.01);
503  }
504 
505  cpl_msg_info(cpl_func, "Strehl: ratio=%g, error=%g; Background: flux=%g, "
506  "noise=%g; Star: peak=%g, flux=%g; PSF: peak=%g, flux=%g",
507  strehl, strehl_err, star_bg, bg_noise, star_peak, star_flux,
508  psf_peak, psf_flux);
509 
510  cpl_msg_info(cpl_func, "%-16s %-10.9g %-8.6g %-8.6g %-8.6g %-8.6g "
511  "%-8.4g %-8.4g", label, pixscale, lam, dlam, m1, m2,
512  strehl, strehl_err);
513 
514  /* Test for various errors */
515 
516  /* M2 < 0*/
517  code = irplib_strehl_compute(im1, m1, 0.0,
518  lam, dlam, pixscale,
520  nx/2, ny/2,
521  star_radius,
522  background_1,
523  background_2,
524  -1, -1,
525  &strehl,
526  &strehl_err,
527  &star_bg,
528  &star_peak,
529  &star_flux,
530  &psf_peak,
531  &psf_flux,
532  &bg_noise);
533  cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT);
534 
535 
536  /* M1 < M2 */
537  code = irplib_strehl_compute(im1, m2, m1,
538  lam, dlam, pixscale,
540  nx/2, ny/2,
541  star_radius,
542  background_1,
543  background_2,
544  -1, -1,
545  &strehl,
546  &strehl_err,
547  &star_bg,
548  &star_peak,
549  &star_flux,
550  &psf_peak,
551  &psf_flux,
552  &bg_noise);
553  cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT);
554 
555 
556  /* lam = 0 */
557  code = irplib_strehl_compute(im1, m1, m2,
558  0.0, dlam, pixscale,
560  nx/2, ny/2,
561  star_radius,
562  background_1,
563  background_2,
564  -1, -1,
565  &strehl,
566  &strehl_err,
567  &star_bg,
568  &star_peak,
569  &star_flux,
570  &psf_peak,
571  &psf_flux,
572  &bg_noise);
573  cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT);
574 
575  /* dlam = 0 */
576  code = irplib_strehl_compute(im1, m1, m2,
577  lam, 0.0, pixscale,
579  nx/2, ny/2,
580  star_radius,
581  background_1,
582  background_2,
583  -1, -1,
584  &strehl,
585  &strehl_err,
586  &star_bg,
587  &star_peak,
588  &star_flux,
589  &psf_peak,
590  &psf_flux,
591  &bg_noise);
592  cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT);
593 
594  /* pixscale = 0 */
595  code = irplib_strehl_compute(im1, m1, m2,
596  lam, dlam, 0.0,
598  nx/2, ny/2,
599  star_radius,
600  background_1,
601  background_2,
602  -1, -1,
603  &strehl,
604  &strehl_err,
605  &star_bg,
606  &star_peak,
607  &star_flux,
608  &psf_peak,
609  &psf_flux,
610  &bg_noise);
611  cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT);
612 
613  /* IRPLIB_STREHL_BOX_SIZE = 0 */
614  code = irplib_strehl_compute(im1, m1, m2,
615  lam, dlam, pixscale,
616  0,
617  nx/2, ny/2,
618  star_radius,
619  background_1,
620  background_2,
621  -1, -1,
622  &strehl,
623  &strehl_err,
624  &star_bg,
625  &star_peak,
626  &star_flux,
627  &psf_peak,
628  &psf_flux,
629  &bg_noise);
630  cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT);
631 
632  /* star_radius = 0 */
633  code = irplib_strehl_compute(im1, m1, m2,
634  lam, dlam, pixscale,
636  nx/2, ny/2,
637  0.0,
638  background_1,
639  background_2,
640  -1, -1,
641  &strehl,
642  &strehl_err,
643  &star_bg,
644  &star_peak,
645  &star_flux,
646  &psf_peak,
647  &psf_flux,
648  &bg_noise);
649  cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT);
650 
651  /* background_1 = 0 */
652  code = irplib_strehl_compute(im1, m1, m2,
653  lam, dlam, pixscale,
655  nx/2, ny/2,
656  star_radius,
657  0.0,
658  background_2,
659  -1, -1,
660  &strehl,
661  &strehl_err,
662  &star_bg,
663  &star_peak,
664  &star_flux,
665  &psf_peak,
666  &psf_flux,
667  &bg_noise);
668  cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT);
669 
670  /* background_2 too small */
671  code = irplib_strehl_compute(im1, m1, m2,
672  lam, dlam, pixscale,
674  nx/2, ny/2,
675  star_radius,
676  background_1,
677  background_1,
678  -1, -1,
679  &strehl,
680  &strehl_err,
681  &star_bg,
682  &star_peak,
683  &star_flux,
684  &psf_peak,
685  &psf_flux,
686  &bg_noise);
687  cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT);
688 
689  /* strehl pointer is NULL */
690  code = irplib_strehl_compute(im1, m1, m2,
691  lam, dlam, pixscale,
693  nx/2, ny/2,
694  star_radius,
695  background_1,
696  background_2,
697  -1, -1,
698  NULL,
699  &strehl_err,
700  &star_bg,
701  &star_peak,
702  &star_flux,
703  &psf_peak,
704  &psf_flux,
705  &bg_noise);
706  cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT);
707 
708  /* strehl_err pointer is NULL */
709  code = irplib_strehl_compute(im1, m1, m2,
710  lam, dlam, pixscale,
712  nx/2, ny/2,
713  star_radius,
714  background_1,
715  background_2,
716  -1, -1,
717  &strehl,
718  NULL,
719  &star_bg,
720  &star_peak,
721  &star_flux,
722  &psf_peak,
723  &psf_flux,
724  &bg_noise);
725  cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT);
726 
727  /* star_bg pointer is NULL */
728  code = irplib_strehl_compute(im1, m1, m2,
729  lam, dlam, pixscale,
731  nx/2, ny/2,
732  star_radius,
733  background_1,
734  background_2,
735  -1, -1,
736  &strehl,
737  &strehl_err,
738  NULL,
739  &star_peak,
740  &star_flux,
741  &psf_peak,
742  &psf_flux,
743  &bg_noise);
744  cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT);
745 
746  /* star_peak pointer is NULL */
747  code = irplib_strehl_compute(im1, m1, m2,
748  lam, dlam, pixscale,
750  nx/2, ny/2,
751  star_radius,
752  background_1,
753  background_2,
754  -1, -1,
755  &strehl,
756  &strehl_err,
757  &star_bg,
758  NULL,
759  &star_flux,
760  &psf_peak,
761  &psf_flux,
762  &bg_noise);
763  cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT);
764 
765  /* psf_peak pointer is NULL */
766  code = irplib_strehl_compute(im1, m1, m2,
767  lam, dlam, pixscale,
769  nx/2, ny/2,
770  star_radius,
771  background_1,
772  background_2,
773  -1, -1,
774  &strehl,
775  &strehl_err,
776  &star_bg,
777  &star_peak,
778  &star_flux,
779  NULL,
780  &psf_flux,
781  &bg_noise);
782  cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT);
783 
784  /* psf_flux pointer is NULL */
785  code = irplib_strehl_compute(im1, m1, m2,
786  lam, dlam, pixscale,
788  nx/2, ny/2,
789  star_radius,
790  background_1,
791  background_2,
792  -1, -1,
793  &strehl,
794  &strehl_err,
795  &star_bg,
796  &star_peak,
797  &star_flux,
798  &psf_peak,
799  NULL,
800  &bg_noise);
801  cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT);
802 
803 
804  /* bg_noise pointer is NULL */
805  code = irplib_strehl_compute(im1, m1, m2,
806  lam, dlam, pixscale,
808  nx/2, ny/2,
809  star_radius,
810  background_1,
811  background_2,
812  -1, -1,
813  &strehl,
814  &strehl_err,
815  &star_bg,
816  &star_peak,
817  &star_flux,
818  &psf_peak,
819  &psf_flux,
820  NULL);
821  cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT);
822 }
823 
824 
825 /*----------------------------------------------------------------------------*/
835 /*----------------------------------------------------------------------------*/
836 static const char * irplib_get_base_name(const char * self)
837 {
838  const char * p = self ? strrchr(self, '/') : NULL;
839 
840  return p ? p + 1 : self;
841 }
#define IRPLIB_STREHL_STAR_RADIUS
The radius of the star, [Arcseconds].
Definition: irplib_strehl.h:81
int main(void)
Find a plugin and submit it to some tests.
Definition: recipe_main.c:61
#define IRPLIB_STREHL_M2
The diameter of the secondary mirror, [m].
Definition: irplib_strehl.h:62
#define IRPLIB_STREHL_M1
The diameter of the primary mirror, [m].
Definition: irplib_strehl.h:53
#define IRPLIB_STREHL_BACKGROUND_R2
The outer radius of the noise-estimation region, [Arcseconds].
Definition: irplib_strehl.h:99
#define IRPLIB_STREHL_BOX_SIZE
The size of the internally used PSF-image, [pixel].
Definition: irplib_strehl.h:71
#define IRPLIB_STREHL_BACKGROUND_R1
The inner radius of the noise-estimation region, [Arcseconds].
Definition: irplib_strehl.h:90