Kernels API¶
frames2py.kernels holds the Kernel protocol and the seven built-in kernels. The kernel
classes are also exported from frames2py. Their semantics are on the
Kernels page; the methods listed here are the Kernel protocol, which
the Accumulator calls. You don't call them yourself unless you are writing a kernel.
frames2py.kernels.Kernel ¶
Bases: Protocol
A representation kernel.
The Accumulator owns validation, the timestamp-range check, the bounds check, the
watermark and the out-of-bounds count; a kernel only turns in-bounds events into
its representation. For each accepted call the Accumulator calls begin_call
once, then passes the call's in-bounds events to accumulate. Publication reads
the representation, then closes the window.
output_spec ¶
Shape and dtype of the representation for a (width, height) sensor.
init_state ¶
Allocate the kernel's state for a (width, height) sensor.
begin_call ¶
Once per accepted accumulate/ingest call, before any accumulation.
accumulate ¶
Merge the call's in-bounds events. watermark includes this call's events.
read ¶
Write the representation, evaluated at watermark, into out.
watermark is the latest accumulated watermark or a later time; None
only before the first in-bounds event. The Accumulator and Engine pass the
accumulated watermark. Must not change the state, whatever watermark is.
Kernels without time dependence ignore it.
Since 1.1, read may be given a time later than the accumulated watermark.
A kernel written for 1.0, which assumed it always received exactly the
accumulated watermark, may need adapting. frames2py.replay.windows() passes
each frame's boundary, later than every event accumulated, and requires a kernel
that evaluates its representation at the time it is given.
close_window ¶
Called after each publication. Windowed kernels start a new window here; running kernels do nothing.
frames2py.kernels.EventCount ¶
Events per pixel in the current window. (H, W) uint32, windowed.
Counts wrap modulo 2**32; they never saturate.
frames2py.kernels.Polarity ¶
Events per pixel and polarity in the current window. (H, W, 2) uint32,
windowed. Channel 0 counts p == 0 (OFF), channel 1 every other p (ON).
Counts wrap modulo 2**32; they never saturate.
frames2py.kernels.TimeSurface ¶
Largest timestamp per pixel. (H, W) uint64, running.
0 means no event, so an event at t = 0 is indistinguishable from none.
frames2py.kernels.ExpDecay ¶
Exponentially decaying event count. (H, W) float32, running.
Once per accepted accumulate() or ingest() call the surface is multiplied
by decay, then each in-bounds event adds 1. The decay is per call, not per unit
of time, so the result depends on how events are batched into calls; use
TimestampDecay for decay in event time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decay
|
float
|
Finite, with |
required |
frames2py.kernels.TimestampDecay ¶
Event-time exponential decay. (H, W) float32, running.
Each pixel reads sum(exp(-(T - t_i) / tau_us)) over its accumulated in-bounds
events, where T is the watermark. Every event weighs 1, whatever its polarity.
Without new in-bounds events T doesn't move and the surface doesn't change; a
consumer can extrapolate a snapshot to a later time T' by multiplying it by
exp(-(T' - T) / tau_us).
In exact arithmetic the result doesn't depend on event order or on how events are split into calls. An accepted event with a far-future timestamp moves the watermark so far that earlier contributions underflow to zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tau_us
|
float
|
Time constant in µs. Finite and > 0; anything else raises |
required |
frames2py.kernels.StackedHistogram ¶
Events per polarity in each of the last bins completed time bins.
(2, bins, H, W) uint32, running.
Bin k covers [k * bin_us, (k + 1) * bin_us) of event time. Read at the watermark
T, the frame shows the bins bins before the one T falls in, oldest first: index
j is bin T // bin_us - bins + j, so the frame covers bins * bin_us µs and never
shows the bin still being filled. Channel 0 counts p == 0 (OFF), channel 1 every
other p (ON). Events older than the frame count for nothing. Counts wrap modulo
2**32; they are never clipped or normalised.
The result doesn't depend on event order or on how events are split into calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bins
|
int
|
Time bins shown, an int |
required |
bin_us
|
int
|
Bin width in µs, an int with |
required |
Anything else, a bool or a float included, raises ValueError.
frames2py.kernels.VoxelGrid ¶
Signed events spread linearly in time over bins knots. (bins, H, W) float32,
running.
Bin k covers [k * bin_us, (k + 1) * bin_us) of event time. Read at the watermark
T, knot j sits at (T // bin_us - bins + 1 + j) * bin_us, oldest first, so the
last knot is at the start of the bin T falls in. The frame covers the bins - 1
completed bins between the first and last knots, (bins - 1) * bin_us µs; the bin
still being filled is never shown. An event in that span, at t = q * bin_us + r, adds
s * (bin_us - r) / bin_us to the knot at q * bin_us and s * r / bin_us to the
next, with s = +1 for p != 0 and -1 for p == 0. Events outside the span
count for nothing. No normalisation.
Each knot's numerator, the sum of s * (bin_us - r) and s * r terms, is kept
exactly as an integer modulo 2**64. It is read as a two's-complement int64 n, so it
is exact while the true sum lies in [-2**63, 2**63 - 1] and wraps outside it. The
output is float32(float64(n) / float64(bin_us)), correctly rounded while
|n| <= 2**53. The result doesn't depend on event order or on how events are split
into calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bins
|
int
|
Knots, an int |
required |
bin_us
|
int
|
Bin width in µs, an int with |
required |
Anything else, a bool or a float included, raises ValueError.