Skip to content

get_func

Module to get write functions.

WriteFunc #

Bases: Protocol

Protocol for type hinting write functions.

Source code in src/careamics/file_io/write/get_func.py
class WriteFunc(Protocol):
    """Protocol for type hinting write functions."""

    def __call__(self, file_path: Path, img: NDArray, *args, **kwargs) -> None:
        """
        Type hinted callables must match this function signature (not including self).

        Parameters
        ----------
        file_path : pathlib.Path
            Path to file.
        img : numpy.ndarray
            Image data to save.
        *args
            Other positional arguments.
        **kwargs
            Other keyword arguments.
        """

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

Type hinted callables must match this function signature (not including self).

Parameters:

Name Type Description Default
file_path Path

Path to file.

required
img ndarray

Image data to save.

required
*args

Other positional arguments.

()
**kwargs

Other keyword arguments.

{}
Source code in src/careamics/file_io/write/get_func.py
def __call__(self, file_path: Path, img: NDArray, *args, **kwargs) -> None:
    """
    Type hinted callables must match this function signature (not including self).

    Parameters
    ----------
    file_path : pathlib.Path
        Path to file.
    img : numpy.ndarray
        Image data to save.
    *args
        Other positional arguments.
    **kwargs
        Other keyword arguments.
    """

get_write_func(data_type) #

Get the write function for the data type.

Parameters:

Name Type Description Default
data_type (tiff, custom)

Data type.

"tiff"

Returns:

Type Description
callable

Write function.

Source code in src/careamics/file_io/write/get_func.py
def get_write_func(data_type: SupportedWriteType) -> WriteFunc:
    """
    Get the write function for the data type.

    Parameters
    ----------
    data_type : {"tiff", "custom"}
        Data type.

    Returns
    -------
    callable
        Write function.
    """
    # error raised here if not supported
    data_type_ = SupportedData(data_type)  # new variable for mypy
    # error if no write func.
    if data_type_ not in WRITE_FUNCS:
        raise NotImplementedError(f"No write function for data type '{data_type}'.")

    return WRITE_FUNCS[data_type_]