55- :func:`estimate_snr` — an SNR estimator using a derivative-based noise
66 estimate and peak-based signal estimate.
77- :func:`estimate_kurtosis` — excess kurtosis of the trace distribution.
8+ - :func:`estimate_skewness` — skewness of the trace distribution.
89
910Notes
1011-----
2728True
2829>>> isinstance(estimate_kurtosis(y), float)
2930True
31+ >>> isinstance(estimate_skewness(y), float)
32+ True
3033"""
3134
3235from __future__ import annotations
3740import numpy as np
3841from numpy .typing import NDArray
3942from scipy .signal import find_peaks
40- from scipy .stats import kurtosis
43+ from scipy .stats import kurtosis , skew
4144
42- __all__ = ["estimate_snr" , "estimate_kurtosis" ]
45+ __all__ = ["estimate_snr" , "estimate_kurtosis" , "estimate_skewness" ]
4346
4447
4548def estimate_snr (
@@ -132,3 +135,27 @@ def estimate_kurtosis(trace: NDArray[np.floating]) -> float:
132135
133136 # Excess kurtosis (normal distribution = 0)
134137 return float (kurtosis (trace , fisher = True , bias = False ))
138+
139+
140+ def estimate_skewness (trace : NDArray [np .floating ]) -> float :
141+ """
142+ Compute the **skewness** of a 1D trace distribution.
143+
144+ Parameters
145+ ----------
146+ trace : numpy.ndarray
147+ 1D input trace. NaNs will be replaced with the median of ``trace``.
148+
149+ Returns
150+ -------
151+ float
152+ Skewness of the distribution:
153+ - Symmetric distribution → 0.0
154+ - Right-skewed (positive skew) → positive
155+ - Left-skewed (negative skew) → negative
156+ """
157+ # Replace NaNs with the median of the trace
158+ trace = np .nan_to_num (trace , nan = np .nanmedian (trace ))
159+
160+ # Skewness
161+ return float (skew (trace , bias = False ))
0 commit comments