API Reference

neo.core provides classes for storing common electrophysiological data types. Some of these classes contain raw data, such as spike trains or analog signals, while others are containers to organize other classes (including both data classes and other container classes).

Classes from neo.io return nested data structures containing one or more class from this module.

Classes:

class neo.core.Block(name=None, description=None, file_origin=None, file_datetime=None, rec_datetime=None, index=None, **annotations)

Main container gathering all the data, whether discrete or continous, for a given recording session.

A block is not necessarily temporally homogeneous, in contrast to Segment.

Usage:

>>> from neo.core import (Block, Segment, ChannelIndex,
...                       AnalogSignal)
>>> from quantities import nA, kHz
>>> import numpy as np
>>>
>>> # create a Block with 3 Segment and 2 ChannelIndex objects
,,, blk = Block()
>>> for ind in range(3):
...     seg = Segment(name='segment %d' % ind, index=ind)
...     blk.segments.append(seg)
...
>>> for ind in range(2):
...     chx = ChannelIndex(name='Array probe %d' % ind,
...                        index=np.arange(64))
...     blk.channel_indexes.append(chx)
...
>>> # Populate the Block with AnalogSignal objects
... for seg in blk.segments:
...     for chx in blk.channel_indexes:
...         a = AnalogSignal(np.random.randn(10000, 64)*nA,
...                          sampling_rate=10*kHz)
...         chx.analogsignals.append(a)
...         seg.analogsignals.append(a)
Required attributes/properties:
None
Recommended attributes/properties:
name:(str) A label for the dataset.
description:(str) Text description.
file_origin:(str) Filesystem path or URL of the original data file.
file_datetime:(datetime) The creation date and time of the original data file.
rec_datetime:(datetime) The date and time of the original recording.
Properties available on this object:
list_units:descends through hierarchy and returns a list of Unit objects existing in the block. This shortcut exists because a common analysis case is analyzing all neurons that you recorded in a session.

Note: Any other additional arguments are assumed to be user-specific metadata and stored in annotations.

Container of:
Segment ChannelIndex
class neo.core.Segment(name=None, description=None, file_origin=None, file_datetime=None, rec_datetime=None, index=None, **annotations)

A container for data sharing a common time basis.

A Segment is a heterogeneous container for discrete or continous data sharing a common clock (time basis) but not necessary the same sampling rate, start or end time.

Usage::
>>> from neo.core import Segment, SpikeTrain, AnalogSignal
>>> from quantities import Hz, s
>>>
>>> seg = Segment(index=5)
>>>
>>> train0 = SpikeTrain(times=[.01, 3.3, 9.3], units='sec', t_stop=10)
>>> seg.spiketrains.append(train0)
>>>
>>> train1 = SpikeTrain(times=[100.01, 103.3, 109.3], units='sec',
...                     t_stop=110)
>>> seg.spiketrains.append(train1)
>>>
>>> sig0 = AnalogSignal(signal=[.01, 3.3, 9.3], units='uV',
...                     sampling_rate=1*Hz)
>>> seg.analogsignals.append(sig0)
>>>
>>> sig1 = AnalogSignal(signal=[100.01, 103.3, 109.3], units='nA',
...                     sampling_period=.1*s)
>>> seg.analogsignals.append(sig1)
Required attributes/properties:
None
Recommended attributes/properties:
name:(str) A label for the dataset.
description:(str) Text description.
file_origin:(str) Filesystem path or URL of the original data file.
file_datetime:(datetime) The creation date and time of the original data file.
rec_datetime:(datetime) The date and time of the original recording
index:(int) You can use this to define a temporal ordering of your Segment. For instance you could use this for trial numbers.

Note: Any other additional arguments are assumed to be user-specific metadata and stored in annotations.

Properties available on this object:
all_data:(list) A list of all child objects in the Segment.
Container of:
Epoch Event AnalogSignal IrregularlySampledSignal SpikeTrain
class neo.core.ChannelIndex(index, channel_names=None, channel_ids=None, name=None, description=None, file_origin=None, coordinates=None, **annotations)

A container for indexing/grouping data channels.

This container has several purposes:

Usage 1 providing channel IDs across multiple Segment::
  • Recording with 2 electrode arrays across 3 segments
  • Each array has 64 channels and is data is represented in a single AnalogSignal object per electrode array
  • channel ids range from 0 to 127 with the first half covering electrode 0 and second half covering electrode 1
>>> from neo.core import (Block, Segment, ChannelIndex,
...                       AnalogSignal)
>>> from quantities import nA, kHz
>>> import numpy as np
...
>>> # create a Block with 3 Segment and 2 ChannelIndex objects
>>> blk = Block()
>>> for ind in range(3):
...     seg = Segment(name='segment %d' % ind, index=ind)
...     blk.segments.append(seg)
...
>>> for ind in range(2):
...     channel_ids=np.arange(64)+ind
...     chx = ChannelIndex(name='Array probe %d' % ind,
...                        index=np.arange(64),
...                        channel_ids=channel_ids,
...                        channel_names=['Channel %i' % chid
...                                       for chid in channel_ids])
...     blk.channel_indexes.append(chx)
...
>>> # Populate the Block with AnalogSignal objects
>>> for seg in blk.segments:
...     for chx in blk.channel_indexes:
...         a = AnalogSignal(np.random.randn(10000, 64)*nA,
...                          sampling_rate=10*kHz)
...         # link AnalogSignal and ID providing channel_index
...         a.channel_index = chx
...         chx.analogsignals.append(a)
...         seg.analogsignals.append(a)
Usage 2 grouping channels::
  • Recording with a single probe with 8 channels, 4 of which belong to a Tetrode
  • Global channel IDs range from 0 to 8
  • An additional ChannelIndex is used to group subset of Tetrode channels
>>> from neo.core import Block, ChannelIndex
>>> import numpy as np
>>> from quantities import mV, kHz
...
>>> # Create a Block
>>> blk = Block()
>>> blk.segments.append(Segment())
...
>>> # Create a signal with 8 channels and a ChannelIndex handling the
>>> # channel IDs (see usage case 1)
>>> sig = AnalogSignal(np.random.randn(1000, 8)*mV, sampling_rate=10*kHz)
>>> chx = ChannelIndex(name='Probe 0', index=range(8),
...                    channel_ids=range(8),
...                    channel_names=['Channel %i' % chid
...                                   for chid in range(8)])
>>> chx.analogsignals.append(sig)
>>> sig.channel_index=chx
>>> blk.segments[0].analogsignals.append(sig)
...
>>> # Create a new ChannelIndex which groups four channels from the
>>> # analogsignal and provides a second ID scheme
>>> chx = ChannelIndex(name='Tetrode 0',
...                    channel_names=np.array(['Tetrode ch1',
...                                            'Tetrode ch4',
...                                            'Tetrode ch6',
...                                            'Tetrode ch7']),
...                    index=np.array([0, 3, 5, 6]))
>>> # Attach the ChannelIndex to the the Block,
>>> # but not the to the AnalogSignal, since sig.channel_index is
>>> # already linked to the global ChannelIndex of Probe 0 created above
>>> chx.analogsignals.append(sig)
>>> blk.channel_indexes.append(chx)
Usage 3 dealing with Unit objects::
>>> from neo.core import Block, ChannelIndex, Unit
...
>>> # Create a Block
>>> blk = Block()
...
>>> # Create a new ChannelIndex and add it to the Block
>>> chx = ChannelIndex(index=None, name='octotrode A')
>>> blk.channel_indexes.append(chx)
...
>>> # create several Unit objects and add them to the
>>> # ChannelIndex
>>> for ind in range(5):
...     unit = Unit(name = 'unit %d' % ind,
...                 description='after a long and hard spike sorting')
...     chx.units.append(unit)
Required attributes/properties:
index:(numpy.array 1D dtype=’i’) Index of each channel in the attached signals (AnalogSignals and IrregularlySampledSignals). The order of the channel IDs needs to be consistent across attached signals.
Recommended attributes/properties:
name:(str) A label for the dataset.
description:(str) Text description.
file_origin:(str) Filesystem path or URL of the original data file.
channel_names:(numpy.array 1D dtype=’S’) Names for each recording channel.
channel_ids:(numpy.array 1D dtype=’int’) IDs of the corresponding channels referenced by ‘index’.
coordinates:(quantity array 2D (x, y, z)) Physical or logical coordinates of all channels.

Note: Any other additional arguments are assumed to be user-specific metadata and stored in annotations.

Container of:
AnalogSignal IrregularlySampledSignal Unit
class neo.core.Unit(name=None, description=None, file_origin=None, **annotations)

A container of SpikeTrain objects from a unit.

A Unit regroups all the SpikeTrain objects that were emitted by a single spike source during a Block. A spike source is often a single neuron but doesn’t have to be. The spikes may come from different Segment objects within the Block, so this object is not contained in the usual Block/ Segment/SpikeTrain hierarchy.

A Unit is linked to ChannelIndex objects from which it was detected. With tetrodes, for instance, multiple channels may record the same Unit.

Usage:

>>> from neo.core import Unit, SpikeTrain
>>>
>>> unit = Unit(name='pyramidal neuron')
>>>
>>> train0 = SpikeTrain(times=[.01, 3.3, 9.3], units='sec', t_stop=10)
>>> unit.spiketrains.append(train0)
>>>
>>> train1 = SpikeTrain(times=[100.01, 103.3, 109.3], units='sec',
...                  t_stop=110)
>>> unit.spiketrains.append(train1)
Required attributes/properties:
None
Recommended attributes/properties:
name:(str) A label for the dataset.
description:(str) Text description.
file_origin:(str) Filesystem path or URL of the original data file.
Note: Any other additional arguments are assumed to be user-specific
metadata and stored in annotations.
Container of:
SpikeTrain
class neo.core.AnalogSignal(signal, units=None, dtype=None, copy=True, t_start=array(0.) * s, sampling_rate=None, sampling_period=None, name=None, file_origin=None, description=None, **annotations)

Array of one or more continuous analog signals.

A representation of several continuous, analog signals that have the same duration, sampling rate and start time. Basically, it is a 2D array: dim 0 is time, dim 1 is channel index

Inherits from quantities.Quantity, which in turn inherits from numpy.ndarray.

Usage:

>>> from neo.core import AnalogSignal
>>> import quantities as pq
>>>
>>> sigarr = AnalogSignal([[1, 2, 3], [4, 5, 6]], units='V',
...                            sampling_rate=1*pq.Hz)
>>>
>>> sigarr
<AnalogSignal(array([[1, 2, 3],
      [4, 5, 6]]) * mV, [0.0 s, 2.0 s], sampling rate: 1.0 Hz)>
>>> sigarr[:,1]
<AnalogSignal(array([2, 5]) * V, [0.0 s, 2.0 s],
    sampling rate: 1.0 Hz)>
>>> sigarr[1, 1]
array(5) * V
Required attributes/properties:
signal:(quantity array 2D, numpy array 2D, or list (data, channel)) The data itself.
units:(quantity units) Required if the signal is a list or NumPy array, not if it is a Quantity
t_start:(quantity scalar) Time when signal begins
sampling_rate:or sampling_period (quantity scalar) Number of samples per unit time or interval between two samples. If both are specified, they are checked for consistency.
Recommended attributes/properties:
name:(str) A label for the dataset.
description:(str) Text description.
file_origin:(str) Filesystem path or URL of the original data file.
Optional attributes/properties:
dtype:(numpy dtype or str) Override the dtype of the signal array.
copy:(bool) True by default.

Note: Any other additional arguments are assumed to be user-specific metadata and stored in annotations.

Properties available on this object:
sampling_rate:(quantity scalar) Number of samples per unit time. (1/sampling_period)
sampling_period:
 (quantity scalar) Interval between two samples. (1/quantity scalar)
duration:(Quantity) Signal duration, read-only. (size * sampling_period)
t_stop:(quantity scalar) Time when signal ends, read-only. (t_start + duration)
times:(quantity 1D) The time points of each sample of the signal, read-only. (t_start + arange(shape`[0])/:attr:`sampling_rate)
channel_index:access to the channel_index attribute of the principal ChannelIndex associated with this signal.
Slicing:
AnalogSignal objects can be sliced. When taking a single column (dimension 0, e.g. [0, :]) or a single element, a Quantity is returned. Otherwise an AnalogSignal (actually a view) is returned, with the same metadata, except that t_start is changed if the start index along dimension 1 is greater than 1. Note that slicing an AnalogSignal may give a different result to slicing the underlying NumPy array since signals are always two-dimensional.
Operations available on this object:
== != + * /
class neo.core.IrregularlySampledSignal(times, signal, units=None, time_units=None, dtype=None, copy=True, name=None, file_origin=None, description=None, **annotations)

An array of one or more analog signals with samples taken at arbitrary time points.

A representation of one or more continuous, analog signals acquired at time t_start with a varying sampling interval. Each channel is sampled at the same time points.

Inherits from quantities.Quantity, which in turn inherits from numpy.ndarray.

Usage:

>>> from neo.core import IrregularlySampledSignal
>>> from quantities import s, nA
>>>
>>> irsig0 = IrregularlySampledSignal([0.0, 1.23, 6.78], [1, 2, 3],
...                                   units='mV', time_units='ms')
>>> irsig1 = IrregularlySampledSignal([0.01, 0.03, 0.12]*s,
...                                   [[4, 5], [5, 4], [6, 3]]*nA)
Required attributes/properties:
times:(quantity array 1D, numpy array 1D, or list) The time of each data point. Must have the same size as signal.
signal:(quantity array 2D, numpy array 2D, or list (data, channel)) The data itself.
units:(quantity units) Required if the signal is a list or NumPy array, not if it is a Quantity.
time_units:(quantity units) Required if times is a list or NumPy array, not if it is a Quantity.
Recommended attributes/properties:.
name:(str) A label for the dataset
description:(str) Text description.
file_origin:(str) Filesystem path or URL of the original data file.
Optional attributes/properties:
dtype:(numpy dtype or str) Override the dtype of the signal array. (times are always floats).
copy:(bool) True by default.

Note: Any other additional arguments are assumed to be user-specific metadata and stored in annotations.

Properties available on this object:
sampling_intervals:
 (quantity array 1D) Interval between each adjacent pair of samples. (times[1:] - times[:-1])
duration:(quantity scalar) Signal duration, read-only. (times[-1] - times[0])
t_start:(quantity scalar) Time when signal begins, read-only. (times[0])
t_stop:(quantity scalar) Time when signal ends, read-only. (times[-1])
Slicing:
IrregularlySampledSignal objects can be sliced. When this occurs, a new IrregularlySampledSignal (actually a view) is returned, with the same metadata, except that times is also sliced in the same way.
Operations available on this object:
== != + * /
class neo.core.Event(times=None, labels=None, units=None, name=None, description=None, file_origin=None, **annotations)

Array of events.

Usage:

>>> from neo.core import Event
>>> from quantities import s
>>> import numpy as np
>>>
>>> evt = Event(np.arange(0, 30, 10)*s,
...             labels=np.array(['trig0', 'trig1', 'trig2'],
...                             dtype='S'))
>>>
>>> evt.times
array([  0.,  10.,  20.]) * s
>>> evt.labels
array(['trig0', 'trig1', 'trig2'],
      dtype='|S5')
Required attributes/properties:
times:(quantity array 1D) The time of the events.
labels:(numpy.array 1D dtype=’S’) Names or labels for the events.
Recommended attributes/properties:
name:(str) A label for the dataset.
description:(str) Text description.
file_origin:(str) Filesystem path or URL of the original data file.

Note: Any other additional arguments are assumed to be user-specific metadata and stored in annotations.

class neo.core.Epoch(times=None, durations=None, labels=None, units=None, name=None, description=None, file_origin=None, **annotations)

Array of epochs.

Usage:

>>> from neo.core import Epoch
>>> from quantities import s, ms
>>> import numpy as np
>>>
>>> epc = Epoch(times=np.arange(0, 30, 10)*s,
...             durations=[10, 5, 7]*ms,
...             labels=np.array(['btn0', 'btn1', 'btn2'], dtype='S'))
>>>
>>> epc.times
array([  0.,  10.,  20.]) * s
>>> epc.durations
array([ 10.,   5.,   7.]) * ms
>>> epc.labels
array(['btn0', 'btn1', 'btn2'],
      dtype='|S4')
Required attributes/properties:
times:(quantity array 1D) The starts of the time periods.
durations:(quantity array 1D) The length of the time period.
labels:(numpy.array 1D dtype=’S’) Names or labels for the time periods.
Recommended attributes/properties:
name:(str) A label for the dataset,
description:(str) Text description,
file_origin:(str) Filesystem path or URL of the original data file.

Note: Any other additional arguments are assumed to be user-specific metadata and stored in annotations,

class neo.core.SpikeTrain(times, t_stop, units=None, dtype=<type 'float'>, copy=True, sampling_rate=array(1.) * Hz, t_start=array(0.) * s, waveforms=None, left_sweep=None, name=None, file_origin=None, description=None, **annotations)

SpikeTrain is a Quantity array of spike times.

It is an ensemble of action potentials (spikes) emitted by the same unit in a period of time.

Usage:

>>> from neo.core import SpikeTrain
>>> from quantities import s
>>>
>>> train = SpikeTrain([3, 4, 5]*s, t_stop=10.0)
>>> train2 = train[1:3]
>>>
>>> train.t_start
array(0.0) * s
>>> train.t_stop
array(10.0) * s
>>> train
<SpikeTrain(array([ 3.,  4.,  5.]) * s, [0.0 s, 10.0 s])>
>>> train2
<SpikeTrain(array([ 4.,  5.]) * s, [0.0 s, 10.0 s])>
Required attributes/properties:
times:(quantity array 1D, numpy array 1D, or list) The times of each spike.
units:(quantity units) Required if times is a list or ndarray, not if it is a Quantity.
t_stop:(quantity scalar, numpy scalar, or float) Time at which SpikeTrain ended. This will be converted to the same units as times. This argument is required because it specifies the period of time over which spikes could have occurred. Note that t_start is highly recommended for the same reason.

Note: If times contains values outside of the range [t_start, t_stop], an Exception is raised.

Recommended attributes/properties:
name:(str) A label for the dataset.
description:(str) Text description.
file_origin:(str) Filesystem path or URL of the original data file.
t_start:(quantity scalar, numpy scalar, or float) Time at which SpikeTrain began. This will be converted to the same units as times. Default: 0.0 seconds.
waveforms:(quantity array 3D (spike, channel_index, time)) The waveforms of each spike.
sampling_rate:(quantity scalar) Number of samples per unit time for the waveforms.
left_sweep:(quantity array 1D) Time from the beginning of the waveform to the trigger time of the spike.
sort:(bool) If True, the spike train will be sorted by time.
Optional attributes/properties:
dtype:(numpy dtype or str) Override the dtype of the signal array.
copy:(bool) Whether to copy the times array. True by default. Must be True when you request a change of units or dtype.

Note: Any other additional arguments are assumed to be user-specific metadata and stored in annotations.

Properties available on this object:
sampling_period:
 (quantity scalar) Interval between two samples. (1/sampling_rate)
duration:(quantity scalar) Duration over which spikes can occur, read-only. (t_stop - t_start)
spike_duration:(quantity scalar) Duration of a waveform, read-only. (waveform.shape[2] * sampling_period)
right_sweep:(quantity scalar) Time from the trigger times of the spikes to the end of the waveforms, read-only. (left_sweep + spike_duration)
times:(quantity array 1D) Returns the SpikeTrain as a quantity array.
Slicing:
SpikeTrain objects can be sliced. When this occurs, a new SpikeTrain (actually a view) is returned, with the same metadata, except that waveforms is also sliced in the same way (along dimension 0). Note that t_start and t_stop are not changed automatically, although you can still manually change them.