idlastro / DAOPHOT-Type Photometry Procedures: CNTRD

[Source code]

NAME
CNTRD
PURPOSE
Compute the centroid  of a star using a derivative search 
XPLANATION
CNTRD uses an early DAOPHOT "FIND" centroid algorithm by locating the 
position where the X and Y derivatives go to zero.   This is usually a 
more "robust"  determination than a "center of mass" or fitting a 2d 
Gaussian  if the wings in one direction are affected by the presence
of a neighboring star.
CALLING SEQUENCE
CNTRD, img, x, y, xcen, ycen, [ fwhm , /KEEPCENTER, /SILENT, /DEBUG
                                EXTENDBOX = ]
INPUTS
IMG - Two dimensional image array
X,Y - Scalar or vector integers giving approximate integer stellar 
      center
OPTIONAL INPUT
FWHM - floating scalar; Centroid is computed using a box of half
        width equal to 1.5 sigma = 0.637* FWHM.  CNTRD will prompt
        for FWHM if not supplied
OUTPUTS
XCEN - the computed X centroid position, same number of points as X
YCEN - computed Y centroid position, same number of points as Y, 
       floating point
Values for XCEN and YCEN will not be computed if the computed
centroid falls outside of the box, or if the computed derivatives
are non-decreasing.   If the centroid cannot be computed, then a 
message is displayed and XCEN and YCEN are set to -1.
OPTIONAL OUTPUT KEYWORDS
/SILENT - Normally CNTRD prints an error message if it is unable
        to compute the centroid.   Set /SILENT to suppress this.
/DEBUG - If this keyword is set, then CNTRD will display the subarray
        it is using to compute the centroid.
EXTENDBOX = {non-negative positive integer}.   CNTRD searches a box with
       a half width equal to 1.5 sigma  = 0.637* FWHM to find the 
       maximum pixel.    To search a larger area, set EXTENDBOX to 
       the number of pixels to enlarge the half-width of the box.
       Default is 0; prior to June 2004, the default was EXTENDBOX= 3
/KeepCenter = By default, CNTRD finds the maximum pixel in a box 
       centered on the input X,Y coordinates, and then extracts a new
       box about this maximum pixel.   Set the /KeepCenter keyword  
       to skip then step of finding the maximum pixel, and instead use
       a box centered on the input X,Y coordinates.                          
PROCEDURE
Maximum pixel within distance from input pixel X, Y  determined 
from FHWM is found and used as the center of a square, within 
which the centroid is computed as the value (XCEN,YCEN) at which 
the derivatives of the partial sums of the input image over (y,x)
with respect to (x,y) = 0.    In order to minimize contamination from
neighboring stars stars, a weighting factor W is defined as unity in 
center, 0.5 at end, and linear in between 
RESTRICTIONS
(1) Does not recognize (bad) pixels.   Use the procedure GCNTRD.PRO
    in this situation. 
(2) DAOPHOT now uses a newer algorithm (implemented in GCNTRD.PRO) in 
    which centroids are determined by fitting 1-d Gaussians to the 
    marginal distributions in the X and Y directions.
(3) The default behavior of CNTRD changed in June 2004 (from EXTENDBOX=3
    to EXTENDBOX = 0).
(4) Stone (1989, AJ, 97, 1227) concludes that the derivative search
    algorithm in CNTRD is not as effective (though faster) as a 
     Gaussian fit (used in GCNTRD.PRO).
MODIFICATION HISTORY
Written 2/25/86, by J. K. Hill, S.A.S.C., following
algorithm used by P. Stetson in DAOPHOT.
Allowed input vectors        G. Hennessy       April,  1992
Fixed to prevent wrong answer if floating pt. X & Y supplied
        W. Landsman        March, 1993
Convert byte, integer subimages to float  W. Landsman  May 1995
Converted to IDL V5.0   W. Landsman   September 1997
Better checking of edge of frame David Hogg October 2000
Avoid integer wraparound for unsigned arrays W.Landsman January 2001
Handle case where more than 1 pixel has maximum value W.L. July 2002
Added /KEEPCENTER, EXTENDBOX (with default = 0) keywords WL June 2004
Some errrors were returning X,Y = NaN rather than -1,-1  WL Aug 2010
turn to caller
tatype
Compute size of box needed to compute centroid
dth of box to be used to compute centroid
tend box 3 pixels on each side to search for max pixel value
ntral X pixel ;Added 3/93
ntral Y pixel
op over X,Y vector
Locate maximum pixel in 'NBIG' sized subimage
ximum pixel value in BIGBOX
w many pixels have maximum value?
coordinate of Max pixel
coordinate of Max pixel
re than 1 pixel at maximum?
coordinate in original image array
coordinate in original image array
--------------------------------------------------------------------
heck *new* center location for range
dded by Hogg
--------------------------------------------------------------------
Extract smaller 'STRBOX' sized subimage centered on maximum pixel
eighting factor W unity in center, 0.5 at end, and linear in between
ind X centroid
ift in X & subtract to get derivative
n't want edges of the array
m X derivatives over Y direction
ject if X derivative not decreasing
ject if centroid outside box
centroid in original array
Find Y Centroid
ject if Y derivative not decreasing
ject if computed Y centroid outside box