:py:mod:`aces.beamset.airyfitter` ================================= .. py:module:: aces.beamset.airyfitter .. autoapi-nested-parse:: =========== airyfitter =========== .. codeauthor:: Dvid McConnell Derived from gaussfitter by Adam Ginsburg 3/17/08 Latest version available at , where it was moved from google code on January 30, 2014 Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: aces.beamset.airyfitter.moments aces.beamset.airyfitter.airy aces.beamset.airyfitter.airy_sq aces.beamset.airyfitter.twodairy aces.beamset.airyfitter.airyfit .. py:function:: moments(data, circle, rotate, vheight, estimator=median, angle_guess=45.0, **kwargs) 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 .. py:function:: airy(x) .. py:function:: airy_sq(x) .. py:function:: twodairy(inpars, circle=False, rotate=True, vheight=True, shape=None) 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 ---------- circle : bool default is an elliptical airy (different x, y widths), but can reduce the input by one parameter if it's a circular airy pattern rotate : bool default allows rotation of the pattern ellipse. Can remove last parameter by setting rotate=0 vheight : bool default allows a variable height-above-zero, i.e. an additive constant for the function. Can remove first parameter by setting this to 0 shape : tuple if shape is set (to a 2-parameter list) then returns an image with the airy pattern defined by inpars .. py:function:: 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) Airy pattern fitter with the ability to fit a variety of different forms of 2-dimensional airy pattern. Parameters ---------- data : `numpy.ndarray` 2-dimensional data array err : `numpy.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 autoderiv : bool 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_error : bool Default is to return only the airy parameters. If ``True``, return fit params & fit error returnfitimage : bool returns (best fit params,best fit image) returnmp : bool returns the full mpfit struct circle : bool 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. rotate : bool Allow rotation of the ellipse. Can remove last parameter of input & fit by setting rotate=False. Angle should be specified in degrees. vheight : bool 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`` usemoment : `numpy.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 fitimage : `numpy.ndarray` If returnfitimage==True, the last return will be a 2D array holding the best-fit model mpfit : `mpfit` 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`.