Skip to content
Snippets Groups Projects
Commit 13ed9a59 authored by Alán Muñoz's avatar Alán Muñoz
Browse files

refactor(dataset): create dispatch function

parent 9f00221f
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,30 @@ from aliby.io.image import ImageLocalOME ...@@ -20,6 +20,30 @@ from aliby.io.image import ImageLocalOME
from aliby.io.omero import BridgeOmero from aliby.io.omero import BridgeOmero
def dispatch_dataset(expt_id: int or str, **kwargs):
"""
Choose a subtype of dataset based on the identifier.
Input:
--------
expt_id: int or string serving as dataset identifier.
Returns:
--------
Callable Dataset instance, either network-dependent or local.
"""
if isinstance(expt_id, int): # Is an experiment online
return Dataset(x, **kwargs["general"].get("server_info"))
elif isinstance(expt_id, str): # Files or Dir
expt_path = Path(expt_id)
if expt_path.is_dir():
return DatasetLocalDir(expt_path)
else:
return DatasetLocalOME(expt_path)
else:
raise Warning("Invalid expt_id")
class DatasetLocalABC(ABC): class DatasetLocalABC(ABC):
""" """
Abstract Base class to fetch local files, either OME-XML or raw images. Abstract Base class to fetch local files, either OME-XML or raw images.
...@@ -74,7 +98,7 @@ class DatasetLocalABC(ABC): ...@@ -74,7 +98,7 @@ class DatasetLocalABC(ABC):
@abstractmethod @abstractmethod
def get_images(self): def get_images(self):
# Return location of images and their unique names # Return a dictionary with the name of images and their unique identifiers
pass pass
...@@ -95,15 +119,15 @@ class DatasetLocalDir(DatasetLocalABC): ...@@ -95,15 +119,15 @@ class DatasetLocalDir(DatasetLocalABC):
) )
def get_images(self): def get_images(self):
return [ return {
folder folder.name: folder
for folder in self.path.glob("*/") for folder in self.path.glob("*/")
if any( if any(
path path
for suffix in self._valid_meta_suffixes for suffix in self._valid_suffixes
for path in folder.glob(f"*.{suffix}") for path in folder.glob(f"*.{suffix}")
) )
] }
class DatasetLocalOME(DatasetLocalABC): class DatasetLocalOME(DatasetLocalABC):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment