• atObjectCenterFind_Ptr
  • atEllipseFind
  • atDACentroid
  • atCentroid

      Gunn's routines to calculate centroids
      With Heidi's enhancements to calculate widths
    
    
    
    

    atObjectCenterFind_Ptr

     This is atObjectCenterFind unpacked for the DA system (i.e. no REGION)
    
    SIGNATURE:
      int
      atObjectCenterFind_Ptr(const U16 **rows, /* data */
      		      int nrow, int ncol, /* size of data array */
      		      int x0, int y0,	/* initial estimate of centre */
      					/* x is col, and y is row */
      		      int sky,		/* level of background */
      		      float sigma,	/* sigma of Gaussian to smooth image
      					   with (ignore if <= 0) */
      		      float dark_variance, /* variance of the background */
      		      float gain,	/* gain of amplifiers */
      		      float *xc, float *yc, /* center of image */
      		      float *dxc, float *dyc, /* errors in xc, yc */
      		      float *peak,	/* peak value */
      		      float *sigsqx, float *sigsqy, 
      		      float *sigsqp, float *sigsqm)
      				/* estimates of the width^2 of the 
      				convolved object along the lines
      				y=0, x=0, y=x, and y=-x */
    

    atEllipseFind

    DESCRIPTION:
    
    This routine finds the position angle and sigmas in the major and minor axis directions of a bivariate Gaussian fit to the center of the image. These quantities are calculated as follows:

    First look at a Gaussian that is rotated but centered on x=0, y=0. It has equation:

    G(x,y) = A exp { -x'^2/(2 a^2) - y'^2/(2 b^2) }, where x' = x cos(pa) + y sin(pa), y' = - x sin(pa) + y cos(pa), and a and b are the sigmas in the directions of the major and minor axes.

    Let's look at the cross section y=0. There,

    G(x,0) = A exp { -x^2/(2 sigx^2) } where 1/sigx^2) = ( cos(pa)/a )^2 + ( sin(pa)/b )^2. We can write a similar equation for x=0: 1/sigy^2) = ( sin(pa)/a )^2 + ( cos(pa)/b )^2.

    To get the sigmas in the y=x and y=-x directions, we must parameterize so that arc length will be preserved. We use y=t/sqrt(2) and x=t/sqrt(2) for the y=x case. Plugging in this parameterization, we find

    1/sigp^2) = (1 + 2 sin(pa) cos(pa))/(2 a^2) (1 - 2 sin(pa) cos(pa))/(2 b^2) Similarly for y=-x: 1/sigm^2) = (1 - 2 sin(pa) cos(pa))/(2 a^2) (1 + 2 sin(pa) cos(pa))/(2 b^2)

    Now we comput the quantites:

    1/sigy^2 - 1/sigx^2 = cos(2 pa) ( - 1/a^2 + 1/b^2) and 1/sigp^2 - 1/sigm^2 = sin(2 pa) (1/a^2 - 1/b^2)

    It is easy to see from the previous two equations that:

    tan(2 pa) = { - (1/sigp^2 - 1/sigm^2) / ( 1/sigy^2 - 1/sigx^2) } To get pa in the right quadrant, use: 2 pa = atan2 { - 1/sigp^2 + 1/sigm^2, 1/sigy^2 - 1/sigx^2 }

    We can then invert the linear equations for the sigmas to find a and b. If sin(pa)^2 < cos(pa)^2, then use the sigx, sigy numbers to calculate a and b. Otherwise, use sigp and sigm.

    RETURNS:

    <0> OK <-10> Zero sigma - peak and counts not calculated <-11> Infinite sigma
    SIGNATURE:
      int atEllipseFind(
        float sigsqx, float sigsqy, float sigsqp, float sigsqm, float sigma,
        float convpeak, float *siga, float *sigb, float *pa, float *peak, float *counts)
    

    atDACentroid

    DESCRIPTION:
    
    RETURNS:
    <listing>
    	<0>	OK
    	<-1>	center isn't locally highest pixel in atObjectCenterFind_Ptr
    	<-2>	object is too close to the edge in atObjectCenterFind_Ptr
    	<-3>	object has vanishing second derivative in atObjectCenterFind_Ptr
    	<-4>	sky is too high in atObjectCenterFind_Ptr
    	<-10>	Zero sigma - peak and counts not calculated after atObjectCenterFind_Ptr
    	<-11>	Infinite sigma after atObjectCenterFind_Ptr
    	<-21>	Error in setfsigma (sigma too large) in atSigmaFind
    	<-22>	Sigma out of range (inf sharp or inf flat) in atSigmaFind
    	<-23>	Too many iterations in atSigmaFind
    	<-24>	Too close to edge in atSigmaFind
    	<-25>	Error in lgausmom - check sky value in atSigmaFind
    	<-26>	Too flat in atFindFocMom, from atSigmaFind
    	<-30>	Zero sigma - peak and counts not calculated after atSigmaFind
    	<-31>	Infinite sigma after atSigmaFind
    </listing>
    
    </HTML>
    
    SIGNATURE:
      int atDACentroid( const U16 **rows, /* data */
      		      int nrow, int ncol, /* size of data array */
      		      int row0, int col0,/* initial estimate of centre */
      		      int sky,		/* level of background */
      		      float sigma,	/* sigma of Gaussian to smooth image
      					   with (ignore if <= 0) */
      		      float dark_variance, /* variance of the background */
      		      float gain,	/* gain of amplifiers */
      		      float *rowc, float *colc, /* center of image */
      		      float *drowc, float *dcolc, /* errors in rowc, colc */
      		      float *peak,	/* peak value */
      		      float *counts, float *siga, 
      		      float *sigb, float *pa)