> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bioptimus.com/llms.txt
> Use this file to discover all available pages before exploring further.

# bioptimus.io.outputs

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`](https://docs.bioptimus.com/sdk-reference/io/outputs#open_output_store) opens any of the three as a dict-like store; on top of it, [`load_output`](https://docs.bioptimus.com/sdk-reference/io/outputs#load_output) reads the full set of arrays into a plain dict (the shape tutorials and the visualizing-results guide expect).

## LabeledArray

```python theme={null}
class LabeledArray(NamedTuple)
```

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

## OutputFormat

```python theme={null}
class OutputFormat(str, enum.Enum)
```

Supported on-disk formats for prediction output.

## OnConflict

```python theme={null}
class OnConflict(str, enum.Enum)
```

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

```python theme={null}
def infer_output_format(path: Path) -> OutputFormat
```

Infers the on-disk format from a tile-output path's extension.

**path**

Path to a written tile-output file.

**Returns**:

The matching [`OutputFormat`](https://docs.bioptimus.com/sdk-reference/io/outputs#outputformat).

**Raises**:

* `BioptimusValueError` - If the extension does not match a known format, tagged `BIO-CFG-001`.

***

#### open\_output\_store

```python theme={null}
@contextlib.contextmanager
def open_output_store(
        path: str | Path,
        output_format: OutputFormat | None = None) -> Iterator[Any]
```

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**

Path to the written tile-output file.

**output\_format**

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

```python theme={null}
def load_output_gene_names(
        path: str | Path,
        output_format: OutputFormat | None = None) -> list[str] | None
```

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**

Path to the written tile-output file.

**output\_format**

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

```python theme={null}
def load_output_width(path: str | Path,
                      output_format: OutputFormat | None = None) -> int
```

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**

Path to the written tile-output file.

**output\_format**

The on-disk format. Inferred from the extension when omitted.

**Returns**:

The number of columns `G` in the `outputs` matrix.

***

#### load\_output\_tile\_count

```python theme={null}
def load_output_tile_count(path: str | Path,
                           output_format: OutputFormat | None = None) -> int
```

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**

Path to the written tile-output file.

**output\_format**

The on-disk format. Inferred from the extension when omitted.

**Returns**:

The number of tiles `N` (rows of the `outputs` matrix).

***

#### load\_output\_columns

```python theme={null}
def load_output_columns(
        path: str | Path,
        column_indices: np.ndarray,
        output_format: OutputFormat | None = None) -> np.ndarray
```

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**

Path to the written tile-output file.

**column\_indices**

The column indices to read, in the desired output order.

**output\_format**

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

```python theme={null}
def load_output(path: str | Path) -> dict[str, Any]
```

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**

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](https://docs.bioptimus.com/guides/get-started/visualizing-results.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.