Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/dev/13917.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug with :func:`mne.set_eeg_reference` not working when passing a single channel name as string, by `Michael Straube`_.
4 changes: 4 additions & 0 deletions mne/_fiff/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ def set_eeg_reference(
logger.info("Applying a custom dict-based reference.")
return _apply_dict_reference(inst, ref_channels)

# We need 'ref_channels' to be a list, even for a single channel name.
if isinstance(ref_channels, str) and ref_channels not in ("average", "REST"):
ref_channels = [ref_channels]

ch_type = _get_ch_type(inst, ch_type)

if projection: # average reference projector
Expand Down
4 changes: 4 additions & 0 deletions mne/_fiff/tests/test_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ def test_set_eeg_reference():
with pytest.raises(ValueError, match='supported for ref_channels="averag'):
set_eeg_reference(raw, ["EEG 001"], True, True)

# Test passing a single channel name as string
reref, ref_data = set_eeg_reference(raw, "EEG 001", copy=True)
_test_reference(raw, reref, ref_data, ["EEG 001"])


@pytest.mark.parametrize(
"ch_type, msg",
Expand Down
2 changes: 1 addition & 1 deletion tutorials/intro/15_inplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
# we specified ``copy=True``:

# sphinx_gallery_thumbnail_number=2
rereferenced_raw, ref_data = mne.set_eeg_reference(original_raw, ["EEG 003"], copy=True)
rereferenced_raw, ref_data = mne.set_eeg_reference(original_raw, "EEG 003", copy=True)
fig_orig = original_raw.plot()
fig_reref = rereferenced_raw.plot()

Expand Down
10 changes: 5 additions & 5 deletions tutorials/preprocessing/55_setting_eeg_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@
# earlobe or mastoid channels, so this is just for demonstration purposes:

# use a single channel reference (left earlobe)
# raw.set_eeg_reference(ref_channels=['A1'])
# raw.set_eeg_reference(ref_channels='A1')

# use average of mastoid channels as reference
# raw.set_eeg_reference(ref_channels=['M1', 'M2'])

# use a bipolar reference (contralateral)
# raw.set_bipolar_reference(anode='[F3'], cathode=['F4'])
# raw.set_bipolar_reference(anode='F3', cathode='F4')

# %%
# If a scalp electrode was used as reference but was not saved alongside the
Expand All @@ -109,14 +109,14 @@
# ``copy=False``.

# add new reference channel (all zero)
raw_new_ref = mne.add_reference_channels(raw, ref_channels=["EEG 999"])
raw_new_ref = mne.add_reference_channels(raw, ref_channels="EEG 999")
raw_new_ref.plot()

# %%
# .. KEEP THESE BLOCKS SEPARATE SO FIGURES ARE BIG ENOUGH TO READ

# set reference to `EEG 050`
raw_new_ref.set_eeg_reference(ref_channels=["EEG 050"])
raw_new_ref.set_eeg_reference(ref_channels="EEG 050")
raw_new_ref.plot()

# %%
Expand Down Expand Up @@ -218,7 +218,7 @@
# :footcite:`YaoEtAl2019` which creates a new virtual channel
# named ``EEG 054-EEG 055``.

raw_bip_ref = mne.set_bipolar_reference(raw, anode=["EEG 054"], cathode=["EEG 055"])
raw_bip_ref = mne.set_bipolar_reference(raw, anode="EEG 054", cathode="EEG 055")
raw_bip_ref.plot()

# %%
Expand Down
Loading