braintools.input.Spike#
- class braintools.input.Spike(sp_times, duration, sp_lens=Quantity(1., 'ms'), sp_sizes=1.0)#
Generate spike input at specified times.
Creates a series of rectangular current pulses (spikes) at specified times with customizable durations and amplitudes. This is useful for simulating synaptic inputs, direct current injections, or any protocol requiring precise timing of current pulses.
- Parameters:
sp_times (
Sequence[Array|ndarray|bool|number|bool|int|float|complex|Quantity]) – The spike time points. Can include units (e.g., ms).duration (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – The total duration of the signal.sp_lens (
float|Sequence[float]) – The duration of each spike. If scalar, same duration for all spikes. If sequence, must match length of sp_times. Default is 1.sp_sizes (
float|Sequence[float]) – The amplitude of each spike. If scalar, same amplitude for all. If sequence, must match length of sp_times. Default is 1.
See also
BurstFor generating bursts of activity.
GaussianPulseFor smooth pulse shapes.
Notes
The spikes are rectangular pulses. For more realistic synaptic currents, consider using DoubleExponential or combining with smoothing operations. This class uses the functional spike API internally.
Examples
Simple spike train with uniform properties:
>>> spikes = Spike( ... sp_times=[10, 20, 30, 200, 300] * u.ms, ... duration=400 * u.ms, ... sp_lens=1 * u.ms, # All spikes 1ms long ... sp_sizes=0.5 * u.nA # All spikes 0.5nA amplitude ... ) >>> array = spikes()
Variable spike properties:
>>> spikes = Spike( ... sp_times=[10, 50, 100] * u.ms, ... duration=150 * u.ms, ... sp_lens=[1, 2, 0.5] * u.ms, # Different durations ... sp_sizes=[0.5, 1.0, 0.3] * u.nA # Different amplitudes ... )
Add to background activity:
>>> from braintools.input import Constant >>> spikes = Spike([10, 50, 100, 150] * u.ms, 200 * u.ms, sp_sizes=1.0) >>> background = Constant([(0.1, 200 * u.ms)]) >>> combined = spikes + background
High-frequency burst simulation:
>>> import numpy as np >>> times = np.arange(0, 50, 2) * u.ms # Every 2ms >>> spikes = Spike( ... sp_times=times, ... duration=100 * u.ms, ... sp_lens=0.5 * u.ms, ... sp_sizes=2.0 * u.pA ... )
Combine with noise for realistic inputs:
>>> from braintools.input import WienerProcess >>> spikes = Spike([20, 40, 60] * u.ms, 100 * u.ms) >>> noise = WienerProcess(100 * u.ms, sigma=0.05) >>> noisy_spikes = spikes + noise
Pattern of increasing amplitudes:
>>> amplitudes = np.linspace(0.5, 2.0, 10) >>> times = np.linspace(10, 190, 10) * u.ms >>> increasing_spikes = Spike( ... sp_times=times, ... duration=200 * u.ms, ... sp_sizes=amplitudes * u.nA ... )
Paired-pulse facilitation protocol:
>>> # Two spikes with short interval >>> paired = Spike( ... sp_times=[50, 70] * u.ms, # 20ms interval ... duration=150 * u.ms, ... sp_lens=2 * u.ms, ... sp_sizes=[1.0, 1.5] * u.nA # Second spike larger ... ) >>> # Repeat the pattern >>> repeated_pairs = paired.repeat(5)
- __init__(sp_times, duration, sp_lens=Quantity(1., 'ms'), sp_sizes=1.0)[source]#
Initialize spike input.
- Parameters:
sp_times (
Sequence[Array|ndarray|bool|number|bool|int|float|complex|Quantity]) – The spike time points.duration (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – The total duration.sp_lens (
float|Sequence[float]) – The spike duration(s). Default is 1 * u.ms.sp_sizes (
float|Sequence[float]) – The spike amplitude(s). Default is 1.
Methods
__init__(sp_times, duration[, sp_lens, sp_sizes])Initialize spike input.
apply(func)Apply a custom function to the input.
clip([min_val, max_val])Clip the input values to a range.
generate()Generate the spike input array using functional API.
repeat(n_times)Repeat the input pattern n times.
scale(factor)Scale the input by a factor.
shift(time_shift)Shift the input in time.
smooth(tau)Apply exponential smoothing to the input.
Attributes
dtGet the time step from global environment.
n_stepsGet the number of time steps.
shapeGet the shape of the input array.