processors#

Real-time, per-frame processors for camera DataProducers.

A FrameProcessor subscribes to a camera’s signals.frame, runs compute(img, idx, ts) on a daemon worker thread, and emits the result on both signals.data (for the DataQueue / CSV logger) and a Qt-compatible valueUpdated(time, value) signal (for the existing SerialWidget plotter).

class mesofield.processors.FrameProcessor[source]#

Bases: object

Base class for per-frame, real-time processors.

Acquisition stays on the camera thread; compute runs on a daemon worker thread fed by a bounded queue (size 1, drop-oldest replace) so processing latency cannot stall the camera. Subclasses implement one method:

def compute(self, img, idx, ts) -> float | None: ...

Returning None skips emission for that frame. Otherwise the scalar is emitted on:

  • self.signals.data(value, ts) – psygnal; pushed onto the DataQueue / CSV logger when the processor is registered with DataManager.register_hardware_device().

  • self.valueUpdated(t, value)pyqtSignal(float, float); Qt’s cross-thread queued connection makes SerialWidget safe to drive from the worker thread.

__init__(name=None, camera=None, sampling_rate=0.0, plot=False, **kwargs)[source]#
Parameters:
  • name (Optional[str])

  • camera (Optional['DataProducer'])

  • sampling_rate (float)

  • plot (bool)

  • kwargs (Any)

Return type:

None

compute(img, idx, ts)[source]#

Subclass hook: return one scalar (or None) per frame.

Called on every frame the attached camera emits. Implementations should be fast — anything heavy will starve the camera buffer. Return None to skip emitting a sample for this frame.

Parameters:
  • img (Any) – Frame from the camera (typically a 2-D ndarray).

  • idx (Any) – Frame index assigned by the camera (monotonic).

  • ts (Any) – Device timestamp for the frame.

Returns:

A single float to be pushed to the data queue / plot, or None to skip this frame.

Return type:

float | None

status()[source]#

Snapshot of the per-run compute-load counters.

Return type:

Dict[str, Any]

attach(camera=None)[source]#

Attach to a camera’s signals.frame and start the worker.

camera defaults to whatever was passed at construction time (self.camera); callers building processors first and attaching later may pass it explicitly.

Parameters:

camera (Optional['DataProducer'])

Return type:

None

class mesofield.processors.FrameMean[source]#

Bases: FrameProcessor

compute(img, idx, ts)[source]#

Subclass hook: return one scalar (or None) per frame.

Called on every frame the attached camera emits. Implementations should be fast — anything heavy will starve the camera buffer. Return None to skip emitting a sample for this frame.

Parameters:
  • img (Any) – Frame from the camera (typically a 2-D ndarray).

  • idx (Any) – Frame index assigned by the camera (monotonic).

  • ts (Any) – Device timestamp for the frame.

Returns:

A single float to be pushed to the data queue / plot, or None to skip this frame.

Return type:

float | None

mesofield.processors.register_processor(name)[source]#

Class decorator registering a FrameProcessor under name.

The name is what a config processors entry uses as its type.

Parameters:

name (str)

mesofield.processors.get_processor_class(name)[source]#

Return the registered class for name, or None.

Parameters:

name (str)

Return type:

Type | None

mesofield.processors.available_processors()[source]#

Sorted list of registered processor type names.

Return type:

List[str]

mesofield.processors.build_processor(spec, camera=None, default_name=None)[source]#

Build a FrameProcessor from a config spec.

spec is either a type-name string or a mapping with a type key. Remaining mapping keys are forwarded to the processor constructor (plot, sampling_rate, and the recognized plot-styling kwargs). enabled is ignored here – callers decide whether to build a disabled entry.

Raises ValueError for an unknown/missing type and TypeError for a spec that is neither a string nor a mapping.

Parameters:
  • spec (Any)

  • camera (Any | None)

  • default_name (str | None)

Return type:

Any

Submodules#