braintools.input.step

Contents

braintools.input.step#

braintools.input.step(amplitudes, step_times, duration=None)#

Generate step function input with multiple levels.

Creates a step function where the amplitude changes at specified time points. The amplitude remains constant between consecutive step times. This is useful for creating protocols with discrete amplitude changes.

Parameters:
  • amplitudes (list or array-like) – Amplitude values for each step. The i-th amplitude starts at step_times[i] and continues until step_times[i+1] (or the end). Supports units.

  • step_times (list or array-like) – Time points where steps occur. Will be automatically sorted. Supports time units.

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

Returns:

current – The step function input array with shape (n_timesteps,).

Return type:

ndarray or Quantity

Examples

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

Simple three-level step function

>>> current = step(
...     amplitudes=[0, 10, 5] * u.pA,
...     step_times=[0, 50, 150] * u.ms,
...     duration=200 * u.ms
... )

Staircase protocol

>>> amplitudes = [0, 2, 4, 6, 8, 10] * u.nA
>>> times = [0, 20, 40, 60, 80, 100] * u.ms
>>> current = step(amplitudes, times, 120 * u.ms)

Multiple pulses with return to baseline

>>> current = step(
...     amplitudes=[0, 5, 0, 10, 0] * u.pA,
...     step_times=[0, 20, 40, 60, 80] * u.ms,
...     duration=100 * u.ms
... )

Unsorted times are automatically sorted

>>> current = step(
...     amplitudes=[5, 0, 10] * u.pA,
...     step_times=[50, 0, 100] * u.ms,  # Will be sorted to [0, 50, 100]
...     duration=150 * u.ms
... )

Protocol with negative values

>>> current = step(
...     amplitudes=[-5, 0, 5, 0, -5] * u.pA,
...     step_times=[0, 25, 50, 75, 100] * u.ms,
...     duration=125 * u.ms
... )

F-I curve protocol

>>> import numpy as np
>>> amplitudes = np.linspace(0, 50, 11) * u.pA
>>> times = np.linspace(0, 1000, 11) * u.ms
>>> current = step(amplitudes, times, 1100 * u.ms)

Notes

  • Step times and their corresponding amplitudes are automatically sorted by time

  • The last amplitude continues until the end of the duration

  • All amplitudes are converted to the same unit as the first amplitude

  • Times before 0 or after duration are ignored