-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding conversion to tensorstore #242
base: main
Are you sure you want to change the base?
Changes from 5 commits
209807a
abd10a8
f8e9158
6658bc3
4afe0fe
cfd13ae
9c0d4ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import math | ||
import os | ||
from copy import deepcopy | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING, Generator, Literal, Sequence, Type | ||
|
||
import numpy as np | ||
|
@@ -344,7 +345,27 @@ def downscale(self): | |
raise NotImplementedError | ||
|
||
def tensorstore(self): | ||
raise NotImplementedError | ||
import tensorstore as ts | ||
|
||
metadata = { | ||
"dtype": self.dtype.str, | ||
"shape": self.shape, | ||
"chunks": self.chunks, | ||
} | ||
ts_spec = { | ||
"driver": "zarr", | ||
"kvstore": { | ||
"driver": "file", | ||
"path": str((Path(self._store.path) / self.path).resolve()), | ||
}, | ||
"metadata": metadata, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There could be a |
||
try: | ||
zarr_dataset = ts.open(ts_spec, open=True).result() | ||
except ValueError as e: | ||
print(f"Error opening Zarr store: {e}") | ||
raise | ||
Comment on lines
+365
to
+367
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the purpose of this? |
||
return zarr_dataset | ||
|
||
|
||
class TiledImageArray(ImageArray): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,6 +250,28 @@ def test_position_data(channels_and_random_5d, arr_name): | |
_ = dataset.data | ||
|
||
|
||
@given( | ||
channels_and_random_5d=_channels_and_random_5d(), | ||
arr_name=short_alpha_numeric, | ||
) | ||
@settings( | ||
max_examples=16, | ||
deadline=2000, | ||
suppress_health_check=[HealthCheck.data_too_large], | ||
) | ||
def test_ome_zarr_to_tensorstore(channels_and_random_5d, arr_name): | ||
"""Test `iohub.ngff.Position.data` to tensortore""" | ||
pytest.importorskip("tensorstore") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add tensorstore to dev requirements and not skip this? |
||
channel_names, random_5d = channels_and_random_5d | ||
with _temp_ome_zarr(random_5d, channel_names, "0") as dataset: | ||
assert_array_almost_equal(dataset.data.numpy(), random_5d) | ||
Comment on lines
+266
to
+267
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this redundant with another test case? |
||
with pytest.raises(KeyError): | ||
with _temp_ome_zarr(random_5d, channel_names, arr_name) as dataset: | ||
t = dataset.data.tensorstore() | ||
t.read().result() | ||
del t | ||
|
||
|
||
@given( | ||
channels_and_random_5d=_channels_and_random_5d(), | ||
arr_name=short_alpha_numeric, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a docstring.