Coder Social home page Coder Social logo

Inconsistent behavior between `Epochs` and `Evoked` in `get_data()` method when picking EEG channels and bads are present about mne-python HOT 7 OPEN

hoechenberger avatar hoechenberger commented on August 17, 2024
Inconsistent behavior between `Epochs` and `Evoked` in `get_data()` method when picking EEG channels and bads are present

from mne-python.

Comments (7)

hoechenberger avatar hoechenberger commented on August 17, 2024 2

My feeling is that we should add exclude parameters to all these get_data() methods if they don't have one already, retaining the current behavior; and do a deprecation cycle for transitioning to either exclude=() or exclude="bads" for all of them

from mne-python.

hoechenberger avatar hoechenberger commented on August 17, 2024 1

@cbrnr Note that I did not pass None in my MWE! I did pass picks="eeg"

The doctoring says:

Note that channels in info['bads'] will be included if their names or indices are explicitly provided.

So something about this point is inconsistent between epochs and evoked at least when passing picks="eeg".

I think what you're mentioning here is being tracked at #12197

from mne-python.

cbrnr avatar cbrnr commented on August 17, 2024

The docstrings are identical, so I think both methods should behave identically. In addition, the docstring says:

None (default) will pick all channels.

I think this should be:

None (default) will pick all good channels.

At least that's how it currently works for Epochs, but not for Evoked apparently.

https://mne.tools/dev/generated/mne.Epochs.html#mne.Epochs.get_data
https://mne.tools/dev/generated/mne.Evoked.html#mne.Evoked.get_data

from mne-python.

larsoner avatar larsoner commented on August 17, 2024

So something about this point is inconsistent between epochs and evoked at least when passing picks="eeg".

Neither get_data has an exclude param, sounds like one is implicitly using exclude="bads" and the other exclude=() under the hood. To change the behavior of one to match the other and be consistent I think we'd need a deprecation cycle, not sure whether or not it's worth the code churn. To update the docstring of both to reflect their actual behavior it wouldn't require a deprecation cycle. Adding exclude to both (to make the behavior more explicit and controllable) is probably worthwhile either way.

from mne-python.

cbrnr avatar cbrnr commented on August 17, 2024

Even if documented I think it would be a bit surprising if Epochs and Evoked used different pick defaults. So I'd document the behavior with whatever version we think makes more sense, be consistent for both methods and deprecate the inconsistent behavior. And yes, an explicit exclude parameter would definitely make sense to me.

from mne-python.

hoechenberger avatar hoechenberger commented on August 17, 2024

I tested the MWE with Raw and now it seems it's actually Epochs who's the odd one:

# %%
import mne

sample_dir = mne.datasets.sample.data_path()
sample_fname = sample_dir / "MEG" / "sample" / "sample_audvis_raw.fif"

raw = mne.io.read_raw_fif(sample_fname)
raw.crop(tmax=60)

events = mne.find_events(raw, stim_channel="STI 014")
raw.pick("eeg")

epochs = mne.Epochs(raw, events=events, preload=True)
evoked = epochs.average()

# %%
for inst_type, inst in zip(["raw", "epochs", "evoked"], [raw, epochs, evoked]):
    print(f"{inst_type}:")
    print(f"    bads: {inst.info['bads']}")
    print(f"    data shape: {inst.get_data(picks='eeg').shape}")
raw:
    bads: ['EEG 053']
    data shape: (60, 36038)
epochs:
    bads: ['EEG 053']
    data shape: (86, 59, 421)
evoked:
    bads: ['EEG 053']
    data shape: (60, 421)

from mne-python.

hoechenberger avatar hoechenberger commented on August 17, 2024

More digging:

  • BaseSpectrum.get_data() features exclude="bads'
  • BaseTFR ditto

from mne-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.