python library for working on mne tag
Project description
tag-mne
python library for handling tag of mne Epochs object
Install
# using pip
pip install tag-mne
Usage
general
import tag_mne as tm
events, event_id = mne.events_from_annotations(mne_raw_object_run1)
# convert mne events and event_id to samples and markers
# markers[i] is string tag corresponding to samples[i]
samples, markers = tm.markers_from_events(events, event_id)
# by doing this, you can tag name of events to each marker
event_names = {'event_1': ['1', '101'], 'event_2': ['2', '102']}
markers = tm.add_event_names(markers, event_names)
# add tag for whole markers
# in this case, 'run:1' tag will be added
markers = tm.add_tag(markers, "run:1")
# do this if you want to tag trial name or number
# for argument 'trial', specify the markers indicate new trials
markers = tm.split_trials(markers, trial = [str(val) for val in range(201, 300)])
# add target or nontarget tag by specifying the markers for target and nontarget events
markers = tm.add_tnt(markers, target = [str(val) for val in range(101, 200)], nontarget = [str(val) for val in range(1, 100)])
# you can remove events which has specific tag
# in this case, it will remove 'misc' events which is irrelevant to analysis
samples, markers = tm.remove(samples, markers, "misc")
# finally, convert to mne events and event_id
events, event_id = tm.events_from_markers(samples, makers)
# create epochs
epochs = mne.Epochs(raw = mne_raw_object_run1,
events = events,
event_id = event_id)
epochs_list = []
epochs_list.append(epochs)
# if you have raw object for different runs or recordings...
# do the same as above
events, event_id = mne.events_from_annotations(mne_raw_object_run2)
samples, markers = tm.markers_from_events(events, event_id)
event_names = {'event_1': ['1', '101'], 'event_2': ['2', '102']}
markers = tm.add_event_names(markers, event_names)
# for this raw, specify 'run:2'
markers = tm.add_tag(markers, "run:2")
markers = tm.split_trials(markers, trial = [str(val) for val in range(201, 300)])
markers = tm.add_tnt(markers, target = [str(val) for val in range(101, 200)], nontarget = [str(val) for val in range(1, 100)])
samples, markers = tm.remove(samples, markers, "misc")
events, event_id = tm.events_from_markers(samples, makers)
# create epochs object for run 2 as well
epochs = mne.Epochs(raw = mne_raw_object_run2,
events = events,
event_id = event_id)
epochs_list.append(epochs)
# epochs_list has two epochs objects correspond to run1 and run2
# you can concatenate these epochs with giving unique event_id for epoch for each run
epochs = tm.concatenate_epochs(epochs_list)
# you can access epoch data with tag
# e.g.,
epochs['run:1/trial:1/target']
# see documentation of __getitem__() methods of mne.Epochs object, how to access data with tag
For classification
# you can get labels for classification
# X: mne.Epochs object
# Y: Y[i] is the label corresponds to X[i], 1: nontarget, 10:target
X, Y = tm.get_binary_epochs(epochs)
## Get values of tag of epochs object
# e.g., with the following code, you can get list of runs in epochs
values = tm.get_values_list(epochs, "run")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tag_mne-0.0.7.tar.gz
(5.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tag_mne-0.0.7.tar.gz.
File metadata
- Download URL: tag_mne-0.0.7.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c0a669efe0eb1a7430d76b703b679d664730b9f496b2e90a692637ca572c20c
|
|
| MD5 |
466cc6dd4aee84a04d31ab77261d1cdb
|
|
| BLAKE2b-256 |
4fabfa78789b2960656219a70743f98dea2460204231d35b8a5610e637fc0695
|
File details
Details for the file tag_mne-0.0.7-py3-none-any.whl.
File metadata
- Download URL: tag_mne-0.0.7-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26bffe1e55fba4f96657b47f396afb315660d51668dfacaf41d91576e313440e
|
|
| MD5 |
4b2e3609c1c8d715b96083d54a24879f
|
|
| BLAKE2b-256 |
b72b69106bda5fcec4d54dd4d9c22a5de5ab27a436ba52d6e3afe2a07e3c8cd6
|