NACO Pipeline Reference Manual  4.4.0
naco_strehl.c
1 /* $Id: naco_strehl.c,v 1.22 2008-04-18 00:25:30 llundin Exp $
2  *
3  * This file is part of the NACO Pipeline
4  * Copyright (C) 2002,2003 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: llundin $
23  * $Date: 2008-04-18 00:25:30 $
24  * $Revision: 1.22 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #define HDRL_USE_EXPERIMENTAL
29 
30 /*-----------------------------------------------------------------------------
31  Includes
32  -----------------------------------------------------------------------------*/
33 
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37 
38 #include "naco_strehl.h"
39 #include "naco_parameter.h"
40 
41 #include "irplib_strehl.h"
42 
43 #ifdef HDRL_USE_EXPERIMENTAL
44 #include "hdrl.h"
45 #endif
46 
47 /*----------------------------------------------------------------------------*/
53 /*----------------------------------------------------------------------------*/
54 
57 /*----------------------------------------------------------------------------*/
79 /*----------------------------------------------------------------------------*/
80 cpl_error_code naco_strehl_compute(const cpl_image * self,
81  const cpl_parameterlist * parlist,
82  const char * recipename,
83  double lam,
84  double dlam,
85  double pos_x,
86  double pos_y,
87  double pixscale,
88  double * pstrehl,
89  double * pstrehl_err,
90  double * pstar_bg,
91  double * pstar_peak,
92  double * pstar_flux,
93  double * ppsf_peak,
94  double * ppsf_flux,
95  double * pbg_noise)
96 {
97 
98  cpl_errorstate cleanstate = cpl_errorstate_get();
99  const double r1 = naco_parameterlist_get_double(parlist, recipename,
100  NACO_PARAM_STAR_R);
101  const double r2 = naco_parameterlist_get_double(parlist, recipename,
102  NACO_PARAM_BG_RINT);
103  const double r3 = naco_parameterlist_get_double(parlist, recipename,
104  NACO_PARAM_BG_REXT);
105 
106 #ifdef HDRL_USE_EXPERIMENTAL
107  hdrl_parameter * hdrl_param = NULL;
108  hdrl_strehl_result hdrl_strehl;
109  hdrl_image * hdrl_self = NULL;
110 
111 #endif
112 
113  skip_if(irplib_strehl_compute(self,
115  lam, dlam,
116  pixscale,
118  pos_x,
119  pos_y,
120  r1, r2, r3,
121  -1, -1,
122  pstrehl,
123  pstrehl_err,
124  pstar_bg,
125  pstar_peak,
126  pstar_flux,
127  ppsf_peak,
128  ppsf_flux,
129  pbg_noise));
130 
131 #ifdef HDRL_USE_EXPERIMENTAL
132 
133  hdrl_self = hdrl_image_create(self, NULL);
134 
135  skip_if (hdrl_self == NULL);
136 
137  /* HDRL uses SI (m) and the mirror dimensions are given as radii */
138  hdrl_param = hdrl_strehl_parameter_create(lam * 1e-6,
139  IRPLIB_STREHL_M1 * 0.5,
140  IRPLIB_STREHL_M2 * 0.5,
141  pixscale, pixscale,
142  r1, r2, r3);
143  if (hdrl_param != NULL)
144  hdrl_strehl = hdrl_strehl_compute(hdrl_self, hdrl_param);
145 
146  if (!cpl_errorstate_is_equal(cleanstate)) {
147  irplib_error_recover(cleanstate, "HDRL Strehl computation failed "
148  "(keeping %g)", *pstrehl);
149  } else if (0.0 < *pstrehl && *pstrehl < 1.0 &&
150  (hdrl_strehl.strehl_value.data <= 0.0 ||
151  hdrl_strehl.strehl_value.data >= 1.0)) {
152  cpl_msg_warning(cpl_func, "Ignoring suspicious HDRL Strehl: %g "
153  "(keeping %g)", hdrl_strehl.strehl_value.data,
154  *pstrehl);
155  } else {
156  cpl_msg_info(cpl_func, "Changing Strehl: %g -> %g",
157  *pstrehl, hdrl_strehl.strehl_value.data);
158  *pstrehl = hdrl_strehl.strehl_value.data;
159  }
160 
161 #endif
162 
163  end_skip;
164 
165 #ifdef HDRL_USE_EXPERIMENTAL
166  hdrl_parameter_delete(hdrl_param);
167  hdrl_image_delete(hdrl_self);
168 #endif
169 
170  return cpl_error_get_code();
171 }
172 
cpl_error_code naco_strehl_compute(const cpl_image *self, const cpl_parameterlist *parlist, const char *recipename, double lam, double dlam, double pos_x, double pos_y, double pixscale, double *pstrehl, double *pstrehl_err, double *pstar_bg, double *pstar_peak, double *pstar_flux, double *ppsf_peak, double *ppsf_flux, double *pbg_noise)
Compute the strehl ratio in an image.
Definition: naco_strehl.c:80
double naco_parameterlist_get_double(const cpl_parameterlist *self, const char *recipe, naco_parameter bitmask)
Retrieve the value of a NACO parameter of type double.
#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_BOX_SIZE
The size of the internally used PSF-image, [pixel].
Definition: irplib_strehl.h:71