mne-tools / mne-tools/mne-python

Function for creating toy data

Open
#10,954 18 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I often find myself generating toy data (e.g. for educational or testing purposes), so I thought a dedicated function might be useful.

It should be as simple as possible, for example:

from numpy.random import default_rng

from mne import create_info
from mne.io import RawArray


def create_toy_data(n_channels=3, duration=25, sfreq=250, seed=None):
    rng = default_rng(seed)
    data = rng.standard_normal(size=(n_channels, int(duration * sfreq))) * 5e-6
    info = create_info(n_channels, sfreq, "eeg")
    return RawArray(data, info)

It is important that there are sensible defaults for all parameters, which makes it possible to generate toy data very quickly:

raw = create_toy_data()

If people think this would be useful, I can go ahead and submit a PR.

Of course, this function could have a lot of additional parameters, such as

  • the kind of generated data (raw, epochs, evoked),
  • the probability distribution to sample from,
  • the channel type,
  • the data scaling,
  • ...

However, I'd say YAGNI until someone really needs a particular feature.

If there is interest, I have two questions:

  1. Where should this function live? I'd put it in mne.misc and export it to mne, but there might be a better place.
  2. The recommended method for generating random numbers is numpy.random.default_rng(seed), but the seed is not compatible with how we are dealing with random state (check_random_state()). If the function gets a seed or random_state parameter, how should we handle this?

So – yay or nay?

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 reviewing the proposed create_toy_data entry point in mne.misc, its export to mne, and the existing create_info and RawArray APIs. Compare the suggested numpy.random.default_rng(seed) approach with the project's check_random_state() handling. Done means the API location, random-state behavior, defaults, and supported output are agreed and implemented with appropriate tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data, testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.