Skip to content

python_on_layers: optional ROI (sub-cube) for finer scale, local-only#16

Open
davidackerman wants to merge 1 commit into
mainfrom
feat-roi-subregion
Open

python_on_layers: optional ROI (sub-cube) for finer scale, local-only#16
davidackerman wants to merge 1 commit into
mainfrom
feat-roi-subregion

Conversation

@davidackerman
Copy link
Copy Markdown
Owner

Summary

Adds an optional `roi` argument to `python_on_layers` so the agent can restrict an analysis to a sub-cube of the volume. When a ROI is supplied:

  • Only the sub-cube is read into Python — zarrita slice on each spatial axis.
  • The auto-picker budgets against the ROI's voxel count rather than the full array, so a smaller ROI unlocks a finer scale that wouldn't fit otherwise. This is the actual point of the feature: high-res analysis of a small region.
  • The Python-side `offset_nm` is shifted to the ROI's world origin, so any positions the user's code reports stay in absolute world coordinates.

Shape

```json
{ "min_nm": [a, b, c], "max_nm": [a, b, c] }
```

Array-axis order (typically z, y, x — same convention as `layers[var].spacing`). All six coords required; for axes the user didn't constrain, the agent fills in the layer's full extent from `describe_dataset`.

Scope

Deliberately narrow for v1 — validate the value-add before broadening.

  • Local Pyodide path only. HF backend (tensorstore slicing) is a follow-up.
  • Zarr only. Precomputed-volume slicing follows.
  • No NG-annotation auto-detection yet. Agent reads `roi` from its tool args today; the "drag a box in NG" path is a phase-2 thing once the plumbing's validated.

Why now

User flagged "we could do higher res as long as it's a smaller ROI" — without this arg, every analysis fights the auto-picker's full-volume budget, which forces coarse scales on big datasets even when only a tiny region is interesting.

Adds an optional 'roi' arg: {min_nm:[a,b,c], max_nm:[a,b,c]} in
array-axis order (matches layer.spacing). When supplied, only the
sub-cube is read into Python AND the auto-picker budgets against the
ROI's voxel count instead of the full array — so a smaller ROI unlocks
a finer scale that wouldn't otherwise fit the runtime budget.

Touchpoints:
- agent.ts: parse + validate roi; per-layer voxel-coord conversion;
  ROI-aware scale picker; pass through to worker as 'roiVoxel' on each
  layer; shift the Python-side offset_nm to the ROI's world origin so
  reported positions stay absolute.
- analysis_worker.ts: readLayerArray now accepts roiVoxel and applies
  zarr.slice on spatial axes; computed offsets shift accordingly.
- System prompt: documents 'roi', including the requirement to fill in
  all six coords (use describe_dataset for unconstrained axes).

Scope intentionally narrow for v1:
- Local Pyodide path only — HF backend (tensorstore slicing) is the
  follow-up PR; needs an HF subtree push to test.
- Zarr only — precomputed-volume ROI is also follow-up.
- NG annotation auto-detection deferred; the agent reads 'roi' from
  its tool args today.
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying tourguide with  Cloudflare Pages  Cloudflare Pages

Latest commit: d3ed342
Status: ✅  Deploy successful!
Preview URL: https://c77ddf81.tourguide-8j4.pages.dev
Branch Preview URL: https://feat-roi-subregion.tourguide-8j4.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant