Skip to content

Convert image to ND2 format

Functions for converting images are not part of the base limnd2 namespace, but are instead accessible through the limnd2.tools namespace.

In order to use functions and classes described on this page, import them like this:

from limnd2.tools import convert_file_to_nd2,\
    convert_file_to_nd2_args, convert_file_to_nd2_cli

Summary

Function documentation

convert_file_to_nd2

convert_file_to_nd2(input_path: str | Path | LimImageSource, output_path: str | Path, extra_dim_type: str = 'multipoint')

Converts an input file or LimImageSource to ND2 format and writes it to the specified output path. You can specify the extra dimension type for parsing, such as "multipoint", "timeloop", or "zstack", this is useful for multipage TIFF files.

PARAMETER DESCRIPTION
input_path

Path to the input file or a LimImageSource object to be converted.

TYPE: str | Path | LimImageSource

output_path

Path where the resulting ND2 file will be saved, if not provided, the input file name will be used with .nd2 extension.

TYPE: str | Path

extra_dim_type

Type of extra dimension to parse, for example with multipage TIFF file, must be one of ["multipoint", "timeloop", "zstack"]. (default is "multipoint").

TYPE: str DEFAULT: 'multipoint'

RETURNS DESCRIPTION
Path

Path to the written ND2 file.

RAISES DESCRIPTION
ValueError

If the input_path is not a valid file path or LimImageSource object.

Examples:

>>> convert_file_to_nd2("input.jpeg", Path("output.nd2"))
>>> convert_file_to_nd2("image.png", "converted_output.nd2", extra_dim_type="timeloop")

convert_file_to_nd2_cli

convert_file_to_nd2_cli(args: list[str] | None = None)

Converts a file to ND2 format using command line arguments for usage in CLI (returns exit code).

Command line arguments should be provided as a list of strings. The specific arguments and their usage are described in the CLI version of this tool: CLI Convert image tool

PARAMETER DESCRIPTION
args

List of command line arguments. If None, uses sys.argv.

TYPE: list[str] | None DEFAULT: None

RETURNS DESCRIPTION
None

Exits the program with exit code 0 if successful, or 1 if an error occurred.

convert_file_to_nd2_args

convert_file_to_nd2_args(args: list[str] | None = None)

Converts a file to ND2 format using command line arguments for usage in Python (returns the output path).

Command line arguments should be provided as a list of strings. The specific arguments and their usage are described in the CLI version of this tool: CLI Convert image tool

PARAMETER DESCRIPTION
args

List of command line arguments. If None, uses sys.argv.

TYPE: list[str] | None DEFAULT: None

RETURNS DESCRIPTION
Path

Path to the converted ND2 file.