Skip to content

Commit

Permalink
add possibility to return a masked array
Browse files Browse the repository at this point in the history
  • Loading branch information
maurov committed Sep 24, 2023
1 parent 229c3c7 commit 0a3b747
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions larch/io/mergegroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,20 @@ 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)
d = np.abs(data - np.median(data))
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]

0 comments on commit 0a3b747

Please sign in to comment.