AssertionError at max(n_smp_read) == smp_exp

Versions:

  • MNE version: 1.8
  • python version: 3.12
  • operating system: Ubuntu 24.04

Hi!
I’m trying to read a channel from an edf file using the code below:

import mne
edf = mne.io.read_raw_edf("my/edf/file.edf")
out = edf.get_data(picks=["my_channel"], return_times=False)

But the edf.get_data line raises an AssertionError as shown in the following traceback:

my_file:35: in edf_data
    out = edf.get_data(picks=["my_channel"], return_times=False)
<decorator-gen-190>:12: in get_data
    ???
myvenv/lib/python3.12/site-packages/mne/io/base.py:956: in get_data
    getitem = self._getitem(
myvenv/lib/python3.12/site-packages/mne/io/base.py:853: in _getitem
    data = self._read_segment(start=start, stop=stop, sel=sel)
<decorator-gen-187>:12: in _read_segment
    ???
myvenv/lib/python3.12/site-packages/mne/io/base.py:472: in _read_segment
    _ReadSegmentFileProtector(self)._read_segment_file(
myvenv/lib/python3.12/site-packages/mne/io/base.py:2598: in _read_segment_file
    return self.__raw.__class__._read_segment_file(
myvenv/lib/python3.12/site-packages/mne/io/edf/edf.py:220: in _read_segment_file
    return _read_segment_file(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
                smp_exp = data.shape[-1]
>               assert max(n_smp_read) == smp_exp
E               AssertionError

myvenv/lib/python3.12/site-packages/mne/io/edf/edf.py:442: AssertionError

I cannot share the edf file but I tested with mne==1.4 and with that version works.

This is a bug, I’ve created an issue here:

We might need the EDF file for debugging though, maybe you can share it privately?

Hi @cbrnr, I apologize but I cannot share the data as I’ve signed a confidentiality agreement. I’ve seen that this problem only occurs in one channel because I can read other channels of the same file.

Let’s continue the discussion in the linked GitHub issue please. Maybe we can figure out the problem without the file.

1 Like

Without a file it will be difficult to debug.

Can you create an anonymized version of the EDF with pyedflib?

from pyedflib import highlevel

signals, signal_headers, header = highlevel.read_edf('input.edf')

# scramble data, this should basically destroy any information contained
random_signals = [np.random.choice(sig, len(sig)) for sig in signals]

# Alternatively: Completely random data with same shape as existing signals
# random_signals = [np.random.unform(min(sig), max(sig), len(sig)) for sig in signals]

# Update headers for anonymization
header['patientname'] = 'anonymous'
header['patient_additional'] = 'anonymous'
header['recording_additional'] = 'anonymous'
header['equipment'] = 'anonymous'
header['admincode'] = 'anon'
header['annotations'] = []

# Create an output EDF file with random data
highlevel.write_edf('output.edf', random_signals, signal_headers, header)

I encountered the same issue. https://physionet.org/content/capslpdb/1.0.0/n4.edf is an edf file that you can reproduce the above AssertionError.
As @joseph.pena said, it works with mne==1.4. But a higher version would report an error.
And I found pyedflib can read this file correctly.

I can read this file fine with the latest dev version with both preload=True and preload=False.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.