00001 #ifndef FOCUS_H 00002 #define FOCUS_H 00003 /******************************************************************************* 00004 * E.S.O. - VLT project 00005 * 00006 * "@(#) $Id: focus.h,v 1.6 2005/06/07 12:49:38 amodigli Exp $" 00007 * 00008 * who when what 00009 * -------- -------- ---------------------------------------------- 00010 * schreib 04/02/02 created 00011 */ 00012 00013 /************************************************************************ 00014 * focus.h 00015 * some functions to fit a 2-D Gaussian for focus finding 00016 *---------------------------------------------------------------------- 00017 */ 00018 00019 /* 00020 * header files 00021 */ 00022 00023 /* 00024 #include <stdio.h> 00025 #include <cxstrutils.h> 00026 #include <cpl.h> 00027 #include <math.h> 00028 #include "eclipse.h" 00029 include "cube_ops.h" 00030 */ 00031 00032 00033 #include "spiffi.h" 00034 #include "utilities.h" 00035 00036 00037 /*---------------------------------------------------------------------------- 00038 * Function ANSI C prototypes 00039 *--------------------------------------------------------------------------*/ 00040 00041 /*-------------------------------------------------------------------------*/ 00062 /*--------------------------------------------------------------------------*/ 00063 00064 double gaussianEllipse(double * xdat, double * parlist) ; 00065 00066 /*---------------------------------------------------------------------------- 00067 gaussianEllipse_deriv() 00068 In : position array xdat, parameter list parlist 00069 The parameters are: 00070 parlist(0): center of Gaussian in x direction 00071 parlist(1): center of Gaussian in y direction 00072 parlist(2): Amplitude of 2d Gaussian 00073 parlist(3): Background level 00074 parlist(4): FWHMx 00075 parlist(5): FWHMy 00076 parlist(6): theta 00077 derivative value of a 2d Gaussian function at position xdat: dervs 00078 dervs[0]: partial derivative by center x 00079 dervs[1]: partial derivative by center y 00080 dervs[2]: partial derivative by the amplitude 00081 dervs[3]: partial derivative by the background 00082 dervs[4]: partial derivative by FWHMx 00083 dervs[5]: partial derivative by FWHMy 00084 dervs[6]: partial derivative by theta 00085 Out : nothing, void 00086 Job : calculates the partial derivatives for a 2d Gaussian function with 00087 parameters parlist at position xdat 00088 ----------------------------------------------------------------------------*/ 00089 00090 void gaussianEllipse_deriv( double * xdat, double * parlist, double * dervs ) ; 00091 00092 /*---------------------------------------------------------------------------- 00093 Function : lsqfitd() 00094 In : xdat: position, coordinates of data points. 00095 xdat is 2 dimensional: XDAT ( XDIM, NDAT ) 00096 xdim: dimension of fit 00097 ydat: data points 00098 wdat: weights for data points 00099 ndat: number of data points 00100 fpar: on input contains initial estimates of the 00101 parameters for non-linear fits, on output the 00102 fitted parameters. 00103 epar: contains estimates of the errors in fitted parameters 00104 mpar: logical mask telling which parameters are free (non-zero) 00105 and which parameters are fixed (0) 00106 npar: number of function parameters ( free + fixed ) 00107 tol: relative tolerance. lsqfit stops when successive iterations 00108 fail to produce a decrement in reduced chi-squared less 00109 than tol. If tol is less than the minimum tolerance 00110 possible, tol will be set to this value. This means 00111 that maximum accuracy can be obtained by setting 00112 tol = 0.0. 00113 its: maximum number of iterations 00114 lab: mixing parameter, lab determines the initial weight 00115 of steepest descent method relative to the Taylor method 00116 lab should be a small value (i.e. 0.01). lab can only 00117 be zero when the partial derivatives are independent 00118 of the parameters. In fact in this case lab should be 00119 exactly equal to zero. 00120 Out : returns number of iterations needed to achieve convergence 00121 according to tol. When this number is negative, the fitting 00122 was not continued because a fatal error occurred: 00123 -1 too many free parameters, maximum is 32 00124 -2 no free parameters 00125 -3 not enough degrees of freedom 00126 -4 maximum number of iterations too small to obtain 00127 a solution which satisfies tol. 00128 -5 diagonal of matrix contains elements which are zero 00129 -6 determinant of the coefficient matrix is zero 00130 -7 square root of a negative number 00131 Job : this is a routine for making a least-squares fit of a 00132 function to a set of data points. The method used is 00133 described in: Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963). 00134 This method is a mixture of the steepest descent method 00135 and the Taylor method. 00136 ---------------------------------------------------------------------------*/ 00137 int lsqfitd ( double * xdat, 00138 int * xdim, 00139 double * ydat, 00140 double * wdat, 00141 int * ndat, 00142 double * fpar, 00143 double * epar, 00144 int * mpar, 00145 int * npar, 00146 double * tol , 00147 int * its , 00148 double * lab ) ; 00149 00150 /*---------------------------------------------------------------------------- 00151 Function : fit2dGaussian() 00152 In : image: reconstructed image of a point source 00153 fit_par: array of 7 free fit parameters of a 2D-Gauss 00154 derv_par: derivatives of the fit_par array 00155 mpar: mask to set free parameters, 1: free, 0: fixed. 00156 lleftx, llefty: lower left starting point of the box in which the fit is carried through 00157 to find the maximum of point source image 00158 halfbox_x: half box length in x-direction in pixels inside which the fit 00159 is carried through 00160 halfbox_y: half box length in y-direction in pixels inside which the fit 00161 is carried through 00162 Out : number of needed iterations 00163 -1 if an error occurred. 00164 Job : fits the image of a point source by using a 2-D Gaussian 00165 fit. 00166 Remark on the fit results for the fit parameters 00167 (fwhmx and fwhmy and theta): theta will always be 00168 between -PI/4 and +PI/4, exchange of the fwhmx and fwhmy 00169 values corresponds to a shift of theta by PI/2. 00170 Consequently, an expected theta > |PI/4| will result 00171 in an exchange of the fwhm values and a shift of theta by 00172 PI/2 to a value < |PI/4| what yields exactly the same image. 00173 ---------------------------------------------------------------------------*/ 00174 /*<python>*/ 00175 int fit2dGaussian ( OneImage * image, 00176 double * fit_par, 00177 double * derv_par, 00178 int * mpar, 00179 int lleftx, 00180 int llefty, 00181 int halfbox_x, 00182 int halfbox_y, int* check ) ; 00183 /*</python>*/ 00184 00185 /*---------------------------------------------------------------------------- 00186 Function : plotGaussian() 00187 In : image: image which should be fitted 00188 parlist: parameters of 2D-Gaussian 00189 Out : image of the 2D-Gaussian 00190 Job : plots an image of a given 2D-Gaussian 00191 ---------------------------------------------------------------------------*/ 00192 00193 /*<python>*/ 00194 OneImage * plotGaussian ( OneImage * image, 00195 double * parlist ) ; 00196 /*</python>*/ 00197 00198 /*---------------------------------------------------------------------------- 00199 Function : determineConversionFactor() 00200 In : cube: reduced data cube of a standard star 00201 mag: brightness of the standard star 00202 exptime: exposure time read from the fits header 00203 llx, lly: lower left point of fitting box 00204 halfbox_x, halfbox_y: half width of a box inside which 00205 a 2D-Gauss fit is carried out 00206 Out : intensity conversion value: magnitude per counts/s 00207 -FLT_MAX if error occurred. 00208 Job : determines an intensity conversion factor for the instrument 00209 by fitting a 2D-Gaussian to an collapsed image of a standard star 00210 with known brightness (only for non-AO observations). 00211 Then the resulting Gaussian is integrated and the counts 00212 are divided by the exposure time (Fits header information) 00213 ---------------------------------------------------------------------------*/ 00214 00215 /*<python>*/ 00216 float determineConversionFactor ( OneCube * cube, 00217 float mag, 00218 float exptime, 00219 int llx, 00220 int lly, 00221 int halfbox_x, 00222 int halfbox_y, int* check ) ; 00223 /*</python>*/ 00224 00225 #endif 00227 /*--------------------------------------------------------------------------*/
1.2.13.1 written by Dimitri van Heesch,
© 1997-2001