Skip to content

Commit

Permalink
Merge pull request #195 from will-moore/plate_pyramids_and_version
Browse files Browse the repository at this point in the history
Plate pyramids and version
  • Loading branch information
sbesson authored May 24, 2022
2 parents bb62c8a + d1b93bc commit 34f9aaf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 33 deletions.
21 changes: 13 additions & 8 deletions ome_zarr/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,21 @@ def init_store(self, path: str, mode: str = "r") -> FSStore:
def init_channels(self) -> None: # pragma: no cover
raise NotImplementedError()

def _get_multiscale_version(self, metadata: dict) -> Optional[str]:
def _get_metadata_version(self, metadata: dict) -> Optional[str]:
"""
Checks the metadata dict for a version
Returns the version of the first object found in the metadata,
checking for 'multiscales', 'plate', 'well' etc
"""
multiscales = metadata.get("multiscales", [])
if multiscales:
dataset = multiscales[0]
return dataset.get("version", None)
for name in ["plate", "well", "image-label"]:
obj = metadata.get(name, None)
if obj:
return obj.get("version", None)
return None

def __repr__(self) -> str:
Expand Down Expand Up @@ -117,8 +127,8 @@ def version(self) -> str:
return "0.1"

def matches(self, metadata: dict) -> bool:
version = self._get_multiscale_version(metadata)
LOGGER.debug(f"V01:{version} v. {self.version}")
version = self._get_metadata_version(metadata)
LOGGER.debug(f"{self.version} matches {version}?")
return version == self.version

def init_store(self, path: str, mode: str = "r") -> FSStore:
Expand Down Expand Up @@ -165,11 +175,6 @@ class FormatV02(FormatV01):
def version(self) -> str:
return "0.2"

def matches(self, metadata: dict) -> bool:
version = self._get_multiscale_version(metadata)
LOGGER.debug(f"{self.version} matches {version}?")
return version == self.version

def init_store(self, path: str, mode: str = "r") -> FSStore:
"""
Not ideal. Stores should remain hidden
Expand Down
2 changes: 2 additions & 0 deletions ome_zarr/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(
self, path: Union[Path, str], mode: str = "r", fmt: Format = CurrentFormat()
) -> None:

LOGGER.debug(f"ZarrLocation.__init__ path:{path}, fmt:{fmt.version}")
self.__fmt = fmt
self.__mode = mode
if isinstance(path, Path):
Expand All @@ -47,6 +48,7 @@ def __init__(

self.__init_metadata()
detected = detect_format(self.__metadata, loader)
LOGGER.debug(f"ZarrLocation.__init__ {path} detected:{detected}")
if detected != fmt:
LOGGER.warning(f"version mismatch: detected:{detected}, requested:{fmt}")
self.__fmt = detected
Expand Down
28 changes: 3 additions & 25 deletions ome_zarr/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ def matches(zarr: ZarrLocation) -> bool:

def __init__(self, node: Node) -> None:
super().__init__(node)
LOGGER.debug(f"Plate created with ZarrLocation fmt:{ self.zarr.fmt}")
self.get_pyramid_lazy(node)

def get_pyramid_lazy(self, node: Node) -> None:
Expand Down Expand Up @@ -496,33 +497,10 @@ def get_pyramid_lazy(self, node: Node) -> None:
LOGGER.debug(f"img_pyramid_shapes: {well_spec.img_pyramid_shapes}")

self.axes = well_spec.img_metadata["axes"]
size_y = well_spec.img_shape[len(self.axes) - 2]
size_x = well_spec.img_shape[len(self.axes) - 1]

# FIXME - if only returning a single stiched plate (not a pyramid)
# need to decide optimal size. E.g. longest side < 1500
TARGET_SIZE = 1500
plate_width = self.column_count * size_x
plate_height = self.row_count * size_y
longest_side = max(plate_width, plate_height)
target_level = 0
for level, shape in enumerate(well_spec.img_pyramid_shapes):
plate_width = self.column_count * shape[-1]
plate_height = self.row_count * shape[-2]
longest_side = max(plate_width, plate_height)
target_level = level
if longest_side <= TARGET_SIZE:
break

LOGGER.debug(f"target_level: {target_level}")

# Create a dask pyramid for the plate
pyramid = []

# This should create a pyramid of levels, but causes seg faults!
# for level in range(5):
for level in [target_level]:

tile_shape = well_spec.img_pyramid_shapes[level]
for level, tile_shape in enumerate(well_spec.img_pyramid_shapes):
lazy_plate = self.get_stitched_grid(level, tile_shape)
pyramid.append(lazy_plate)

Expand Down

0 comments on commit 34f9aaf

Please sign in to comment.