gauss

The gauss module provides a class for representing and evaluating truncated Gaussian distributions.

This module defines the Gaussian class, which allows users to create Gaussian distributions with specified lower and upper cutoffs. The eval method of the Gaussian class can then be used to evaluate the distribution at given locations.

class piran.gauss.Gaussian(lower: float, upper: float, peak: float, width: float)

Implements a truncated Gaussian distribution.

The distribution is defined as:

\[f(x) = \exp\left(-\frac{(x - \mu)^2}{\sigma^2}\right)\]

for \(\text{lower} \le x \le \text{upper}\), and \(f(x) = 0\) otherwise. Note that this is not normalised.

Parameters:
lowerfloat

The lower cutoff; values of x below this are treated as having zero probability.

upperfloat

The upper cutoff; values of x above this are treated as having zero probability.

peakfloat

The mean (\(\mu\)) or expectation of the distribution.

widthfloat

The standard deviation (\(\sigma\)) of the distribution.

Methods

eval(X)

Evaluate the Gaussian distribution at the given locations.

Examples

>>> X_min = 0.0
>>> X_max = 1.0
>>> X_m = 0.0
>>> X_w = 0.577
>>> gaussian = Gaussian(X_min, X_max, X_m, X_w)
eval(X: ndarray) ndarray

Evaluate the Gaussian distribution at the given locations.

Parameters:
Xnp.ndarray

The location(s) at which to evaluate the distribution.

Returns:
np.ndarray

The value(s) of the Gaussian distribution at the given location(s). Returns 0 if the input X is outside of the range [lower, upper].

Raises:
TypeError:

If the input X is of incorrect type (for example a list).

Examples

>>> from astropy import units as u
>>> gaussian = Gaussian(0.0, 1.0, 0.0, 0.577)
>>> print(gaussian.eval([-1, 0, 1] * u.dimensionless_unscaled))
[0.       1.       0.049606]
piran.gauss.from_gyrofrequency_params(gyrofreq, mean, delta, lower, upper) Gaussian

Create a Gaussian distribution using gyrofrequency-based parameters.

This function computes the lower and upper cutoffs, mean, and width for a truncated Gaussian distribution based on the supplied [electron] gyrofrequency and scaling parameters.

Parameters:
gyrofreqfloat

The gyrofrequency in rad/s.

meanfloat

The scaling factor for the mean (center) of the distribution, as a multiple of gyrofreq.

deltafloat

The scaling factor for the width (standard deviation) of the distribution, as a multiple of gyrofreq.

lowerfloat

The lower cutoff, as a multiple of the width away from the mean.

upperfloat

The upper cutoff, as a multiple of the width away from the mean.

Returns:
Gaussian

A Gaussian object with the computed lower cutoff, upper cutoff, mean, and width.