from_neo#
- class braintools.file.from_neo(spiketrains, *, capacity=None, t_start=None, t_stop=None)#
Build a
SpikeTrainsfromneo.SpikeTrainobjects.Each
neo.SpikeTrainbecomes one neuron. By default the population’st_startandt_stopare the earliestt_startand the latestt_stopof the inputs.- Parameters:
spiketrains (
Sequence[Any]) – The spike trains, one per neuron (for examplesegment.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, asbrainunittime Quantities. They are needed to keep the bounds of a population with zero neurons:to_neothen returns an empty list, which cannot carry them. For an emptyspiketrains,t_startdefaults to 0 andt_stoptot_start.t_stop (
Any) – Recording bounds overriding the defaults above, asbrainunittime Quantities. They are needed to keep the bounds of a population with zero neurons:to_neothen returns an empty list, which cannot carry them. For an emptyspiketrains,t_startdefaults to 0 andt_stoptot_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.
overflowis True if any input carries the annotationbraintools_overflow=True(as written byto_neo()). An empty sequence gives zero neurons, in the unit oft_start(ort_stop) if given and otherwise witht_start = t_stop = 0 s.- Return type:
- Raises:
ValueError – If a train has more than
capacityspikes, or a spike lies outside explicitt_start/t_stop.TypeError – If an element is not a
neo.SpikeTrainor its unit is not a time, ort_start/t_stopis not a time Quantity.ImportError – If
neoorquantitiesis missing (pip install braintools[neo]).
See also
to_neoThe inverse conversion.
braintools.spike.SpikeTrains.from_listBuild from ragged arrays.
Notes
Host-only (not under
jax.jit/jax.vmap). The times are converted to JAX’s default float dtype, so withjax_enable_x64off 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"))