Skip to content

fix EDF round-trip - #14296

Merged
drammock merged 21 commits into
mne-tools:mainfrom
drammock:edf
Sep 11, 2026
Merged

drammock merged 21 commits into
mne-tools:mainfrom
drammock:edf

Conversation

@drammock

Copy link
Copy Markdown
Member

closes #13201

Will self-review momentarily to guide review.

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need for you to leave inline comments this ended up looking pretty straightforward! But if you want to make them to call out things for me specifically to look at (or just to document the challenges / suffering involved 😄 ) feel free

Comment thread mne/export/_edf_bdf.py Resolved
Comment thread mne/export/_edf_bdf.py Resolved
Comment thread mne/io/base.py Resolved

@drammock drammock left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Locally, the remaining failing checks seem to be an EDFIO bug, where it fails to properly truncate a physical_min float value to 8 characters. Example:

np.float64(-1e-05) gets converted to -1.001e-05 (10 chars, not 8) because of how edfio.edf_signal._round_float_to_8_characters works (it searches for a literal decimal point and uses its index, and in the input here there is no decimal point). I'll open an upstream issue/PR later today.

Comment thread mne/export/tests/test_export.py Resolved
Comment thread mne/export/_edf_bdf.py Outdated
Comment on lines +67 to +71
digital_min, digital_max = -32768, 32767 # 16-bit
signal_class = EdfSignal
writer_class = Edf
else: # BDF
digital_min, digital_max = -8388607, 8388607 # 24-bit
digital_min, digital_max = -8388608, 8388607 # 24-bit

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this was another bug revealed by testing roundtrip equivalance of files in the testing dataset. Or at least, this change fixed RT-equivalence for that file... and it reflects the actual digital minima so I think it's a genuine bugfix

Comment thread mne/export/_edf_bdf.py Resolved
Comment thread mne/export/_edf_bdf.py Resolved
Comment thread mne/io/edf/edf.py Resolved
Comment thread mne/io/edf/edf.py Resolved
Comment thread mne/io/edf/edf.py Resolved
Comment thread mne/io/edf/edf.py Resolved
Comment thread mne/utils/docs.py Resolved
Comment thread mne/utils/docs.py Resolved
@larsoner

Copy link
Copy Markdown
Member

Locally, the remaining failing checks seem to be an EDFIO bug, where it fails to properly truncate a physical_min float value to 8 characters.

For these maybe for now we can just pytest.mark.xfail them. Then once edfio is fixed we can conditionally mark that way based on edfio version (and hopefully see pip-pre succeed).

I'll take a quick look at the one that seems like it should succeed but if this already improves the situation, I'm inclined to merge as-is (or if you want to pytest.param("<filename>", marks=pytest.mark.xfail(...)) that one file you can)

Comment thread mne/export/_export.py Resolved
@larsoner

Copy link
Copy Markdown
Member

Ohhh there are existing tests that now fail, that's not so good. Want me to look at those?

@drammock

Copy link
Copy Markdown
Member Author

Ohhh there are existing tests that now fail, that's not so good. Want me to look at those?

sure. I've just xfailed 2 of them (they're affected by the float-truncation problem I mentioned before) but there's one other test that's now failing and might indicate that I broke something when user passes a concrete physical_range to the export function

@larsoner

Copy link
Copy Markdown
Member

Okay so one thing will make a couple of the tests pass even with the EDFIO bug -- writing uV instead of V for EEG channels. It hits the bug less often, and I think it's what we do in main anyway.

A second fix is to make it so that a symmetric digital range is used (when digital_range != "orig") as this allows us to get true zero. This was one failing test I think. (Could alternatively adjust the atol of the test, but storing true zero is nicer and more backward compatible I think.)

I also found it much easier to follow the logic by hoisting the physical / digital range triages out of the loops. Then the if clauses happen in one place rather than being split into "before loop" and "in loop". I'll push a commit for this and you can look!

* upstream/main: (75 commits)
  Brain GUI modernization (Phase 7) (mne-tools#14270)
  Fix bug with SciPy 1.18.0 EEGLAB reading (mne-tools#14293)
  remove plotting abs as the defauls for plotting volumetric (mne-tools#13989)
  Coregistration GUI modernisation (phase 4) (mne-tools#14285)
  Dipole GUI interactivity and visual enhancements (phase 2) (mne-tools#14291)
  Width [circle deploy] [skip azp] [skip actions]
  Post-release deprecations (mne-tools#14290)
  FIX: Come on [circle deploy] [skip azp] [skip actions]
  PyVista try again [circle deploy] [skip azp] [skip actions]
  FIX: PyVista [circle deploy] [skip azp] [skip actions]
  FIX: Really [circle deploy] [skip azp] [skip actions]
  FIX: Doc
  Release commit [circle deploy]
  MAINT: Update code credit (mne-tools#14289)
  MAINT: Update pre-commit hook versions (mne-tools#14288)
  BUG: use fixed normalized CTPS cutoff for automatic ECG detection (mne-tools#14279)
  Move toward docstacks [circle deploy] [skip azp] [skip actions]
  Fix tfce (mne-tools#14286)
  FIX: Improve channel name rendering in `plot_alignment` (mne-tools#13773)
  Don't shift placeholder proc_history dates in anonymize_info (mne-tools#14248)
  ...

# Conflicts:
#	mne/io/edf/tests/test_edf.py

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@drammock feel free to mark for merge-when-green if you're happy with my changes

@drammock

Copy link
Copy Markdown
Member Author

@drammock feel free to mark for merge-when-green if you're happy with my changes

I want to be cautious here. Locally when I patched EDFIO to avoid the float-to-string error, those same tests were still failing (which probably means something else is still broken/incorrect now). I'll take a look now

Comment thread mne/_fiff/utils.py
remap_dict["uv"] = "µV"
remap_dict["μv"] = "µV" # greek letter mu vs micro sign. use micro
remap_dict["\x83\xcav"] = "µV" # for shift-jis mu, use micro
remap_dict["\x83\xcaV".lower()] = "µV" # for shift-jis mu, use micro

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

puzzled by this change; presumably it was added as a lowercase v by the original committer because that's what's attested in their files. This change keeps the same behavior but in a (to me) confusing/roundabout way. Can you explain the thinking here?

Comment thread mne/export/tests/test_export.py Resolved
Comment thread mne/export/_edf_bdf.py Resolved
@larsoner larsoner added the backport-candidate on-merge: backport to maint/1.13 label Sep 11, 2026
Comment thread mne/_fiff/utils.py Resolved
@drammock
drammock merged commit 8198b6d into mne-tools:main Sep 11, 2026
1 of 3 checks passed
@drammock
drammock deleted the edf branch September 11, 2026 15:26
larsoner added a commit that referenced this pull request Sep 11, 2026
Comment thread mne/_fiff/utils.py
# character in shift-jis encoding, it gets read in as utf-8, where `\xca` is an
# (uppercase) Ê. Elsewhere in the codebase we call a `.lower()` on these strings
# so if the keys here aren't also `.lower()` then the key will fail to be
matched.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Uhoh we got this in main and maint/1.13 🤦

I guess we'll go with a 1.13.2!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

dangit 🦶🏻🔫

larsoner added a commit to natinew77-creator/mne-python that referenced this pull request Sep 11, 2026
* upstream/main: (22 commits)
  fix EDF round-trip (mne-tools#14296)
  Brain GUI modernization (Phase 7) (mne-tools#14270)
  Fix bug with SciPy 1.18.0 EEGLAB reading (mne-tools#14293)
  remove plotting abs as the defauls for plotting volumetric (mne-tools#13989)
  Coregistration GUI modernisation (phase 4) (mne-tools#14285)
  Dipole GUI interactivity and visual enhancements (phase 2) (mne-tools#14291)
  Width [circle deploy] [skip azp] [skip actions]
  Post-release deprecations (mne-tools#14290)
  FIX: Come on [circle deploy] [skip azp] [skip actions]
  PyVista try again [circle deploy] [skip azp] [skip actions]
  FIX: PyVista [circle deploy] [skip azp] [skip actions]
  FIX: Really [circle deploy] [skip azp] [skip actions]
  FIX: Doc
  Release commit [circle deploy]
  MAINT: Update code credit (mne-tools#14289)
  MAINT: Update pre-commit hook versions (mne-tools#14288)
  BUG: use fixed normalized CTPS cutoff for automatic ECG detection (mne-tools#14279)
  Move toward docstacks [circle deploy] [skip azp] [skip actions]
  Fix tfce (mne-tools#14286)
  FIX: Improve channel name rendering in `plot_alignment` (mne-tools#13773)
  ...

# Conflicts:
#	mne/viz/backends/tests/test_renderer.py
larsoner added a commit to natinew77-creator/mne-python that referenced this pull request Sep 11, 2026
larsoner added a commit to natinew77-creator/mne-python that referenced this pull request Sep 11, 2026
* upstream/main: (25 commits)
  ENH: add the JupyterLite notebook setup cell (JupyterLite split 4/5) (mne-tools#14150)
  FIX: Ver [circle deploy] [skip azp] [skip actions]
  Hotfix
  fix EDF round-trip (mne-tools#14296)
  Brain GUI modernization (Phase 7) (mne-tools#14270)
  Fix bug with SciPy 1.18.0 EEGLAB reading (mne-tools#14293)
  remove plotting abs as the defauls for plotting volumetric (mne-tools#13989)
  Coregistration GUI modernisation (phase 4) (mne-tools#14285)
  Dipole GUI interactivity and visual enhancements (phase 2) (mne-tools#14291)
  Width [circle deploy] [skip azp] [skip actions]
  Post-release deprecations (mne-tools#14290)
  FIX: Come on [circle deploy] [skip azp] [skip actions]
  PyVista try again [circle deploy] [skip azp] [skip actions]
  FIX: PyVista [circle deploy] [skip azp] [skip actions]
  FIX: Really [circle deploy] [skip azp] [skip actions]
  FIX: Doc
  Release commit [circle deploy]
  MAINT: Update code credit (mne-tools#14289)
  MAINT: Update pre-commit hook versions (mne-tools#14288)
  BUG: use fixed normalized CTPS cutoff for automatic ECG detection (mne-tools#14279)
  ...
larsoner added a commit to wmvanvliet/mne-python that referenced this pull request Sep 16, 2026
…d-sphere

* commit '0311e444b0450ce9d2b2b304cebe7d5343533357':
  Fix static doc viewing in IDEs (mne-tools#14195)
  Fix COLA for odd sizes (mne-tools#14312)
  add type hints to mne/_fiff/ module (mne-tools#14278)
  ENH: wire the JupyterLite build into the docs (JupyterLite split 5/5) (mne-tools#14157)
  MAINT: Update pre-commit hook versions (mne-tools#14306)
  Small documentation fix for "Frequency and time-frequency sensor analysis" tutorial (mne-tools#14304)
  FIX: don't mutate cached ICA sources in plot_sources properties (mne-tools#14303)
  Fix bug with lite backend closing (mne-tools#14302)
  Fix for NumPy eig change [circle deploy] (mne-tools#14300)
  No PyQt5 [circle deploy] [skip azp] [skip actions]
  ENH: add the JupyterLite notebook setup cell (JupyterLite split 4/5) (mne-tools#14150)
  FIX: Ver [circle deploy] [skip azp] [skip actions]
  Hotfix
  fix EDF round-trip (mne-tools#14296)
  Brain GUI modernization (Phase 7) (mne-tools#14270)
  Fix bug with SciPy 1.18.0 EEGLAB reading (mne-tools#14293)
  remove plotting abs as the defauls for plotting volumetric (mne-tools#13989)
  Coregistration GUI modernisation (phase 4) (mne-tools#14285)
  Dipole GUI interactivity and visual enhancements (phase 2) (mne-tools#14291)
larsoner added a commit to CarinaFo/mne-python that referenced this pull request Sep 16, 2026
* upstream/main: (91 commits)
  Fix static doc viewing in IDEs (mne-tools#14195)
  Fix COLA for odd sizes (mne-tools#14312)
  add type hints to mne/_fiff/ module (mne-tools#14278)
  ENH: wire the JupyterLite build into the docs (JupyterLite split 5/5) (mne-tools#14157)
  MAINT: Update pre-commit hook versions (mne-tools#14306)
  Small documentation fix for "Frequency and time-frequency sensor analysis" tutorial (mne-tools#14304)
  FIX: don't mutate cached ICA sources in plot_sources properties (mne-tools#14303)
  Fix bug with lite backend closing (mne-tools#14302)
  Fix for NumPy eig change [circle deploy] (mne-tools#14300)
  No PyQt5 [circle deploy] [skip azp] [skip actions]
  ENH: add the JupyterLite notebook setup cell (JupyterLite split 4/5) (mne-tools#14150)
  FIX: Ver [circle deploy] [skip azp] [skip actions]
  Hotfix
  fix EDF round-trip (mne-tools#14296)
  Brain GUI modernization (Phase 7) (mne-tools#14270)
  Fix bug with SciPy 1.18.0 EEGLAB reading (mne-tools#14293)
  remove plotting abs as the defauls for plotting volumetric (mne-tools#13989)
  Coregistration GUI modernisation (phase 4) (mne-tools#14285)
  Dipole GUI interactivity and visual enhancements (phase 2) (mne-tools#14291)
  Width [circle deploy] [skip azp] [skip actions]
  ...
@larsoner larsoner added the release-highlight Will be put in the highlight section of the release announcement label Dec 1, 2026
@larsoner larsoner removed the release-highlight Will be put in the highlight section of the release announcement label Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-candidate on-merge: backport to maint/1.13

Projects

None yet

Development

Successfully merging this pull request may close these issues.

edf export changes channel values

2 participants