Skip to main content
Format-aware readers for written tile-output files. The tile-output writers in bioptimus.inference.writers persist per-tile predictions to disk in one of three interchangeable containers — Zarr, HDF5, or NPZ — using the same key names, which are defined once by OutputSchema and read back through it here. This module provides the single format-aware read side shared by the aggregation helpers (bioptimus.inference.aggregate) and the cohort gene-set selection (bioptimus.data.cohort.Cohort.select_genes), so neither has to know how each container is opened. open_output_store opens any of the three as a dict-like store; on top of it, load_output reads the full set of arrays into a plain dict (the shape tutorials and the visualizing-results guide expect).

LabeledArray

A per-tile array paired with its column labels (one label per column).

OutputFormat

Supported on-disk formats for prediction output.

OnConflict

Policy for writing a per-tile array that already exists in a store. MERGE (the default) combines columns by label — new labels are appended and same-named labels are replaced, keeping the rest. OVERWRITE replaces the whole array (and its labels) with the new one. ERROR raises if the array is already present.

infer_output_format

Infers the on-disk format from a tile-output path’s extension.
Path to a written tile-output file.
Returns: The matching OutputFormat. Raises:
  • BioptimusValueError - If the extension does not match a known format, tagged BIO-CFG-001.

open_output_store

Opens a written tile-output file as a dict-like store. Dispatches on the on-disk format and yields a store that supports in and [] uniformly across a numpy NpzFile, a Zarr group, and an h5py file, so callers read the same keys regardless of container.
Path to the written tile-output file.
The on-disk format. Inferred from the extension when omitted.
Returns: A context manager yielding a dict-like store for the file’s arrays; it supports in and [] uniformly across the three containers. Raises:
  • BioptimusValueError - If the extension does not match a known format, tagged BIO-CFG-001.

load_output_gene_names

Reads only the output gene-name panel from a tile-output file. Reads the output_gene_names array without materializing the (potentially large) outputs matrix, so a caller can resolve gene indices before deciding which columns to load. Zarr/HDF5 read the names lazily; NPZ still decompresses the names array (but not outputs).
Path to the written tile-output file.
The on-disk format. Inferred from the extension when omitted.
Returns: The gene names in panel order, or None when the file has no panel (for example an embedding store).

load_output_width

Reads the number of columns of the outputs matrix without loading it. Zarr/HDF5 expose the array shape lazily, so the width is read from metadata without materializing the (N_tiles, G) matrix. Lets a caller validate the stored panel width against the gene-name panel before slicing columns.
Path to the written tile-output file.
The on-disk format. Inferred from the extension when omitted.
Returns: The number of columns G in the outputs matrix.

load_output_tile_count

Reads the number of tiles (rows of outputs) without loading it. Zarr/HDF5 expose the array shape lazily, so the tile count is read from metadata without materializing the (N_tiles, G) matrix. Lets a caller validate that a per-tile array is row-aligned with the store before writing.
Path to the written tile-output file.
The on-disk format. Inferred from the extension when omitted.
Returns: The number of tiles N (rows of the outputs matrix).

load_output_columns

Reads only the given columns of the outputs matrix into memory. For Zarr and HDF5, the store slices the requested columns on read, so the full (N_tiles, G) panel is never materialized — only (N_tiles, k) for the k requested genes. NPZ has no lazy column access, so it decompresses the full array and then slices (still correct, just not memory-saving).
Path to the written tile-output file.
The column indices to read, in the desired output order.
The on-disk format. Inferred from the extension when omitted.
Returns: An (N_tiles, len(column_indices)) float32 array of the selected columns, in the order given by column_indices.

load_output

Loads a written tile-output file into a dictionary. Reads a tile-output file written by bioptimus.inference.writers in any supported format (Zarr, HDF5, or NPZ) fully into memory.
Path to the written tile-output file.
Returns: A dict with keys outputs, coords, metadata, and optionally gene_names (M-Optimus predictions), input_gene_names, thumbnail, tissue_mask, and tissue_ratios. See https://docs.bioptimus.com/guides/get-started/visualizing-results