Stats.Moment#
Stats.Moment.py
Copyright (c) 2024-2025, SAXS Team, KEK-PF
- compute_meanstd(x, y)#
Compute the mean and standard deviation of a distribution defined by x and y.
- Parameters:
x (array-like) – The x-values of the distribution.
y (array-like) – The y-values of the distribution.
- Returns:
M1 (float) – The mean of the distribution.
std (float) – The standard deviation of the distribution.
- class Moment(x, y)#
Bases:
object
A class to represent the moment of a distribution defined by x and y. .. attribute:: x
The x-values of the distribution.
- type:
array-like
- y#
The y-values of the distribution.
- Type:
array-like
- y_#
The processed y-values of the distribution. If None, it has not been computed yet.
- Type:
array-like or None
- M#
The mean of the distribution. If None, it has not been computed yet.
- Type:
float or None
- std#
The standard deviation of the distribution. If None, it has not been computed yet.
- Type:
float or None
- lpm_percent#
The estimated percentage of low-q plateau in the distribution. If None, it has not been computed yet.
- Type:
float or None
Initialize the Moment object. :param x: The x-values of the distribution. :type x: array-like :param y: The y-values of the distribution. :type y: array-like
- get_y_(**kwargs)#
- Get the processed y-values of the distribution.
If y_ is None, it will be computed using the provided processing function.
- Parameters:
**kwargs (keyword arguments) – Additional keyword arguments to pass to the processing function.
- Returns:
y_ – The processed y-values of the distribution.
- Return type:
array-like
- debug_plot(ax)#
Plot the original and processed y-values for debugging purposes.
- Parameters:
ax (matplotlib.axes.Axes) – The axes to plot on.
- get_meanstd()#
- Get the mean and standard deviation of the distribution.
If M and std are None, they will be computed using the processed y-values.
- Returns:
M (float) – The mean of the distribution.
std (float) – The standard deviation of the distribution.
- is_in_nsigma(n, px)#
Check if a given x-value is within n standard deviations from the mean.
- Parameters:
n (float) – The number of standard deviations.
px (float) – The x-value to check.
- Returns:
True if px is within n standard deviations from the mean, False otherwise.
- Return type:
bool
- get_nsigma_points(n)#
Get the indices of the x-values that are within n standard deviations from the mean.
- Parameters:
n (float) – The number of standard deviations.
- Returns:
(i, j) – The indices of the first and last x-values within n standard deviations from the mean. If no such points exist, returns (None, None).
- Return type:
tuple of int
- get_lpm_percent(debug=True)#
Estimate the percentage of low-q plateau in the distribution.
- Parameters:
debug (bool, optional) – If True, enables debug mode for more verbose output, by default True.
- Returns:
lpm_percent – The estimated percentage of low-q plateau in the distribution.
- Return type:
float