Skip to content

Commit

Permalink
Zarr file axis order
Browse files Browse the repository at this point in the history
Ensure reading non-editable zarr files the c axis, if present, has a
stride of 1.  PR #1625 changed this.
  • Loading branch information
manthey committed Oct 25, 2024
1 parent 33f838d commit db191ec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
- Better handle images with signed pixel data ([#1695](../../pull/1695))
- Reduce loading geojs when switching views in Girder ([#1699](../../pull/1699))

### Changes

- Ensure reading non-editable zarr files the c axis, if present, has a stride of 1 ([#1703](../../pull/1703))

## 1.30.1

### Improvements
Expand Down
14 changes: 10 additions & 4 deletions sources/zarr/large_image_source_zarr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,16 @@ def _validateZarr(self):
stride = 1
self._strides = {}
self._axisCounts = {}
for _, k in sorted(
(-self._axes.get(k, 'tzc'.index(k) if k in 'tzc' else -1), k)
for k in self._axes if k not in 'xys'
):
# If we aren't in editable mode, prefer the channel axis to have a
# stride of 1, then the z axis, then the t axis, then sorted by the
# axis name.
axisOrder = ((-'tzc'.index(k) if k in 'tzc' else 1, k)
for k in self._axes if k not in 'xys')
# In editable mode, prefer the order that the axes are being written.
if self._editable:
axisOrder = ((-self._axes.get(k, 'tzc'.index(k) if k in 'tzc' else -1), k)
for k in self._axes if k not in 'xys')
for _, k in sorted(axisOrder):
self._strides[k] = stride
self._axisCounts[k] = baseArray.shape[self._axes[k]]
stride *= baseArray.shape[self._axes[k]]
Expand Down
9 changes: 9 additions & 0 deletions test/test_source_zarr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import large_image_source_zarr

from .datastore import datastore


def testZarrAxisOrder():
imagePath = datastore.fetch('synthetic_multiaxis.zarr.db')
source = large_image_source_zarr.open(imagePath)
assert source.metadata['IndexStride']['IndexC'] == 1

0 comments on commit db191ec

Please sign in to comment.