Skip to content

feat(datasets): add MartinezPeon2025 hand-grip and MILimbEEG imagery datasets - #1198

Merged
bruAristimunha merged 20 commits into
NeuroTechX:developfrom
bruAristimunha:datasets/mi-clinical
Oct 4, 2026
Merged

bruAristimunha merged 20 commits into
NeuroTechX:developfrom
bruAristimunha:datasets/mi-clinical

Conversation

@bruAristimunha

@bruAristimunha bruAristimunha commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Port two existing loaders onto current develop: MartinezPeon2025 (was KMIHandGrip2025) and MILimbEEG, including registry, current metadata API, DOI cache, summary and docs.

  • KMI keeps the expansion-branch warning that class equals recording block: within-recording evaluation can exploit nonstationarity; prefer cross-subject evaluation. Both metadata and signal downloads forward path/update/verbosity. Reject incomplete 84-second records; inclusive imagery windows contain 2000 actual samples.
  • MILimbEEG loads imagery I files only, not executed M files; handles 16 EEG columns with or without sample index; microvolts to volts; rejects incomplete four-second records. Removes synthetic padding, uses inclusive 499/125-second endpoints, and preserves EDGE boundary annotations through event reconstruction/filtering. First and final trials survive without padding.
  • CSV counts not verified against all releases are deliberately unspecified rather than copied from misleading source rows. Native flags are not silently cleared or interpolated.

Reconciliation and scientific deferrals

Compared corrected f7fe4b0 with expansion 4e7771c. MILimbEEG identical; KMI differs only by the necessary block-confound warning, retained here.
Deferred Rehab2025OpenBCI: corrected uses S6/4s whereas expansion uses S4/3s justified by ERD rather than an authoritative code-to-task map; expansion also documents three railed channels but loader does not mark them bad. Neither conflicting mapping is certified.
Deferred Medvedeva2026: expansion corrects imagery to execution, consistent with description of actual intact/paretic hand movements. Not an MI candidate.
Deferred Russo2024: source explicitly says ExG-to-anatomical mapping is inferred, not an author wiring table, and scaling is assumed microvolts. Do not silently impose a speculative montage/calibration.

Validation

Isolated MNE home/data and explicit worktree imports. Offline suite: 2075 passed, 478 skipped, 464 deselected, including 6 focused synthetic SI/window/transport/filtering tests. Touched pre-commit passes. Excluded network-marked cases, real-data test_epochs, test_dataset_accept, inherited-prefetch selected-session test, and separately measured NEMAR policy gate. No real downloads, Voyager jobs or paper reruns.

Draft blockers — do not merge

NEMAR policy: two expected failures, no confirmed IDs. Read-only discovery inspected descriptions of 787 nemarDatasets repositories; no match established; web search provider unavailable. No invented IDs/versions/exemptions/pending entries, publication or rehosting. Full real-data source calibration, actual counts/repetitions and channel flags remain unvalidated. Full CI is not claimed green. The small EDGE annotation preservation fix also occurs in the parallel Pan/Polo draft and should be reconciled when either lands.

Simplification (2026-09-29, head fce51a442)

Depends on #1200. Merge #1200 (mne>=1.13, shared download/marker helpers, OpenNeuro mirror mixin) first. This branch merges it (git merge --no-ff, no rebase).

Pass 4 (ponytail): reuse existing code, no nested functions (head d9eaeba48)

  • Merges refactor(datasets): require mne>=1.13, spell colin27 montages, share loader code #1200 at 058ae05e6, which now requires mne>=1.13 and drops the pass-3 helpers that re-implemented existing code.
  • MILimbEEG downloads through develop's download_and_extract_subject_zip, behind the same extracted-folder check its ten develop callers use. The archive now extracts into MNE-milimbeeg-data/MILimbEEG/, not next to the cached archive. Both subject-folder layouts (archive root or one wrapper folder) are still resolved.
  • MILimbEEG marks stored-trial joins with mne.Annotations(onsets, 0.0, "EDGE boundary"), which replaces edge_boundary_annotations. Its header-row check is now any(isinstance(v, str) for v in frame.iloc[0]), with no Series.map(lambda).
  • Montage names are spelled colin27_1020 directly (KMIHandGrip2025, MILimbEEG).
  • Nested functions/lambdas added by this PR: 1 (lambda-arg) → 0.
  • LOC added vs refactor(datasets): require mne>=1.13, spell colin27 montages, share loader code #1200: moabb/datasets/*.py 501 → 492; moabb/tests/*.py (net) 112 → 113.
  • Behaviour:
    • The class fingerprint (metadata/summary/DOI) is identical.
    • The loader fingerprint (synthetic CSV trials in every layout, plus real zips through data_path) is identical apart from the recorded data_dl calls, which now carry an explicit fname=None.
  • Coverage (pass 3 → pass 4): kmi_handgrip2025 85→85, milimbeeg 87→86.
  • Proof: the offline suite (PR tests, test_loader_utils.py, test_preprocessing.py, test_datasets.py, test_metadata.py, test_doi_validation.py) had 2515 passed, 0 failed. ruff 0.15.20 and git diff --check are clean.

Pass 3: shared helpers, NEMAR skip, new montage names (head 1448857b3)

  • MILimbEEG uses download_and_extract_zip and edge_boundary_annotations.
  • The montage calls in KMIHandGrip and MILimbEEG use resolve_montage_name.
  • The preprocessing.py change is now owned by refactor(datasets): require mne>=1.13, spell colin27 montages, share loader code #1200.
  • NEMAR: added to NEMAR_ID_EXEMPT (# no public NEMAR mirror yet; tracked in #1198): KMIHandGrip2025, MILimbEEG. No ids were invented, NEMAR_ID_PENDING is untouched, and test_all_datasets_have_valid_nemar_id passes locally.
  • LOC added, measured against refactor(datasets): require mne>=1.13, spell colin27 montages, share loader code #1200 (i.e. after it merges): moabb/datasets/*.py 500 → 501 (+0%); moabb/tests/*.py (net) 110 → 112 (+2%; includes the NEMAR-exempt lines).
  • Coverage (pass 2 → pass 3, offline suite + test_loader_utils.py): kmi_handgrip2025 85→85, milimbeeg 87→87. No touched file dropped by more than 2 pp.
  • Behaviour: Fingerprints (class metadata/summary/DOI + fake data through the real loaders) identical to pass 2, except the recorded data_dl call now has positional path, force_update, verbose (same values).
  • Proof: offline pytest <PR tests> test_loader_utils.py test_preprocessing.py test_datasets.py test_metadata.py test_doi_validation.py --cov=moabb/datasets (isolated MNE home, empty MNE_DATA, no downloads; test_dataset_accept and TestData::test_epochs deselected): 0 failed. Also ruff 0.15.20 and git diff --check.
added LOC vs develop before after pass 1 after pass 2
moabb/datasets/*.py 657 657 500 (-24%)
moabb/tests/*.py (net) 133 127 110 (-17%)

PR tests collected (pass 2): 6 → 6. Coverage of touched dataset files (pass-1 before → now, offline suite): kmi_handgrip2025 78→85, milimbeeg 88→87.

Pass 2 — loaders and tests

  • MILimbEEG: vestigial pad/gap removed (loader fingerprint proves no effect), _label_of → regex, compact channel list
  • KMIHandGrip2025: _file_map folded into data_path, dead list-type checks removed, _read_run takes the label directly, shorter docstrings
  • tests: shared download-flag dict, stronger path checks, 10-line epoch construction → direct last-trial-fits check
  • Kept on purpose: MILimbEEG header-row/transposed-file handling and shape checks.
  • Proof: offline pytest <PR tests> test_datasets.py test_metadata.py test_doi_validation.py --cov=moabb/datasets (isolated MNE home, no downloads; test_dataset_accept/TestData::test_epochs deselected); behaviour fingerprint before/after on fake source data (per-run data hash, channels/types, sfreq, annotations, events, montage) and class fingerprint (subjects, sessions, event_id, interval, code, DOI, METADATA hash, summary-CSV row, docstring DOIs) identical except Dataset summary rendered once instead of twice; ruff 0.15.20, git diff --check.
  • Unchanged and expected: Test_Datasets::test_all_datasets_have_valid_nemar_id[<new classes>] fails (no nemar_id, not in NEMAR_ID_PENDING) — NEMAR-ID decision still open.

Pass 1 — test audit

  • test_milimb_si_and_last_window[True|False]: filter round-trip replaced by a direct EDGE boundary onset assertion (500/125). test_milimb_transport_flags: tautological len(...) == 1 strengthened to the exact extracted subject path (now checks zip extraction + folder resolution) at equal LOC.
  • Retained on purpose: indexed/unindexed CSV variants (documented 17- vs 16-column files), short-trial rejection, KMI last-trial Epochs shape, record-JSON → 5×data_dl manifest mock.
  • Tests collected 6 → 6; test LOC 133 → 127 (−5%). Coverage: kmi_handgrip2025 78→78%, milimbeeg 88→88%, preprocessing 40→40%. Follow-up noted (not changed): vestigial pad = 0/empty gap in milimbeeg._get_single_subject_data. Proof: offline pytest <PR tests> moabb/tests/test_datasets.py moabb/tests/test_metadata.py moabb/tests/test_doi_validation.py --cov=moabb/datasets --cov-report=term-missing -p no:cacheprovider (isolated MNE home, no downloads; test_dataset_accept/TestData::test_epochs deselected). Pre-existing on this branch, untouched: Test_Datasets::test_all_datasets_have_valid_nemar_id[<new classes>] fails (no nemar_id, not in NEMAR_ID_PENDING).

…>68.7%)

Replace the MNE-behaviour filter round-trip in test_milimb_si_and_last_window
with a direct assertion that the EDGE boundary annotation sits at the
stored-trial join (subsumes the bare description-presence check), and make
test_milimb_transport_flags assert the resolved subject folder instead of a
bare list length. No test removed; 6 LOC fewer. Per-file coverage unchanged:
kmi_handgrip2025 78%, milimbeeg 88%, preprocessing 40%.
- resolve_montage_name (moabb.datasets._montage, re-exported by utils): MNE 1.13
  renamed standard_1005/1020 (and the other standard_* templates) to colin27_*,
  warns on the old names and 1.14 removes them. Returns the spelling the installed
  MNE knows; electrode files are byte-identical (dig positions checked equal on
  MNE 1.10.2, 1.12.1 and 1.13.2). Every make_standard_montage/set_montage call in
  moabb now goes through it; METADATA montage labels are descriptive and unchanged.
- download_and_extract_zip: download once, extract unless a marker exists,
  optional warn + forced re-download of a corrupted archive.
- read_raw_brainvision_repaired: repair stale DataFile/MarkerFile references in a
  temporary header (strict mode raises on missing entries/siblings).
- rename_stimulus_codes, edge_boundary_annotations; SetRawAnnotations keeps
  'EDGE boundary' markers.
- moabb.datasets._openneuro_mirror moved here verbatim (byte-identical copies in
  NeuroTechX#1186 and NeuroTechX#1189), with dataset-agnostic tests.
# Conflicts:
#	docs/source/whats_new.rst
#	moabb/datasets/preprocessing.py
…tage names

Merges NeuroTechX#1200 (datasets/shared-loader-helpers): local zip/BrainVision/EDGE-boundary
code replaced by moabb.datasets.utils helpers, montage calls spelled with the
MNE 1.13 colin27_* names via resolve_montage_name, new classes without a public
NEMAR mirror listed in NEMAR_ID_EXEMPT. Behaviour fingerprints unchanged.
MNE 1.13 renamed the standard_* templates to colin27_* (identical .elc
files). With the floor at 1.13 the resolve_montage_name shim and the
_montage module are not needed: every call site spells the new name.
- download_and_extract_zip -> extend download_and_extract_subject_zip with
  keyword-only fname and redownload_corrupted (defaults keep the 10
  develop callers unchanged)
- read_raw_brainvision_repaired -> mne.io.read_raw_brainvision(overrides=)
  at the call sites (MNE >= 1.13)
- edge_boundary_annotations -> mne.Annotations(onsets, 0.0, 'EDGE boundary')
- drop_native_stim / relabel_annotations / write_dataset_description ->
  drop_channels / annotations.rename / mne_bids.make_dataset_description
- tests: no nested functions, Mock data_dl
…tions

- download_and_extract_zip -> develop's download_and_extract_subject_zip
  behind the usual extracted-folder check (MNE-milimbeeg-data/MILimbEEG)
- edge_boundary_annotations -> mne.Annotations(onsets, 0.0, "EDGE boundary")
- colin27_1020 montage name spelled directly (mne>=1.13)
- MILimbEEG header sniff: generator instead of Series.map(lambda)
The Mendeley record 10.17632/msgzn862ns.1 ('EEG signals of KMI levels of the
right and left hands', creators Martinez Peon, Dulce Citlalli; Perez Espinoza,
Marcos; issued 2025-12-12) gives the dataset no official name and links no
paper, so rule 2 applies: first-author compound surname + record year.
Also aligns metadata with the record description: reference unset (A2 is one
of the 20 recorded columns; the record states no reference), sampling rate
marked as inferred, all-right-handed cohort, protocol wording, level-list
discrepancy documented.
Evidence: ~/Projects/moabb/.paper-audit/reports/mi-clinical/KMIHandGrip2025/report.md
…audit)

Paper: cohort of 60 Ecuadorian adults recruited among ESPOL colleagues and
neurosurgery patients of the Hospital Luis Vernaza; two amputees, one
hydrocephalus after ventricular infarct, 18 post-COVID-19 -> health_status
'mixed' (was 'healthy'); 52%/48% female/male (31/29 in
Test_Subject_Annotations.csv), three left-handed, average age 36; monopolar
against a neutral ear-lobe electrode; only one subject performed up to four
repetitions; tasks presented randomly up to 5 times per run.
Evidence: ~/Projects/moabb/.paper-audit/reports/mi-clinical/MILimbEEG/report.md
@bruAristimunha bruAristimunha changed the title feat(datasets): add KMI hand-grip and MILimbEEG imagery datasets feat(datasets): add MartinezPeon2025 hand-grip and MILimbEEG imagery datasets Sep 30, 2026
bruAristimunha and others added 3 commits October 4, 2026 17:55
The published Mendeley v2 export (10.17632/x8psbz3f6x.2) prefixes every
per-trial CSV with a header row whose first cell is empty and whose
remaining cells are the integer column indices 0..15, followed by 500
data rows. pandas' type inference coerces those integer column names to
floats, so the previous header check ('any string in iloc[0]') never
triggered: _read_trial kept 501 rows and raised 'Expected a complete
four-second stored trial' for every real file.

The fix peeks at the raw first line and tries to parse every comma-
separated field as a float; a failure (empty leading cell or a textual
header) switches to header=0. Short trials (<500 samples) are still
rejected explicitly, with no zero-padding. Adds a regression test that
feeds the exact ',0,1,...,15' Mendeley v2 header and asserts the loader
yields (16, 500) in volts.
@bruAristimunha
bruAristimunha marked this pull request as ready for review October 4, 2026 17:39
@bruAristimunha
bruAristimunha merged commit 336f6a5 into NeuroTechX:develop Oct 4, 2026
9 of 11 checks passed
@bruAristimunha
bruAristimunha deleted the datasets/mi-clinical branch October 6, 2026 10:18
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