Skip to content
Snippets Groups Projects
Commit 1b219755 authored by Arin Wongprommoon's avatar Arin Wongprommoon
Browse files

[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
parent 0ce72d00
No related branches found
No related tags found
No related merge requests found
#!/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
......
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