Skip to content

resolve_channel_positions: place a montage in REVE's position bank - #1400

Merged
bruAristimunha merged 7 commits into
braindecode:masterfrom
bruAristimunha:feat/channel-position-resolver
Oct 14, 2026
Merged

bruAristimunha merged 7 commits into
braindecode:masterfrom
bruAristimunha:feat/channel-position-resolver

Conversation

@bruAristimunha

@bruAristimunha bruAristimunha commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Adds braindecode.modules.resolve_channel_positions(chs_info, bank, montage=None, on_missing="error"), one function of about 60 lines, and uses it in REVE.

Each channel gets the first match among:

  • the montage-qualified name: montage="biosemi128" makes A1 read biosemi128_A1, near the vertex, instead of the 10-20 earlobe A1;
  • its name;
  • its name ignoring case and an EEG prefix or -REF / -LE / -AR suffix;
  • its legacy alias (T3/T4/T5/T6);
  • for a bipolar A-B, the midpoint of A and B.

Channels left over follow on_missing:

  • "error" raises;
  • "drop" leaves them out, and REVE then reads only the kept input channels;
  • "nearest" takes the bank entry closest to the channel's loc, and drops a channel that has no loc.

No position is invented.

RevePositionBank.forward now raises for an unknown name instead of returning fewer rows than channels. Exact bank names give the same default_pos as before.

Tests use a 6-entry bank written to a temporary file, not a copy of the bank.

…bank

One rule per channel, first match wins: montage-qualified bank name
(montage="biosemi128" -> biosemi128_A1), exact name, normalised name
(case, EEG prefix, -REF/-LE/-AR, legacy T3-T6 and MNE's location
aliases), the channel's loc, the midpoint of a bipolar A-B pair, then
on_missing ("error" with difflib suggestions that are never applied,
"drop", or "nearest" to snap positioned channels to a bank entry).
Returns the positions, the kept indices and per-channel provenance
(rule, bank name, distance). A position is never invented.

raw.set_montage gives loc in the head frame while REVE's bank holds the
montage files' own frames (46-57 mm apart for standard_1005), so loc is
registered onto the bank (trimmed similarity fit on the channels named
in both, else MNE's standard_1005 template). A named channel whose
registered loc lies more than 30 mm from its bank entry is a name
collision (BioSemi-128 A1/A2/C1-C6 against REVE's 10-20 entries) and
keeps its loc, with a warning.

Tests run offline on a copy of REVE's released bank.
…ing)

REVE(montage=None, on_missing="error") resolves its default positions
with the shared rule: exact bank names give the same default_pos and
outputs as before (bank rows round-trip float32 -> float64 -> float32),
channels outside the bank are placed from their loc or as bipolar
midpoints instead of raising, and model.channel_provenance records the
rule per channel. on_missing="drop" leaves channels out; forward then
reads only the kept input channels when it gets no pos (TorchScript
keeps working). The pos= forward override is unchanged.

Fixes BioSemi-128 A1/A2 (and C1-C6) landing on the bank's 10-20 sites of
the same names: their loc is used with a warning, and
montage="biosemi128" reads the bank's biosemi128_* entries.
RevePositionBank.forward raises for an unknown name instead of returning
fewer rows than channels.
Copilot AI balanced review requested due to automatic review settings October 14, 2026 10:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 14, 2026 10:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…on-resolver

# Conflicts:
#	braindecode/models/reve.py
Copilot AI balanced review requested due to automatic review settings October 14, 2026 10:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 14, 2026 11:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 14, 2026 11:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bruAristimunha bruAristimunha changed the title resolve_channel_positions: place any montage in a position bank (REVE) resolve_channel_positions: place a montage in REVE's position bank Oct 14, 2026
@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.12%. Comparing base (25aa682) to head (8e7d769).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1400      +/-   ##
==========================================
+ Coverage   90.10%   90.12%   +0.02%     
==========================================
  Files         167      167              
  Lines       21740    21786      +46     
==========================================
+ Hits        19589    19635      +46     
  Misses       2151     2151              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI balanced review requested due to automatic review settings October 14, 2026 12:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bruAristimunha
bruAristimunha merged commit 3b07640 into braindecode:master Oct 14, 2026
10 checks passed
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.

2 participants