Next: Simulating Data
Up: XIMGFIT v0.999 Manual
Previous: Derivative Functions
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:
Rather than supply the Guess function with
,
, and
, the matrix
[[
,
], [
,
]] 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: Simulating Data
Up: XIMGFIT v0.999 Manual
Previous: Derivative Functions
Andrew Ptak
2001-10-11