From 0a3b747cc3202085b276a115f30ea908ec76d5b8 Mon Sep 17 00:00:00 2001 From: "opd16@lbm16jade" Date: Sun, 24 Sep 2023 10:53:48 +0200 Subject: [PATCH] add possibility to return a masked array --- larch/io/mergegroups.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/larch/io/mergegroups.py b/larch/io/mergegroups.py index 6aec688d4..ec94f1128 100644 --- a/larch/io/mergegroups.py +++ b/larch/io/mergegroups.py @@ -333,10 +333,11 @@ def rebin_piecewise_constant(x1, y1, x2): return y2 -def reject_outliers(data, m=2.0, return_mask=False): +def reject_outliers(data, m=5.189, return_ma=False): """Reject outliers Modified from: https://stackoverflow.com/questions/11686720/is-there-a-numpy-builtin-to-reject-outliers-from-a-list + See also: https://www.itl.nist.gov/div898/handbook/eda/section3/eda35h.htm """ if not isinstance(data, np.ndarray): data = np.array(data) @@ -344,7 +345,8 @@ def reject_outliers(data, m=2.0, return_mask=False): mdev = np.median(d) s = d / (mdev if mdev else 1.0) mask = s < m - if return_mask: - return data[mask], mask + if return_ma: + imask = s > m + return np.ma.masked_array(data=data, mask=imask) else: return data[mask]