Skip to content

ENH: Allow overriding existing EDF channel units - #14567

Open
divya-git03 wants to merge 1 commit into
mne-tools:mainfrom
divya-git03:enh/edf-overwrite-units
Open

divya-git03 wants to merge 1 commit into
mne-tools:mainfrom
divya-git03:enh/edf-overwrite-units

Conversation

@divya-git03

Copy link
Copy Markdown

Summary

This PR addresses #14427 by allowing users to override existing channel units specified in EDF file headers when reading data with mne.io.read_raw_edf().

Previously, the units parameter could only be used when channel units were missing from the original EDF header. This change allows users to explicitly override those units.

Changes

  • Allow a string passed to units to override units for all non-STIM channels.
  • Support channel-specific unit overrides through a dictionary mapping channel names to units.
  • Preserve the original header units for channels not specified in the dictionary.
  • Validate dictionary values and raise a clear error for unknown channel names.
  • Leave STIM channels unchanged.
  • Preserve the existing BDF behavior.
  • Update the EDF API documentation and add a changelog entry.

Tests

Added and updated regression coverage for:

  • String-based unit overrides and resulting signal scaling.
  • Channel-specific dictionary overrides.
  • Preservation of units for unspecified channels.
  • STIM channel preservation.
  • Overrides when earlier channels are excluded.
  • EDF files containing TAL annotation channels.
  • Channel reordering after applying overrides.
  • Missing units in EDF headers.
  • Invalid dictionary values and unknown channel names.
  • Existing BDF unit-override restrictions.

Updated the existing test_ch_types expectation to reflect the new EDF behavior.

Validation

  • pytest mne/io/edf/tests/test_edf.py -q — 78 passed, 35 skipped.
  • pytest mne/tests/test_docstring_parameters.py -q — 14 passed, 5 skipped.
  • pre-commit run --files ... — passed.
  • git diff --check — passed.
  • python -m py_compile mne/io/edf/edf.py — passed.

Dataset-dependent tests were skipped because the MNE testing dataset was unavailable. Documentation tests requiring optional dependencies were also skipped.

Closes #14427.

@welcome

welcome Bot commented Nov 19, 2026

Copy link
Copy Markdown

Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴

This branch has not been deployed

No deployments
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.

Allow overwriting incorrect units in EDF header with mne.io.read_raw_edf

1 participant