Skip to main content
Streaming writers for persisting tile-level predictions. Provides a PredictionWriter protocol and three concrete implementations (ZarrWriter, HDF5Writer, NPZWriter) that save per-tile outputs and metadata to disk in a memory-efficient way. Zarr and HDF5 writers stream results row-by-row so that the full output tensor never needs to reside in memory. The NPZ writer accumulates results in Python lists and flushes on close.

OutputFormat

Supported on-disk formats for prediction output.

PredictionWriter

Abstract base for streaming prediction writers.

open

Pre-allocates storage once the embedding dim is known.
int
required
Total number of tiles to be written.
int
required
Dimensionality of each prediction vector.

write

Writes a single tile’s model response.
ModelResponse
required
The model response to persist.

set_thumbnail

Stores a slide thumbnail image.
NDArray
required
RGB image array of shape (H, W, 3).

set_metadata

Stores slide-level metadata alongside the arrays.
dict[str, Any]
required
Key-value pairs (slide_name, tile_size, etc.).

set_tissue_mask

Stores the tissue mask used during extraction.
NDArray
required
Binary mask array of shape (H, W), dtype uint8.

set_gene_names

Stores input and output gene name lists. Default implementation is a no-op. Subclasses that support gene annotation should override this.
list[str] | None
Ordered Ensembl IDs for bulk RNA input.
list[str] | None
Ordered Ensembl IDs for predicted output.

close

Flushes and finalises the output file.

ZarrWriter

Streams tile predictions into a Zarr directory store.

open

Pre-allocates Zarr datasets for outputs, coordinates, and tissue ratios.
int
required
Total number of tiles to be written.
int
required
Dimensionality of each prediction vector.

write

Writes a single tile response into the Zarr datasets.
ModelResponse
required
The model response to persist.

set_thumbnail

Stores a slide thumbnail as a Zarr dataset.
NDArray
required
RGB image array of shape (H, W, 3).

set_metadata

Stores metadata as Zarr root attributes.
dict[str, Any]
required
Key-value pairs (slide_name, tile_size, etc.).

set_tissue_mask

Stores the tissue mask as a Zarr dataset.
NDArray
required
Binary mask array of shape (H, W), dtype uint8.

set_gene_names

Stores gene name arrays as Zarr string datasets.
list[str] | None
Ordered Ensembl IDs for bulk RNA input.
list[str] | None
Ordered Ensembl IDs for predicted output.

close

Logs output path (Zarr stores are flushed on write).

HDF5Writer

Streams tile predictions into an HDF5 file.

open

Opens the HDF5 file and pre-allocates datasets.
int
required
Total number of tiles to be written.
int
required
Dimensionality of each prediction vector.

write

Writes a single tile response into the HDF5 datasets.
ModelResponse
required
The model response to persist.

set_thumbnail

Stores a slide thumbnail as an HDF5 dataset.
NDArray
required
RGB image array of shape (H, W, 3).

set_metadata

Stores metadata as HDF5 file-level attributes.
dict[str, Any]
required
Key-value pairs (slide_name, tile_size, etc.).

set_tissue_mask

Stores the tissue mask as an HDF5 dataset.
NDArray
required
Binary mask array of shape (H, W), dtype uint8.

set_gene_names

Stores gene name arrays as HDF5 string datasets.
list[str] | None
Ordered Ensembl IDs for bulk RNA input.
list[str] | None
Ordered Ensembl IDs for predicted output.

close

Closes the HDF5 file handle and flushes to disk.

NPZWriter

Accumulates tile predictions in memory, saves as compressed npz.

open

Allocates in-memory arrays for accumulating results.
int
required
Total number of tiles to be written.
int
required
Dimensionality of each prediction vector.

write

Writes a single tile response into the in-memory arrays.
ModelResponse
required
The model response to persist.

set_thumbnail

Stores the slide thumbnail for later NPZ serialization.
NDArray
required
RGB image array of shape (H, W, 3).

set_metadata

Stores metadata for later NPZ serialization.
dict[str, Any]
required
Key-value pairs (slide_name, tile_size, etc.).

set_tissue_mask

Stores the tissue mask for later NPZ serialization.
NDArray
required
Binary mask array of shape (H, W), dtype uint8.

set_gene_names

Stores gene name lists for later NPZ serialization.
list[str] | None
Ordered Ensembl IDs for bulk RNA input.
list[str] | None
Ordered Ensembl IDs for predicted output.

close

Flushes all accumulated arrays to a compressed .npz file.

create_writer

Creates a writer for the requested format.
OutputFormat
required
Output format.
Path
required
Destination file or directory path.
PredictionWriter
An initialised (but not yet opened) PredictionWriter.