Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when reading an EDF file (resampling) #12897

Open
cbrnr opened this issue Oct 13, 2024 · 6 comments
Open

Error when reading an EDF file (resampling) #12897

cbrnr opened this issue Oct 13, 2024 · 6 comments
Labels

Comments

@cbrnr
Copy link
Contributor

cbrnr commented Oct 13, 2024

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?

@cbrnr cbrnr added the BUG label Oct 13, 2024
@skjerns
Copy link
Contributor

skjerns commented Oct 14, 2024

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)

@cbrnr
Copy link
Contributor Author

cbrnr commented Oct 14, 2024

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.

@joseph-pq
Copy link

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

@skjerns
Copy link
Contributor

skjerns commented Oct 15, 2024

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)

@h-mayorquin
Copy link

commenting to follow up on this.

@cbrnr
Copy link
Contributor Author

cbrnr commented Oct 16, 2024

@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
Labels
Projects
None yet
Development

No branches or pull requests

4 participants