-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
20d3f41
commit d94a773
Showing
9 changed files
with
215 additions
and
85 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,25 +1,66 @@ | ||
"""A module to handle OME-NGFF images stored in Zarr format.""" | ||
|
||
from ngio.core.image_like_handler import ImageLikeHandler | ||
from ngio.core.image_like_handler import ImageLike | ||
from ngio.io import StoreOrGroup | ||
from ngio.ngff_meta.fractal_image_meta import ImageMeta, PixelSize | ||
|
||
|
||
class ImageHandler(ImageLikeHandler): | ||
class Image(ImageLike): | ||
"""A class to handle OME-NGFF images stored in Zarr format. | ||
This class provides methods to access image data and ROI tables. | ||
""" | ||
|
||
@property | ||
def channel_names(self) -> list[str]: | ||
"""Return the names of the channels in the image.""" | ||
return self.metadata.channel_names | ||
def __init__( | ||
self, | ||
store: StoreOrGroup, | ||
*, | ||
path: str | None = None, | ||
idx: int | None = None, | ||
pixel_size: PixelSize | None = None, | ||
highest_resolution: bool = False, | ||
strict: bool = True, | ||
cache: bool = True, | ||
) -> None: | ||
"""Initialize the MultiscaleHandler in read mode. | ||
def get_channel_idx_by_label(self, label: str) -> int: | ||
"""Return the index of the channel with the given label.""" | ||
return self.metadata.get_channel_idx_by_label(label=label) | ||
Note: Only one of `path`, `idx`, 'pixel_size' or 'highest_resolution' | ||
should be provided. | ||
def get_channel_idx_by_wavelength_id(self, wavelength_id: int) -> int: | ||
"""Return the index of the channel with the given wavelength id.""" | ||
return self.metadata.get_channel_idx_by_wavelength_id( | ||
wavelength_id=wavelength_id | ||
store (StoreOrGroup): The Zarr store or group containing the image data. | ||
path (str | None): The path to the level. | ||
idx (int | None): The index of the level. | ||
pixel_size (PixelSize | None): The pixel size of the level. | ||
highest_resolution (bool): Whether to get the highest resolution level. | ||
strict (bool): Whether to raise an error where a pixel size is not found | ||
to match the requested "pixel_size". | ||
cache (bool): Whether to cache the metadata. | ||
""" | ||
super().__init__( | ||
store=store, | ||
path=path, | ||
idx=idx, | ||
pixel_size=pixel_size, | ||
highest_resolution=highest_resolution, | ||
strict=strict, | ||
meta_mode="image", | ||
cache=cache, | ||
) | ||
|
||
@property | ||
def metadata(self) -> ImageMeta: | ||
"""Return the metadata of the image.""" | ||
return super().metadata | ||
|
||
@property | ||
def channel_labels(self) -> list[str]: | ||
"""Return the names of the channels in the image.""" | ||
return self.metadata.channel_labels | ||
|
||
def get_channel_idx( | ||
self, | ||
label: str | None = None, | ||
wavelength_id: str | None = None, | ||
) -> int: | ||
"""Return the index of the channel.""" | ||
return self.metadata.get_channel_idx(label=label, wavelength_id=wavelength_id) |
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 |
---|---|---|
@@ -1,35 +1,78 @@ | ||
"""A module to handle OME-NGFF images stored in Zarr format.""" | ||
|
||
import zarr | ||
from zarr.store.common import StoreLike | ||
|
||
from ngio.core.image_like_handler import ImageLikeHandler | ||
from ngio.core.image_like_handler import ImageLike | ||
from ngio.io import StoreOrGroup | ||
from ngio.ngff_meta.fractal_image_meta import LabelMeta, PixelSize | ||
|
||
|
||
class LabelHandler(ImageLikeHandler): | ||
class Label(ImageLike): | ||
"""A class to handle OME-NGFF images stored in Zarr format. | ||
This class provides methods to access image data and ROI tables. | ||
""" | ||
|
||
pass | ||
def __init__( | ||
store: StoreOrGroup, | ||
*, | ||
path: str | None = None, | ||
idx: int | None = None, | ||
pixel_size: PixelSize | None = None, | ||
highest_resolution: bool = False, | ||
strict: bool = True, | ||
cache: bool = True, | ||
) -> None: | ||
"""Initialize the MultiscaleHandler in read mode. | ||
Note: Only one of `path`, `idx`, 'pixel_size' or 'highest_resolution' | ||
should be provided. | ||
class LabelGroupHandler: | ||
store (StoreOrGroup): The Zarr store or group containing the image data. | ||
path (str | None): The path to the level. | ||
idx (int | None): The index of the level. | ||
pixel_size (PixelSize | None): The pixel size of the level. | ||
highest_resolution (bool): Whether to get the highest resolution level. | ||
strict (bool): Whether to raise an error where a pixel size is not found | ||
to match the requested "pixel_size". | ||
cache (bool): Whether to cache the metadata. | ||
""" | ||
super().__init__( | ||
store, | ||
path=path, | ||
idx=idx, | ||
pixel_size=pixel_size, | ||
highest_resolution=highest_resolution, | ||
strict=strict, | ||
meta_mode="label", | ||
cache=cache, | ||
) | ||
|
||
def metadata(self) -> LabelMeta: | ||
"""Return the metadata of the image.""" | ||
return super().metadata | ||
|
||
|
||
class LabelGroup: | ||
"""A class to handle the /labels group in an OME-NGFF file.""" | ||
|
||
def __init__(self, group: zarr.Group, group_name: str = "labels") -> None: | ||
def __init__(self, group: StoreLike) -> None: | ||
"""Initialize the LabelGroupHandler.""" | ||
self._group = group | ||
|
||
@property | ||
def group_name(self) -> str: | ||
"""Return the name of the group.""" | ||
return "labels" | ||
|
||
def list(self) -> list[str]: | ||
"""List all labels in the group.""" | ||
return list(self._group.array_keys()) | ||
|
||
def get(self, name: str) -> LabelHandler: | ||
def get(self, name: str) -> Label: | ||
"""Get a label from the group.""" | ||
raise NotImplementedError("Not yet implemented.") | ||
|
||
def write(self, name: str, data: LabelHandler) -> None: | ||
def write(self, name: str, data: Label) -> None: | ||
"""Create a label in the group.""" | ||
raise NotImplementedError("Not yet implemented.") |
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 |
---|---|---|
@@ -1,6 +1,21 @@ | ||
"""IO and validation of NGFF metadata.""" | ||
|
||
from ngio.ngff_meta.fractal_image_meta import ImageMeta, PixelSize, SpaceUnits | ||
from ngio.ngff_meta.fractal_image_meta import ( | ||
Dataset, | ||
ImageLabelMeta, | ||
ImageMeta, | ||
LabelMeta, | ||
PixelSize, | ||
SpaceUnits, | ||
) | ||
from ngio.ngff_meta.meta_handler import get_ngff_image_meta_handler | ||
|
||
__all__ = ["get_ngff_image_meta_handler", "ImageMeta", "PixelSize", "SpaceUnits"] | ||
__all__ = [ | ||
"Dataset", | ||
"ImageMeta", | ||
"LabelMeta", | ||
"ImageLabelMeta", | ||
"PixelSize", | ||
"SpaceUnits", | ||
"get_ngff_image_meta_handler", | ||
] |
Oops, something went wrong.