Skip to content

Consolidate STUDY time-frequency stats behavior - #217

Merged
suraj-ranganath merged 2 commits into
feature/fable5-architecture-closeoutfrom
phase/210-study-timefreq-stats
Jun 12, 2026
Merged

suraj-ranganath merged 2 commits into
feature/fable5-architecture-closeoutfrom
phase/210-study-timefreq-stats

Conversation

@suraj-ranganath

Copy link
Copy Markdown
Member

Fixes #210. Part of #207. This consolidates robust STUDY clustering provenance, cached measure plotting/read helpers, trialinfo/factor matching utilities, time-frequency bootstrap helpers, and documented empirical p-value conventions with focused regression coverage.

@claude

claude Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 3m 24s —— View job


Code review

  • Overall assessment: Looks good overall — clean, well-scoped consolidation with matching regression tests. One behavioral edge case worth confirming.
  • Highest-risk area: bootstrap_indices unification in timefreqfunc/_bootstrap.py (newtimef vs. newcrossf had subtly different single-value baseboot handling).
  • Merge recommendation: Safe to merge after confirming the newtimef baseline-NaN note below.

Blocking

None.

Important

newtimef single-value baseboot now thresholds at times <= baseboot instead of times <= 0 — src/eegprep/functions/timefreqfunc/_bootstrap.py:70

The two original helpers differed in their values.size == 1 branch:

  • old newtimef._bootstrap_indices: when baseboot is a single non-zero value and baseline is NaN/empty, it selected np.nonzero(times <= 0)[0] (the pre-stimulus baseline period).
  • old newcrossf._bootstrap_indices: selected np.nonzero(times <= values[0])[0].

The merged helper always uses times <= values[0], so the newtimef path (limit_to_baseboot=False) now changes behavior when a caller passes baseline=NaN with the default baseboot=1: it selects times <= 1 rather than times <= 0. Since baseboot=1 is an EEGLAB flag meaning "use the baseline period," treating it as a 1 ms time threshold is a semantic shift, and the bootstrap baseline window can include an extra sample in (0, 1].

This is an edge case (only triggers when baseline is explicitly NaN — the default baseline=0 still returns baseln), but it is a real change from the pre-refactor behavior in a PR whose goal is to consolidate without changing behavior. The added test does not distinguish the two, because times = [-100, 0, 100, 200] has no sample in (0, 1]:

np.testing.assert_array_equal(bootstrap_indices(times, baseline=np.nan, baseboot=1, baseln=baseln), [0, 1])

Suggested fix: preserve the original newtimef semantics by using times <= 0 in the non-limit_to_baseboot branch, or confirm the change is intended and add a test case with a sample in (0, baseboot] to lock in the chosen behavior.

Fix this →

Nits

trialinfo_rows all-scalar dict now returns one row instead of zero — src/eegprep/functions/studyfunc/_study_utils.py:218

The shared trialinfo_rows returns [value] when a dict has no list/tuple/ndarray columns, whereas the old std_builddesignmat._trial_rows returned [] (zero rows) for that case. This only matters for a columnar trialinfo dict whose values are all scalars (atypical for EEGLAB-loaded trialinfo, which uses list columns), so impact is low — flagging only because it's a quiet semantic merge between two previously-distinct helpers.

Test gaps

  • The newtimef baseline-NaN case above is the one changed behavior not pinned by a test. A case where times contains a sample in (0, baseboot] would catch any future regression and document the intended semantics.

EEGLAB parity notes

  • pop_clust finite-outliers path correctly routes through robust_kmeans, and the outlier label convention (label 0 for outliers via labels[:] = 0) matches what std_createclust expects, so the ["robust_kmeans", clus_num] provenance and the separate outlier cluster are consistent with EEGLAB clustering output. Verified against robust_kmeans.py:31,44,55.
  • The cached measure-plot consolidation (plot_measure_data shared by std_measureplot and pop_chanplot) keeps channel/component plots on the single std_readdata cache contract, which is the right parity direction.

Checked: correctness of the bootstrap/range-mask/trialinfo consolidations, robust_kmeans outlier labeling vs. std_createclust, std_clustplot history replay (covered by new test), import resolution in _study_utils, and changed-behavior test coverage.

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Addressed the Claude review edge case in d4ed7bb: the shared bootstrap helper now preserves the original newtimef single-value baseboot behavior by using times <= 0 when limit_to_baseboot is false, while newcrossf keeps times <= baseboot. Added a distinguishing test with a sample in (0, baseboot].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant