aces.beamset.gaussfitter¶
Latest version available at <https://github.com/keflavich/gaussfitter>, where it was moved from google code on January 30, 2014
Module Contents¶
Functions¶
|
Returns (height, amplitude, x, y, width_x, width_y, rotation angle) |
|
Returns a 2d gaussian function of the form: |
|
Gaussian fitter with the ability to fit a variety of different forms of |
- aces.beamset.gaussfitter.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 gaussian parameters of a 2D distribution 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.gaussfitter.twodgaussian(inpars, circle=False, rotate=True, vheight=True, shape=None)[source]¶
Returns a 2d gaussian function of the form: .. code-bloke:: python
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 * np.exp ( - ( ((x-center_x)/width_x)**2 + ((y-center_y)/width_y)**2 ) / 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 ———- circle : bool
default is an elliptical gaussian (different x, y widths), but can reduce the input by one parameter if it’s a circular gaussian
- rotatebool
default allows rotation of the gaussian ellipse. Can remove last parameter by setting rotate=0
- vheightbool
default allows a variable height-above-zero, i.e. an additive constant for the Gaussian 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 gaussian defined by inpars
- aces.beamset.gaussfitter.gaussfit(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]¶
Gaussian fitter with the ability to fit a variety of different forms of 2-dimensional gaussian. Parameters ———- data : numpy.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 Gaussian function. 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 Gaussian 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 gaussian (different x, y widths), but the input is reduced by one parameter if it’s a circular gaussian.
- rotatebool
Allow rotation of the gaussian 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 Gaussian 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 Gaussian 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==Truereturns 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.