Skip to content

Commit be5eb7c

Browse files
authored
Minor updates to Zarr access patterns. (#50)
* Minor updates to Zarr access patterns. * Zarr3 doesn't support structured dtype access - convert to numpy array first * Zarr3 doesn't have create_dataset, replace with create_array. * DEP: Add min version pin for zarr.
1 parent 6ac002b commit be5eb7c

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ scikit-image
55
torch
66
torchvision
77
tqdm
8-
zarr
8+
zarr>2
99
matplotlib
1010
seaborn
1111
networkx

torch_mesmer/eval.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ def main(device: str,
138138

139139
X_test = z_test['X'][:]
140140
y_test = z_test['y'][:].astype(int)
141-
mpps = z_test['meta']['pixel_size'][:]
141+
# NOTE: Zarr doesn't support structured arrays - must be converted to numpy
142+
# array explicitly before attempting to access fields
143+
mpps = z_test['meta'][:]["pixel_size"]
142144

143145
# Load model and application
144146
model = Mesmer(

torch_mesmer/preprocess.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,17 @@ def convert_to_zarr(filename, out_dir=None):
4545
print(f" Writing {split}.")
4646

4747
# Store 'X' — chunked across C, H, W (one sample per chunk)
48-
store.create_dataset(
48+
store.create_array(
4949
"X",
5050
data=X,
5151
chunks=(1, C, H, W), # chunk = one full image (all channels, full spatial dims)
52-
dtype=X.dtype,
5352
)
5453

5554
# Store 'y' — chunked across C, H, W (one sample per chunk)
56-
store.create_dataset(
55+
store.create_array(
5756
"y",
5857
data=y,
5958
chunks=(1, C, H, W),
60-
dtype=y.dtype,
6159
)
6260

6361
meta_dtype = np.dtype(
@@ -71,7 +69,7 @@ def convert_to_zarr(filename, out_dir=None):
7169
meta_ary["specimen"] = data["meta"][crop_val:, -1]
7270

7371
# Store 'metadata' — no spatial chunking needed, one scalar per sample
74-
store.create_dataset(
72+
store.create_array(
7573
"meta",
7674
data=meta_ary,
7775
)

0 commit comments

Comments
 (0)