File: read_neo_format.py

package info (click to toggle)
python-mne 1.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 100,172 kB
  • sloc: python: 166,349; pascal: 3,602; javascript: 1,472; sh: 334; makefile: 236
file content (38 lines) | stat: -rw-r--r-- 1,387 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
"""
.. _ex-read-neo:

===============================================
How to use data in neural ensemble (NEO) format
===============================================

This example shows how to create an MNE-Python `~mne.io.Raw` object from data
in the `neural ensemble <https://neo.readthedocs.io>`__ format. For general
information on creating MNE-Python's data objects from NumPy arrays, see
:ref:`tut-creating-data-structures`.
"""

# %%

import neo
import mne

# %%
# This example uses NEO's ``ExampleIO`` object for creating fake data. The data
# will be all zeros, so the plot won't be very interesting, but it should
# demonstrate the steps to using NEO data. For actual data and different file
# formats, consult the NEO documentation.

reader = neo.io.ExampleIO('fakedata.nof')
block = reader.read(lazy=False)[0]  # get the first block
segment = block.segments[0]         # get data from first (and only) segment
signals = segment.analogsignals[0]  # get first (multichannel) signal

data = signals.rescale('V').magnitude.T
sfreq = signals.sampling_rate.magnitude
ch_names = [f'Neo {(idx + 1):02}' for idx in range(signals.shape[1])]
ch_types = ['eeg'] * len(ch_names)  # if not specified, type 'misc' is assumed

info = mne.create_info(ch_names=ch_names, ch_types=ch_types, sfreq=sfreq)
raw = mne.io.RawArray(data, info)
raw.plot(show_scrollbars=False)