ezmsg.sigproc.streamstamp#

Stamp segment and config_id on a stream whose source does not.

A source should set segment itself, changing it on the first message that does not continue the previous one, and config_id, changing it when its layout changes. Place StreamStamp right after a source that does not, so that every stateful stage downstream resets across a gap instead of filtering through it, and compares one int per message instead of inspecting the layout.

Classes

class StreamStamp(*args, settings=None, **kwargs)[source]#

Bases: BaseTransformerUnit[StreamStampSettings, AxisArray, AxisArray, StreamStampTransformer]

Parameters:

settings (Settings | None)

SETTINGS#

alias of StreamStampSettings

class StreamStampSettings(tolerance: float | None)[source]#

Bases: Settings

Parameters:

tolerance (float | None)

tolerance: float | None#

Largest difference, in seconds, between a chunk’s offset and where the previous chunk ended that still counts as continuous.

There is no default because it depends on the source. Two chunks’ offsets can each be off by the source’s timestamp jitter, so allow about twice that. Err on the large side: a timing slip of a sample or two costs a filter far less than the reset a reported gap causes downstream.

None turns detection off: every message keeps the segment it arrived with, though it still gets a config_id. Can be changed while running.

__init__(tolerance)#
Parameters:

tolerance (float | None)

Return type:

None

class StreamStampState[source]#

Bases: object

tracker: SegmentTracker | None = None#
upstream: int | None = None#

The upstream segment of the previous message.

config_id: int = 0#

compute_config_id of the current layout, for messages that do not declare one.

class StreamStampTransformer(*args, **kwargs)[source]#

Bases: BaseStatefulTransformer[StreamStampSettings, AxisArray, AxisArray, StreamStampState]

Start a new segment wherever the stream’s offsets show a gap, and stamp a config_id.

Each chunk’s stream-axis offset is compared with where the previous chunk ended; a jump forward or backward of more than tolerance seconds starts a new segment, and so does a change of the upstream segment or of the stream’s layout (e.g. its sample rate). The output segment is this transformer’s own counter, starting at 0, not the upstream one.

Only gaps between chunks are seen: a chunk’s LinearAxis cannot describe a gap within it. Split such chunks first (see ezmsg.baseproc.find_gaps()).

Gap detection needs a LinearAxis on the stream dimension. A message whose stream axis is a CoordinateAxis keeps the segment it arrived with.

A message that declares a config_id keeps it. Any other gets compute_config_id() of its layout, computed only when the layout changes.

NONRESET_SETTINGS_FIELDS: ClassVar[frozenset[str]] = frozenset({'tolerance'})#
WARN_UNDECLARED_CONFIG: ClassVar[bool] = False#

Warn, once per class, on receiving an AxisArray with no config_id.

Set False only on a processor whose job is to receive such messages, such as the adapter that stamps a config_id on them. Read only for an undeclared message.