Reading and analyzing data with Neo#

Getting started#

Neo is a library for working with neurophysiology data in the Python programming language. One of the big advantages of Neo is that it works with many different file formats: it doesn’t matter which format your data is stored in, Neo provides a standard way to read the data, and then represents it in a standardised way, as a set of Python objects.

The first step in reading data is to import the appropriate Neo input-output (or IO) module for your data. For this example, we’re going to work with membrane potential traces stored in a text file, so we use the AsciiSignalIO module:

In [1]: from neo.io import AsciiSignalIO

In [2]: data = AsciiSignalIO("example_data.txt", delimiter=" ").read()

Note

For a full list of IO modules provided by Neo, see List of implemented IO modules.

In [3]: data
Out[3]: 
[Block with [<neo.core.segment.Segment object at 0x7f6bb64293d0>] segments
 file_origin: 'example_data.txt'
 # segments (N=[<neo.core.segment.Segment object at 0x7f6bb64293d0>])
 0: Segment with [<AnalogSignal(array([[-58.469, -52.855, -58.79 , -58.815],
       [-59.061, -50.518, -52.003, -57.24 ],
       [-59.01 , -50.51 , -51.988, -57.199],
       ...,
       [-56.535, -56.653, -56.374, -53.659],
       [-56.501, -56.62 , -56.42 , -53.64 ],
       [-56.468, -56.586, -56.464, -53.621]], dtype=float32) * mV, [0.0 s, 10.001 s], sampling rate: 1.0 kHz)>] analogsignals
    # analogsignals (N=[<AnalogSignal(array([[-58.469, -52.855, -58.79 , -58.815],
       [-59.061, -50.518, -52.003, -57.24 ],
       [-59.01 , -50.51 , -51.988, -57.199],
       ...,
       [-56.535, -56.653, -56.374, -53.659],
       [-56.501, -56.62 , -56.42 , -53.64 ],
       [-56.468, -56.586, -56.464, -53.621]], dtype=float32) * mV, [0.0 s, 10.001 s], sampling rate: 1.0 kHz)>])
    0: AnalogSignal with 4 channels of length 10001; units mV; datatype float32
       name: 'multichannel'
       sampling rate: 1.0 kHz
       time: 0.0 s to 10.001 s]

Different data files can contain different amounts of data, from single traces to multiple recording sessions. To provide consistent behaviour, for all IO modules, the read() method returns a list of data blocks. A Block typically represents a recording session. Each block contains a list of segments, where each Segment contains data recorded at the same time.

In this example file, we see a single type of data, the “analog signal”, which represents continuous time series sampled at a fixed interval. The other types of data that can be contained in a Segment are discussed below under Data types.

Note

read() reads the entire file into memory at once. If you only want to access part of the data, you can do so using Neo’s “lazy” data loading - see the section on Performance and memory consumption below.

Neo data objects are based on NumPy arrays, and behave very similarly. For example, they can be plotted just like arrays:

In [4]: import matplotlib.pyplot as plt

In [5]: signal = data[0].segments[0].analogsignals[0]

In [6]: plt.plot(signal.times, signal)
Out[6]: 
[<matplotlib.lines.Line2D at 0x7f6bb5eae3d0>,
 <matplotlib.lines.Line2D at 0x7f6bb3671f50>,
 <matplotlib.lines.Line2D at 0x7f6bb366a3d0>,
 <matplotlib.lines.Line2D at 0x7f6bb3672910>]

In [7]: plt.xlabel(f"Time ({signal.times.units.dimensionality.string})")
Out[7]: Text(0.5, 0, 'Time (s)')

In [8]: plt.ylabel(f"Membrane potential ({signal.units.dimensionality.string})")
Out[8]: Text(0, 0.5, 'Membrane potential (mV)')

In [9]: plt.savefig("example_plot.png")
_images/example_plot.png

You now know enough to start using Neo. For more examples, see Examples. If you want to know more, read on.

NumPy#

Neo is based on NumPy. All Neo data classes behave like NumPy arrays, but have extra functionality.

The first addition is support for units. In contrast to a plain NumPy array, an AnalogSignal knows the units of the data it contains, e.g.:

In [10]: signal.units
Out[10]: array(1.) * mV

This helps avoid errors like adding signals with different units, lets you auto-generate figure axis labels, and makes it easy to change units, like here from millivolts to volts e.g.:

In [11]: signal.magnitude[:5]
Out[11]: 
array([[-58.469, -52.855, -58.79 , -58.815],
       [-59.061, -50.518, -52.003, -57.24 ],
       [-59.01 , -50.51 , -51.988, -57.199],
       [-58.96 , -50.503, -51.973, -57.158],
       [-58.911, -50.495, -51.958, -57.117]], dtype=float32)

In [12]: signal.rescale("V").magnitude[:5]
Out[12]: 
array([[-0.058469  , -0.052855  , -0.05879   , -0.058815  ],
       [-0.059061  , -0.050518  , -0.052003  , -0.05724001],
       [-0.05901   , -0.05051   , -0.051988  , -0.05719901],
       [-0.05896   , -0.050503  , -0.051973  , -0.057158  ],
       [-0.058911  , -0.050495  , -0.051958  , -0.057117  ]],
      dtype=float32)

The second addition is support for structured metadata. Some of these metadata are required. For example, an AnalogSignal must always have a sampling_rate attribute, and Neo will produce an Exception if you try to add two signals with different sampling rates:

In [13]: signal.sampling_rate
Out[13]: array(1.) * kHz

Some of these metadata are recommended but optional, like a name for each signal. Such metadata appear as attributes of the data objects:

In [14]: signal.name
Out[14]: 'multichannel'

And finally, some metadata are fully optional. These are stored in the annotations and array_annotations attributes:

In [15]: signal.array_annotations
Out[15]: {'channel_index': array([0, 1, 2, 3])}

For more information about this, see Annotations.

Most NumPy array methods also work on Neo data objects, e.g.:

In [16]: signal.mean()
Out[16]: array(-56.33598, dtype=float32) * mV

Data objects can be sliced like arrays (array annotations are automatically sliced appropriately):

In [17]: signal[100:110, 1:3]
Out[17]: 
AnalogSignal with 2 channels of length 10; units mV; datatype float32
name: 'multichannel'
sampling rate: 1.0 kHz
time: 0.1 s to 0.11 s

In [18]: signal[100:110, 1:3].array_annotations
Out[18]: {'channel_index': array([1, 2])}

To convert a Neo data object to a plain NumPy array, use the magnitude attribute:

In [19]: signal[100:110, 1:3].magnitude
Out[19]: 
array([[-60.654, -60.   ],
       [-60.724, -60.   ],
       [-60.792, -60.   ],
       [-60.859, -60.   ],
       [-60.924, -60.   ],
       [-60.989, -60.   ],
       [-61.052, -60.   ],
       [-61.114, -60.   ],
       [-61.175, -60.   ],
       [-61.234, -60.   ]], dtype=float32)

Data types#

The following classes directly represent data as arrays of numerical values with associated metadata (units, sampling frequency, etc.).

  • AnalogSignal: A regular sampling of a single- or multi-channel continuous analog signal.

  • IrregularlySampledSignal: A non-regular sampling of a single- or multi-channel continuous analog signal.

  • SpikeTrain: A set of action potentials (spikes) emitted by the same unit in a period of time (with optional waveforms).

  • Event: An array of time points representing one or more events in the data.

  • Epoch: An array of time intervals representing one or more periods of time in the data.

  • ImageSequence: A three dimensional array representing a sequence of images.

AnalogSignal#

We have already met the AnalogSignal, which represents continuous time series sampled at a fixed interval.

In addition to reading data from a file, as above, it is also possible to create new signal objects directly, e.g.:

In [20]: import numpy as np

In [21]: from quantities import mV, kHz

In [22]: from neo import AnalogSignal

In [23]: signal = AnalogSignal(np.random.normal(-65.0, 5.0, size=(100, 5)),
   ....:                       units=mV, sampling_rate=1 * kHz)
   ....: 

In [24]: signal
Out[24]: 
AnalogSignal with 5 channels of length 100; units mV; datatype float64
sampling rate: 1.0 kHz
time: 0.0 s to 0.1 s

IrregularlySampledSignal#

IrregularlySampledSignal represents continuous time series sampled at non-regular time points. This means that instead of specifying the sampling rate or sampling interval, you must specify the array of times at which the signal was sampled.

In [25]: from quantities import ms, nA

In [26]: from neo import IrregularlySampledSignal

In [27]: isignal = IrregularlySampledSignal(
   ....:              times=[0.0, 1.11, 4.27, 16.38, 19.33] * ms,
   ....:              signal=[0.5, 0.8, 0.5, 0.7, 0.2] * nA,
   ....:              description="input current")
   ....: 

In [28]: isignal
Out[28]: 
IrregularlySampledSignal with 1 channels of length 5; units nA; datatype float64
description: 'input current'
sample times: [ 0.    1.11  4.27 16.38 19.33] ms

Note

in case of multi-channel data, samples are assumed to have been taken at the same time points in all channels. If you need to specify different time points for different channels, use one signal object per channel.

SpikeTrain#

A SpikeTrain represents the times of occurrence of action potentials (spikes).

In [29]: from neo import SpikeTrain

In [30]: spike_train = SpikeTrain([3, 4, 5], units='sec', t_stop=10.0)

In [31]: spike_train
Out[31]: 
SpikeTrain containing 3 spikes; units s; datatype float64 
time: 0.0 s to 10.0 s

It may also contain the waveforms of the action potentials, stored as AnalogSignals within the spike train object - see the reference documentation for more on this.

Event#

It is common in electrophysiology experiments to record the times of specific events, such as the times at which stimuli are presented. An Event contains an array of times at which events occurred, together with an optional array of labels for the events, e.g.:

In [32]: from neo import Event

In [33]: events = Event(np.array([5, 15, 25]), units="second",
   ....:                labels=["apple", "rock", "elephant"],
   ....:                name="stimulus onset")
   ....: 

In [34]: events
Out[34]: 
Event containing 3 events with labels; time units s; datatype int64 
name: 'stimulus onset'

Epoch#

A variation of events is where something occurs over a certain period of time, in which case we need to know both the start time and the duration. An Epoch contains an array of start or onset times together with an array of durations (or a single value if all epochs have the same duration), and an optional array of labels.

In [35]: from neo import Epoch

In [36]: epochs = Epoch(times=np.array([5, 15, 25]),
   ....:                durations=2.0,
   ....:                units="second",
   ....:                labels=["apple", "rock", "elephant"],
   ....:                name="stimulus presentations")
   ....: 

In [37]: epochs
Out[37]: 
Epoch containing 3 epochs with labels; time units s; datatype int64 
name: 'stimulus presentations'

ImageSequence#

In addition to electrophysiology, neurophysiology signals may be obtained through functional microscopy. The ImageSequence class represents a sequence of images, as a 3D array organized as [frame][row][column]. It behaves similarly to AnalogSignal, but in 3D rather than 2D.

In [38]: from quantities import Hz, micrometer

In [39]: from neo import ImageSequence

In [40]: img_sequence_array = [[[column for column in range(20)]for row in range(20)]
   ....:                       for frame in range(10)]
   ....: 

In [41]: image_sequence = ImageSequence(img_sequence_array, units='dimensionless',
   ....:                                sampling_rate=1 * Hz,
   ....:                                spatial_scale=1 * micrometer)
   ....: 

In [42]: image_sequence
Out[42]: 
ImageSequence 10 frames with width 20 px and height 20 px; units dimensionless; datatype int64 
sampling rate: 1.0 Hz
spatial_scale: 1.0 um

Annotations#

Neo objects have certain required metadata, such as the sampling_rate for AnalogSignals. There are also certain recommended metadata, such as a name and description. For any metadata not covered by the required or recommended fields, additional annotations can be added, e.g.:

In [43]: from quantities import um as µm

In [44]: signal.annotate(pipette_tip_diameter=1.5 * µm)

In [45]: signal.annotations
Out[45]: {'pipette_tip_diameter': array(1.5) * um}

For those IO modules that support writing data to file, annotations will also be written, provided they can be serialized to JSON format.

Array annotations#

Since certain Neo objects contain array data, it is sometimes necessary to annotate individual array elements, or individual columns.

For 1D arrays, the array annotations should have the same length as the array, e.g.

In [46]: events.shape
Out[46]: (3,)

In [47]: events.array_annotate(secondary_labels=["red", "green", "blue"])

For 2D arrays, the array annotations should match the shape of the channel dimension, e.g.

In [48]: signal.shape
Out[48]: (100, 5)

In [49]: signal.array_annotate(quality=["good", "good", "noisy", "good", "noisy"])

Dataset structure#

The overall structure of a Neo dataset is shown in this figure:

Illustration of the main Neo data types

Beyond the core data classes, Neo has various classes for grouping and structuring different data objects. We have already met two of them, the Block and Segment.

Tree structure#

Block and Segment provide a basic two-level hierarchical structure: Blocks contain Segments, which contain data objects.

Segments are used to group data that have a common time basis, i.e. that were recorded at the same time. A Segment can be considered as equivalent to a “trial”, “episode”, “run”, “recording”, etc., depending on the experimental context.

Segments have the following attributes, used to access lists of data objects:

  • analogsignals

  • epochs

  • events

  • imagesequences

  • irregularlysampledsignals

  • spiketrains

Block is the top-level container gathering all of the data, discrete and continuous, for a given recording session. It contains Segment and Group (see next section) objects in the attributes segments and groups.

Grouping and linking objects#

Sometimes your data have a structure that goes beyond a simple two-level hierarchy. For example, suppose that you wish to group together signals that were recorded from the same tetrode in multi-tetrode recording setup.

For this, Neo provides a Group class:

In [50]: from neo import Group

In [51]: signal1 = AnalogSignal(np.random.normal(-65.0, 5.0, size=(100, 5)), units=mV, sampling_rate=1 * kHz)

In [52]: signal2 = AnalogSignal(np.random.normal(-65.0, 5.0, size=(1000, 5)), units=nA, sampling_rate=10 * kHz)

In [53]: group = Group(objects=(signal1, signal2))

In [54]: group
Out[54]: 
Group with [<AnalogSignal(array([[-72.28982184, -61.34050696, -65.43097861, -64.51332407,
        -64.92455046],
       [-63.16893876, -63.21084664, -67.78487516, -61.49326229,
        -69.71046286],
       [-70.82961193, -56.27975552, -53.8999454 , -69.76908061,
        -57.9857716 ],
       [-67.27615257, -71.13039091, -70.7893112 , -63.10851473,
        -61.39670882],
       [-55.75432596, -60.14982449, -62.96652727, -64.7743543 ,
        -68.37156067],
       [-50.14398691, -71.3377945 , -59.06648428, -62.46334023,
        -68.88508591],
       [-65.81939727, -57.89080083, -63.57009213, -70.19074385,
        -65.68666232],
       [-59.86434245, -62.23373613, -54.27805865, -65.25184458,
        -58.48885417],
       [-53.26661946, -67.94230603, -59.54538277, -63.73542284,
        -65.63680199],
       [-64.20460978, -71.19370227, -63.87527535, -64.96048255,
        -59.25359002],
       [-71.18934153, -59.17534577, -65.19278821, -67.21963205,
        -71.4750216 ],
       [-67.51284386, -74.84306316, -66.57575736, -60.0653828 ,
        -65.01354564],
       [-60.70679585, -63.55756597, -52.11079565, -67.69324796,
        -71.50761744],
       [-64.63921807, -66.22632464, -76.3132166 , -65.76948496,
        -60.96216588],
       [-65.02516185, -70.57164635, -69.23412558, -69.01333857,
        -61.84257984],
       [-69.12986255, -74.46502561, -65.41928612, -72.98016457,
        -68.68061159],
       [-68.01070344, -63.37985317, -64.71900548, -64.3680291 ,
        -68.68534718],
       [-64.90596917, -66.76181982, -62.27069354, -66.75850078,
        -64.28961035],
       [-70.57819031, -74.47414357, -54.7464954 , -61.11522284,
        -75.13913866],
       [-61.91686013, -70.39561067, -72.84719594, -64.06392644,
        -60.87442062],
       [-68.55778047, -75.39861225, -70.47450394, -69.22566818,
        -66.57130255],
       [-69.52082171, -62.53784272, -72.82266137, -60.32536953,
        -50.07081454],
       [-59.06152366, -61.8355871 , -73.22382306, -60.89734895,
        -61.33762038],
       [-65.20910187, -58.21392341, -62.06045295, -62.99801888,
        -76.46737107],
       [-69.04357449, -52.47117879, -68.2755752 , -67.27624293,
        -67.28618693],
       [-60.70591735, -64.84250573, -67.32486116, -67.10473746,
        -71.36567103],
       [-65.52487765, -62.75669002, -61.76586027, -61.88132842,
        -64.56514401],
       [-60.65505086, -70.18566485, -62.03562883, -59.86063605,
        -55.21262886],
       [-61.83459267, -76.68961982, -58.62828808, -59.09968657,
        -73.72425647],
       [-68.75808425, -71.4067779 , -64.2277318 , -68.4294074 ,
        -79.03361569],
       [-64.11010743, -60.60473852, -58.34967065, -60.70594818,
        -61.97600923],
       [-73.08438251, -63.66005895, -69.94449571, -64.65612093,
        -66.65582071],
       [-62.59939112, -62.79378136, -71.41482761, -71.30176185,
        -67.69776932],
       [-71.13011594, -59.05013015, -65.08254748, -63.8717728 ,
        -59.10426475],
       [-57.82989983, -64.74571121, -66.23798751, -63.25710524,
        -58.85906709],
       [-66.89724472, -63.64069759, -72.28117796, -55.5640452 ,
        -76.026383  ],
       [-77.3473609 , -60.08257816, -60.62563411, -61.56485774,
        -62.37895883],
       [-65.6754782 , -67.39315703, -64.60366876, -63.62703811,
        -59.41768345],
       [-64.72294518, -64.1188099 , -59.32498216, -63.68725181,
        -66.31890757],
       [-68.1005684 , -60.74112127, -67.33874871, -76.46654886,
        -67.21822098],
       [-68.66830106, -62.03162315, -61.30665956, -64.77513424,
        -62.3582495 ],
       [-61.10290186, -64.9045993 , -61.92516234, -70.8793811 ,
        -59.10405335],
       [-58.94028737, -56.23835509, -68.82472449, -61.13989852,
        -61.14573369],
       [-76.73614918, -66.11255616, -68.83769565, -73.2078023 ,
        -63.21715144],
       [-72.25857047, -67.58235112, -66.64451329, -63.67032562,
        -59.34200092],
       [-63.79442053, -63.44179705, -62.95848299, -68.28843402,
        -67.64541591],
       [-64.45724861, -67.63341729, -74.34177251, -57.84476839,
        -63.20773084],
       [-61.09075989, -57.24751471, -62.58539984, -64.79656869,
        -66.40270635],
       [-53.95822472, -65.23169164, -63.47735452, -71.41534957,
        -65.81734288],
       [-62.71989688, -60.84944218, -62.93139704, -52.04569494,
        -64.96977771],
       [-73.34468529, -66.43224208, -63.9322824 , -64.96031666,
        -64.98235419],
       [-61.15388177, -60.10113824, -59.95958463, -63.40927135,
        -57.46306376],
       [-69.19649658, -58.86990427, -65.87195743, -61.12740595,
        -63.10719227],
       [-60.8545269 , -66.1583101 , -62.33184191, -64.17952759,
        -71.87203778],
       [-59.2069812 , -67.59359252, -56.54958128, -66.8441785 ,
        -70.71729034],
       [-66.00181994, -61.54842171, -65.9223856 , -66.74545105,
        -64.76060724],
       [-62.64477579, -64.27272454, -55.922327  , -65.10204101,
        -62.33359763],
       [-67.33017876, -58.16644984, -65.61091455, -62.91931759,
        -60.56302543],
       [-67.22502025, -66.41380102, -65.84624161, -61.7631257 ,
        -74.30519864],
       [-56.89352652, -62.48536479, -60.15585065, -70.07137654,
        -63.73570451],
       [-68.67206885, -62.95793469, -63.65784767, -61.25999087,
        -69.46098305],
       [-66.47441509, -57.5602785 , -73.90550289, -65.97281061,
        -70.00264849],
       [-56.2830641 , -53.80977297, -77.02830969, -64.56542234,
        -66.39215205],
       [-79.33181323, -65.90090923, -62.35359498, -61.05351732,
        -59.35881884],
       [-76.94086807, -67.27180095, -71.14345749, -59.71518941,
        -66.05109811],
       [-61.51572241, -67.73944669, -62.2727508 , -60.97821845,
        -64.61261344],
       [-66.43651198, -72.82409892, -64.81924639, -67.99138691,
        -66.90725051],
       [-73.78035423, -62.96897932, -55.88563857, -71.89689451,
        -66.36255116],
       [-67.20215112, -61.02612911, -66.55741396, -70.56039806,
        -59.29729567],
       [-63.02549531, -68.43388211, -61.81856496, -62.3250195 ,
        -74.67218619],
       [-62.54405897, -69.05388125, -69.15124892, -65.78241397,
        -65.49480877],
       [-71.19027911, -59.36652143, -57.14566724, -51.57100291,
        -61.8552742 ],
       [-56.2167761 , -65.64029289, -76.19468666, -69.11395471,
        -80.42934444],
       [-74.18510262, -62.26573609, -64.35274168, -62.99238681,
        -76.12952555],
       [-64.68047708, -66.38842865, -65.00326282, -65.18915   ,
        -64.85659035],
       [-66.68546128, -60.52829649, -56.9121095 , -68.70695135,
        -59.61590851],
       [-60.56923319, -71.51507351, -67.02989762, -63.98874479,
        -57.25170649],
       [-63.97728695, -67.24956029, -70.34566053, -62.29710614,
        -64.10900241],
       [-68.2068585 , -64.97817486, -58.43011959, -58.89177169,
        -61.67725186],
       [-64.50468338, -68.03399039, -70.86178805, -66.78980852,
        -59.76829105],
       [-54.05670621, -68.959684  , -60.65527919, -68.61719653,
        -61.45274034],
       [-72.17702971, -72.35914598, -63.0662582 , -76.86933776,
        -60.62827766],
       [-66.49047086, -74.69574841, -61.33291578, -67.12308838,
        -74.32117957],
       [-63.03071105, -60.54191165, -70.52047852, -66.81033302,
        -66.03987958],
       [-71.3194163 , -69.78557441, -60.56613318, -64.66297416,
        -63.44859613],
       [-61.55457438, -67.00681342, -68.69956617, -68.24855559,
        -63.35561675],
       [-63.38266051, -60.17030736, -62.06019861, -66.97632251,
        -61.35113431],
       [-69.78795299, -73.54138617, -64.58797736, -51.91390872,
        -65.7929148 ],
       [-69.90666859, -69.34184543, -67.3567047 , -67.92067942,
        -62.02953767],
       [-64.44927996, -66.60103511, -68.46129331, -58.52471664,
        -74.74758954],
       [-56.31032843, -65.78508983, -61.63069078, -69.64069175,
        -71.1197874 ],
       [-65.64528865, -58.71422178, -71.4846604 , -66.03442412,
        -54.95280676],
       [-61.85748573, -62.05428917, -74.05001084, -63.41035023,
        -58.98138011],
       [-69.09142203, -63.08839446, -64.52283052, -64.81730629,
        -63.35962228],
       [-65.33258609, -61.40195815, -70.43175621, -63.11222834,
        -64.92363979],
       [-64.52600771, -62.02475738, -57.29595345, -72.62104255,
        -54.77026107],
       [-65.24649164, -60.24017334, -67.04587646, -66.90114394,
        -60.42147042],
       [-72.09521492, -67.29212914, -65.31179495, -62.11643224,
        -67.5835439 ],
       [-61.20790444, -65.89512154, -60.98172942, -69.32779895,
        -75.40434088],
       [-73.69097816, -65.39176449, -66.87460694, -60.82182854,
        -63.72557654]]) * mV, [0.0 s, 0.1 s], sampling rate: 1.0 kHz)>, <AnalogSignal(array([[-59.82543704, -70.15907349, -58.57301446, -62.998512  ,
        -66.42542829],
       [-64.60037497, -62.57444889, -65.93812392, -68.18954509,
        -61.24868476],
       [-63.18574124, -64.72810949, -62.79675152, -57.35701448,
        -61.33576714],
       ...,
       [-67.83793017, -64.98827915, -64.1470583 , -64.11842544,
        -68.27804215],
       [-66.29219675, -58.55305343, -65.98289298, -71.9972074 ,
        -62.50693787],
       [-59.93279961, -66.25699587, -73.77202639, -64.18830033,
        -70.83981971]]) * nA, [0.0 s, 0.1 s], sampling rate: 10.0 kHz)>] analogsignals

Since AnalogSignals can contain data from multiple channels, sometimes we wish to include only a subset of channels in a group. For this, Neo provides the ChannelView class, e.g.:

In [55]: from neo import ChannelView

In [56]: channel_of_interest = ChannelView(obj=signal1, index=[2])

In [57]: signal_with_spikes = Group(objects=(channel_of_interest, spike_train))

In [58]: signal_with_spikes
Out[58]: Group with [<SpikeTrain(array([3., 4., 5.]) * s, [0.0 s, 10.0 s])>] spiketrains, [<neo.core.view.ChannelView object at 0x7f6bb5d65ad0>] channelviews

Performance and memory consumption#

In some cases you may not wish to load everything in memory, because it could be too big, or you know you only need to access a subset of the data in a file.

For this scenario, some IO modules provide an optional argument to their read() methods: lazy=True/False.

With lazy=True all data objects (AnalogSignal/SpikeTrain/Event/Epoch/ImageSequence) are replaced by proxy objects (AnalogSignalProxy/SpikeTrainProxy/EventProxy/EpochProxy/ImageSequenceProxy).

By default (if not specified), lazy=False, i.e. all data are loaded.

These proxy objects contain metadata (name, sampling_rate, …) so they can be inspected, but they do not contain any array-like data.

When you want to load the actual data from a proxy object, use the load() method to return a real data object of the appropriate type.

Furthermore load() has a time_slice argument, which allows you to load only a slice of data from the file. In this way the consumption of memory can be finely controlled.

Examples#

For more examples of using Neo, see Examples.

Citing Neo#

If you use Neo in your work, please mention the use of Neo in your Methods section, using our RRID: RRID:SCR_000634.

If you wish to cite Neo in publications, please use:

Garcia S., Guarino D., Jaillet F., Jennings T.R., Pröpper R., Rautenberg P.L., Rodgers C., Sobolev A.,Wachtler T., Yger P. and Davison A.P. (2014) Neo: an object model for handling electrophysiology data in multiple formats. Frontiers in Neuroinformatics 8:10: doi:10.3389/fninf.2014.00010

A BibTeX entry for LaTeX users is:

@article{neo14,
    author = {Garcia S. and Guarino D. and Jaillet F. and Jennings T.R. and Pröpper R. and
              Rautenberg P.L. and Rodgers C. and Sobolev A. and Wachtler T. and Yger P.
              and Davison A.P.},
    doi = {10.3389/fninf.2014.00010},
    full_text = {https://www.frontiersin.org/articles/10.3389/fninf.2014.00010/full},
    journal = {Frontiers in Neuroinformatics},
    month = {February},
    title = {Neo: an object model for handling electrophysiology data in multiple formats},
    volume = {8:10},
    year = {2014}
}