braintools.input.Ramp#

class braintools.input.Ramp(c_start, c_end, duration, t_start=None, t_end=None)#

Generate linearly changing (ramp) input current.

Creates a linear ramp from a starting value to an ending value over a specified duration. Optionally, the ramp can be confined to a specific time window within the total duration.

Parameters:
  • c_start (float) – The starting current value. Can include units.

  • c_end (float) – The ending current value. Must have same units as c_start.

  • duration (float | Quantity) – The total duration of the input signal.

  • t_start (float | Quantity | None) – Time point when the ramp starts. Before this, the output is c_start. Default is 0.

  • t_end (float | Quantity | None) – Time point when the ramp ends. After this, the output is c_end. Default is duration.

c_start#

The starting current value.

Type:

float

c_end#

The ending current value.

Type:

float

duration#

The total duration.

Type:

Quantity or float

t_start#

The ramp start time.

Type:

Quantity or float or None

t_end#

The ramp end time.

Type:

Quantity or float or None

Raises:

UnitMismatchError – If c_start and c_end have incompatible units.

See also

Step

For instantaneous changes.

Section

For piecewise constant inputs.

Notes

The ramp is linear between t_start and t_end. Before t_start, the output is c_start. After t_end, the output is c_end. This uses the functional ramp API internally.

Examples

Simple linear ramp:

>>> ramp = Ramp(
...     c_start=0 * u.pA,
...     c_end=10 * u.pA,
...     duration=100 * u.ms
... )
>>> array = ramp()

Decreasing ramp (from high to low):

>>> down_ramp = Ramp(
...     c_start=10 * u.pA,
...     c_end=0 * u.pA,
...     duration=100 * u.ms
... )

Ramp with delay and early stop:

>>> # Ramp starts at 50ms and ends at 150ms
>>> delayed_ramp = Ramp(
...     c_start=0 * u.nA,
...     c_end=5 * u.nA,
...     duration=200 * u.ms,
...     t_start=50 * u.ms,
...     t_end=150 * u.ms
... )

Combine with oscillations for amplitude modulation:

>>> from braintools.input import Sinusoidal
>>> envelope = Ramp(0, 1, 500 * u.ms)
>>> carrier = Sinusoidal(1.0, 20 * u.Hz, 500 * u.ms)
>>> am_signal = envelope * carrier

Create sawtooth wave by repeating:

>>> single_tooth = Ramp(0, 1, 50 * u.ms)
>>> sawtooth = single_tooth.repeat(10)  # 500ms total

Complex protocols with transformations:

>>> # Ramp with saturation
>>> ramp = Ramp(-2, 2, 400 * u.ms)
>>> saturated = ramp.clip(-1, 1)
>>>
>>> # Smoothed ramp (reduces sharp corners)
>>> smooth_ramp = ramp.smooth(tau=5 * u.ms)

I-V curve measurement protocol:

>>> # Slow voltage ramp for I-V curves
>>> iv_ramp = Ramp(
...     c_start=-100 * u.pA,
...     c_end=100 * u.pA,
...     duration=1000 * u.ms
... )
>>> # Add small oscillation to avoid hysteresis
>>> from braintools.input import Sinusoidal
>>> wobble = Sinusoidal(5 * u.pA, 100 * u.Hz, 1000 * u.ms)
>>> iv_protocol = iv_ramp + wobble

Sequential ramps for plasticity protocols:

>>> up_ramp = Ramp(0, 1, 100 * u.ms)
>>> plateau = Constant([(1, 50)])
>>> down_ramp = Ramp(1, 0, 100 * u.ms)
>>> protocol = up_ramp & plateau & down_ramp
__init__(c_start, c_end, duration, t_start=None, t_end=None)[source]#

Initialize ramp input.

Parameters:
  • c_start (float) – The starting current value.

  • c_end (float) – The ending current value.

  • duration (float | Quantity) – The total duration.

  • t_start (float | Quantity | None) – The ramp start time. Default is 0.

  • t_end (float | Quantity | None) – The ramp end time. Default is duration.

Methods

__init__(c_start, c_end, duration[, ...])

Initialize ramp 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 ramp 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.