# @title Data retrieval import os, requests fname = 'motor_imagery.npz' url = "https://osf.io/ksqv8/download" if not os.path.isfile(fname): try: r = requests.get(url) except requests.ConnectionError: print("!!! Failed to download data !!!") else: if r.status_code != requests.codes.ok: print("!!! Failed to download data !!!") else: with open(fname, "wb") as fid: fid.write(r.content)
# @title Install packages (`nilearn`, `nimare`. `duecredit`), import `matplotlib` and set defaults # install packages to visualize brains and electrode locations !pip install nilearn --quiet !pip install nimare --quiet !pip install duecredit --quiet from matplotlib import rcParams from matplotlib import pyplot as plt rcParams['figure.figsize'] = [20, 4] rcParams['font.size'] = 15 rcParams['axes.spines.top'] = False rcParams['axes.spines.right'] = False rcParams['figure.autolayout'] = True
# @title Data loading import numpy as np alldat = np.load(fname, allow_pickle=True)['dat'] # select just one of the recordings here. 11 is nice because it has some neurons in vis ctx. dat1 = alldat dat2 = alldat print(dat1.keys()) print(dat2.keys())
dict_keys(['t_off', 'stim_id', 't_on', 'srate', 'V', 'scale_uv', 'locs', 'hemisphere', 'lobe', 'gyrus', 'Brodmann_Area']) dict_keys(['t_off', 'stim_id', 't_on', 'srate', 'V', 'scale_uv', 'locs', 'hemisphere', 'lobe', 'gyrus', 'Brodmann_Area'])
This is one of multiple ECoG datasets from Miller 2019, recorded in a clinical settings with a variety of tasks. Raw data and dataset paper are here:
This particular dataset was originally described in this paper:
dat2 are data from the two blocks performed in each subject. The first one was the actual movements, the second one was motor imagery. For the movement task, from the original dataset instructions:
Patients performed simple, repetitive, motor tasks of hand (synchronous flexion and extension of all fingers, i.e., clenching and releasing a fist at a self-paced rate of ~1-2 Hz) or tongue (opening of mouth with protrusion and retraction of the tongue, i.e., sticking the tongue in and out, also at ~1-2 Hz). These movements were performed in an interval-based manner, alternating between movement and rest, and the side of move- ment was always contralateral to the side of cortical grid placement.
For the imagery task, from the original dataset instructions:
Following the overt movement experiment, each subject performed an imagery task, imagining making identical movement rather than executing the movement. The imagery was kinesthetic rather than visual (“imagine yourself performing the actions like you just did”; i.e., “don’t imagine what it looked like, but imagine making the motions”).
Sample rate is always 1000Hz, and the ECoG data has been notch-filtered at 60, 120, 180, 240 and 250Hz, followed by z-scoring across time and conversion to float16 to minimize size. Please convert back to float32 after loading the data in the notebook, to avoid unexpected behavior.
dat['V']: continuous voltage data (time by channels)
dat['srate']: acquisition rate (1000 Hz). All stimulus times are in units of this.
dat['t_on']: time of stimulus onset in data samples
dat['t_off']: time of stimulus offset, always 400 samples after
dat['stim_id]: identity of stimulus (11 = tongue, 12 = hand), real or imaginary stimulus
dat['scale_uv']: scale factor to multiply the data values to get to microvolts (uV).
dat['locs]`: 3D electrode positions on the brain surface
from nilearn import plotting from nimare import utils plt.figure(figsize=(8, 8)) locs = dat1['locs'] view = plotting.view_markers(utils.tal2mni(locs), marker_labels=['%d'%k for k in np.arange(locs.shape)], marker_color='purple', marker_size=5) view