Next: Derivative Functions
Up: Adding Models
Previous: Defining Parameters
Next, the model itself needs to be defined, following the line
def Eval(self, x, y). ``self'' is where information for the model
is stored. From the Gaussian mode, the fit parameter values are extracted
into variables, for clarity:
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
You can now manipulate these variables as a function of x, y using the usual
relations (+, -, *, /), raising to a power with **, and the usual
trigonometric and log functions. Note that these functions need to be
listed on the ``from Numeric import `` line at the top of the file. For
example, if Gaussian had needed the log function, that line should read:
from Numeric import pi, cos, sin, exp, log. For a complete list of
functions available, see http://xfiles.llnl.gov/NumDoc4.html#pgfId=36127.
The remainder of the Gaussian function is then:
cost = cos(theta/radeg)
sint = sin(theta/radeg)
dx = x-xc
dy = y-yc
rx = dx*cost + dy*sint
ry = -dx*sint + dy*cost
z2 = rx*rx/(sigmax*sigmax)+ry*ry/(sigmay*sigmay)
return(norm*exp(-z2/2))
Hopefully, this is clear enough for any well-behaved function. At a lower
level, the variables x and y contain images where each pixel is the offset
from the center of the image in arcseconds. The basically means that each
statement involving x or y (or a variable derived from them as in dx, dy
above) are computing values for the entire image. This is the main reason
that ximgfit would probably not be much fast if it were written entirely in
C or Fortran... the typical image will have thousands to tens of thousands
of pixels, and the calculations for these pixels
are occurring in compiled C code. The return statement returns the final
model image, and as shown above can contain a final calculation step.
Note that conditionals are possible but
the user would probably be better off emulating the same effect with
exponential cut-offs. In addition to being easier to code, the partial
derivative functions would be better behaved.
Next: Derivative Functions
Up: Adding Models
Previous: Defining Parameters
Andrew Ptak
2001-10-11