Skip to content

Error when reading an EDF file (resampling) #12897

Closed

Description

@cbrnr

From the forum:

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 might have been introduced by #11549.

@skjerns do you have time to take a look?

Activity

  1. skjerns commented on Oct 14, 2024

    @skjerns
    Contributor

    The bug seems to be specific to that certain EDF-file. Without a file to reproduce I'm at loss :-/

    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)
  2. cbrnr commented on Oct 14, 2024

    @cbrnr
    ContributorAuthor

    Unfortunately, I do not have the file either. The original reporter in the forum says he can't share the file, but it seems to happen with one specific channel only. However, I already mentioned that this might make it impossible for us to fix the problem.

  3. joseph-pq commented on Oct 14, 2024

    @joseph-pq

    Hi, @skjerns . I made an anonymized version with two signals: "working_ch" and "failing_ch".
    output.zip

  4. skjerns commented on Oct 15, 2024

    @skjerns
    Contributor

    Can reproduce. Will look into it.

    Workaround is to use preload=True

    import mne
    edf = mne.io.read_raw_edf("my/edf/file.edf", preload=True)
    out = edf.get_data(picks=["my_channel"], return_times=False)
  5. h-mayorquin commented on Oct 16, 2024

    @h-mayorquin

    commenting to follow up on this.

  6. cbrnr commented on Oct 16, 2024

    @cbrnr
    ContributorAuthor

    @h-mayorquin you don't have to comment if you want to follow a PR/issue, there's a "Subscribe" button for this purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions