-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from typing import Literal | ||
|
||
from pydantic_zarr.v2 import ArraySpec, GroupSpec | ||
|
||
from ome_zarr_models.base import BaseAttrs, BaseGroup | ||
|
||
|
||
class BaseOMEAttrs(BaseAttrs): | ||
""" | ||
Base class for all OME attributes. | ||
""" | ||
|
||
version: Literal["0.5"] = "0.5" | ||
ome: BaseAttrs | ||
|
||
|
||
class BaseGroupv05(GroupSpec[BaseOMEAttrs, ArraySpec | GroupSpec], BaseGroup): # type: ignore[misc] | ||
""" | ||
Base class for all v0.5 OME-Zarr groups. | ||
""" | ||
|
||
@property | ||
def ome_zarr_version(self) -> Literal["0.5"]: | ||
""" | ||
OME-Zarr version. | ||
""" | ||
return "0.5" | ||
|
||
@property | ||
def ome_attributes(self) -> BaseAttrs: | ||
""" | ||
OME-Zarr attributes. | ||
""" | ||
return self.attributes.ome # type: ignore[no-any-return] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from pydantic_zarr.v2 import ArraySpec, GroupSpec | ||
|
||
from ome_zarr_models.v04.labels import LabelsAttrs | ||
from ome_zarr_models.v05.base import BaseGroupv05, BaseOMEAttrs | ||
|
||
__all__ = ["Labels", "LabelsAttrs"] | ||
|
||
|
||
class OMELabelsAttrs(BaseOMEAttrs): | ||
ome: LabelsAttrs | ||
|
||
|
||
class Labels(GroupSpec[OMELabelsAttrs, ArraySpec | GroupSpec], BaseGroupv05): # type: ignore[misc] | ||
""" | ||
An OME-Zarr labels dataset. | ||
""" |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import json | ||
from pathlib import Path | ||
from typing import TypeVar | ||
|
||
import zarr | ||
|
||
from ome_zarr_models.base import BaseAttrs | ||
|
||
T = TypeVar("T", bound=BaseAttrs) | ||
|
||
|
||
def json_to_zarr_group(*, json_fname: str) -> zarr.Group: | ||
""" | ||
Create an empty Zarr group, and set attributes from a JSON file. | ||
""" | ||
group = zarr.open_group(store=zarr.MemoryStore()) | ||
with open(Path(__file__).parent / "data" / json_fname) as f: | ||
attrs = json.load(f) | ||
|
||
group.attrs.put(attrs) | ||
return group |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"ome": { | ||
"version": "0.5", | ||
"labels": ["cell_space_segmentation"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from ome_zarr_models.v04.labels import LabelsAttrs | ||
from ome_zarr_models.v05.labels import Labels, OMELabelsAttrs | ||
from tests.v05.conftest import json_to_zarr_group | ||
|
||
|
||
def test_labels() -> None: | ||
zarr_group = json_to_zarr_group(json_fname="labels_example.json") | ||
ome_group = Labels.from_zarr(zarr_group) | ||
assert ome_group.ome_attributes == LabelsAttrs( | ||
labels=["cell_space_segmentation"], version="0.5" | ||
) |