Skip to content

Keep the threshold scaler across a segment; test segment handling - #42

Merged
cboulay merged 2 commits into
devfrom
feature/segments
Nov 14, 2026
Merged

cboulay merged 2 commits into
devfrom
feature/segments

Conversation

@cboulay

@cboulay cboulay commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Part of the gap-handling work tracked in ezmsg-org/ezmsg-sigproc#247. The sources (ezmsg-nwb, ezmsg-blackrock, ezmsg-neo, ezmsg-xdf) now set AxisArray.segment; this checks what the event processors do with it.

Findings

An audit of every processor, backed by the new tests:

  • segment and attrs already reach every output. All of them build their output with replace(message, ...).
  • The default reset on a new segment (ezmsg-baseproc 1.16) is correct for all but one. What these processors carry between chunks belongs to the samples before the gap:
Processor Carried state At a new segment
ThresholdCrossing last samples, refractory counts reset
ThresholdCrossing with auto_scale_tau the above, plus the scaler's running statistics reset, scaler kept (changed here)
Refractory samples since the last event reset
SparseKernelInserter kernel tails spilling into the next chunk reset (tail dropped)
BinnedKernelActivation, Rate activation level, partly filled bin, bin schedule reset
BinnedEventAggregator none of its own; its sigproc binner resets itself reset
PoissonEvent integrated rate, next threshold reset (redraws)

The one change

ThresholdCrossingTransformer._reset_segment keeps the auto-scaler. Its running mean and variance describe the signal and are not dated by a gap; rebuilding it mis-scales the samples after every gap. The scaler sees the new segment itself and applies its own rule (reset_on_resume), the same as a standalone AdaptiveStandardScaler in ezmsg-sigproc.

Tests

tests/test_segments.py, for each of the six processors (and ThresholdCrossing with peak alignment):

  • segment and attrs reach the output;
  • the first message of a new segment gives the same output as a fresh processor;
  • for all but ThresholdCrossing, the same message without a segment change does not, so the test can tell the difference.

Plus one for the scaler being kept. 185 passed against ezmsg-sigproc 3.12.0, the first release whose scaler keeps its statistics across a segment.

Not changed

Requires ezmsg>=3.10.0b6, ezmsg-baseproc>=1.16.0 and ezmsg-sigproc>=3.12.0.

With ezmsg-baseproc 1.16 a stateful processor is reset when a message's
segment changes, which is right for everything these processors carry
between chunks: a tail of samples, refractory counts, a kernel's decaying
activation, a partly filled bin. Nothing here needed changing for that, and
every output already carries the input's segment and attrs.

The one exception is ThresholdCrossing's auto-scaler, whose running
statistics describe the signal and are not dated by a gap. It is now kept
across a new segment, where a full reset used to rebuild it, and applies its
own rule (reset_on_resume) to the segment it sees.

tests/test_segments.py pins both properties for every processor: segment and
attrs reach the output, and the first message of a new segment is processed
as a fresh processor would.

Requires ezmsg>=3.10.0b6 and ezmsg-baseproc>=1.16.0.
The first release whose AdaptiveStandardScaler keeps its statistics across a
segment, which ThresholdCrossing's auto-scaler relies on.
@cboulay
cboulay marked this pull request as ready for review November 14, 2026 06:04
@cboulay
cboulay merged commit 1c2c5af into dev Nov 14, 2026
4 checks passed
@cboulay
cboulay deleted the feature/segments branch November 14, 2026 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant