linumpy.cli.args#

Common argument-parsing helpers for linumpy CLI scripts.

Attributes#

Functions#

get_available_cpus()

Get the number of available CPUs, respecting environment variables.

parse_processes_arg(n_processes)

Parse the n_processes argument, respecting system limits.

add_processes_arg(parser)

Add the --n_processes argument to parser.

add_overwrite_arg(parser)

Add the -f / --overwrite flag to parser.

assert_output_exists(output, parser, args)

Error out if output already exists and overwrite flag is not set.

add_verbose_arg(parser)

Add the -v / --verbose argument to parser.

detect_shift_units(resolution)

Detect whether OME-Zarr resolution is in mm or µm, return (res_x_um, res_y_um).

Module Contents#

linumpy.cli.args.get_available_cpus()[source]#

Get the number of available CPUs, respecting environment variables.

Checks in order: 1. LINUMPY_MAX_CPUS - maximum CPUs to use (explicit limit) 2. LINUMPY_RESERVED_CPUS - CPUs to reserve for overhead (default: 0)

Returns:

int

Return type:

Number of available CPUs

linumpy.cli.args.DEFAULT_N_CPUS[source]#
linumpy.cli.args.parse_processes_arg(n_processes)[source]#

Parse the n_processes argument, respecting system limits.

Parameters:

n_processes (int | None) – Number of processes requested. If None or <= 0, uses the default (get_available_cpus()).

Returns:

int

Return type:

Number of processes to use

linumpy.cli.args.add_processes_arg(parser)[source]#

Add the --n_processes argument to parser.

Parameters:

parser (argparse.ArgumentParser | argparse._ActionsContainer)

Return type:

argparse.Action

linumpy.cli.args.add_overwrite_arg(parser)[source]#

Add the -f / --overwrite flag to parser.

Parameters:

parser (argparse.ArgumentParser)

Return type:

None

linumpy.cli.args.assert_output_exists(output, parser, args)[source]#

Error out if output already exists and overwrite flag is not set.

Parameters:
Return type:

None

linumpy.cli.args.add_verbose_arg(parser)[source]#

Add the -v / --verbose argument to parser.

Parameters:

parser (argparse.ArgumentParser)

Return type:

None

linumpy.cli.args.detect_shift_units(resolution)[source]#

Detect whether OME-Zarr resolution is in mm or µm, return (res_x_um, res_y_um).

OME-Zarr resolution can be in mm (OME-NGFF standard) or µm depending on the writer. Detects by magnitude: values < 1.0 are assumed mm, >= 1.0 are assumed µm.

Parameters:

resolution (sequence) – Resolution tuple from read_omezarr (res_z, res_y, res_x).

Returns:

res_x_um, res_y_um – XY resolution in microns per pixel.

Return type:

float