From 1b2197555ff6e842423796254f9bf845402f1a57 Mon Sep 17 00:00:00 2001 From: Arin Wongprommoon <arin.wongprommoon@ed.ac.uk> Date: Thu, 12 Jan 2023 16:13:54 +0000 Subject: [PATCH] [WIP] feat(aliby): base image class lazy-loads dummy image WHY IS THIS CHANGE NEEDED?: - need function that creates the expected output from dummy image file, as an interface for other classes' get_data_lazy() methods HOW DOES THE CHANGE SOLVE THE PROBLEM?: - create abstract method that loads the dummy image file and returns 2d dask array - define function to get examples directory, following logfile_parser.legacy WHAT SIDE EFFECTS DOES THIS CHANGE HAVE?: - only able to handle one TIF file (i.e. 1 z-section) EVIDENCE THAT COMMIT WORKS: - created a test class that extends BaseLocalImage and has a get_data_lazy() function that extends the base class's function; it is able to load the dummy image into a dask array REFERENCES: - issue #53 --- src/aliby/io/image.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/aliby/io/image.py b/src/aliby/io/image.py index 3ff5e3d1..a2b1e6e1 100644 --- a/src/aliby/io/image.py +++ b/src/aliby/io/image.py @@ -1,8 +1,9 @@ #!/usr/bin/env python3 import typing as t -from abc import ABC, abstractproperty +from abc import ABC, abstractmethod, abstractproperty from datetime import datetime +from importlib_resources import files from pathlib import Path, PosixPath import dask.array as da @@ -13,6 +14,11 @@ from tifffile import TiffFile from agora.io.metadata import dir_to_meta +def get_examples_dir(): + """Get examples directory which stores dummy image for tiler""" + return files("aliby").parent.parent / "examples" / "tiler" + + 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. @@ -68,6 +74,21 @@ class BaseLocalImage(ABC): ) return self._rechunked_img + @abstractmethod + def get_data_lazy(self) -> da.Array: + """Return 5D dask array. For lazy-loading multidimensional tiff files. Dummy image.""" + examples_dir = get_examples_dir() + # TODO: Make this robust to having multiple TIFF images, one for each z-section, + # all falling under the same "pypipeline_unit_test_00_000001_Brightfield_*.tif" + # naming scheme. The aim is to create a multidimensional dask array that stores + # the z-stacks. + img_filename = "pypipeline_unit_test_00_000001_Brightfield_003.tif" + img_path = examples_dir / img_filename + # img has two dimensions: x, y + # This line assumes that the image being imported is of shape (1, *, *). + img = imread(str(img_path))[0] + return img + @abstractproperty def name(self): pass -- GitLab