mne-tools / mne-tools/mne-python

No bounds checks for `{raw,epochs}.get_data()` with `tmin` or `tmax`

Open
#11,810 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
3.5k
Forks
1.6k
Avg merge
1d 6h
Merged PRs (30d)
100

Description

I was a bit surprised to find out that .get_data() in combination with tmin or tmax arguments does not perform any bounds checks, but instead just returns the (entire) data array. I expected an error, a warning, or at least an info message stating that a given tmin or tmax argument exceeded the available data range.

Is this an intentional decision? If so, it should at least be documented. I think the current behavior is very dangerous, because it can lead to bugs that are really hard to find.

n_channels = 32
sfreq = 256
data = np.ones((n_channels, 100 * sfreq))
info = mne.create_info(n_channels, sfreq)
raw = mne.io.RawArray(data, info)
onsets = np.arange(1 * sfreq, 91 * sfreq, sfreq, dtype=int)
events = np.column_stack(
    (onsets, np.zeros(len(onsets), dtype=int), np.ones(len(onsets), dtype=int))
)
epochs = mne.Epochs(raw, events, tmin=-0.2, tmax=0.5)

epochs.get_data(tmin=-0.6, tmax=1.8)  # both tmin and tmax exceed data range!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied example and inspecting the get_data() entry points for Raw and Epochs. Determine whether out-of-range tmin or tmax should raise, warn, report information, or be documented as intentional; completion should make the behavior explicit and cover both objects consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.