ecpi.common.num.gaussian_tools module
Section author: ECLAIRs GP team
Generic functions to generate and fit gaussians based on ‘CodedMaskImage.py’ python program of Cyril Lachaud modfied from http://scipy-cookbook.readthedocs.io/items/FittingData.html
Summary
Functions:
fit the 2D distribution with 2D gaussian function |
|
Returns a gaussian function + offset with the given parameters |
|
Returns a gaussian function with the given parameters |
|
Returns a gaussian function + offset with the given parameters |
|
Returns a gaussian function with the given parameters |
|
Returns a gaussian function + offset with the given parameters |
|
Returns a gaussian function with the given parameters |
|
Returns a gaussian function + offset with the given parameters |
|
Guess the gaussian parameters of a distribution |
Reference
- fit_gaussian_2d(data, fit_method, fit_sigma, verbose=False)[source]
fit the 2D distribution with 2D gaussian function
The fit success parameter is the parameter returned by the optimize.leastsq function.
Returns (height, x, y, sigma_x, sigma_y), the gaussian parameters of a 2D distribution found by a fit.
error is computed based on the covariance matrix.
- Parameters
data (2D array) – 2D distribution to fit
fit_method (string) – fit method to be used: ‘gaussian_2d_fixedwidth’, ‘gaussian_2d_1width’ or ‘gaussian_2d_2width’
fit_sigma (float>0) – standard deviation of the gaussian fit_function. Default is 1.555.
verbose (bool) – verbosity parameter. Default=False
- Returns
success_flag, fitparameters (height, x, y, sigma_x, sigma_y), error (=0 if success=0)
- Return type
bool, (floats), float
- gaussian_1d(height, center, sigma)[source]
Returns a gaussian function + offset with the given parameters
- Parameters
height (float) – height of the gaussian function
center (float) – center of the gaussian function
sigma (float) – sigma of the gaussian function
- gaussian_2d_1width(height, center_x, center_y, sigma)[source]
Returns a gaussian function with the given parameters
sigma is the same for x and y direction.
- Parameters
height (float) – height of the gaussian function
center_x (float) – center in x of the gaussian function
center_y (float) – center in y of the gaussian function
sigma (float) – sigma of the gaussian function
- Returns
gaussian function with the given parameters
- Return type
lambda function
- gaussian_2d_1width_offset(height, center_x, center_y, sigma, offset)[source]
Returns a gaussian function + offset with the given parameters
sigma is the same for x and y direction.
- Parameters
height (float) – height of the gaussian function
center_x (float) – center in x of the gaussian function
center_y (float) – center in y of the gaussian function
sigma (float) – sigma of the gaussian function
offset – offset of the gaussian function
:type offset float
- Returns
gaussian function with the given parameters
- Return type
lambda function
- gaussian_2d_2width(height, center_x, center_y, sigma_x, sigma_y)[source]
Returns a gaussian function with the given parameters
- Parameters
height (float) – height of the gaussian function
center_x (float) – center in x of the gaussian function
center_y (float) – center in y of the gaussian function
sigma_x (float) – sigma in x of the gaussian function
sigma_x – sigma in y of the gaussian function
- Returns
gaussian function with the given parameters
- Return type
lambda function
- gaussian_2d_2width_offset(height, center_x, center_y, sigma_x, sigma_y, offset)[source]
Returns a gaussian function + offset with the given parameters
- Parameters
height (float) – height of the gaussian function
center_x (float) – center in x of the gaussian function
center_y (float) – center in y of the gaussian function
sigma_x (float) – sigma in x of the gaussian function
sigma_x – sigma in y of the gaussian function
offset – offset of the gaussian function
:type offset float
- Returns
gaussian function with the given parameters
- Return type
lambda function
- gaussian_2d_fixedwidth(height, center_x, center_y)[source]
Returns a gaussian function with the given parameters
sigma is unique and fixed.
FWHM_fit = FWHM_PSF = sqrt(m**2+d**2) (=sqrt(m**2+1) en pixel) m = mask element d = detector pitch sigma = sqrt(m**2+1)/2.3548 (with m=2.53) sigma = 1.155 pixel
- Parameters
height (float) – height of the gaussian function
center_x (float) – center in x of the gaussian function
center_y (float) – center in y of the gaussian function
- Returns
gaussian function with the given parameters
- Return type
lambda function
- gaussian_2d_fixedwidth_offset(height, center_x, center_y, offset)[source]
Returns a gaussian function + offset with the given parameters
sigma is unique and fixed.
FWHM_fit = FWHM_PSF = sqrt(m**2+d**2) (=sqrt(m**2+1) en pixel) m = mask element d = detector pitch sigma = sqrt(m**2+1)/2.3548 (with m=2.53) sigma = 1.155 pixel
- Parameters
height (float) – height of the gaussian function
center_x (float) – center in x of the gaussian function
center_y (float) – center in y of the gaussian function
offset – offset of the gaussian function
:type offset float
- Returns
gaussian function with the given parameters
- Return type
lambda function
- gaussian_2d_moments(data, fit_method, fit_sigma)[source]
Guess the gaussian parameters of a distribution
Use for initial fitting parameters
the gaussian parameters of a 2D distribution by calculating its moments
Modified from : http://scipy-cookbook.readthedocs.io/items/FittingData.html
- Parameters
data (float 2D-array) – 2D distribution to evaluate
fit_method (string) – fit method that will be used: ‘gaussian_2d_fixedwidth’, ‘gaussian_2d_1width’ or ‘gaussian_2d_2width’
fit_sigma (float>0) – standard deviation of the gaussian fit_function. Default is 1.555.
- Returns
(height, x, y), (height, x, y, sigma_x, sigma_y) or (height, x, y, sigma) depending on fit_method
- Return type
floats (number of which depend on the fit_method)