neutronpy.functions.gaussian¶
-
neutronpy.functions.
gaussian
(p, q)[source]¶ Returns an arbitrary number of Gaussian profiles.
Parameters: - p : ndarray
Parameters for the Gaussian, in the following format:
p[0] Constant background p[1] Linear background slope p[2] Area under the first peak p[3] Position of the first peak p[4] FWHM of the first peak p[5] Area under the second peak p[…] etc. - q : ndarray
One dimensional input array.
Returns: - out : ndarray
One dimensional Gaussian profile.
Notes
A Gaussian profile is defined as:
\[f(q) = \frac{a}{\sigma \sqrt{2\pi}} e^{-\frac{(q-q_0)^2}{2\sigma^2}},\]where the integral over the whole function is a, and
\[fwhm = 2 \sqrt{2 \ln{2}} \sigma.\]Examples
Plot a single gaussian with an integrated intensity of 1, centered at zero, and fwhm of 0.3:
>>> import matplotlib.pyplot as plt >>> import numpy as np >>> p = np.array([0., 0., 1., 0., 0.3]) >>> x = np.linspace(-1, 1, 101) >>> y = gaussian(p, x) >>> plt.plot(x, y) >>> plt.show()
Plot two gaussians, equidistant from the origin with the same intensity and fwhm as above:
>>> p = np.array([0., 0., 1., -0.3, 0.3, 1., 0.3, 0.3]) >>> x = np.linspace(-1, 1, 101) >>> y = gaussian(p, x) >>> plt.plot(x, y) >>> plt.show()