Skip to content

Conversation

@sappelhoff
Copy link
Member

@sappelhoff sappelhoff commented Mar 18, 2020

closes #7471

These are the files I could catch that did still assume MNE-Python to auto apply an average ref projection. Also, the docstr of set_eeg_reference was still assuming that.

I wasn't sure with tutorials/preprocessing/plot_55_setting_eeg_reference.py --> see my inline "todo" comment there marked with XXX

PS: What was the PR that removed the auto average ref behavior of MNE?

# XXX: IS THIS TRUE?
# For these reasons, when performing inverse imaging, *MNE-Python will
# automatically average-reference the EEG channels if they are present and no
# reference strategy has been specified*. If you want to perform inverse
Copy link
Member Author

Choose a reason for hiding this comment

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

note: I am uncertain about how to change the lines above. Will MNE-Python or will it NOT apply auto average refs?

Copy link
Member

Choose a reason for hiding this comment

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

As far as I can tell, it is not automatically applied:

  • _check_reference is called in _apply_inverse here
  • _check_reference (here) calls _needs_eeg_average_ref_proj (here), which returns True if (1) there are EEG channels present, and (2) a custom ref has not been applied, and (3) EEG average reference proj is not already there.

Instead, the user will get a ValueError.

In fact, it doesn't even seem to be possible any more to avoid this constraint by setting average reference to an empty list:

raw = mne.io.read_raw_fif(sample_data_raw_file, verbose=False).crop(tmax=30).load_data()               
raw = raw.set_eeg_reference([])                                                                        
mne.minimum_norm.inverse._check_reference(raw)
# ValueError: EEG average reference is mandatory for inverse modeling, use set_eeg_reference method.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @drammock

@codecov
Copy link

codecov bot commented Mar 18, 2020

Codecov Report

Merging #7474 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #7474   +/-   ##
=======================================
  Coverage   90.08%   90.08%           
=======================================
  Files         454      454           
  Lines       82539    82608   +69     
  Branches    13051    13066   +15     
=======================================
+ Hits        74353    74420   +67     
- Misses       5360     5361    +1     
- Partials     2826     2827    +1     

@sappelhoff
Copy link
Member Author

sappelhoff commented Mar 18, 2020

def set_eeg_reference(self, ref_channels='average', projection=False,
class SetChannelsMixin(MontageMixin) has a set_eeg_reference method which is just pointing to mne.set_eeg_reference.

Instead of duplicating the docstring in that class method, can we somehow "import it" from the original mne.set_eeg_reference?

@drammock
Copy link
Member

Instead of duplicating the docstring in that class method, can we somehow "import it" from the original mne.set_eeg_reference?

You can take a look at mne/utils/docs.py to see docdict; frequently re-used docstring elements are put there, and then inserted via %(docdict_key_name)s where they're needed. There are also decorators @copy_function_doc_to_method_doc and @copy_doc.

@sappelhoff
Copy link
Member Author

sappelhoff commented Mar 18, 2020

Cool, this decorator would be perfect for it:

def copy_function_doc_to_method_doc(source):

except for two things:

  1. the method I would like to receive a copy of the function docstring does not have a parameter that the function has (copy, the 3rd param of the function)
  2. the function has two return values, the method only one (that one is congruent between method and function though).

perhaps the decorator could be extended with an optional parameter to delete a list of params by indices (currently, it's only deleting the first param, index 0) ... and extend the param deletion to a deletion of return values as well?

@larsoner
Copy link
Member

perhaps the decorator could be extended with an optional parameter to delete a list of params by indices (currently, it's only deleting the first param, index 0) ... and extend the param deletion to a deletion of return values as well?

Maybe but it's not too difficult just to split the docstring into needed parts. Also we have to be wary of adding complexity to our docstring modifiers since they are executed on import.

See how I dealt with this sort of thing recently in MaxFilter:

https://github.com/mne-tools/mne-python/blob/master/mne/preprocessing/maxwell.py#L63-L93

There is a function that uses all the same params except for a couple (e.g., st_duration, st_correlation which are not allowed) so I grouped params and made entries in docs.py:

https://github.com/mne-tools/mne-python/blob/master/mne/utils/docs.py#L298-L384

@sappelhoff sappelhoff changed the title DOC: MNE does no longer auto apply average ref MRG: [DOC] MNE does no longer auto apply average ref Mar 18, 2020
@sappelhoff
Copy link
Member Author

okay, thanks. Ready from my side.

@drammock
Copy link
Member

@sappelhoff you have a "double line break" error in the docstring test. to iterate more quickly to find a solution, you can do make docstring locally from the root of the repo, to see if your fixes work.

@sappelhoff
Copy link
Member Author

@sappelhoff you have a "double line break" error in the docstring test. to iterate more quickly to find a solution, you can do make docstring locally from the root of the repo, to see if your fixes work.

I tried several things now but couldn't find the issue :-/

@agramfort
Copy link
Member

agramfort commented Mar 18, 2020 via email

sappelhoff and others added 3 commits March 18, 2020 22:49
Co-Authored-By: Alexandre Gramfort <alexandre.gramfort@m4x.org>
@drammock
Copy link
Member

@sappelhoff I fixed the double line break error (locally, at least). The problem was that there was a line break between the end of the Returns section and the %(docdict_key)s code, and the thing that gets filled in by the %(docdict_key)s code begins with another linebreak. I also pushed a fix for slightly nicer formatting in the notes section.

@sappelhoff sappelhoff force-pushed the refdoc branch 2 times, most recently from cd8a202 to 8e396b9 Compare March 19, 2020 09:45
Co-authored-by: Daniel McCloy <drammock@users.noreply.github.com>
@sappelhoff
Copy link
Member Author

Thanks a lot @drammock

@larsoner larsoner merged commit fcbe5ae into mne-tools:master Mar 19, 2020
@larsoner
Copy link
Member

Thanks @sappelhoff

@sappelhoff sappelhoff deleted the refdoc branch March 19, 2020 13:22
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.

Update docs and code: set_eeg_reference([]) and the automatic average

4 participants