Core API¶
The top level of frames2py exports the names below (its __all__). The kernel classes are
also exported there; they are documented on the Kernels page. The other
public modules are frames2py.kernels, frames2py.publish, frames2py.adapters.evt,
frames2py.adapters.aedat4, frames2py.adapters.hdf5, frames2py.recorder,
frames2py.viewer and frames2py.replay.
frames2py.Engine ¶
Accumulates events from one producer and publishes snapshots for consumers.
ingest() does its work on the caller's thread and never waits for a consumer.
Consumers call snapshot() whenever they like, or wait_for_newer() to block until
a newer snapshot is published; snapshot() and stats take no lock. Publication
happens only inside ingest() and stop(): there is no timer thread.
The first ingest() that doesn't raise makes its thread the producer for the
Engine's lifetime, reset() included; ingest() from any other thread raises
RuntimeError. start(), stop() and reset() may be called from any thread:
they and ingest() take one lock, so each runs whole, never interleaved with another.
Raises RuntimeError on construction on a free-threaded build with the GIL disabled,
unless that minor version has been verified (3.14).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_size
|
tuple[int, int]
|
|
required |
kernel
|
str | Kernel
|
A kernel instance, or |
'event_count'
|
snapshot_interval_ms
|
float
|
|
16.0
|
ingest ¶
Accumulate one call's events, then publish if the interval allows.
A no-op while stopped. Raises RuntimeError if called from a thread other than
the producer's. Otherwise raises TypeError for a malformed array and
ValueError if any event has t >= 2**63, in both cases before any state or
statistic changes.
snapshot ¶
The latest published snapshot, shared, not copied; or None before the first
publication and after reset() until the next. Takes no lock.
wait_for_newer ¶
Block until a snapshot newer than sequence is published, then return the latest.
A snapshot is newer when its meta.sequence is greater than sequence; with
None, any published snapshot is. If one is already published the call returns it
at once. Otherwise it returns the snapshot published at the moment it reads it after a
publication, which needn't be sequence + 1: publications in between may be skipped.
Passing back the returned meta.sequence gives strictly increasing snapshots.
timeout is in seconds on the monotonic clock. None or math.inf waits without
limit; 0 checks once without blocking; values above threading.TIMEOUT_MAX are
honoured. On timeout the call returns None, and only if no newer snapshot is
published when it checks after the timeout has elapsed.
stop() and reset() wake nobody: the publication stop() makes for a pending
window wakes waiters like any other, and after reset() a waiter returns the first
publication after it, whose sequence is larger than any before the reset. A reset that
lands between a publication and the waiter's read leaves the waiter waiting for the
next one. A SIGINT raises KeyboardInterrupt out of a main-thread wait and leaves the
Engine unchanged, as CPython's Lock.acquire() allows: a SIGINT arriving as the wait
starts blocking is acted on at its next wake, which is a publication, the timeout, or
another SIGINT.
If a SIGINT interrupts the producer's thread during a publication, one waiter may stay blocked until its timeout, or indefinitely without one: the interrupted publication may have taken that waiter off the registry without waking it. Later publications wake every other waiter as usual. Pass a timeout if the producer can be interrupted.
The call never takes the lock that ingest() holds. Each publication releases the
waiters registered before it, one lock release each, on the publishing thread; it
never waits for a waiter.
Raises:
| Type | Description |
|---|---|
TypeError
|
sequence is not an integer (an |
ValueError
|
sequence is negative, or timeout is negative or NaN. |
RuntimeError
|
called on the producer's thread, which can't publish while it waits. |
stop ¶
Publish events accumulated since the last publication, if any, then make
ingest() a no-op. The latest snapshot stays readable.
reset ¶
Clear the kernel state, counters, watermark and published snapshot.
The snapshot sequence, uptime_ns and the producer thread carry on. The next
ingest() publishes, as the first one does.
frames2py.Accumulator ¶
Accumulates events through one kernel.
Synchronous and single-threaded: each call does its work on the caller's thread
and returns. There is no publication; read() returns the current
representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_size
|
tuple[int, int]
|
|
required |
kernel
|
str | Kernel
|
A kernel instance, or |
required |
watermark
property
¶
The largest timestamp among accumulated in-bounds events, or None.
events_out_of_bounds
property
¶
Events skipped by the bounds check since construction or reset().
accumulate ¶
Accumulate one call's events.
Raises TypeError for a malformed array and ValueError if any event has
t >= 2**63, in both cases before anything changes. Out-of-bounds events are
counted and otherwise ignored.
frames2py.EVENT_DTYPE
module-attribute
¶
One event: t µs, x column, y row, p polarity (0 is OFF, anything else ON).
13 bytes, little-endian, no padding.
frames2py.EngineStats
dataclass
¶
A frozen diagnostic view of an Engine's counters.
The fields are read one after another, not as one instant-consistent snapshot.
Attributes:
| Name | Type | Description |
|---|---|---|
events_ingested |
int
|
Events in accepted |
events_out_of_bounds |
int
|
The subset of those rejected by the bounds check. |
snapshots_published |
int
|
Publications since construction or the last |
uptime_ns |
int
|
Nanoseconds since the Engine was constructed. |
frames2py.SnapshotMeta
dataclass
¶
Metadata published with each snapshot.
Attributes:
| Name | Type | Description |
|---|---|---|
watermark |
int | None
|
The largest timestamp among accumulated in-bounds events at
publication, or |
sequence |
int
|
Publication number. It increases with every publication for the
Engine's lifetime, across |