braintools.input.Step#
- class braintools.input.Step(amplitudes, step_times, duration=None)#
Generate step function input with multiple levels.
Creates a step function where the input jumps to specified amplitude values at given time points. This is useful for protocols requiring instantaneous changes in stimulation level.
- Parameters:
amplitudes (
Sequence[float]) – Amplitude values for each step. The length should match step_times. Can include units for dimensional consistency.step_times (
Sequence[float|Quantity]) – Time points where steps occur. Will be automatically sorted if not in ascending order.duration (
float|Quantity) – Total duration of the input signal.
See also
Notes
If step_times are not sorted, they will be automatically sorted along with their corresponding amplitudes. The functional step API is used internally for array generation.
Examples
Simple three-level step function:
>>> steps = Step( ... amplitudes=[0, 10, 5] * u.pA, ... step_times=[0, 50, 150] * u.ms, ... duration=200 * u.ms ... ) >>> array = steps()
Staircase protocol for I-V curve:
>>> # Incrementally increasing current steps >>> amplitudes = np.arange(0, 101, 10) * u.pA >>> times = np.arange(0, 1100, 100) * u.ms >>> staircase = Step(amplitudes, times, 1200 * u.ms)
Multiple pulses with return to baseline:
>>> pulses = Step( ... amplitudes=[0, 5, 0, 10, 0, 15, 0] * u.pA, ... step_times=[0, 20, 40, 60, 80, 100, 120] * u.ms, ... duration=150 * u.ms ... )
Combine with noise for realistic stimulation:
>>> from braintools.input import WienerProcess >>> steps = Step([0, 1, 0.5], [0, 100, 200] * u.ms, 300 * u.ms) >>> noise = WienerProcess(300 * u.ms, sigma=0.1) >>> noisy_steps = steps + noise
Create complex protocols with transformations:
>>> # Smoothed steps for gradual transitions >>> sharp_steps = Step( ... [0, 1, 0.5, 1, 0], ... [0, 50, 100, 150, 200] * u.ms, ... 250 * u.ms ... ) >>> smooth_steps = sharp_steps.smooth(tau=10 * u.ms) >>> >>> # Clipped to physiological range >>> clipped = sharp_steps.clip(0, 0.8)
Unsorted times are automatically handled:
>>> # Times will be sorted to [0, 50, 100] >>> steps = Step( ... amplitudes=[5, 0, 10] * u.pA, ... step_times=[50, 0, 100] * u.ms, ... duration=150 * u.ms ... )
Sequential composition:
>>> baseline = Step([0], [0 * u.ms], 100 * u.ms) >>> test = Step([0, 1, 0], [0, 20, 80] * u.ms, 100 * u.ms) >>> protocol = baseline & test & baseline
Methods
__init__(amplitudes, step_times[, duration])Initialize step 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 step 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.