Skip to content

GDF reader bug #12517

Closed
Closed

Description

@anamelnich

The lowpass filter in raw.info is not set correctly when uploading raw gdf file and doesn't update after filtering. I noticed it while trying to plot continuous data and getting a ZeroDivision error.
gdf file: [2024-02-28_13_14_s01_s01_r01.gdf]
Code to replicate:

import mne

file_path = '2024-02-28_13_14_s01_s01_r01.gdf'
raw = mne.io.read_raw_gdf(file_path, preload=True)
print(raw.info)
#raw.plot()

raw.filter(1, 50, fir_design="firwin")
print(raw.info)
raw.plot()

Error:

Traceback (most recent call last):
  File "...eegplot_test.py", line 11, in <module>
    raw.plot()
  File "...MNE-Python/1.6.1_0/.mne-python/lib/python3.11/site-packages/mne/io/base.py", line 1808, in plot
    return plot_raw(
           ^^^^^^^^^
  File "<decorator-gen-157>", line 12, in plot_raw
  File "...MNE-Python/1.6.1_0/.mne-python/lib/python3.11/site-packages/mne/viz/raw.py", line 258, in plot_raw
    decim, picks_data = _handle_decim(info, decim, lowpass)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...MNE-Python/1.6.1_0/.mne-python/lib/python3.11/site-packages/mne/viz/utils.py", line 1987, in _handle_decim
    decim = max(int(info["sfreq"] / (lp * 3) + 1e-6), 1)
                    ~~~~~~~~~~~~~~^~~~~~~~~~
ZeroDivisionError: float division by zero

raw.info before filtering:

<Info | 8 non-empty values
 bads: []
 ch_names: FP1, FPZ, FP2, F7, F3, FZ, F4, F8, FC5, FC1, FC2, FC6, M1, T7, ...
 chs: 67 EEG, 1 Stimulus
 custom_ref_applied: False
 highpass: 1.0 Hz
 lowpass: 0.0 Hz
 meas_date: 2024-02-28 19:14:52 UTC
 nchan: 68
 projs: []
 sfreq: 512.0 Hz
 subject_info: 4 items (dict)
>

raw.info after filtering:

<Info | 8 non-empty values
 bads: []
 ch_names: FP1, FPZ, FP2, F7, F3, FZ, F4, F8, FC5, FC1, FC2, FC6, M1, T7, ...
 chs: 67 EEG, 1 Stimulus
 custom_ref_applied: False
 highpass: 1.0 Hz
 lowpass: 0.0 Hz
 meas_date: 2024-02-28 19:14:52 UTC
 nchan: 68
 projs: []
 sfreq: 512.0 Hz
 subject_info: 4 items (dict)
>

Other information:
MNE version: 1.6.1
Operating system: macOS 12

Activity

  1. welcome commented on Mar 26, 2024

    @welcome

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

  2. cbrnr commented on Mar 26, 2024

    @cbrnr
    Contributor

    Note that I get the following warnings when loading the file:

    RuntimeWarning: Channels contain different highpass filters. Highest filter setting will be stored.
    RuntimeWarning: Channels contain different lowpass filters. Lowest filter setting will be stored.
    
  3. larsoner commented on Mar 27, 2024

    @larsoner
    Member

    We could either restrict info["lowpass"] to be strictly less than zero or (my vote) improve the sufficient-lowpass check to only run if info["lowpass"] > 0

  4. cbrnr commented on Mar 27, 2024

    @cbrnr
    Contributor

    Whatever you end up deciding, I just confirmed with @schloegl that the file in question does indeed have all zeros for its filter settings, so we need to deal with such files gracefully.

  5. larsoner commented on Mar 27, 2024

    @larsoner
    Member

    Yeah if we know this can happen with GDF files on some systems we could detect the behavior for at least that format

  6. cbrnr commented on Mar 27, 2024

    @cbrnr
    Contributor

    I think even with EDF it is not guaranteed that those header fields contain sane values. We could use fallback values of 0 Hz and fs/2 Hz in such cases, respectively.

  7. HansujaB commented on Mar 15, 2026

    @HansujaB
    Contributor

    Hi @larsoner @cbrnr , I would be interested in working on this issue. Before starting, I wanted to clarify the preferred approach.

    From the discussion it seems there are a few possible options:

    1. Update the sufficient-lowpass check in the plotting code to only run when info["lowpass"] > 0
    2. Handle invalid header values during file reading (e.g., using fallback values like sfreq/2)
    3. Another approach to ensure info["lowpass"] is always valid

    Should this be handled in the reader or in the plotting logic? I’d be happy to work on a PR once the intended behavior is clear.

  8. larsoner commented on Mar 16, 2026

    @larsoner
    Member

    We should fix the reader to put in reasonable values when the ones in the file are unrealistic

  9. HansujaB commented on Mar 18, 2026

    @HansujaB
    Contributor

    @larsoner
    I looked through edf.py , It seems the only change we need to fix this is ,

    • before: if np.isnan(info["lowpass"]):
    • after: if np.isnan(info["lowpass"]) or info["lowpass"] <= 0:

    There is already a regression test (test_edf_lowpass_zero) in mne/io/edf/tests/test_edf.py that checks that a 0 Hz lowpass is mapped to Nyquist, so no additional test is needed. With this change, the problematic GDF file now produces a valid info["lowpass"], and raw.plot() works without errors.

    Should I open a PR for this?

  10. larsoner commented on Mar 18, 2026

    @larsoner
    Member

    @HansujaB yes please!

  11. HansujaB commented on Mar 18, 2026

    @HansujaB
    Contributor

    @larsoner Done!

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions