next up previous
Next: Simulating Data Up: XIMGFIT v0.999 Manual Previous: Derivative Functions

Guess Function (optional)

2-D image fitting is very sensitive to the choice of initial parameters. Accordingly, it would be nice to automate the step of guessing initial parameters. This can be added by defining the function Guess. Most models will have the parameters centroid x, y, characteristic length scales, and a rotation. Note that while most models describe the length scales as being in the x and y directions, in reality with rotation being a parameters, these designations become arbitrary and in essence the parameters are defined for the major and minor axes. In order to facilitate guesses for these parameters, the moments of the data image are computed:
$\displaystyle Sum = \sum I(x,y)$     (1)
$\displaystyle x_{com} = \sum I(x,y)*x/Sum$     (2)
$\displaystyle y_{com} = \sum I(x,y)*y/Sum$     (3)
$\displaystyle xx = \sum I(x,y)*x*x/Sum$     (4)
$\displaystyle xy = \sum I(x,y)*x*y/Sum$     (5)
$\displaystyle yy = \sum I(x,y)*y*y/Sum$     (6)

Rather than supply the Guess function with $xx$, $yy$, and $xy$, the matrix [[$xx$, $xy$], [$xy$, $yy$]] is diagonalized, and the eigenvalues and the rotation of the eigenvectors are computed. As an example, the Guess function in the case of Gaussian model is:
    def Guess(self, dataimg, x, y, sum, xcom, ycom, xaxis, yaxis, rot):
        # Get current params
        xc = self.params[0].value
        yc = self.params[1].value
        norm = self.params[2].value
        sigmax = self.params[3].value
        sigmay = self.params[4].value
        theta = self.params[5].value
        if norm == 0.:
            norm = 1.
            self.params[2].value = norm
            
        # Renormalize
        norm = self.Total(x, y)/sum

        # Set xc, yc to center-of-mass values
        xc = xcom
        yc = ycom

        # xaxis and yaxis are already sigma params
        sigmax = xaxis
        sigmay = yaxis

        theta = rot

        # Save new params
        self.params[0].value = xc
        self.params[1].value = yc
        self.params[2].value = norm
        self.params[3].value = sigmax
        self.params[4].value = sigmay
        self.params[5].value = theta

        return
The function Total returns the integral (i.e., sum over x, y) of the model.
next up previous
Next: Simulating Data Up: XIMGFIT v0.999 Manual Previous: Derivative Functions
Andrew Ptak 2001-10-11