Skip to content

Commit aad2818

Browse files
committed
Moved outlier rejection to a dedicated method.
1 parent 7eaca07 commit aad2818

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

rtanalysis/rtanalysis.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,13 @@ def fit(self, rt, accuracy, verbose=True):
4848
# Ensure that accuracy values are boolean.
4949
assert accuracy.dtype == bool
5050

51-
if self.outlier_cutoff_sd is not None:
52-
cutoff = rt.std() * self.outlier_cutoff_sd
53-
if verbose:
54-
print(f"outlier rejection excluded {(rt > cutoff).sum()} trials")
55-
rt = rt.mask(rt > cutoff)
51+
rt = self.reject_outlier_rt(rt, verbose=verbose)
5652

5753
self.mean_accuracy_ = accuracy.mean()
5854
try:
5955
assert self.mean_accuracy_ > 0
6056
except AssertionError as e:
61-
raise ValueError("accuracy is zero") from e
57+
raise ValueError("Accuracy is zero!") from e
6258

6359
rt = rt.mask(~accuracy)
6460
self.mean_rt_ = rt.mean()
@@ -107,3 +103,12 @@ def _ensure_series_type(var):
107103
if not isinstance(var, pd.Series):
108104
var = pd.Series(var)
109105
return var
106+
107+
def reject_outlier_rt(self, rt, verbose=True):
108+
if self.outlier_cutoff_sd is None:
109+
return rt
110+
cutoff = rt.std() * self.outlier_cutoff_sd
111+
if verbose:
112+
n_excluded = (rt > cutoff).sum()
113+
print(f"Outlier rejection excluded {n_excluded} trials.")
114+
return rt.mask(rt > cutoff)

0 commit comments

Comments
 (0)