aces.beamset.airyfitter

Derived from gaussfitter by Adam Ginsburg <adam.g.ginsburg@gmail.com> 3/17/08 Latest version available at <https://github.com/keflavich/gaussfitter>, where it was moved from google code on January 30, 2014

Module Contents

Functions

moments(data, circle, rotate, vheight[, estimator, ...])

Returns (height, amplitude, x, y, width_x, width_y, rotation angle)

airy(x)

airy_sq(x)

twodairy(inpars[, circle, rotate, vheight, shape])

Returns a 2d airy pattern of the form:

airyfit(data[, err, params, autoderiv, return_error, ...])

Airy pattern fitter with the ability to fit a variety of different forms of

aces.beamset.airyfitter.moments(data, circle, rotate, vheight, estimator=median, angle_guess=45.0, **kwargs)[source]

Returns (height, amplitude, x, y, width_x, width_y, rotation angle) the parameters of a 2D airy pattern by calculating its moments. Depending on the input parameters, will only output a subset of the above. If using masked arrays, pass estimator=np.ma.median

aces.beamset.airyfitter.airy(x)[source]
aces.beamset.airyfitter.airy_sq(x)[source]
aces.beamset.airyfitter.twodairy(inpars, circle=False, rotate=True, vheight=True, shape=None)[source]

Returns a 2d airy pattern of the form: x’ = np.cos(rota) * x - np.sin(rota) * y y’ = np.sin(rota) * x + np.cos(rota) * y (rota should be in degrees) g = b + a * airy (sqrt((x’ - xc)/xw)**2 + ((y’ - yc)/yw)**2 )) inpars = [b,a,center_x,center_y,width_x,width_y,rota] (b is background height, a is peak amplitude) where x and y are the input parameters of the returned function, and all other parameters are specified by this function However, the above values are passed by list. The list should be: inpars = (height,amplitude,center_x,center_y,width_x,width_y,rota) You can choose to ignore / neglect some of the above input parameters using the following options:

Parameters

circlebool

default is an elliptical airy (different x, y widths), but can reduce the input by one parameter if it’s a circular airy pattern

rotatebool

default allows rotation of the pattern ellipse. Can remove last parameter by setting rotate=0

vheightbool

default allows a variable height-above-zero, i.e. an additive constant for the function. Can remove first parameter by setting this to 0

shapetuple

if shape is set (to a 2-parameter list) then returns an image with the airy pattern defined by inpars

aces.beamset.airyfitter.airyfit(data, err=None, params=(), autoderiv=True, return_error=False, circle=False, fixed=np.repeat(False, 7), limitedmin=[False, False, False, False, True, True, True], limitedmax=[False, False, False, False, False, False, True], usemoment=np.array([], dtype='bool'), minpars=np.repeat(0, 7), maxpars=[0, 0, 0, 0, 0, 0, 180], rotate=True, vheight=True, quiet=True, returnmp=False, returnfitimage=False, **kwargs)[source]

Airy pattern fitter with the ability to fit a variety of different forms of 2-dimensional airy pattern.

Parameters

datanumpy.ndarray

2-dimensional data array

errnumpy.ndarray or None

error array with same size as data array. Defaults to 1 everywhere.

params(height, amplitude, x, y, width_x, width_y, rota)

Initial input parameters for airy pattern. If not input, these will be determined from the moments of the system, assuming no rotation

autoderivbool

Use the autoderiv provided in the lmder.f function (the alternative is to us an analytic derivative with lmdif.f: this method is less robust)

return_errorbool

Default is to return only the airy parameters. If True, return fit params & fit error

returnfitimagebool

returns (best fit params,best fit image)

returnmpbool

returns the full mpfit struct

circlebool

The default is to fit an elliptical airy pattern (different x, y widths), but the input is reduced by one parameter if it’s a circular pattern.

rotatebool

Allow rotation of the ellipse. Can remove last parameter of input & fit by setting rotate=False. Angle should be specified in degrees.

vheightbool

Allows a variable height-above-zero, i.e. an additive constant background for the function. Can remove the first fitter parameter by setting this to False

usemomentnumpy.ndarray, dtype=’bool’

Array to choose which parameters to use a moment estimation for. Other parameters will be taken from params.

Returns

(params, [parerr], [fitimage]) | (mpfit, [fitimage]) parameters : list

The default output is a set of parameters with the same shape as the input parameters

fitimagenumpy.ndarray

If returnfitimage==True, the last return will be a 2D array holding the best-fit model

mpfitmpfit object

If returnmp==True returns a mpfit object. This object contains a covar attribute which is the 7x7 covariance array generated by the mpfit class in the mpfit_custom.py module. It contains a param attribute that contains a list of the best fit parameters in the same order as the optional input parameter params.