Skip to content

DOC: clarify add_reference_channels usage (Takeover #13664)#13846

Open
Dpereaptkhamur-13 wants to merge 13 commits intomne-tools:mainfrom
Dpereaptkhamur-13:doc-ref-channel-clarification
Open

DOC: clarify add_reference_channels usage (Takeover #13664)#13846
Dpereaptkhamur-13 wants to merge 13 commits intomne-tools:mainfrom
Dpereaptkhamur-13:doc-ref-channel-clarification

Conversation

@Dpereaptkhamur-13
Copy link
Copy Markdown

Reference issue (if any)

What does this implement/fix?

This PR completes the documentation clarification for add_reference_channels originally started in #13664. It addresses the mathematical requirements for average referencing in the docstrings, as requested in issue #13618.
Changes include:

  • Added an explicit note to the add_reference_channels docstring explaining average reference recomputation.
  • Included a properly formatted towncrier entry in doc/changes/dev/13618.notable.rst to resolve the check failures seen in the previous PR.

Additional information

@HansujaB
Copy link
Copy Markdown
Contributor

HansujaB commented Apr 18, 2026

Hey @Dpereaptkhamur-13 , I believe you don't have an account on circle ci that's why those checks are failing , login into your account & those tests will pass !

@Dpereaptkhamur-13
Copy link
Copy Markdown
Author

Hi @HansujaB, thank you for the tip! I have now logged into CircleCI and authorized the account. The tests should be ready to run once a maintainer approves the workflow. Thanks again for the help!

@tsbinns
Copy link
Copy Markdown
Contributor

tsbinns commented Apr 20, 2026

Hi @Dpereaptkhamur-13, thanks for opening the PR.

Right now, the message has been added to add_reference_channels. However, the risk is that people are calling set_eeg_reference without calling add_reference_channels first. So, this note about the proper procedure could be easily missed by the people who need to see it most.

Rather, the note should be included in set_eeg_reference, such that people see this, and then go back to use add_refence_channels. I'd suggest looking at how this was handled in #13664 and adding the note to the docdict: https://github.com/Farzah11/mne-python/blob/a8e92a3a7d8a83a021d81da9c6b1b38f678ad53f/mne/utils/docs.py#L4106-L4112

Just make sure if you use this text to action the suggested changes: https://github.com/mne-tools/mne-python/pull/13664/changes#r2892847499 and https://github.com/mne-tools/mne-python/pull/13664/changes#r2892851172

Then, it would be good to also add a note to the setting_eeg_reference tutorial, similar to in #13664: https://github.com/Farzah11/mne-python/blob/a8e92a3a7d8a83a021d81da9c6b1b38f678ad53f/tutorials/preprocessing/55_setting_eeg_reference.py#L144-L150
However, also keep in mind the formatting suggestion to get this to render properly: https://github.com/mne-tools/mne-python/pull/13664/changes#r2892854083

@Dpereaptkhamur-13
Copy link
Copy Markdown
Author

Hi @tsbinns, thank you for the detailed feedback! That makes complete sense—moving the clarification to set_eeg_reference and the tutorials ensures it's visible to users regardless of which function they check first. I will update mne/utils/docs.py and the preprocessing tutorial file accordingly. I'll ping you again once the changes are pushed!

Comment thread mne/utils/docs.py Outdated
.. note::
If you wish to add a new reference channel (e.g., a mastoid)
to the data, use :func:`mne.add_reference_channels`
**before** calling this function.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest specifically mentioning average referencing for sensor-space analyses. E.g.:

When performing average referencing in sensor-space analyses and the original reference electrode is not present as a zero-filled channel, this must first be added using :func:~mne.add_reference_channels before calling :func:~mne.set_eeg_reference to avoid biasing the reference.

Also, please add a citation for the paper where this gets discussed (10.3389/frsip.2023.1064138). Have a look at :footcite: and :footbibliography: for examples of doing this after adding the citation to our BibTeX file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @drammock, I've updated the documentation note with the sensor-space details and added the citation to references.bib as requested. I also included the footbibliography in the tutorial. Ready for another look!

Comment on lines +149 to +153

# .. note::
# If you wish to add a new reference channel (e.g., a mastoid)
# to the data, use :func:`mne.add_reference_channels`
# **before** calling this function.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the tutorial note on line 150 with the expanded detail and citation as suggested. All feedback from the review should now be addressed. Thanks for the guidance!

Comment thread mne/channels/channels.py Outdated
Comment on lines +815 to +820
note:: If you are adding a new reference channel to data that
will eventually be used with an average reference,
you should also call :meth:`mne.io.Raw.set_eeg_reference`
(or the equivalent Epochs/Evoked method) to ensure the
mathematical reference is updated correctly.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This information isn't so relevant to add_reference_channels. The purpose of this function isn't to change the reference, it just adds zero-filled channels.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have addressed all the feedback:

Removed the irrelevant note from mne/channels/channels.py.

Expanded the note in the tutorial with sensor-space details and the citation.

Added the bibliography to the tutorial file.

Everything should be consistent now. Thank you for the detailed reviews!

Comment thread mne/utils/docs.py
A new virtual reference electrode is created by averaging the current
EEG signal by setting ``ref_channels='average'``. Bad EEG channels are
automatically excluded if they are properly set in ``info['bads']``.
automatically excluded if they are pproperly set in ``info['bads']``.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
automatically excluded if they are pproperly set in ``info['bads']``.
automatically excluded if they are properly set in ``info['bads']``.

Comment thread mne/utils/docs.py
Comment on lines +4109 to +4113
"add_reference_channels_note": """.. note:: When performing average referencing in sensor-space analyses and the
original reference electrode is not present as a zero-filled channel,
this must first be added using :func:`~mne.add_reference_channels`
before calling :func:`~mne.set_eeg_reference` to avoid biasing the
reference :footcite:`AppelhoffSanderson2023`. """,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"add_reference_channels_note": """.. note:: When performing average referencing in sensor-space analyses and the
original reference electrode is not present as a zero-filled channel,
this must first be added using :func:`~mne.add_reference_channels`
before calling :func:`~mne.set_eeg_reference` to avoid biasing the
reference :footcite:`AppelhoffSanderson2023`. """,
.. note::
When performing average referencing in sensor-space analyses and the original
reference electrode is not present as a zero-filled channel, this must first be
added using :func:`~mne.add_reference_channels`, before calling
:func:`~mne.set_eeg_reference`. This is necessary to avoid biasing the reference
:footcite:`AppelhoffSanderson2023`.

Comment on lines +149 to +155

# .. note:: When performing average referencing in sensor-space analyses and
# the original reference electrode is not present as a zero-filled
# channel, this must first be added using
# :func:`~mne.add_reference_channels` before calling
# :func:`~mne.set_eeg_reference` to avoid biasing the reference
# :footcite:`AppelhoffSanderson2023`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please copy the changes from the note in the docstring, including the proper formatting.

Comment thread mne/channels/channels.py
Comment on lines +815 to +816
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these blank lines.

Comment thread doc/references.bib
Comment on lines +2570 to +2578
@article{AppelhoffSanderson2023,
author = {Appelhoff, Stefan and Sanderson, Nathan},
title = {The importance of adding a zero-filled channel for the reference electrode when re-referencing to average reference},
journal = {Frontiers in Signal Processing},
year = {2023},
doi = {10.3389/frsip.2023.1064138},
volume = {3},
pages = {1064138}
} No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things:

  1. This author and title information is wrong. This needs to be corrected.
  2. The bibliography file isn't perfectly alphabetical, but please try to stick the citation in roughly the right place, not just at the end of the file.

@@ -0,0 +1 @@
Clarify average EEG reference behavior in documentation for add_reference_channels. No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple things:

  • Now that the changes for this PR are a bit clearer, the changelog entry text should be updated.
  • You would need to add your name with the newcontrib tag to the end of the text.
  • The number in the file name must match the PR number.
  • This is not a notable change. other would be more appropriate.

Precise details for all of this are in the contribution guide. Please follow the instructions there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants