Repository navigation
Closed
Description
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
Metadata
Metadata
Assignees
Labels
No labels
Activity
welcome commentedon Mar 26, 2024
Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴
cbrnr commentedon Mar 26, 2024
Note that I get the following warnings when loading the file:
larsoner commentedon Mar 27, 2024
We could either restrict
info["lowpass"]to be strictly less than zero or (my vote) improve the sufficient-lowpass check to only run ifinfo["lowpass"] > 0cbrnr commentedon Mar 27, 2024
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.
larsoner commentedon Mar 27, 2024
Yeah if we know this can happen with GDF files on some systems we could detect the behavior for at least that format
cbrnr commentedon Mar 27, 2024
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.
HansujaB commentedon Mar 15, 2026
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:
info["lowpass"] > 0sfreq/2)info["lowpass"]is always validShould 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.
larsoner commentedon Mar 16, 2026
We should fix the reader to put in reasonable values when the ones in the file are unrealistic
HansujaB commentedon Mar 18, 2026
@larsoner
I looked through edf.py , It seems the only change we need to fix this is ,
if np.isnan(info["lowpass"]):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?
larsoner commentedon Mar 18, 2026
@HansujaB yes please!
HansujaB commentedon Mar 18, 2026
@larsoner Done!