magscope.camera#
Camera manager and dummy camera implementations for MagScope.
This module defines the CameraManager process responsible for coordinating camera acquisition with the shared VideoBuffer, along with several simulation-oriented CameraBase implementations used when hardware is not available. The manager exchanges IPC messages with the GUI to keep camera settings synchronized and ensures buffers are properly released as acquisition states change.
Classes#
Manager process that feeds frames from a CameraBase into shared buffers. |
|
Abstract base class describing the camera interface used by managers. |
|
Noise camera that generates random images at a configurable frame rate. |
|
Noise camera that reuses cached random frames for higher throughput. |
|
Bead simulator producing synthetic frames for testing without hardware. |
Module Contents#
- class magscope.camera.CameraManager[source]#
Bases:
magscope.processes.ManagerProcessBaseManager process that feeds frames from a CameraBase into shared buffers.
The manager owns a camera instance (dummy by default), connects it to the shared VideoBuffer, relays camera settings to the GUI, and orchestrates buffer lifecycles based on acquisition and processing state. Its main loop reacts to pool flags, drains buffers to avoid overflow, and triggers camera fetches when connected.
- camera: CameraBase[source]#
- setup()[source]#
Connect to the camera and publish its current settings.
Connection failures are logged as warnings so the rest of the system can continue running in simulation mode. When a connection succeeds, broadcast the initial camera settings to keep the GUI in sync with the camera process.
- do_main_loop()[source]#
Main process loop handling buffer lifecycle and fetching frames.
The video processor reports consumed stacks through shared completion counters. This manager drains those completions into camera buffer releases, returns unreserved stacks while acquisition is paused, and purges excess buffered data when capacity gets too low.
- _release_unattached_buffers()[source]#
Return buffers that are no longer tracked by the processing pool.
- _release_completed_pool_buffers()[source]#
Release camera buffers for stacks already consumed by workers.
- set_camera_setting(name: str, value: str)[source]#
Apply a setting to the camera and broadcast the full settings set.
- set_simulated_focus(offset: float)[source]#
Adjust the simulated camera focus when using
DummyCameraBeads.
- class magscope.camera.CameraBase[source]#
Abstract base class describing the camera interface used by managers.
Concrete cameras must expose immutable dimensions and dtype metadata, a minimal settings API (__getitem__/__setitem__), and methods for connecting, fetching frames into a VideoBuffer, and releasing buffers back to the device or simulation pool.
- video_buffer: magscope.datatypes.VideoBuffer | None = None[source]#
- abstractmethod connect(video_buffer)[source]#
Attempts to connect to the camera.
But does not start an acquisition. This method should set the value of self.is_connected to True if successful or False if not.
- abstractmethod fetch()[source]#
Checks if the camera has new images.
If the camera has a new image, then it holds the camera’s buffered image in a queue (self.camera_buffers). And stores the image and timestamp in the video buffer (self._video_buffer).
The timestamp should be the seconds since the unix epoch: (January 1, 1970, 00:00:00 UTC)
- abstractmethod get_setting(name: str) str[source]#
Should return the current value of the setting from the camera
- abstractmethod set_setting(name: str, value: str)[source]#
Should set the value of the setting on the camera
- class magscope.camera.DummyCameraNoise[source]#
Bases:
CameraBaseNoise camera that generates random images at a configurable frame rate.
- connect(video_buffer)[source]#
Attempts to connect to the camera.
But does not start an acquisition. This method should set the value of self.is_connected to True if successful or False if not.
- fetch()[source]#
Checks if the camera has new images.
If the camera has a new image, then it holds the camera’s buffered image in a queue (self.camera_buffers). And stores the image and timestamp in the video buffer (self._video_buffer).
The timestamp should be the seconds since the unix epoch: (January 1, 1970, 00:00:00 UTC)
- class magscope.camera.DummyCameraFastNoise[source]#
Bases:
CameraBaseNoise camera that reuses cached random frames for higher throughput.
- connect(video_buffer)[source]#
Attempts to connect to the camera.
But does not start an acquisition. This method should set the value of self.is_connected to True if successful or False if not.
- fetch()[source]#
Checks if the camera has new images.
If the camera has a new image, then it holds the camera’s buffered image in a queue (self.camera_buffers). And stores the image and timestamp in the video buffer (self._video_buffer).
The timestamp should be the seconds since the unix epoch: (January 1, 1970, 00:00:00 UTC)
- class magscope.camera.DummyCameraBeads[source]#
Bases:
CameraBaseBead simulator producing synthetic frames for testing without hardware.
- settings = ['framerate', 'fixed_n', 'fixed_z', 'tethered_n', 'tethered_z', 'tethered_z_sigma',...[source]#
- connect(video_buffer)[source]#
Attempts to connect to the camera.
But does not start an acquisition. This method should set the value of self.is_connected to True if successful or False if not.
- fetch()[source]#
Checks if the camera has new images.
If the camera has a new image, then it holds the camera’s buffered image in a queue (self.camera_buffers). And stores the image and timestamp in the video buffer (self._video_buffer).
The timestamp should be the seconds since the unix epoch: (January 1, 1970, 00:00:00 UTC)