File: read_neo_format.py

package info (click to toggle)
python-mne 1.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 131,492 kB
  • sloc: python: 213,302; javascript: 12,910; sh: 447; makefile: 144
file content (40 lines) | stat: -rw-r--r-- 1,456 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
39
40
"""
.. _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`.
"""

# Authors: The MNE-Python contributors.
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.

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)