Skip to content

Reading lowest pyramid level fails when an axis collapses to size 1 #142

Description

@tlambert03

Small, low-priority bug found while adding zarr3 support (#140/#141).

Bug

read_tensorstore() squeezes singleton dims:

# src/microsim/cosem/_tstore.py
slices = tuple((slice(None) if s > 1 else 0) for s in data.shape)
data = data[slices]

then reverses axes based on grid_scale:

slices = tuple(slice(None, None, int(np.sign(scale))) for scale in img.grid_scale)
data = data[slices]

When the smallest pyramid level has an axis of size 1 (e.g. s11 of jrc_mus-skel-muscle-1/fibsem-uint8), the squeeze drops it to rank 2, but grid_scale still has 3 entries, so the second indexing op raises:

IndexError: Indexing expression requires 3 dimensions, and cannot be applied to a domain of rank 2

Repro:

from microsim.cosem import CosemDataset
img = CosemDataset.fetch("jrc_mus-skel-muscle-1").image(name="fibsem-uint8")
img.read(level=-1)  # lowest level -> IndexError

Not zarr3-specific — any image whose lowest level collapses an axis would hit it.

Proposed fix

Squeeze the per-axis grid_scale slices the same way (drop entries for axes that were squeezed out), or skip squeezed axes when building the reversal slices, so the two indexing ops stay rank-consistent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions