Backend ROI: tensorstore + zarr-python + tunnel honor roiVoxel#19
Merged
Conversation
PR #16 wired up ROI slicing in the local Pyodide worker only; the HF backend ignored the field, so runtime='backend' (the only option for N5) would load the full array no matter what — defeating the "finer scale on a smaller cube" point of the feature. This patch threads roiVoxel through every backend load path: - LayerSpec gains an optional RoiVoxel { start, stop } field (array-axis order, parallel to axesOrder, matching the wire format the frontend already sends). - _load_via_tensorstore builds a per-axis slice tuple so chunks outside the ROI are never fetched. - _load_via_zarr_python (fallback) does the same via numpy-style indexing on the zarr.Array. - read_zarr_scale (tunnel path) gains a `selection` kwarg; _load_layer constructs one when roiVoxel is set so only chunks intersecting the cube come back over the WS tunnel. - _layer_to_globals shifts each per-axis offset by roi.start * voxel_nm, so Python code reporting absolute centroids / fly_to targets stays in the original layer's world frame. Net: ROI now actually saves backend memory AND bandwidth (matters for tunneled local-data layers most), not just frontend coords.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR #16 wired ROI slicing into the local Pyodide worker only; the HF backend silently ignored the `roiVoxel` field, so any `runtime="backend"` analysis (which is the only option for N5) loaded the full array regardless of the ROI. That defeated the point of the feature — "smaller cube → finer scale reachable" can't happen if the whole volume comes back anyway. This PR threads ROI through every backend load path.
Changes
What this unblocks
Running the trace from earlier ("measure mito properties in a 500³ nm ROI") against the macrophage dataset (n5, backend-only) now actually slices to the ROI — the agent's request stops being a no-op for the spatial restriction.
Deploy
Backend-only change. After merge, needs a `git subtree push --prefix hf-space …` to land on the running Space.