Skip to content

Commit

Permalink
Parse all prefiltering of edf/bdf in _read_edf_header and remain them…
Browse files Browse the repository at this point in the history
… in _raw_extras

Select channels of sel but stim chanenl to set highpass/lowpass in info
  • Loading branch information
rcmdnk committed Feb 19, 2024
1 parent d22a503 commit 0f2f7c2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
12 changes: 6 additions & 6 deletions mne/io/edf/edf.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,9 @@ def _get_info(
info["subject_info"]["weight"] = float(edf_info["subject_info"]["weight"])

# Filter settings
_set_prefilter(info, edf_info, "highpass")
_set_prefilter(info, edf_info, "lowpass")
if filt_ch_idxs := [x for x in sel if x not in stim_channel_idxs]:
_set_prefilter(info, edf_info, filt_ch_idxs, "highpass")
_set_prefilter(info, edf_info, filt_ch_idxs, "lowpass")

if np.isnan(info["lowpass"]):
info["lowpass"] = info["sfreq"] / 2.0
Expand Down Expand Up @@ -746,9 +747,10 @@ def _prefilter_float(filt):
return np.nan


def _set_prefilter(info, edf_info, key):
def _set_prefilter(info, edf_info, ch_idxs, key):
value = 0
if len(values := edf_info.get(key, [])):
values = [x for i, x in enumerate(values) if i in ch_idxs]
if len(np.unique(values)) > 1:
warn(
f"Channels contain different {key} filters. "
Expand Down Expand Up @@ -936,9 +938,7 @@ def _read_edf_header(fname, exclude, infer_types, include=None):
digital_max = np.array([float(_edf_str_num(fid.read(8))) for ch in channels])[
sel
]
prefiltering = np.array([_edf_str(fid.read(80)).strip() for ch in channels])[
sel
]
prefiltering = np.array([_edf_str(fid.read(80)).strip() for ch in channels])
highpass, lowpass = _parse_prefilter_string(prefiltering)

# number of samples per record
Expand Down
6 changes: 4 additions & 2 deletions mne/io/edf/tests/test_edf.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,9 @@ def test_edf_set_prefilter(edf_info, hp, lp, hp_warn, lp_warn):
else:
ctx = nullcontext()
with ctx:
_set_prefilter(info, edf_info, "highpass")
_set_prefilter(
info, edf_info, list(range(len(edf_info["highpass"]))), "highpass"
)

if lp_warn:
ctx = pytest.warns(
Expand All @@ -723,7 +725,7 @@ def test_edf_set_prefilter(edf_info, hp, lp, hp_warn, lp_warn):
else:
ctx = nullcontext()
with ctx:
_set_prefilter(info, edf_info, "lowpass")
_set_prefilter(info, edf_info, list(range(len(edf_info["lowpass"]))), "lowpass")
assert info["highpass"] == hp
assert info["lowpass"] == lp

Expand Down
13 changes: 6 additions & 7 deletions mne/report/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,12 @@ def test_render_non_fiff(tmp_path):
fnames_out.append(fname_out)

report = Report()
with pytest.warns(RuntimeWarning, match="Channels contain different"):
report.parse_folder(
data_path=tmp_path,
render_bem=False,
on_error="raise",
raw_butterfly=False,
)
report.parse_folder(
data_path=tmp_path,
render_bem=False,
on_error="raise",
raw_butterfly=False,
)

# Check correct paths and filenames
_, _, content_titles, _ = report._content_as_html()
Expand Down

0 comments on commit 0f2f7c2

Please sign in to comment.