neutronpy.functions.gaussian2d

neutronpy.functions.gaussian2d(p, q)[source]

Returns an arbitrary number of two-dimensional Gaussian profiles.

Parameters:
p : ndarray

Parameters for the Gaussian, in the following format:

p[0] Constant background
p[1] Linear background slope
p[2] Volume under the first peak
p[3] X position of the first peak
p[4] Y position of the first peak
p[5] FWHM_x of the first peak
p[6] FWHM_y of the first peak
p[7] Area under the second peak
p[…] etc.
q : tuple

Tuple of two one-dimensional input arrays.

Returns:
out : ndarray

One dimensional Gaussian profile.

Notes

A Gaussian profile is defined as:

\[f(q) = \frac{a}{\sigma \sqrt{2\pi}} e^{-\left(\frac{(q_x-q_x0)^2}{2\sigma_x^2} + \frac{(q_y-q_y0)^2}{2\sigma_y^2}\right)},\]

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 (0, 0), and fwhm of 0.3:

>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> p = np.array([0., 0., 1., 0., 0., 0.3, 0.3])
>>> x, y = np.meshgrid(np.linspace(-1, 1, 101), np.linspace(-1, 1, 101))
>>> z = gaussian(p, (x, y))
>>> plt.pcolormesh(x, y, z)
>>> 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, 0.3, 0.3, 1., 0.3, 0.3, 0.3, 0.3])
>>> x, y = np.meshgrid(np.linspace(-1, 1, 101), np.linspace(-1, 1, 101))
>>> z = gaussian(p, x)
>>> plt.pcolormesh(x, y, z)
>>> plt.show()