braintools.input.Section#

class braintools.input.Section(values, durations)#

Generate input current with different sections.

A section input consists of different constant values maintained for specified durations. This is useful for creating protocols with distinct phases, such as baseline, stimulation, and recovery periods.

Parameters:
  • values (Sequence) – The current values for each period. Can be scalars or arrays for multi-channel inputs. Units are preserved if provided.

  • durations (Sequence) – The duration for each period. Should have the same length as values. Can be specified with or without units.

values#

The stored current values for each section.

Type:

Sequence

durations#

The stored durations for each section.

Type:

Sequence

duration#

Total duration calculated as sum of all section durations.

Type:

Quantity or float

Raises:

ValueError – If values and durations have different lengths.

See also

Constant

Similar but with (value, duration) pairs.

Step

Creates steps at specific time points.

Notes

The Section class uses the functional API internally to generate the actual current arrays. It provides a composable interface that allows combining with other inputs using operators.

Examples

Simple three-phase protocol:

>>> section = Section(
...     values=[0, 1, 0] * u.pA,
...     durations=[100, 300, 100] * u.ms
... )
>>> array = section()  # Generate the array

Multi-channel input:

>>> values = [np.zeros(3), np.ones(3) * 5, np.zeros(3)] * u.nA
>>> section = Section(
...     values=values,
...     durations=[50, 100, 50] * u.ms
... )

Combine with other inputs:

>>> # Add noise to section input
>>> from braintools.input import WienerProcess
>>> noisy_section = section + WienerProcess(500 * u.ms, sigma=0.1)

>>> # Modulate with sinusoid
>>> from braintools.input import Sinusoidal
>>> sine = Sinusoidal(0.2, 10 * u.Hz, 500 * u.ms)
>>> modulated = section * (1 + sine)

Complex protocol with smooth transitions:

>>> # Create step protocol and smooth it
>>> protocol = Section(
...     values=[0, 0.5, 1.0, 1.5, 1.0, 0.5, 0],
...     durations=[50, 30, 100, 150, 100, 30, 50]
... )
>>> smooth_protocol = protocol.smooth(tau=10 * u.ms)

Sequential composition:

>>> baseline = Section([0], [200])
>>> stim = Section([0.5, 1.0, 0.5], [50, 100, 50])
>>> recovery = Section([0], [200])
>>> full_protocol = baseline & stim & recovery
__init__(values, durations)[source]#

Initialize section input.

Parameters:
  • values (Sequence) – The current values for each period.

  • durations (Sequence) – The duration for each period.

Methods

__init__(values, durations)

Initialize section 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 section input array.

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

dt

Get the time step from global environment.

n_steps

Get the number of time steps.

shape

Get the shape of the input array.