From 08c74b904bc906e12c1b55668c61c806377709cd Mon Sep 17 00:00:00 2001 From: Enning Yang Date: Mon, 4 May 2026 09:40:28 -0400 Subject: [PATCH] Fix yeo7 off-by-1 indexing and MATLAB column_vector compatibility - SLM._surfstat_to_brainstat_rft: vertid is stored 1-based (inherited from peak_clus), so subtract 1 before indexing the 0-based yeo7 array. Previously a peak on the last mesh vertex raised an IndexError, and other peaks were silently misindexed (#347). - peak_clus.column_vector: replace mustBeVector (R2020b+) with an explicit isvector check so the validator works on R2019b/R2020a (#285). --- brainstat/stats/SLM.py | 6 +++++- brainstat_matlab/stats/@SLM/peak_clus.m | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/brainstat/stats/SLM.py b/brainstat/stats/SLM.py index c6dfa520..8ac161c2 100644 --- a/brainstat/stats/SLM.py +++ b/brainstat/stats/SLM.py @@ -322,7 +322,11 @@ def _surfstat_to_brainstat_rft(self) -> None: ) yeo_names, _ = fetch_yeo_networks_metadata(7) yeo_names.insert(0, "Undefined") - yeo7_index = yeo7[self.P["peak"]["vertid"][i]] + # vertid is stored as 1-based (inherited from SurfStat / + # MATLAB conventions in peak_clus); subtract 1 before + # indexing the 0-based yeo7 array (see #347). + vertid = self.P["peak"]["vertid"][i] + yeo7_index = yeo7[vertid - 1] if vertid is not None else None if "yeo7" not in self.P["peak"]: self.P["peak"]["yeo7"] = [] self.P["peak"]["yeo7"].append(np.take(yeo_names, yeo7_index)) diff --git a/brainstat_matlab/stats/@SLM/peak_clus.m b/brainstat_matlab/stats/@SLM/peak_clus.m index 1581be96..5997c762 100755 --- a/brainstat_matlab/stats/@SLM/peak_clus.m +++ b/brainstat_matlab/stats/@SLM/peak_clus.m @@ -157,8 +157,10 @@ function v_col = column_vector(v) % Converts the input vector to a column vector. -arguments - v {mustBeVector} +% Note: mustBeVector was introduced in MATLAB R2020b; an explicit check +% is used here to keep compatibility with R2019b and R2020a (see #285). +if ~isempty(v) && ~isvector(v) + error('column_vector:NotAVector', 'Input must be a vector.'); end v_col = v(:); end