Skip to content

tiff

Write tiff function.

write_tiff(file_path, img, *args, **kwargs) #

Write tiff files.

Parameters:

Name Type Description Default
file_path Path

Path to file.

required
img ndarray

Image data to save.

required
*args

Positional arguments passed to tifffile.imwrite.

()
**kwargs

Keyword arguments passed to tifffile.imwrite.

{}

Raises:

Type Description
ValueError

When the file extension of file_path does not match the Unix shell-style pattern '.tif'.

Source code in src/careamics/file_io/write/tiff.py
def write_tiff(file_path: Path, img: NDArray, *args, **kwargs) -> None:
    # TODO: add link to tiffile docs for args kwrgs?
    """
    Write tiff files.

    Parameters
    ----------
    file_path : pathlib.Path
        Path to file.
    img : numpy.ndarray
        Image data to save.
    *args
        Positional arguments passed to `tifffile.imwrite`.
    **kwargs
        Keyword arguments passed to `tifffile.imwrite`.

    Raises
    ------
    ValueError
        When the file extension of `file_path` does not match the Unix shell-style
        pattern '*.tif*'.
    """
    if not fnmatch(
        file_path.suffix, SupportedData.get_extension_pattern(SupportedData.TIFF)
    ):
        raise ValueError(
            f"Unexpected extension '{file_path.suffix}' for save file type 'tiff'."
        )
    tifffile.imwrite(file_path, img, *args, **kwargs)