braintools.input.spike

Contents

braintools.input.spike#

braintools.input.spike(sp_times, sp_lens, sp_sizes, duration)#

Format current input like a series of short-time spikes.

Creates a series of rectangular current pulses (spikes) at specified times with specified durations and amplitudes. Useful for simulating synaptic inputs or direct current injection protocols.

Parameters:
  • sp_times (Sequence) – The spike time-points. Supports time units (e.g., ms).

  • sp_lens (float | Sequence) – The length of each spike. If scalar, same duration for all spikes. If list, must match length of sp_times. Supports time units.

  • sp_sizes (float | Sequence) – The amplitude of each spike. If scalar, same amplitude for all. If list, must match length of sp_times. Supports current units.

  • duration (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – The total duration of the signal.

Returns:

current – The formatted spike input current.

Return type:

ndarray or Quantity

Raises:
  • ValueError – If sp_times is not an iterable.

  • UnitMismatchError – If spike sizes have different units.

Examples

>>> import brainunit as u
>>> import brainstate
>>> brainstate.environ.set(dt=0.1 * u.ms)

Simple spike train with uniform properties

>>> current = spike(
...     sp_times=[10, 20, 30, 200, 300] * u.ms,
...     sp_lens=1 * u.ms,  # All spikes 1ms long
...     sp_sizes=0.5 * u.nA,  # All spikes 0.5nA amplitude
...     duration=400 * u.ms
... )

Variable spike properties

>>> current = spike(
...     sp_times=[10, 50, 100] * u.ms,
...     sp_lens=[1, 2, 0.5] * u.ms,  # Different durations
...     sp_sizes=[0.5, 1.0, 0.3] * u.nA,  # Different amplitudes
...     duration=150 * u.ms
... )

High-frequency burst

>>> import numpy as np
>>> times = np.arange(0, 50, 2) * u.ms  # Every 2ms
>>> current = spike(
...     sp_times=times,
...     sp_lens=0.5 * u.ms,
...     sp_sizes=1.0 * u.pA,
...     duration=100 * u.ms
... )

Notes

  • All spike times, lengths, and sizes are converted to appropriate units

  • Overlapping spikes will overwrite each other (last one wins)

  • Spikes extending beyond duration are truncated