braintools.input.Constant#
- class braintools.input.Constant(I_and_duration)#
Generate constant input with specified durations.
Creates a piecewise constant input where each piece has a specific value and duration. This is similar to Section but uses (value, duration) pairs for convenience.
- Parameters:
I_and_duration (
Sequence[tuple]) – List of (value, duration) pairs. Each tuple specifies the current value and how long it should be maintained. Values can include units.- Variables:
See also
Notes
Constant internally uses the functional constant API. The composable interface allows for easy combination with other inputs and transformations.
Examples
Simple two-phase protocol:
>>> import brainstate >>> import brainunit as u >>> from braintools.input import Constant >>> const = Constant([ ... (0 * u.pA, 100 * u.ms), ... (10 * u.pA, 200 * u.ms) ... ]) >>> brainstate.environ.set(dt=0.1 * u.ms) >>> array = const() >>> array.shape (3000,)
Multi-step current injection:
>>> # Incrementally increasing steps >>> steps = Constant([ ... (0 * u.nA, 50 * u.ms), ... (0.5 * u.nA, 50 * u.ms), ... (1.0 * u.nA, 50 * u.ms), ... (1.5 * u.nA, 50 * u.ms), ... (0 * u.nA, 50 * u.ms), ... ])
Smooth transitions between levels:
>>> # Create sharp steps and smooth them >>> const = Constant([ ... (0, 100), ... (1, 100), ... (0.5, 100), ... (0, 100) ... ]) >>> smoothed = const.smooth(tau=20 * u.ms)
Combine with oscillations:
>>> from braintools.input import Sinusoidal >>> baseline = Constant([(0.5, 500)]) >>> oscillation = Sinusoidal(0.2, 5 * u.Hz, 500) >>> combined = baseline + oscillation
Create complex protocols:
>>> # Paired-pulse protocol >>> protocol = Constant([ ... (0 * u.pA, 100 * u.ms), # baseline ... (5 * u.pA, 20 * u.ms), # first pulse ... (0 * u.pA, 50 * u.ms), # inter-pulse interval ... (5 * u.pA, 20 * u.ms), # second pulse ... (0 * u.pA, 100 * u.ms), # recovery ... ]) >>> # Add noise for more realistic stimulation >>> from braintools.input import WienerProcess >>> noisy_protocol = protocol + WienerProcess(290 * u.ms, sigma=0.1)
Use transformations:
>>> # Scale amplitude >>> scaled = const.scale(0.5) >>> >>> # Clip to physiological range >>> clipped = const.clip(-80, 40) >>> >>> # Repeat pattern >>> repeated = const.repeat(3)
Methods
__init__(I_and_duration)Initialize constant 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 constant 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.