From 7b0a239b9f17cbd416063863c82ca52ade00a02e Mon Sep 17 00:00:00 2001 From: jmoore Date: Tue, 20 Oct 2020 14:37:10 +0200 Subject: [PATCH 1/2] HCS: add Plate spec --- ome_zarr/reader.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ome_zarr/reader.py b/ome_zarr/reader.py index 2cd93a7b..1261eae5 100644 --- a/ome_zarr/reader.py +++ b/ome_zarr/reader.py @@ -2,6 +2,7 @@ import logging from abc import ABC +from string import ascii_uppercase from typing import Any, Dict, Iterator, List, Optional, Type, Union, cast import dask.array as da @@ -48,6 +49,8 @@ def __init__( self.specs.append(Multiscales(self)) if OMERO.matches(zarr): self.specs.append(OMERO(self)) + if Plate.matches(zarr): + self.specs.append(Plate(self)) @property def visible(self) -> bool: @@ -336,6 +339,34 @@ def __init__(self, node: Node) -> None: LOGGER.error(f"failed to parse metadata: {e}") +class Plate(Spec): + @staticmethod + def matches(zarr: BaseZarrLocation) -> bool: + return bool("plate" in zarr.root_attrs) + + def __init__(self, node: Node) -> None: + super().__init__(node) + # TODO: start checking metadata version + self.plate_data = self.lookup("plate", {}) + self.rows = self.plate_data.get("rows", 0) + self.cols = self.plate_data.get("columns", 0) + + # FIXME: shouldn't hard code + self.acquisitions = ["PlateAcquisition Name 0"] + self.fields = ["Field_1"] + self.row_labels = ascii_uppercase[0 : self.rows] + self.col_labels = range(1, self.cols + 1) + + for acq in self.acquisitions: + for row in self.row_labels: + for col in self.col_labels: + for field in self.fields: + path = f"{acq}/{row}/{col}/{field}" + child_zarr = self.zarr.create(path) + if child_zarr.exists(): + node.add(child_zarr, visibility=True) + + class Reader: """Parses the given Zarr instance into a collection of Nodes properly ordered depending on context. From c9f4901ff42519910c6e87ebd25d715bedad6547 Mon Sep 17 00:00:00 2001 From: jmoore Date: Wed, 21 Oct 2020 09:22:51 +0200 Subject: [PATCH 2/2] HCS: only first field is visible --- ome_zarr/reader.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ome_zarr/reader.py b/ome_zarr/reader.py index 1261eae5..32df81e6 100644 --- a/ome_zarr/reader.py +++ b/ome_zarr/reader.py @@ -353,10 +353,11 @@ def __init__(self, node: Node) -> None: # FIXME: shouldn't hard code self.acquisitions = ["PlateAcquisition Name 0"] - self.fields = ["Field_1"] + self.fields = ["Field_1", "Field_2", "Field_3", "Field_4"] self.row_labels = ascii_uppercase[0 : self.rows] self.col_labels = range(1, self.cols + 1) + visibility = True for acq in self.acquisitions: for row in self.row_labels: for col in self.col_labels: @@ -364,7 +365,8 @@ def __init__(self, node: Node) -> None: path = f"{acq}/{row}/{col}/{field}" child_zarr = self.zarr.create(path) if child_zarr.exists(): - node.add(child_zarr, visibility=True) + node.add(child_zarr, visibility=visibility) + visibility = False class Reader: