Neo core API Reference#
Relationships between Neo objects#
- Object:
With a star = inherits from
Quantity
- Attributes:
In red = required
In white = recommended
- Relationships:
In cyan = one to many

Click here for a better quality SVG diagram
Note
This figure does not include ChannelView
and RegionOfInterest
.
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 classes 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 continuous, for a given recording session.
A block is not necessarily temporally homogeneous, in contrast to
Segment
.Usage:
>>> from neo.core import Block, Segment, Group, AnalogSignal >>> from quantities import nA, kHz >>> import numpy as np >>> >>> # create a Block with 3 Segment and 2 Group 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): ... group = Group(name='Array probe %d' % ind) ... blk.groups.append(group) ... >>> # Populate the Block with AnalogSignal objects ... for seg in blk.segments: ... for group in blk.groups: ... a = AnalogSignal(np.random.randn(10000, 64)*nA, ... sampling_rate=10*kHz) ... group.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.
Note: Any other additional arguments are assumed to be user-specific metadata and stored in
annotations
.
- 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 continuous 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
.- Container of:
Epoch
Event
AnalogSignal
IrregularlySampledSignal
SpikeTrain
- class neo.core.Group(objects=None, name=None, description=None, file_origin=None, allowed_types=None, **annotations)#
Can contain any of the data objects, views, or other groups, outside the hierarchy of the segment and block containers. A common use is to link the
SpikeTrain
objects within aBlock
, possibly across multiple Segments, that were emitted by the same neuron.- Required attributes/properties:
None
- Recommended attributes/properties:
- objects
(Neo object) Objects with which to pre-populate the
Group
- name
(str) A label for the group.
- description
(str) Text description.
- file_origin
(str) Filesystem path or URL of the original data file.
- Optional arguments:
- allowed_types
(list or tuple) Types of Neo object that are allowed to be added to the Group. If not specified, any Neo object can be added.
- Note: Any other additional arguments are assumed to be user-specific
metadata and stored in
annotations
.- Container of:
AnalogSignal
,IrregularlySampledSignal
,SpikeTrain
,Event
,Epoch
,ChannelView
,Group
- 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, array_annotations=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 fromnumpy.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.
- array_annotations
(dict) Dict mapping strings to numpy arrays containing annotations for all data points
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
)
- Slicing:
AnalogSignal
objects can be sliced. When taking a single column (dimension 0, e.g. [0, :]) or a single element, aQuantity
is returned. Otherwise anAnalogSignal
(actually a view) is returned, with the same metadata, except thatt_start
is changed if the start index along dimension 1 is greater than 1. Note that slicing anAnalogSignal
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, array_annotations=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 fromnumpy.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 aQuantity
.
- 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.
- array_annotations
(dict) Dict mapping strings to numpy arrays containing annotations for all data points
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 newIrregularlySampledSignal
(actually a view) is returned, with the same metadata, except thattimes
is also sliced in the same way.- Operations available on this object:
== != + * /
- class neo.core.ChannelView(obj, index, name=None, description=None, file_origin=None, array_annotations=None, **annotations)#
A tool for indexing a subset of the channels within an
AnalogSignal
orIrregularlySampledSignal
;- Required attributes/properties:
- obj
(AnalogSignal or IrregularlySampledSignal) The signal being indexed.
- index
(list/1D-array) boolean or integer mask to select the channels of interest.
- Recommended attributes/properties:
- name
(str) A label for the view.
- description
(str) Text description.
- file_origin
(str) Filesystem path or URL of the original data file.
- array_annotations
(dict) Dict mapping strings to numpy arrays containing annotations for all data points
- Note: Any other additional arguments are assumed to be user-specific
metadata and stored in
annotations
.
- class neo.core.Event(times=None, labels=None, units=None, name=None, description=None, file_origin=None, array_annotations=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='U')) >>> >>> evt.times array([ 0., 10., 20.]) * s >>> evt.labels array(['trig0', 'trig1', 'trig2'], dtype='<U5')
- Required attributes/properties:
- times
(quantity array 1D) The time of the events.
- labels
(numpy.array 1D dtype=’U’ or list) 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.
- Optional attributes/properties:
- array_annotations
(dict) Dict mapping strings to numpy arrays containing annotations for all data points
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, array_annotations=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='U')) >>> >>> epc.times array([ 0., 10., 20.]) * s >>> epc.durations array([ 10., 5., 7.]) * ms >>> epc.labels array(['btn0', 'btn1', 'btn2'], dtype='<U4')
- Required attributes/properties:
- times
(quantity array 1D, numpy array 1D or list) The start times of each time period.
- durations
(quantity array 1D, numpy array 1D, list, quantity scalar or float) The length(s) of each time period. If a scalar/float, the same value is used for all time periods.
- labels
(numpy.array 1D dtype=’U’ or list) Names or labels for the time periods.
- units
(quantity units or str) Required if the 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:
- array_annotations
(dict) Dict mapping strings to numpy arrays containing annotations for all data points
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=None, copy=True, sampling_rate=array(1.) * Hz, t_start=array(0.) * s, waveforms=None, left_sweep=None, name=None, file_origin=None, description=None, array_annotations=None, **annotations)#
SpikeTrain
is aQuantity
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 orndarray
, not if it is aQuantity
.- t_stop
(quantity scalar, numpy scalar, or float) Time at which
SpikeTrain
ended. This will be converted to the same units astimes
. This argument is required because it specifies the period of time over which spikes could have occurred. Note thatt_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 astimes
. Default: 0.0 seconds.- waveforms
(quantity array 3D (spike, channel, 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.
- array_annotations
(dict) Dict mapping strings to numpy arrays containing annotations for all data points
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 newSpikeTrain
(actually a view) is returned, with the same metadata, except thatwaveforms
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.
- class neo.core.ImageSequence(image_data, units=None, dtype=None, copy=True, t_start=array(0.) * s, spatial_scale=None, frame_duration=None, sampling_rate=None, name=None, description=None, file_origin=None, **annotations)#
Representation of a sequence of images, as an array of three dimensions organized as [frame][row][column].
Inherits from
quantities.Quantity
, which in turn inherits fromnumpy.ndarray
.usage:
>>> from neo.core import ImageSequence >>> import quantities as pq >>> >>> img_sequence_array = [[[column for column in range(20)]for row in range(20)] ... for frame in range(10)] >>> image_sequence = ImageSequence(img_sequence_array, units='V', ... sampling_rate=1 * pq.Hz, ... spatial_scale=1 * pq.micrometer) >>> image_sequence ImageSequence 10 frames with width 20 px and height 20 px; units V; datatype int64 sampling rate: 1.0 spatial_scale: 1.0 >>> image_sequence.spatial_scale array(1.) * um
- Required attributes/properties:
- image_data
(3D NumPy array, or a list of 2D arrays) The data itself
- units
(quantity units)
- sampling_rate
or frame_duration (quantity scalar) Number of samples per unit time or duration of a single image frame. If both are specified, they are checked for consistency.
- spatial_scale
(quantity scalar) size for a pixel.
- t_start
(quantity scalar) Time when sequence begins. Default 0.
- 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/
frame_duration
)- frame_duration
(quantity scalar) Duration of each image frame. (1/
sampling_rate
)- spatial_scale
Size of a pixel
- duration
(Quantity) Sequence duration, read-only. (size *
frame_duration
)- t_stop
(quantity scalar) Time when sequence ends, read-only. (
t_start
+duration
)
- class neo.core.RectangularRegionOfInterest(x, y, width, height)#
Representation of a rectangular ROI
Usage:
>>> roi = RectangularRegionOfInterest(20.0, 20.0, width=5.0, height=5.0) >>> signal = image_sequence.signal_from_region(roi)
- Required attributes/properties:
- x, y
(integers or floats) Pixel coordinates of the centre of the ROI
- width
(integer or float) Width (x-direction) of the ROI in pixels
- height
(integer or float) Height (y-direction) of the ROI in pixels
- class neo.core.CircularRegionOfInterest(x, y, radius)#
Representation of a circular ROI
Usage:
>>> roi = CircularRegionOfInterest(20.0, 20.0, radius=5.0) >>> signal = image_sequence.signal_from_region(roi)
- Required attributes/properties:
- x, y
(integers or floats) Pixel coordinates of the centre of the ROI
- radius
(integer or float) Radius of the ROI in pixels
- class neo.core.PolygonRegionOfInterest(*vertices)#
Representation of a polygonal ROI
Usage:
>>> roi = PolygonRegionOfInterest( ... (20.0, 20.0), ... (30.0, 20.0), ... (25.0, 25.0) ... ) >>> signal = image_sequence.signal_from_region(roi)
- Required attributes/properties:
- vertices
tuples containing the (x, y) coordinates, as integers or floats, of the vertices of the polygon