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:
- Raises:
ValueError – If values and durations have different lengths.
See also
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
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
dtGet the time step from global environment.
n_stepsGet the number of time steps.
shapeGet the shape of the input array.