00001 #ifndef ABSOLUTE_H 00002 #define ABSOLUTE_H 00003 /******************************************************************************* 00004 * E.S.O. - VLT project 00005 * 00006 * "@(#) $Id: absolute.h,v 1.6 2005/04/19 11:43:24 amodigli Exp $" 00007 * 00008 * who when what 00009 * -------- -------- ---------------------------------------------- 00010 * schreib 14/11/00 created 00011 */ 00012 00013 /************************************************************************ 00014 * absolute.h 00015 * routines to determine the absolute positions of the slitlets out of 00016 * an emission line frame 00017 *---------------------------------------------------------------------- 00018 */ 00019 00020 /* 00021 * header files 00022 */ 00023 00024 /* #include <stdio.h> */ 00025 /* #include <math.h> */ 00026 /* #include <float.h> */ 00027 /* #include <inttypes.h> */ 00028 00029 /* #include "eclipse.h" */ 00030 /* #include "spiffi_types.h" */ 00031 #include <cpl.h> 00032 #include "spectrum_ops.h" 00033 00034 /*---------------------------------------------------------------------------- 00035 * Function ANSI C prototypes 00036 *--------------------------------------------------------------------------*/ 00037 00038 /*---------------------------------------------------------------------------- 00039 Function : edge() 00040 In : position array xdat, parameter list parlist, number of 00041 parameters in the list npar 00042 ndat: number of data elements 00043 The parameters are: 00044 parlist(0): pos1 00045 parlist(1): pos2 00046 parlist(2): intensity left 00047 parlist(3): intensity right 00048 Out : function value of a linear slope function 00049 that means a function with a constant intensity value for 00050 xdat values smaller than pos1, linear increasing between pos1 00051 and pos2, constant intensity value for 00052 xdat values greater than pos2 00053 Job : calculates the value of a slope function with parameters 00054 parlist at the position xdat 00055 ---------------------------------------------------------------------------*/ 00056 00057 float edge ( float * xdat, float * parlist/*, int * npar, int * ndat */) ; 00058 00059 /*---------------------------------------------------------------------------- 00060 Function : boltz() 00061 In : position array xdat, parameter list parlist 00062 The parameters are: 00063 parlist(0): background1 00064 parlist(1): background2 00065 parlist(2): central position 00066 parlist(3): width 00067 Out : function value of a Boltzmann function 00068 that is 00069 y = (parlist(0) - parlist(1)) / (1+exp((x-parlist(2))/parlist(3))) + parlist(1) 00070 Job : calculates the value of a Boltzmann function with parameters 00071 parlist at the position xdat 00072 ---------------------------------------------------------------------------*/ 00073 00074 float boltz ( float * xdat, float * parlist ) ; 00075 00076 /*---------------------------------------------------------------------------- 00077 Function : edge_deriv() 00078 In : position array xdat, parameter list parlist, number of 00079 parameters in the list npar 00080 The parameters are: 00081 parlist(0): pos1 00082 parlist(1): pos2 00083 parlist(2): intensity left 00084 parlist(3): intensity right 00085 derivative value of a hat function at position xdat: dervs 00086 dervs[0]: partial derivative by pos1 00087 dervs[1]: partial derivative by pos2 00088 dervs[2]: partial derivative by intensity left 00089 dervs[3]: partial derivative by intensity right 00090 Out : nothing, void 00091 Job : calculates the partial derivatives for a slope function with 00092 parameters parlist at position xdat 00093 ---------------------------------------------------------------------------*/ 00094 00095 void edge_deriv( float * xdat, float * parlist, float * dervs/*, int * npar */) ; 00096 00097 /*---------------------------------------------------------------------------- 00098 Function : boltz_deriv() 00099 In : position array xdat, parameter list parlist 00100 The parameters are: 00101 parlist(0): background1 00102 parlist(1): background2 00103 parlist(2): central position 00104 parlist(3): width 00105 derivative value of a Boltzmann function at position xdat: dervs 00106 dervs[0]: partial derivative by background1 00107 dervs[1]: partial derivative by background2 00108 dervs[2]: partial derivative by central position 00109 dervs[3]: partial derivative by the width 00110 Out : nothing, void 00111 Job : calculates the partial derivatives for a Boltzmann function with 00112 parameters parlist at position xdat 00113 ----------------------------------------------------------------------------*/ 00114 00115 void boltz_deriv( float * xdat, float * parlist, float * dervs ) ; 00116 00117 /*---------------------------------------------------------------------------- 00118 Function : lsqfit() 00119 In : xdat: position, coordinates of data points. 00120 xdat is 2 dimensional: XDAT ( XDIM, NDAT ) 00121 xdim: dimension of fit 00122 ydat: data points 00123 wdat: weights for data points 00124 ndat: number of data points 00125 fpar: on input contains initial estimates of the 00126 parameters for non-linear fits, on output the 00127 fitted parameters. 00128 epar: contains estimates of the errors in fitted parameters 00129 mpar: logical mask telling which parameters are free (non-zero) 00130 and which parameters are fixed (0) 00131 npar: number of function parameters ( free + fixed ) 00132 tol: relative tolerance. lsqfit stops when successive iterations 00133 fail to produce a decrement in reduced chi-squared less 00134 than tol. If tol is less than the minimum tolerance 00135 possible, tol will be set to this value. This means 00136 that maximum accuracy can be obtained by setting 00137 tol = 0.0. 00138 its: maximum number of iterations 00139 lab: mixing parameter, lab determines the initial weight 00140 of steepest descent method relative to the Taylor method 00141 lab should be a small value (i.e. 0.01). lab can only 00142 be zero when the partial derivatives are independent 00143 of the parameters. In fact in this case lab should be 00144 exactly equal to zero. 00145 Out : returns number of iterations needed to achieve convergence 00146 according to tol. When this number is negative, the fitting 00147 was not continued because a fatal error occurred: 00148 -1 too many free parameters, maximum is 32 00149 -2 no free parameters 00150 -3 not enough degrees of freedom 00151 -4 maximum number of iterations too small to obtain 00152 a solution which satisfies tol. 00153 -5 diagonal of matrix contains elements which are zero 00154 -6 determinant of the coefficient matrix is zero 00155 -7 square root of a negative number 00156 Job : this is a routine for making a least-squares fit of a 00157 function to a set of data points. The method used is 00158 described in: Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963). 00159 This method is a mixture of the steepest descent method 00160 and the Taylor method. 00161 ---------------------------------------------------------------------------*/ 00162 00163 int lsqfit ( float * xdat, 00164 int * xdim, 00165 float * ydat, 00166 float * wdat, 00167 int * ndat, 00168 float * fpar, 00169 float * epar, 00170 int * mpar, 00171 int * npar, 00172 float * tol , 00173 int * its , 00174 float * lab ) ; 00175 00176 /*---------------------------------------------------------------------------- 00177 Function : lsqfit_edge() 00178 In : xdat: position, coordinates of data points. 00179 xdat is 2 dimensional: XDAT ( XDIM, NDAT ) 00180 xdim: dimension of fit 00181 ydat: data points 00182 wdat: weights for data points 00183 ndat: number of data points 00184 fpar: on input contains initial estimates of the 00185 parameters for non-linear fits, on output the 00186 fitted parameters. 00187 epar: contains estimates of the errors in fitted parameters 00188 mpar: logical mask telling which parameters are free (non-zero) 00189 and which parameters are fixed (0) 00190 npar: number of function parameters ( free + fixed ) 00191 tol: relative tolerance. lsqfit stops when successive iterations 00192 fail to produce a decrement in reduced chi-squared less 00193 than tol. If tol is less than the minimum tolerance 00194 possible, tol will be set to this value. This means 00195 that maximum accuracy can be obtained by setting 00196 tol = 0.0. 00197 its: maximum number of iterations 00198 lab: mixing parameter, lab determines the initial weight 00199 of steepest descent method relative to the Taylor method 00200 lab should be a small value (i.e. 0.01). lab can only 00201 be zero when the partial derivatives are independent 00202 of the parameters. In fact in this case lab should be 00203 exactly equal to zero. 00204 Out : returns number of iterations needed to achieve convergence 00205 according to tol. When this number is negative, the fitting 00206 was not continued because a fatal error occurred: 00207 -1 too many free parameters, maximum is 32 00208 -2 no free parameters 00209 -3 not enough degrees of freedom 00210 -4 maximum number of iterations too small to obtain 00211 a solution which satisfies tol. 00212 -5 diagonal of matrix contains elements which are zero 00213 -6 determinant of the coefficient matrix is zero 00214 -7 square root of a negative number 00215 Job : this is a routine for making a least-squares fit of a 00216 function to a set of data points. The method used is 00217 described in: Marquardt, J.Soc.Ind.Appl.Math. 11. 431 (1963). 00218 This method is a mixture of the steepest descent method 00219 and the Taylor method. 00220 ---------------------------------------------------------------------------*/ 00221 00222 int lsqfit_edge ( float * xdat, 00223 int * xdim, 00224 float * ydat, 00225 float * wdat, 00226 int * ndat, 00227 float * fpar, 00228 float * epar, 00229 int * mpar, 00230 int * npar, 00231 float * tol , 00232 int * its , 00233 float * lab ) ; 00234 00235 /*---------------------------------------------------------------------------- 00236 Function : fitSlitsEdge() 00237 In : lineImage: emission line frame 00238 par: fit parameter data structure of fitted lines 00239 slit_pos: allocated dummy array for the slitlet positions [32][4] 00240 box_length: pixel length of the row box within the fit is done 00241 y_box: small box in spectral direction within the slitlet 00242 may lie. 00243 diff_tol: maximum tolerable difference of the resulting fit position 00244 with respect to the expected position. If difference is 00245 greater the expected position is taken. 00246 Out : slit_pos: beginning and end position of the slitlets to 00247 sub-pixel accuracy 00248 0 if it worked, 00249 -1 if there was no line image given, 00250 -2 if there were no line fit parameters given, 00251 -3 if there was no dummy array for the slit positions 00252 allocated 00253 -4 if the given box length is impossible 00254 -5 if the given y box length is impossible 00255 -6 if the given difference tolerance is too small 00256 -7 if there were no emission lines found in the first image columns 00257 -8 if not all slitlets could be found 00258 Job : fits the beginning and end position of the slitlets 00259 by using non-linear least square fitting of a hat function 00260 fits a step function to the slitlet edges exposed and indicated 00261 by the brightest emission lines. To achieve this, the fit 00262 parameters are used to find the brightest emission line 00263 and to get its position for each column. 00264 The least squares fit is done by using a box smaller than 00265 the size of two slitlets 00266 ---------------------------------------------------------------------------*/ 00267 /*<python>*/ 00268 int fitSlitsEdge( OneImage * lineImage, 00269 FitParams ** par, 00270 float ** slit_pos, 00271 int box_length, 00272 float y_box, 00273 float diff_tol ) ; 00274 /*</python>*/ 00275 00276 /*---------------------------------------------------------------------------- 00277 Function : fitSlitsBoltz() 00278 In : lineImage: emission line frame 00279 par: fit parameter data structure of fitted lines 00280 slit_pos: allocated dummy array for the slitlet positions [32][2] 00281 box_length: pixel length of the row box within the fit is done 00282 y_box: small box in spectral direction within the slitlet 00283 may lie. 00284 diff_tol: maximum tolerable difference of the resulting fit position 00285 with respect to the expected position. If difference is 00286 greater the expected position is taken. 00287 Out : slit_pos: beginning and end position of the slitlets to 00288 sub-pixel accuracy 00289 0 if it worked, 00290 -1 if there was no line image given, 00291 -2 if there were no line fit parameters given, 00292 -3 if there was no dummy array for the slit positions 00293 allocated 00294 -4 if the given box length is impossible 00295 -5 if the given y box length is impossible 00296 -6 if the given difference tolerance is too small 00297 -7 if there were no emission lines found in the first image columns 00298 -8 if not all slitlets could be found 00299 Job : fits the beginning and end position of the slitlets 00300 by using non-linear least square fitting of a Boltzmann function 00301 fits a Boltzmann function to the slitlet edges exposed and indicated 00302 by the brightest emission lines. To achieve this, the fit 00303 parameters are used to find the brightest emission line 00304 and to get its position for each column. 00305 The least squares fit is done by using a box smaller than 00306 the size of two slitlets 00307 ---------------------------------------------------------------------------*/ 00308 00309 /*<python>*/ 00310 int fitSlitsBoltz( OneImage * lineImage, 00311 FitParams ** par, 00312 float ** slit_pos, 00313 int box_length, 00314 float y_box, 00315 float diff_tol ) ; 00316 /*</python>*/ 00317 00318 /*---------------------------------------------------------------------------- 00319 Function : fitSlitsBoltzSingleLine() 00320 In : lineImage: emission line frame 00321 slit_pos: allocated dummy array for the slitlet positions [32][2] 00322 box_length: pixel length of the row box within the fit is done 00323 y_box: small box in spectral direction within the slitlet 00324 may lie. 00325 low_pos, high_pos: pixel positions in spectral direction between which the line 00326 should be located. 00327 Out : slit_pos: beginning and end position of the slitlets to 00328 sub-pixel accuracy 00329 0 if it worked, 00330 -1 if it failed, 00331 Job : fits the beginning and end position of the slitlets 00332 by using non-linear least square fitting of a Boltzmann function 00333 fits a Boltzmann function to the slitlet edges exposed and indicated 00334 by the brightest emission lines. The slitlet is searched within 00335 user given positions. 00336 The least squares fit is done by using a box smaller than 00337 the size of two slitlets 00338 ---------------------------------------------------------------------------*/ 00339 00340 int fitSlitsBoltzSingleLine ( OneImage * lineImage, 00341 float ** slit_pos, 00342 int box_length, 00343 float y_box, 00344 int low_pos, 00345 int high_pos ) ; 00346 00347 00348 /*---------------------------------------------------------------------------- 00349 Function : fitSlitsBoltzWithEstimate() 00350 In : lineImage: emission line frame 00351 slit_pos: estimation array for the slitlet positions [min32][2] 00352 box_length: pixel length of the row box within the fit is done 00353 y_box: small box in spectral direction within the slitlet 00354 may lie. 00355 low_pos, high_pos: pixel positions in spectral direction between which the line 00356 should be located. 00357 Out : slit_pos: beginning and end position of the slitlets to 00358 sub-pixel accuracy 00359 0 if it worked, 00360 -1 if it failed, 00361 Job : fits the beginning and end position of the slitlets 00362 by using non-linear least square fitting of a Boltzmann function 00363 fits a Boltzmann function to the slitlet edges exposed and indicated 00364 by the brightest emission lines. The slitlet is searched within 00365 user given positions. 00366 The least squares fit is done by using a box smaller than 00367 the size of two slitlets 00368 ---------------------------------------------------------------------------*/ 00369 00370 /*<python>*/ 00371 int fitSlitsBoltzWithEstimate ( OneImage * lineImage, 00372 float ** slit_pos, 00373 int box_length, 00374 float y_box, 00375 float diff_tol, 00376 int low_pos, 00377 int high_pos ) ; 00378 /*</python>*/ 00379 00380 /*---------------------------------------------------------------------------- 00381 Function : fitSlitsEdgeWithEstimate() 00382 In : lineImage: emission line frame 00383 slit_pos: estimation array for the slitlet positions [min32][2] 00384 box_length: pixel length of the row box within the fit is done 00385 y_box: small box in spectral direction within the slitlet 00386 may lie. 00387 low_pos, high_pos: pixel positions in spectral direction between which the line 00388 should be located. 00389 Out : slit_pos: beginning and end position of the slitlets to 00390 sub-pixel accuracy 00391 0 if it worked, 00392 -1 if it failed, 00393 Job : fits the beginning and end position of the slitlets 00394 by using non-linear least square fitting of an edge function 00395 fits a linear edge function to the slitlet edges exposed and indicated 00396 by the brightest emission lines. The slitlet is searched within 00397 user given positions. 00398 The least squares fit is done by using a box smaller than 00399 the size of two slitlets 00400 ---------------------------------------------------------------------------*/ 00401 00402 /*<python>*/ 00403 int fitSlitsEdgeWithEstimate ( OneImage * lineImage, 00404 float ** slit_pos, 00405 int box_length, 00406 float y_box, 00407 float diff_tol, 00408 int low_pos, 00409 int high_pos ) ; 00410 /*</python>*/ 00411 00412 00413 #endif 00415 /*--------------------------------------------------------------------------*/
1.2.13.1 written by Dimitri van Heesch,
© 1997-2001