Skip to content

feat(atlas): multi-region get_mesh and batched atlas mesh prefetch - #448

Open
FelipeCybis wants to merge 7 commits into
get-bounding-boxfrom
atlas-mesh
Open

FelipeCybis wants to merge 7 commits into
get-bounding-boxfrom
atlas-mesh

Conversation

@FelipeCybis

Copy link
Copy Markdown
Member

Stacked on #446; #263 stacks on top of this one.

What

  • get_mesh / get_atlas_mesh now take regions and sides like get_masks (one region or a sequence, one side for all or one per region) and return a {acronym: (vertices, faces)} dict, with _L/_R-suffixed keys for single-hemisphere requests. All vertices go through world_to_base in one batched pass.
  • fetch_brainglobe_atlas prefetches every region mesh on the first fetch of an atlas. BrainGlobe 3 downloads meshes lazily, one S3 exists + get round trip per region (about 1 s each). We list the remote mesh directory once and pull every missing mesh in a single concurrent s3fs.get call: the 839 Allen mouse meshes take about 20 s instead of about 14 min, and get_mesh works offline afterwards.

Notes

@codecov

codecov Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.87234% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/confusius/atlas/_accessor.py 98.41% 1 Missing ⚠️
src/confusius/datasets/_brainglobe.py 96.77% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

📖 Doc preview: https://confusius.tools/pr-preview/pr-448/

@FelipeCybis

Copy link
Copy Markdown
Member Author

@sdiebolt this should be good to be reviewed!

get_atlas_mesh's clip step materialized the full lazily derived z/y/x
coordinate grids of an oblique atlas only to reduce them to per-axis
min/max. Add get_bounding_box, which maps the 8 corners of the
voxel-coordinate box through the voxel-to-world affine (identical
bounds, O(1) in grid size), and clip meshes with it.

Closes #444
…dict

`get_mesh`/`get_atlas_mesh` now mirror `get_masks`: `regions` and `sides`
broadcast through a shared `_normalize_regions_and_sides` helper, all vertices
are warped through `world_to_base` in one batched pass, and the result is a
`{acronym: (vertices, faces)}` dict with `_L`/`_R` keys for single-hemisphere
requests.

The atlas fixtures move to `tests/unit/conftest.py` so other test modules can
build on the same mock atlas, and the child region gains its own mesh so a
multi-region call that mis-splits the batched vertex transform cannot pass.
BrainGlobe 3 downloads each region mesh lazily on first access, one S3
`exists` + `get` round trip per region (about a second each). On the first
fetch of an atlas, `fetch_brainglobe_atlas` now lists the remote mesh
directory once and pulls every missing mesh in a single concurrent `s3fs.get`
call (839 Allen mouse meshes in ~20 s instead of ~14 min), so `get_mesh`
works offline afterwards.

Regions with no remote mesh (e.g. RSPd4 in the Allen mouse atlas) and an
unreachable bucket both warn and fall back to BrainGlobe's lazy download, and
a failed batch removes any partially written file, as BrainGlobe does, since
it treats any existing file as a valid cached mesh.
Both now return a dict of meshes, so the plural name matches the API.

This branch has not been deployed

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant