hispecdrp.primitives.utils.stats
Robust statistics helpers used by HISPEC DRP primitives.
Biweight estimators, weighted moments, outlier-resistant summary stats, and posterior mode / uncertainty extraction.
Functions
|
Calculate the biweight location of an array. |
|
Calculate the biweight midvariance of an array. |
|
Return the mode, and the left and right errors of a distribution. |
|
Calculate the median absolute deviation of an array. |
|
Compute robust mean and standard deviation using iterative outlier rejection based on biweight location and midvariance. |
|
Calculate the weighted mean of an array. |
|
Calculate the weighted quantile of an array. |
|
Calculate the weighted standard deviation of an array. |
- biweight_location(x, M=None, c=6.0)[source]
Calculate the biweight location of an array.
- biweight_midvariance(x, M=None, c=9.0)[source]
Calculate the biweight midvariance of an array.
See https://docs.astropy.org/en/latest/api/astropy.stats.biweight_midvariance.html for details.
- get_err_from_posterior(x, posterior)[source]
Return the mode, and the left and right errors of a distribution. The errors are defined with a 68% confidence level.
Note: Copy pasted from BREADS https://github.com/jruffio/breads
- Parameters:
x (Sampling of the 1D posterior)
posterior (Posterior array)
- Returns:
Mode, left error, right error
- mad(x, M=None)[source]
Calculate the median absolute deviation of an array.
- Parameters:
x – Array of values.
M – Optional median value. If None, it will be calculated as the median of x.
- Returns:
np.ndarray – Median absolute deviation of the array.
- robust_stats(x, w=None, n_sigma=4.0, maxiters=100)[source]
Compute robust mean and standard deviation using iterative outlier rejection based on biweight location and midvariance. Final mean and standard deviation are computed using the remaining good data points based on the weighted mean and weighted standard deviation.
- Parameters:
- Returns:
float – Robust weighted mean.
float – Robust weighted standard deviation.
- weighted_mean(x, w)[source]
Calculate the weighted mean of an array.
- Parameters:
x (np.ndarray) – Array of values.
w (np.ndarray) – Array of weights.
- Returns:
float – Weighted mean.
- weighted_quantile(x, w=None, q=0.5)[source]
Calculate the weighted quantile of an array.
- Parameters:
x (np.ndarray) – Array of values.
w (np.ndarray) – Array of weights (defaults to uniform weights).
q (float) – Quantile to compute (0 <= q <= 1).
- weighted_stddev(x, w, mu=None)[source]
Calculate the weighted standard deviation of an array.
- Parameters:
x (np.ndarray) – Array of values.
w (np.ndarray) – Array of weights.
mu (float | None, optional) – Pre-computed weighted mean. If None, it will be calculated from x and w.
- Returns:
float – Weighted standard deviation or NaN if no valid data.