events¶
Event generation and configuration for simulations.
toric_spines_sim.events
¶
Event generation and configuration for simulations.
EventGenerator
¶
Bases: ABC
Pure-interface base class for all event stream generators.
Subclasses must implement :meth:generate. This class provides the
shared IO methods :meth:generate_to_file and :meth:load_from_file.
generate(labels=None)
abstractmethod
¶
Generate event times for all streams.
Args: labels: Optional override for stream labels.
Returns: TsGroup mapping stream indices to Ts objects (timestamps in ms).
Source code in toric_spines_sim/events/base.py
generate_to_file(path, labels=None)
¶
Generate events and save to file with times in ms.
Source code in toric_spines_sim/events/base.py
load_from_file(path)
staticmethod
¶
Load event times from file as TsGroup.
Source code in toric_spines_sim/events/base.py
DeterministicEventGenerator(rate_curves, n_synapses_per_axon, T_ms, delay_ms=0.0, labels=None, routing_mode='roundrobin')
¶
Bases: EventGenerator
Deterministic event generator using rate curves.
Generates events at times determined by integrating the rate curve. For a flat rate curve, this produces periodic (regularly spaced) events. For varying rate curves, event density follows the rate profile.
Can operate in shared mode (single rate curve routed to multiple axons) or independent mode (per-axon rate curves).
Args:
rate_curves: Single RateCurve for shared mode, or sequence of
RateCurves (one per axon) for independent mode.
n_synapses_per_axon: Number of synapses attached to each axon.
len(n_synapses_per_axon) is the number of axons (N_A).
The total number of output channels is sum(n_synapses_per_axon).
T_ms: Total simulation time in milliseconds.
delay_ms: Time before events start (ms). Default: 0.0.
labels: Optional labels for each output channel. Length must equal
sum(n_synapses_per_axon). Default labels are A{a}S{s}.
TSRecipe / TSSimulator ignore those labels and map by
TsGroup index to syn_0, syn_1, … — use
remap_axon_channel_events_to_synapses when axon assignments
are not point-file order.
routing_mode: How to route master events to axons in shared mode.
"broadcast": every master event goes to all axons.
"roundrobin": events distributed cyclically among axons.
Only used in shared mode. Defaults to "roundrobin".
Source code in toric_spines_sim/events/generators.py
generate(labels=None)
¶
Generate deterministic event times for all output channels.
Source code in toric_spines_sim/events/generators.py
StochasticEventGenerator(rate_curves, n_synapses_per_axon, T_ms, delay_ms=0.0, seed=None, labels=None, routing_weights=None, arp_ms=0.0)
¶
Bases: EventGenerator
Stochastic event generator using inhomogeneous Poisson process.
Generates events via thinning algorithm applied to rate curves. Supports absolute refractory period (ARP) to enforce minimum ISI.
Can operate in shared mode (single rate curve routed to multiple axons) or independent mode (per-axon rate curves with independent processes).
Args:
rate_curves: Single RateCurve for shared mode, or sequence of
RateCurves (one per axon) for independent mode.
n_synapses_per_axon: Number of synapses attached to each axon.
len(n_synapses_per_axon) is the number of axons (N_A).
The total number of output channels is sum(n_synapses_per_axon).
T_ms: Total simulation time in milliseconds.
delay_ms: Time before events start (ms). Default: 0.0.
seed: Random seed for reproducibility. Default: None.
labels: Optional labels for each output channel. Length must equal
sum(n_synapses_per_axon). Default labels are A{a}S{s}.
TSRecipe / TSSimulator map by TsGroup index to
syn_i; use remap_axon_channel_events_to_synapses when
axon assignments are not point-file order.
routing_weights: Probability of routing each master event to each axon.
Only used in shared mode. Must sum to 1. Defaults to uniform.
arp_ms: Absolute refractory period in ms. Can be scalar (same for all
axons) or per-axon list. Default: 0.0.
Source code in toric_spines_sim/events/generators.py
generate(labels=None)
¶
Generate stochastic event times for all output channels.
Source code in toric_spines_sim/events/generators.py
RateCurve
¶
Bases: ABC
Abstract base class for rate curves.
Subclasses must implement rate_at for getting instantaneous rate,
max_rate for the upper bound (used in thinning), and get_isis
for deterministic event generation.
rate_at(t_ms, T_ms=None)
abstractmethod
¶
Return the instantaneous rate at time t_ms (Hz).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t_ms
|
float
|
Time in milliseconds. |
required |
T_ms
|
float
|
Total duration in milliseconds. Required by curves whose shape
is defined over a finite window (currently |
None
|
Source code in toric_spines_sim/events/rate_curves.py
max_rate()
abstractmethod
¶
get_isis(T_ms, delay_ms)
abstractmethod
¶
Compute inter-spike intervals for deterministic generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T_ms
|
float
|
Total simulation time in milliseconds. |
required |
delay_ms
|
float
|
Initial delay before events start. |
required |
Returns:
| Type | Description |
|---|---|
list of float
|
ISIs in ms. Cumulative sum plus delay gives event times. |
Source code in toric_spines_sim/events/rate_curves.py
FlatRateCurve(rate_hz)
¶
LinearRateCurve(rate_start_hz, rate_end_hz)
¶
Bases: RateCurve
Linear ramp from rate_start_hz at t=0 to rate_end_hz at t=T_ms.
Stochastic generators pass T_ms into rate_at so Poisson thinning
follows the same ramp as deterministic get_isis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate_start_hz
|
float
|
Rate at t=0 (Hz). |
required |
rate_end_hz
|
float
|
Rate at t=T_ms (Hz). |
required |
Examples:
Source code in toric_spines_sim/events/rate_curves.py
StepRateCurve(rates_hz, step_duration_ms)
¶
Bases: RateCurve
Piecewise-constant (step) rate curve.
Args: rates_hz: List of rates for each step phase (in Hz). step_duration_ms: Duration of each step phase in ms.
Source code in toric_spines_sim/events/rate_curves.py
SineRateCurve(peak_rate_hz, freq_hz, baseline=0.0, phase_rad=None, phase_deg=None)
¶
Bases: RateCurve
Sinusoidally modulated rate curve.
Rate follows: r(t) = peak_rate_hz * max(0, sin(2π * freq_hz * t_ms/1000 + phase) + baseline)
Args: peak_rate_hz: Peak amplitude of the sine wave in Hz. freq_hz: Frequency of modulation in Hz. baseline: Offset added to sine wave (default: 0.0). phase_rad: Phase offset in radians (mutually exclusive with phase_deg). phase_deg: Phase offset in degrees (mutually exclusive with phase_rad).
Raises: ValueError: If both phase_rad and phase_deg are provided.
Source code in toric_spines_sim/events/rate_curves.py
to_sine_v1_params()
¶
Return compact parameters for JSON serialization and plot reconstruction.