ngff_zarr.cli

Module Contents

Classes

_ReplacingTextIO

Text-stream proxy whose write never raises UnicodeEncodeError.

Functions

_build_console

Create a Rich Console resilient to legacy Windows encodings.

_apply_omero_metadata

Apply OMERO metadata to multiscales based on CLI arguments.

_series_output_target

Resolve the output store and display path for one series of a file.

_multiscales_to_ngff_zarr

_apply_cli_metadata_overrides

Apply user CLI metadata overrides (dims, scale, translation, units, name) to an NgffImage.

_parse_orientation_arg

Parse the CLI --orientation argument into an axes_orientations mapping.

_ngff_image_to_multiscales

main

API

class ngff_zarr.cli._ReplacingTextIO(stream)

Text-stream proxy whose write never raises UnicodeEncodeError.

A last resort for streams that cannot be reconfigured in place (for example an ipykernel OutStream, which has no reconfigure). Characters the underlying stream’s encoding cannot represent are replaced rather than raising, so Rich can render without crashing (see issue #37). All other stream behavior is delegated to the wrapped stream.

Initialization

write(text)
flush()
__getattr__(name)
ngff_zarr.cli._build_console() rich.console.Console

Create a Rich Console resilient to legacy Windows encodings.

In some Windows environments the standard output stream uses a legacy code page such as cp1252 – for example a Jupyter/IPython ! shell-out, or git-bash. Rich emits Unicode box-drawing and spinner glyphs that those code pages cannot encode, so the underlying str.encode raises UnicodeEncodeError and the CLI crashes before doing any work (see issue #37).

Reconfigure the stream to UTF-8 so the glyphs encode cleanly. If the stream cannot be reconfigured in place, bind the console to a proxy that replaces any un-encodable characters at write time, so rendering degrades gracefully instead of raising.

ngff_zarr.cli._apply_omero_metadata(live, args, multiscales)

Apply OMERO metadata to multiscales based on CLI arguments.

If –no-omero is specified, skip OMERO computation. If –omero-window is specified, use manual values. Otherwise, compute OMERO metadata from the image data.

ngff_zarr.cli._series_output_target(
args: argparse.Namespace,
output_store: ngff_zarr._zarr_types.StoreLike | None,
series_name: str,
series_index: int,
n_series: int,
) tuple[ngff_zarr._zarr_types.StoreLike | None, str | None]

Resolve the output store and display path for one series of a file.

Returns a (store, display_path) tuple.

With a single requested output path but several series in the source (every Aperio .svs whole-slide file has Baseline + Thumbnail + Label + Macro series, for example), the destination depends on the requested format:

  • For a single-file .ozx output, the primary (first) series is written to the exact requested path so the file the user asked for is actually created, and additional series are written alongside it as <base>_<series_name>.ozx (preserving the zip format). Previously the .ozx request was silently discarded and replaced with <base>_<series_name>.ome.zarr directories, so the requested .ozx never appeared.

  • For directory-style .zarr / .ome.zarr output, each series is written to its own <base>_<series_name>.ome.zarr directory, the long-standing documented behavior.

ngff_zarr.cli._multiscales_to_ngff_zarr(
live,
args,
output_store,
rich_dask_progress,
multiscales,
chunks_per_shard=None,
)
ngff_zarr.cli._apply_cli_metadata_overrides(ngff_image, args, live)

Apply user CLI metadata overrides (dims, scale, translation, units, name) to an NgffImage.

ngff_zarr.cli._parse_orientation_arg(values, live)

Parse the CLI --orientation argument into an axes_orientations mapping.

Accepts either a single preset name ("LPS"/"RAS") or an even number of ordered dim/value pairs, e.g. x right-to-left y anterior-to-posterior z inferior-to-superior.

ngff_zarr.cli._ngff_image_to_multiscales(
live,
ngff_image,
args,
progress,
rich_dask_progress,
subtitle,
method,
)
ngff_zarr.cli.main()