diff --git a/aliby/io/image.py b/aliby/io/image.py index 257f5f6b3d85bc7fc18f6e8cc6f1e8e11cbdbe0d..2f8878dece28eea2b52c730fe28ef3f5d935ed7c 100644 --- a/aliby/io/image.py +++ b/aliby/io/image.py @@ -1,17 +1,35 @@ #!/usr/bin/env python3 -from pathlib import Path +import typing as t from datetime import datetime - -import xmltodict -from tifffile import TiffFile +from pathlib import Path, PosixPath import dask.array as da +import xmltodict from dask.array.image import imread +from tifffile import TiffFile from aliby.io.omero import Argo, get_data_lazy +def get_image_class(source: t.Union[str, int, t.Dict[str, str], PosixPath]): + """ + Wrapper to pick the appropiate Image class depending on the source of data. + """ + if isinstance(source, int): + instatiator = Image + elif isinstance(source, dict) or ( + isinstance(source, (str, PosixPath)) and Path(source).is_dir() + ): + instatiator = ImageDirectory + elif isinstance(source, str) and Path(source).is_file(): + instatiator = ImageLocal + else: + raise ("Invalid data source at {}".format(source)) + + return instatiator + + class ImageLocal: def __init__(self, path: str, dimorder=None, *args, **kwargs): self.path = path