amep.functions.Gaussian2d#
- class amep.functions.Gaussian2d#
Bases:
BaseFunction
Two-dimensional Gaussian.
- __init__()#
Two-dimensional Gaussian function.
- Return type:
None.
Examples
>>> import amep >>> import numpy as np >>> x = np.linspace(-10, 10, 500) >>> y = np.linspace(-10, 10, 500) >>> X,Y = np.meshgrid(x,y) >>> g2d = amep.functions.Gaussian2d() >>> Z = g2d.generate( ... amep.utils.mesh_to_coords(X,Y), ... p=[1,0,0,2,5,np.pi/3] ... ).reshape(X.shape) >>> fig, axs = amep.plot.new(figsize=(3,3)) >>> amep.plot.field(axs, Z, X, Y) >>> axs.set_xlabel(r'$x$') >>> axs.set_ylabel(r'$y$') >>> fig.savefig('./figures/functions/functions-Gaussian2d.png')
Methods
__init__
()Two-dimensional Gaussian function.
f
(p, x)2D Gaussian.
fit
(xdata, ydata[, p0, sigma, maxit, verbose])Fits the function self.f to the given data by using ODR (orthogonal distance regression).
generate
(x[, p])Returns the y values for given x values.
Attributes
Returns the fit errors for each parameter as an array.
keys
mean
name
nparams
output
Returns an array of the optimal fit parameters.
Returns the dictionary of fit results including parameter names, parameter values, and fit errors.
std
- property errors: ndarray#
Returns the fit errors for each parameter as an array.
- Returns:
Fit errors.
- Return type:
np.ndarray
- f(p, x)#
2D Gaussian.
- Parameters:
p (list) – Parameters.
x (np.ndarray) – x-values as 2d array of shape (N,2).
- Returns:
1D array of shape (N,).
- Return type:
np.ndarray
Examples
>>>
- fit(xdata: ndarray, ydata: ndarray, p0: list | None = None, sigma: ndarray | None = None, maxit: int | None = None, verbose: bool = False) None #
Fits the function self.f to the given data by using ODR (orthogonal distance regression).
- Parameters:
xdata (np.ndarray) – x values.
ydata (np.ndarray) – y values.
p0 (list or None, optional) – List of initial values. The default is None.
sigma (np.ndarray or None, optional) – Absolute error for each data point. The default is None.
maxit (int, optional) – Maximum number of iterations. The default is 200.
verbose (bool, optional) – If True, the main results are printed. The default is False.
- Return type:
None.
- generate(x: ndarray, p: list | None = None) ndarray #
Returns the y values for given x values.
- Parameters:
x (np.ndarray) – x values.
p (list, optional) – List of parameters. The default is None.
- Returns:
y – f(x)
- Return type:
np.ndarray
- property params: ndarray#
Returns an array of the optimal fit parameters.
- Returns:
Fit parameter values.
- Return type:
np.ndarray
- property results: dict#
Returns the dictionary of fit results including parameter names, parameter values, and fit errors.
- Returns:
Fit results.
- Return type:
dict