cameras#

class mesofield.devices.cameras.MMCamera[source]#

Bases: BaseCamera, DataProducer, HardwareDevice

Micro-Manager-backed camera.

Inherits the common camera surface (identity, output paths, manifest metadata, arm / set_sequence defaults, status, calibration) from BaseCamera, and duck-types the DataProducer / HardwareDevice Protocols so existing isinstance() checks keep working. The actual frame flow is driven by pymmcore-plus’s MDA event system; this class wires those events into the standard DeviceSignals bundle and constructs a CustomWriter (OME-TIFF) or CV2Writer (MP4) for the output.

__init__(cfg)[source]#
Parameters:

cfg (dict)

set_sequence(build_mda)[source]#

Build the MDA sequence (Micro-Manager backend only).

Parameters:

build_mda (Callable[[DataProducer], Any])

initialize()[source]#

Apply the YAML properties block to the underlying camera.

Each {device_id: {property: value}} pair is forwarded to the backend (core.setROI for ROIs, core.setProperty otherwise) with special handling for the synthetic fps, viewer_type, and auto_contrast keys.

start_led_sequence(pattern)[source]#

Start the LED pattern.

If led_serial is configured on this camera, sends the configured raw byte sequences via MM’s SerialManager. Otherwise falls back to the original Arduino-Switch.State.loadSequence/startSequence path.

Return type:

None

stop_led_sequence()[source]#

Stop the LED pattern (mirror of start_led_sequence()).

Return type:

None

start()[source]#

Launch the MDA sequence non-blocking.

Returns:

Always True. The sequence runs asynchronously on the camera backend; lifecycle is reported via self.signals.

Return type:

bool

stop()[source]#

Stop acquisition.

Non-primary Micro-Manager cameras must be told explicitly to halt their sequence acquisition — the primary camera’s MDA driver does not stop them.

Return type:

bool

get_data()[source]#

Return the latest captured frame, or None if not active.

snap()[source]#

Capture a single frame via mmcore.snap() and save a snapshot PNG.

start_live()[source]#

Begin continuous (untimed) sequence acquisition for preview.

Return type:

None

stop_live()[source]#

End the continuous sequence acquisition started by start_live.

Return type:

None

shutdown()[source]#

Cancel any in-flight MDA on the Micro-Manager backend.

info()[source]#

Return the verbose multi-line description (module path, MRO, properties).

Return type:

str

class mesofield.devices.cameras.OpenCVCamera[source]#

Bases: BaseCamera, QThread

Background-thread OpenCV camera capturing to MP4.

Emits via self.signals (a mesofield.signals.DeviceSignals):
  • signals.started / signals.finished for lifecycle.

  • signals.data(idx, device_ts) per frame, consumed by DataManager.register_hardware_device().

Plus Qt live-preview signals (GUI-only, decoupled from DataQueue):
  • frame_ready(np.ndarray) / image_ready(np.ndarray).

Inherits the common camera surface (identity, output paths, manifest metadata, arm/set_sequence defaults) from BaseCamera, and runs its own capture loop on top of QThread.

__init__(cfg)[source]#
Parameters:

cfg (Dict[str, Any])

initialize()[source]#

Verify the camera can be opened. Returns immediately afterwards.

Return type:

bool

set_writer(make_path)[source]#

Resolve the output path and build the CV2Writer.

BaseCamera.set_writer resolves output_path, constructs the CV2Writer (the project’s shared MP4 writer), and copies its sidecar path onto metadata_path. The capture loop drives the writer directly via begin/add_frame/finish.

Parameters:

make_path (Callable[[str, str, str, bool], str])

Return type:

None

start()[source]#

Spawn the capture thread and begin writing frames to MP4.

Returns:

True if the thread started, False if it was already running.

Return type:

bool

stop()[source]#

Signal the capture thread to stop and wait for it to join.

Return type:

bool

shutdown()[source]#

Tear down the capture thread.

stop() joins the capture thread; its run() finally-block releases the CV2Writer and writes the sidecar JSON.

Return type:

None

snap()[source]#

Open the camera, read one frame, return it without recording.

Return type:

ndarray

start_live()[source]#

Start the capture thread WITHOUT a writer (preview-only).

Return type:

None

stop_live()[source]#

End preview capture started by start_live.

Return type:

None

get_data()[source]#

Return the most recent frame index/timestamp pair, or None.

Return type:

Dict[str, Any] | None

save_data(path=None)[source]#

No-op: the MP4 and its _frame_metadata.json sidecar are written by the CV2Writer when the capture loop finishes.

Parameters:

path (str | None)

Return type:

None

run(self)[source]#
Return type:

None