-
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
81 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,43 @@ | ||
from importlib.metadata import PackageNotFoundError, version | ||
|
||
import zarr | ||
|
||
import ome_zarr_models.v04.hcs | ||
import ome_zarr_models.v04.image | ||
import ome_zarr_models.v04.image_label | ||
import ome_zarr_models.v04.labels | ||
import ome_zarr_models.v04.well | ||
from ome_zarr_models.base import BaseGroup | ||
from ome_zarr_models.v04.base import BaseGroupv04 | ||
|
||
try: | ||
__version__ = version("ome_zarr_models") | ||
except PackageNotFoundError: # pragma: no cover | ||
__version__ = "uninstalled" | ||
|
||
|
||
_V04_groups: list[type[BaseGroupv04]] = [ | ||
ome_zarr_models.v04.hcs.HCS, | ||
ome_zarr_models.v04.image_label.ImageLabel, | ||
ome_zarr_models.v04.image.Image, | ||
ome_zarr_models.v04.labels.Labels, | ||
ome_zarr_models.v04.well.Well, | ||
] | ||
|
||
|
||
def load_ome_zarr_group(group: zarr.Group) -> BaseGroup: | ||
""" | ||
Create an ome-zarr-models object from an existing OME-Zarr group. | ||
This function will 'guess' which type of OME-Zarr data exists by | ||
trying to validate each group metadata definition against your data. | ||
If validation is successful, that data class is returned without | ||
trying any more. | ||
""" | ||
for group_cls in _V04_groups: | ||
try: | ||
return group_cls.from_zarr(group) | ||
except Exception: | ||
continue | ||
|
||
raise RuntimeError(f"Could not find any matches for group {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
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 typing import Literal | ||
|
||
from ome_zarr_models.base import BaseGroup | ||
|
||
|
||
class BaseGroupv04(BaseGroup): | ||
""" | ||
Base class for all v0.4 OME-Zarr groups. | ||
""" | ||
|
||
@property | ||
def ome_zarr_version(self) -> Literal["0.4"]: | ||
""" | ||
OME-Zarr version. | ||
""" | ||
return "0.4" | ||
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
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
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