from_neo

Contents

from_neo#

class braintools.file.from_neo(spiketrains, *, capacity=None, t_start=None, t_stop=None)#

Build a SpikeTrains from neo.SpikeTrain objects.

Each neo.SpikeTrain becomes one neuron. By default the population’s t_start and t_stop are the earliest t_start and the latest t_stop of the inputs.

Parameters:
  • spiketrains (Sequence[Any]) – The spike trains, one per neuron (for example segment.spiketrains). Trains may use different time units; all are converted to the unit of the first train.

  • capacity (int | None) – Padded number of spike slots per neuron. Defaults to the longest train (at least 1).

  • t_start (Any) – Recording bounds overriding the defaults above, as brainunit time Quantities. They are needed to keep the bounds of a population with zero neurons: to_neo then returns an empty list, which cannot carry them. For an empty spiketrains, t_start defaults to 0 and t_stop to t_start.

  • t_stop (Any) – Recording bounds overriding the defaults above, as brainunit time Quantities. They are needed to keep the bounds of a population with zero neurons: to_neo then returns an empty list, which cannot carry them. For an empty spiketrains, t_start defaults to 0 and t_stop to t_start.

Returns:

Spike times as Quantities in the brainunit equivalent of the first train’s unit (seconds if there is no equivalent), sorted per neuron. overflow is True if any input carries the annotation braintools_overflow=True (as written by to_neo()). An empty sequence gives zero neurons, in the unit of t_start (or t_stop) if given and otherwise with t_start = t_stop = 0 s.

Return type:

SpikeTrains

Raises:
  • ValueError – If a train has more than capacity spikes, or a spike lies outside explicit t_start/t_stop.

  • TypeError – If an element is not a neo.SpikeTrain or its unit is not a time, or t_start/t_stop is not a time Quantity.

  • ImportError – If neo or quantities is missing (pip install braintools[neo]).

See also

to_neo

The inverse conversion.

braintools.spike.SpikeTrains.from_list

Build from ragged arrays.

Notes

Host-only (not under jax.jit/jax.vmap). The times are converted to JAX’s default float dtype, so with jax_enable_x64 off they are rounded to float32.

Examples

>>> import neo
>>> import quantities as pq
>>> from braintools.file._neo import from_neo
>>> trains = [neo.SpikeTrain([3., 1.] * pq.ms, t_start=0. * pq.ms, t_stop=4. * pq.ms),
...           neo.SpikeTrain([0.002] * pq.s, t_start=0. * pq.s, t_stop=0.005 * pq.s)]
>>> st = from_neo(trains)
>>> st.times
Quantity([[ 1.  3.]
          [ 2. inf]], "ms")
>>> st.t_start, st.t_stop
(Quantity(0., "ms"), Quantity(5., "ms"))
>>>
>>> import brainunit as u
>>> empty = from_neo([], t_start=0. * u.ms, t_stop=5. * u.ms)
>>> empty.n_neurons, empty.t_stop
(0, Quantity(5., "ms"))