writer#
Custom OME.TIFF + MP4 writers for MDASequences.
CustomWriter extends pymmcore-plus’s public OMETiffWriter with two
additions:
bigtiff=Trueon the underlying tifffile call – mesoscope acquisitions routinely exceed the classic-TIFF 4 GiB ceiling.A per-frame
<filename>_frame_metadata.jsonsidecar emitted fromfinalize_metadata(), containing the same metadata pymmcore-plus accumulates internally. This is the legacymesofieldcontract every downstream parser already reads.
The sidecar JSON is the current source of truth for per-frame metadata. The
broader goal (tracked separately) is to push the same fields into the OME-XML
embedded in the TIFF itself so the JSON becomes supplementary and redundant;
see the TODO in OMETiffWriter._sequence_metadata() upstream.
CV2Writer subclasses the public OMETiffWriter purely to reuse its
inherited frameReady plumbing (the machinery that turns MMCamera/MDA signals
into new_array / write_frame / store_frame_metadata calls and
accumulates pymmcore-plus metadata). It overrides every TIFF-specific method to
emit MP4/AVI instead – there is no public MP4 handler in pymmcore-plus to
inherit from, and inheriting the public OMETiffWriter avoids depending on
pymmcore-plus’s private _5d_writer_base module.
- class mesofield.data.writer.CustomWriter[source]#
Bases:
OMETiffWriterOME-TIFF writer extending pymmcore-plus’s
OMETiffWriter.Two divergences from the public base:
Uses
bigtiff=Trueso 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.
- class mesofield.data.writer.CustomJSONEncoder[source]#
Bases:
JSONEncoder- default(object)[source]#
Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return super().default(o)
- mesofield.data.writer.configure_opencv_codec()[source]#
Configure environment so OpenCV can locate the bundled OpenH264 DLL.
Safe to call repeatedly. Silences OpenCV/FFMPEG logging and prepends the project’s
external/video-codecsdirectory to PATH / DLL search.- Return type:
None
- class mesofield.data.writer.CV2Writer[source]#
Bases:
OMETiffWriterWrite frames to an mp4/avi video using OpenCV.
Subclasses the public
OMETiffWriteronly to reuse its inherited MDA-signal handling (frameReady/sequenceStarted/sequenceFinished/store_frame_metadataand theframe_metadatasaccumulation). Every TIFF-specific method (__init__/new_array/write_frame/finalize_metadata) is overridden below to emit video instead, so none ofOMETiffWriter’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 toCMMCorePlus.run_mdaas an output handler.Direct (
begin/add_frame/finish) for cameras that run their own capture loop (e.g.OpenCVCamera).
- new_array(position_key, dtype, sizes)[source]#
Create a new tifffile file and memmap for this position.
- 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.VideoWriterfor a self-driven loop.