Sensors and DVS Pipeline¶
Event camera (DVS) data loading, preprocessing, spike encoding, and bit-true
ADC-to-spike window encoding. The public package exports DVSLoader,
events_to_spike_trains, events_to_frames, ADCSpikeWindowConfig,
ADCSpikeWindowResult, adc_to_spike_windows, adc_to_spike_windows_q,
available_backends, and quantise_adc.
from sc_neurocore.sensors import DVSLoader, events_to_spike_trains
loader = DVSLoader(width=128, height=128)
events = loader.from_numpy(raw_events)
spikes = events_to_spike_trains(events, width=128, height=128)
from sc_neurocore.sensors import ADCSpikeWindowConfig, adc_to_spike_windows
config = ADCSpikeWindowConfig(decimation=8, threshold_q=256)
windows = adc_to_spike_windows(raw_adc_samples, config, backend="auto")
See Tutorial 45: DVS Pipeline.
API¶
sc_neurocore.sensors.dvs
¶
DVS (Dynamic Vision Sensor) event processing pipeline.
Load event camera data, convert to spike trains or frames, and feed into SC-NeuroCore networks for processing and FPGA deployment.
Supports raw event arrays (structured numpy) and integration with the Tonic library for standard DVS datasets (N-MNIST, DVS-Gesture, N-Cars, etc.).
structured array with fields (x, y, t, p)
x: pixel x coordinate y: pixel y coordinate t: timestamp (microseconds) p: polarity (0=OFF, 1=ON)
DVSLoader
dataclass
¶
Load and preprocess DVS event camera data.
Parameters¶
width : int Sensor width in pixels. height : int Sensor height in pixels.
Source code in src/sc_neurocore/sensors/dvs.py
| Python | |
|---|---|
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
n_pixels
property
¶
Return the total number of pixels in the DVS frame.
from_numpy(events)
¶
Load events from structured numpy array.
Expected fields: 'x', 'y', 't', 'p' (or positional columns). Returns structured array with named fields.
Source code in src/sc_neurocore/sensors/dvs.py
| Python | |
|---|---|
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
from_tonic(dataset_name, index=0)
¶
Load events from a Tonic dataset (requires tonic package).
Parameters¶
dataset_name : str Tonic dataset name: 'nmnist', 'dvs_gesture', 'ncars', etc. index : int Sample index in the dataset.
Returns¶
(events, target) tuple
Source code in src/sc_neurocore/sensors/dvs.py
| Python | |
|---|---|
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
events_to_spike_trains(events, width, height, dt_us=1000.0, duration_us=None)
¶
Convert DVS events to binary spike train matrix.
Parameters¶
events : structured ndarray with x, y, t, p fields width, height : int Sensor dimensions. dt_us : float Time bin width in microseconds (default 1000 = 1ms). duration_us : float, optional Total duration. If None, inferred from event timestamps.
Returns¶
ndarray of shape (n_bins, width * height * 2) Binary spike trains. Channels: [ON pixels, OFF pixels].
Source code in src/sc_neurocore/sensors/dvs.py
| Python | |
|---|---|
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
events_to_frames(events, width, height, dt_us=10000.0, duration_us=None)
¶
Convert DVS events to event count frames.
Parameters¶
events : structured ndarray width, height : int dt_us : float Frame duration in microseconds (default 10000 = 10ms). duration_us : float, optional
Returns¶
ndarray of shape (n_frames, 2, height, width) Event count frames with ON and OFF channels.
Source code in src/sc_neurocore/sensors/dvs.py
| Python | |
|---|---|
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
sc_neurocore.sensors.adc_to_spike_kernel
¶
Bit-true integer reference for the ADC-to-spike decimating rate-code encoder.
Each decimation window of raw ADC samples is centred and quantised to a Q-format
code, sign-aware averaged, and converted into a deterministic rate code: the
spike count is |window| // threshold and the polarity is the window sign. This
is the per-window arithmetic of the synthesisable sensor bridge in
hdl/sensors/adc_to_spike_quantiser.v and the cycle-stepped golden model in
tools/adc_to_spike_reference.py (Indiveri 2003 rate coding); the cycle-accurate
handshake/drain FSM stays in that reference, while this kernel is the hot
per-window compute.
The whole path is exact integer arithmetic (sign-aware Q-format rounding, truncate-toward-zero window averaging, floor-division rate code), so the Python floor and the Rust, Julia, Go and Mojo backends agree bit-for-bit; the parity tolerance is exactly zero.
ADCSpikeWindowConfig
dataclass
¶
Fixed-point and decimation contract for the ADC-to-spike encoder.
Attributes¶
adc_width : int
Raw ADC sample width in bits (must exceed one).
q_int : int
Q-format integer bits (must be positive).
q_frac : int
Q-format fractional bits (must be non-negative).
decimation : int
Number of ADC samples averaged into one spike window (must be positive).
signed_input : bool
True if the ADC delivers two's-complement samples, False for
offset-binary samples centred at mid-scale.
threshold_q : int
Q-format magnitude that emits one spike (must be positive).
Source code in src/sc_neurocore/sensors/adc_to_spike_kernel.py
| Python | |
|---|---|
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
q_total
property
¶
Total Q-format bit width.
q_min
property
¶
Most negative representable Q-format code.
q_max
property
¶
Most positive representable Q-format code.
validate()
¶
Raise :class:ValueError if any field is out of contract.
Raises¶
ValueError If the ADC width, Q-format, decimation or threshold are invalid.
Source code in src/sc_neurocore/sensors/adc_to_spike_kernel.py
| Python | |
|---|---|
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
ADCSpikeWindowResult
dataclass
¶
Per-window outputs of the ADC-to-spike encoder.
Each array is indexed by completed decimation window.
Attributes¶
window_values_q : numpy.ndarray
Sign-aware averaged Q-format window codes, int32.
spike_counts : numpy.ndarray
Deterministic per-window spike counts (|window| // threshold),
int32.
polarities : numpy.ndarray
True where the window code is negative, bool_.
Source code in src/sc_neurocore/sensors/adc_to_spike_kernel.py
| Python | |
|---|---|
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
quantise_adc(sample, config)
¶
Centre and quantise one raw ADC sample to a Q-format code.
Mirrors ADCToSpikeReference.quantise_adc: two's-complement or offset-binary
centring, Q-format up-shift or sign-aware round-down, then saturation.
Parameters¶
sample : int Raw ADC sample. config : ADCSpikeWindowConfig Fixed-point contract.
Returns¶
int Saturated Q-format code.
Source code in src/sc_neurocore/sensors/adc_to_spike_kernel.py
| Python | |
|---|---|
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
adc_to_spike_windows_q(samples, config=None)
¶
Pure-Python ADC-to-spike window encoder — the bit-true floor reference.
Parameters¶
samples : array_like
Raw ADC samples; the first n_windows * decimation are consumed.
config : ADCSpikeWindowConfig, optional
Fixed-point/decimation contract (defaults to Q8.8, decimation 8).
Returns¶
ADCSpikeWindowResult Per-window averaged codes, spike counts and polarities.
Raises¶
ValueError
If the config is invalid or fewer than decimation samples are given.
Source code in src/sc_neurocore/sensors/adc_to_spike_kernel.py
| Python | |
|---|---|
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
available_backends()
¶
Probe which acceleration backends can run the ADC-to-spike kernel.
Returns¶
dict
Mapping of backend name to availability, in fastest-first order. The
python floor is always True.
Source code in src/sc_neurocore/sensors/adc_to_spike_kernel.py
| Python | |
|---|---|
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
adc_to_spike_windows(samples, config=None, *, backend='auto')
¶
Encode ADC samples into spike windows through the fastest available backend.
Parameters¶
samples : array_like
Raw ADC samples.
config : ADCSpikeWindowConfig, optional
Fixed-point/decimation contract.
backend : str, optional
"auto" (default) selects the fastest available backend in
:data:FASTEST_FIRST_BACKENDS order; a specific name forces that backend.
Returns¶
ADCSpikeWindowResult Bit-identical to the Python floor for every backend.
Raises¶
ValueError
If backend is not a known name.
ImportError
If an explicitly requested accelerator backend is unavailable.
Source code in src/sc_neurocore/sensors/adc_to_spike_kernel.py
| Python | |
|---|---|
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |