data#

Acquisition-time data management.

Centralises three responsibilities:

  • manager orchestrates per-run data collection, notes, and timestamp writing.

  • writer defines the OME-TIFF (CustomWriter) and MP4 (CV2Writer) frame handlers.

  • batch provides batch / post-hoc utilities used by analysis scripts.

CustomWriter and CV2Writer are re-exported from this package so that from mesofield.data import CustomWriter continues to work in existing experiment scripts.

class mesofield.data.CustomWriter[source]#

Bases: OMETiffWriter

OME-TIFF writer extending pymmcore-plus’s OMETiffWriter.

Two divergences from the public base:

  • Uses bigtiff=True so multi-GiB mesoscope acquisitions write cleanly.

  • Emits the per-frame metadata JSON sidecar mesofield’s downstream parsers (and the AcquisitionManifest’s metadata_path) depend on.

Everything else – filename validation, frame writing, OME-XML sequence metadata, memmap handling – is inherited from OMETiffWriter.

__init__(filename)[source]#
Parameters:

filename (Path | str)

Return type:

None

new_array(position_key, dtype, sizes)[source]#

Mirror OMETiffWriter.new_array() but with bigtiff=True.

Upstream’s implementation hardcodes the imwrite call; we duplicate it here to flip the bigtiff flag. Keep the bodies in sync if a pymmcore-plus bump changes the upstream version.

Parameters:
Return type:

memmap

finalize_metadata()[source]#

Write the per-frame metadata sidecar.

Called by OMETiffWriter.sequenceFinished after the last frame. Serialises self.frame_metadatas (the dict pymmcore-plus accumulates for us in frameReady) to JSON at <filename>_frame_metadata.json.

Return type:

None

class mesofield.data.CV2Writer[source]#

Bases: OMETiffWriter

Write frames to an mp4/avi video using OpenCV.

Subclasses the public OMETiffWriter only to reuse its inherited MDA-signal handling (frameReady / sequenceStarted / sequenceFinished / store_frame_metadata and the frame_metadatas accumulation). Every TIFF-specific method (__init__ / new_array / write_frame / finalize_metadata) is overridden below to emit video instead, so none of OMETiffWriter’s tifffile machinery is ever reached.

Two usage modes share the same codec/fourcc/metadata logic:

  • MDA-driven (new_array / write_frame / finalize_metadata) when handed to CMMCorePlus.run_mda as an output handler.

  • Direct (begin / add_frame / finish) for cameras that run their own capture loop (e.g. OpenCVCamera).

__init__(filename, fps=30, fourcc='H264')[source]#
Parameters:
Return type:

None

new_array(position_key, dtype, sizes)[source]#

Create a new tifffile file and memmap for this position.

Parameters:
write_frame(ary, index, frame)[source]#

Write a frame to the file.

Parameters:
Return type:

None

finalize_metadata()[source]#

Called during sequenceFinished before clearing sequence metadata.

Subclasses may override this method to flush any accumulated frame metadata to disk at the end of the sequence.

Return type:

None

begin(width, height, is_color=True)[source]#

Open the underlying cv2.VideoWriter for a self-driven loop.

Parameters:
Return type:

None

add_frame(frame)[source]#

Write one frame to the direct-mode video (uint8 frames pass through).

Parameters:

frame (ndarray)

Return type:

None

finish(extra_metadata=None)[source]#

Release the direct-mode writer and write the metadata sidecar.

Parameters:

extra_metadata (dict | None)

Return type:

None

Submodules#