-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This code was merged into iohub, so until a new release is made and we can pin the version we have helper functions stored in ome_tmp
- Loading branch information
Showing
2 changed files
with
97 additions
and
36 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
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,92 @@ | ||
from typing import Literal | ||
|
||
import numpy as np | ||
from iohub.ngff import TransformationMeta | ||
|
||
|
||
def _get_all_transforms(node, image: str | Literal["*"]) -> list[TransformationMeta]: | ||
"""Get all transforms metadata | ||
for one image array or the whole FOV. | ||
Parameters | ||
---------- | ||
image : str | Literal["*"] | ||
Name of one image array (e.g. "0") to query, | ||
or "*" for the whole FOV | ||
Returns | ||
------- | ||
list[TransformationMeta] | ||
All transforms applicable to this image or FOV. | ||
""" | ||
transforms: list[TransformationMeta] = ( | ||
[t for t in node.metadata.multiscales[0].coordinate_transformations] | ||
if node.metadata.multiscales[0].coordinate_transformations is not None | ||
else [] | ||
) | ||
if image != "*" and image in node: | ||
for i, dataset_meta in enumerate(node.metadata.multiscales[0].datasets): | ||
if dataset_meta.path == image: | ||
transforms.extend( | ||
node.metadata.multiscales[0].datasets[i].coordinate_transformations | ||
) | ||
elif image != "*": | ||
raise ValueError(f"Key {image} not recognized.") | ||
return transforms | ||
|
||
|
||
def get_effective_scale( | ||
node, | ||
image: str | Literal["*"], | ||
) -> list[float]: | ||
"""Get the effective coordinate scale metadata | ||
for one image array or the whole FOV. | ||
Parameters | ||
---------- | ||
image : str | Literal["*"] | ||
Name of one image array (e.g. "0") to query, | ||
or "*" for the whole FOV | ||
Returns | ||
------- | ||
list[float] | ||
A list of floats representing the total scale | ||
for the image or FOV for each axis. | ||
""" | ||
transforms = node._get_all_transforms(image) | ||
|
||
full_scale = np.ones(len(node.axes), dtype=float) | ||
for transform in transforms: | ||
if transform.type == "scale": | ||
full_scale *= np.array(transform.scale) | ||
|
||
return [float(x) for x in full_scale] | ||
|
||
|
||
def get_effective_translation( | ||
node, | ||
image: str | Literal["*"], | ||
) -> TransformationMeta: | ||
"""Get the effective coordinate translation metadata | ||
for one image array or the whole FOV. | ||
Parameters | ||
---------- | ||
image : str | Literal["*"] | ||
Name of one image array (e.g. "0") to query, | ||
or "*" for the whole FOV | ||
Returns | ||
------- | ||
list[float] | ||
A list of floats representing the total translation | ||
for the image or FOV for each axis. | ||
""" | ||
transforms = node._get_all_transforms(image) | ||
full_translation = np.zeros(len(node.axes), dtype=float) | ||
for transform in transforms: | ||
if transform.type == "translation": | ||
full_translation += np.array(transform.translation) | ||
|
||
return [float(x) for x in full_translation] |