Skip to content

math

Utility math functions which can be shared between Tasks.

Functions:

Name Description
gaussian

Calculate a 1D Gaussian distirbution.

sigma_to_fwhm

Convert the standard deviation of a Gaussian to Full Width at Half Maximum (FWHM).

gaussian(x_vals, amp, x0, sigma, bkgnd)

1D Gaussian distribution with specified parameters.

Parameters:

Name Type Description Default
x_vals NDArray[float64]

Values over which to calculate the distribution.

required
amp float

Amplitude of the distribution.

required
x0 float

Center (mean) of the distribution

required
sigma float

Standard deviation of the distribution.

required
bkgnd float | NDArray[float64]

Background/noise. Constant offset (float) or an array of offsets of the same length as x_vals.

required

Returns:

Name Type Description
distribution NDArray[float64]

Calculated Gaussian distribution based on given parameters. Same shape as x_vals.

Source code in lute/tasks/math.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def gaussian(
    x_vals: npt.NDArray[np.float64], amp: float, x0: float, sigma: float, bkgnd: float
) -> npt.NDArray[np.float64]:
    """1D Gaussian distribution with specified parameters.

    Args:
        x_vals (npt.NDArray[np.float64]): Values over which to calculate the
            distribution.

        amp (float): Amplitude of the distribution.

        x0 (float): Center (mean) of the distribution

        sigma (float): Standard deviation of the distribution.

        bkgnd (float | npt.NDArray[np.float64]): Background/noise. Constant
            offset (float) or an array of offsets of the same length as `x_vals`.

    Returns:
        distribution (npt.NDArray[np.float64]): Calculated Gaussian distribution
            based on given parameters. Same shape as x_vals.
    """
    numerator = -((x_vals - x0) ** 2)
    return amp * np.exp(numerator / (2 * sigma**2)) + bkgnd

sigma_to_fwhm(sigma)

Convert the standard deviation of a Gaussian to Full Width Half Max.

Parameters:

Name Type Description Default
sigma float

Standard deviation of a Gaussian.

required

Returns:

Name Type Description
fhwm float

Full width at half max of a Gaussian.

Source code in lute/tasks/math.py
43
44
45
46
47
48
49
50
51
52
53
def sigma_to_fwhm(sigma: float) -> float:
    """Convert the standard deviation of a Gaussian to Full Width Half Max.

    Args:
        sigma (float): Standard deviation of a Gaussian.

    Returns:
        fhwm (float): Full width at half max of a Gaussian.
    """
    constant: float = (8 * np.log(2)) ** 0.5
    return sigma * constant