Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ data-cache/
*.nii.gz
*.npy
*.npz
!src/mouse_brain_planner/assets/vasculature/lambada_p60_606_major_vessels_v1.npz
!src/mouse_brain_planner/assets/vasculature/vessap_bl6j1_major_vessels_50um_v1.npz
*.pdf
43 changes: 9 additions & 34 deletions ATLAS_DATA.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,40 +179,15 @@ clearance. The workflow remains archived in the backend and is absent from the p
50 µm prepared grid does not acquire 25 µm vascular resolution merely because it is composited
over a 25 µm atlas image.

## Archived LAMBADA major-vessel evidence

The repository retains a derivative of Renier, de Launoit, and Skriabine's
P60_606 graph, [Zenodo record 18876865](https://zenodo.org/records/18876865), DOI
`10.5281/zenodo.18876865`, CC BY 4.0. It is bound to the accepted Allen 25 µm array shape and
contains maximal consecutive in-bounds runs whose point radius is at least 15 µm (diameter at
least 30 µm). Those deterministic extraction facts do not qualify it as a display layer.

AP and DV orientation evidence passed, but the source describes hemisphere specimens and the
exact graph has no persisted biological hemisphere/laterality binding. Whole-brain coverage and
ML polarity are unqualified, and the application does not mirror the source. The production
reference endpoints never load this derivative. Nothing from it is overlaid in slices, Dorsal,
or 3D.

The source also omits pial and choroidal vessels, and the derivative omits smaller vessels. Full
identity, extraction, coordinate qualification, checks, counts, and limitations are in
[LAMBADA Major Vessels](docs/LAMBADA_MAJOR_VESSELS.md) and
[Third-Party Software and Data](THIRD_PARTY.md).

## VesSAP display-only major-vessel reference

The current visible reference is a bundled derivative of the public VesSAP `BL6J-no1` 3 µm
whole-brain skeleton/radius volumes. It retains nominal diameter ≥30 µm source centerlines,
preserves true source adjacency, applies the authors' Euler plus B-spline Allen transform with
the reviewed ML reflection, and reduces the paths on a 50 µm display grid.

The adjacent manifest binds the exact source files, transform, atlas identity, extraction
statistics, NPZ digest, and mandatory limitations. The backend serves metadata and geometry only
after all checks pass; the same geometry is overlaid in all five modes. It is one fixed cleared
C57BL/6J specimen, omits smaller vessels, and has no subject-registration or tissue-distortion
error bound. `vessel.major.reference.analyze` therefore fails with
`VESSEL_ANALYSIS_UNAVAILABLE` before accessing a project or geometry.

See [VesSAP Major Vessels](docs/VESSAP_MAJOR_VESSELS.md) for the exact data and transform record.
## Optional VesSAP major-vessel reference

The VesSAP display layer is loaded only when its NPZ and manifest are installed under the
application data directory. The data files are not stored in this repository or application
bundle. The loader validates their source identity, transform, atlas binding, digest, arrays,
bounds, and extraction statistics before exposing the five-view geometry.

See [VesSAP External Major-vessel Data](docs/VESSAP_MAJOR_VESSELS.md) for the file locations and
data contract.

## No official CCF bregma

Expand Down
5 changes: 0 additions & 5 deletions COORDINATE_SYSTEMS.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,6 @@ An ontology identity does not guarantee voxel or mesh geometry. In the reviewed
four 2D overlays contain zero selected pixels, and 3D reports that no reviewed geometry exists;
no inferred surface is substituted.

The archived LAMBADA P60_606 derivative is not displayed. Its exact qualification found
supporting AP and DV orientation evidence but rejected biological ML/laterality and whole-brain
coverage because the source is a hemisphere specimen and its graph has no persisted hemisphere
binding. Numeric points on both sides of the atlas midpoint do not establish bilateral anatomy.
No mirroring or display-axis guess is permitted.

VesSAP remains one fixed cleared reference, not the current animal. The shared coordinate frame
permits an overlay but does not supply subject registration, tissue-distortion, or inter-animal
Expand Down
139 changes: 23 additions & 116 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,140 +1,47 @@
# Development

Brain3D has one supported product path: a SwiftUI + SceneKit macOS application and a Python 3.12
scientific service connected by typed NDJSON. Scientific transforms, atlas access, calibration,
probe/region analysis, vessel qualification, and persistence stay in Python; Swift owns
presentation, input, accessibility, native file handling, and schema-checked SceneKit display
payloads. No vessel-analysis capability is currently exposed.

Start with [Architecture](docs/ARCHITECTURE.md), [Code Audit](docs/CODE_AUDIT.md),
[ADR-005](docs/ADR-005-independent-slice-viewer.md), and
[Scientific Validation](SCIENTIFIC_VALIDATION.md).

## Environment

- Apple Silicon (`arm64`)
- macOS 14 or later
- CPython `>=3.12,<3.13`
- Swift 6-compatible toolchain
- committed `uv.lock`
## Setup

```bash
uv python install 3.12
uv lock --check
uv sync --frozen --group dev
uv run --frozen mouse-brain-planner atlas download allen_mouse_25um
```

Build and open the macOS app:

```bash
native/Brain3D/Scripts/build-app.sh
open native/Brain3D/build/Brain3D.app
```

The default dependency graph deliberately excludes PySide6, PyVista, PyVistaQt, and VTK. Do not
reintroduce a second GUI or renderer into the base environment.
The Swift app communicates with the Python service over typed NDJSON. Start with
[Architecture](docs/ARCHITECTURE.md), [Coordinate Systems](COORDINATE_SYSTEMS.md), and the
architecture decisions in [docs](docs/).

## Quality gate
## Checks

```bash
uv lock --check
uv sync --frozen --group dev
uv run --frozen ruff format --check .
uv run --frozen ruff check .
uv run --frozen mypy --no-incremental
uv run --frozen pytest -q
.venv/bin/python scripts/verify_minimal_runtime.py
swift test --package-path native/Brain3D
swift test --package-path native/Brain3D --no-parallel
native/Brain3D/Scripts/build-app.sh
codesign --verify --deep --strict native/Brain3D/build/Brain3D.app
```

The minimal verifier checks that Qt/VTK modules are absent and exchanges real `hello` and
`shutdown` frames through `mouse-brain-planner bridge`. A green gate establishes engineering
consistency, not stereotaxic, vascular-clearance, usability, or surgical accuracy.

Useful focused runs:

```bash
uv run --frozen pytest tests/unit/test_atlas_space.py -q
uv run --frozen pytest tests/unit/test_brainglobe_adapter.py -q
uv run --frozen pytest tests/unit/test_slice_renderer.py -q
uv run --frozen pytest tests/integration/test_bridge_stdio.py -q
swift test --package-path native/Brain3D
```

The normal Python suite uses synthetic volumes and local fakes. The real density-archive and
real-atlas checks remain explicit opt-in tests because their external data are not committed.

## Run the product path

```bash
native/Brain3D/Scripts/build-app.sh
open native/Brain3D/build/Brain3D.app
uv run --frozen mouse-brain-planner atlas list
uv run --frozen mouse-brain-planner atlas download allen_mouse_25um
uv run --frozen mouse-brain-planner validate-project /absolute/path/Plan.mouseplan
```

`mouse-brain-planner` without a subcommand prints help. `mouse-brain-planner bridge` is intended
for the native process boundary and integration diagnostics.

## Source layout
## Repository layout

```text
native/Brain3D/ SwiftUI shell, typed client, native tests/build
Sources/Brain3DScene/ SceneKit brain/probe rendering; archived vessel primitives
src/mouse_brain_planner/
atlas/ BrainGlobe 2.3.1 boundary
bridge/ versioned service and handlers
coordinates/ named frames, order conversion, transforms
domain/ Pydantic scientific/project models
persistence/ deterministic migrations and atomic packages
rendering/ raster slices and dorsal projection
probes/ source-traceable NP1 and synthetic test catalog
surgery/ product-reachable probe/measurement geometry
analysis/ region traversal plus archived vessel-analysis algorithms
vasculature/ VesSAP display geometry plus archived qualification workflows
tests/ headless unit/contract/integration tests
docs/ audit, architecture, validation, and ADRs
native/Brain3D/ SwiftUI and SceneKit application
src/mouse_brain_planner/ Python atlas and planning service
tests/ Python tests and fixtures
docs/ architecture and technical references
scripts/ verification and benchmark utilities
```

The old Qt/PyVista/VTK application was removed after the audit in
[Legacy Removal](docs/LEGACY_REMOVAL.md). Its last complete snapshot is Git commit `51fe26d`.

## Dependency direction

- Swift never reimplements coordinate transforms or scientific classification.
- The bridge imports no macOS UI framework and must run headlessly.
- Only the BrainGlobe adapter owns upstream atlas objects.
- All API coordinates name their frame, order, units, origin, directions, atlas identity, and
transform/calibration identity.
- Project files store model state and immutable data references, never UI objects or complete
atlas/vessel volumes.
- The rejected LAMBADA derivative, archived population density, and archived 2D subject evidence
remain separate types and workflows. None is a subject-vessel layer. The runtime vessel
geometry endpoint serves only the digest-checked VesSAP display reference; analysis fails
closed with `VESSEL_ANALYSIS_UNAVAILABLE`, and LAMBADA is never loaded.

## Coordinate-change checklist

Any change involving axes, units, indexing, laterality, transforms, picking, or projection must:

1. name the source and destination frames and units;
2. use centralized BrainGlobe `[AP,DV,ML]` ↔ domain `[AP,ML,DV]` conversion;
3. validate finite values and half-open atlas bounds;
4. distinguish continuous voxel coordinates, discrete indices, corner anchors, and centers;
5. add asymmetric laterality and forward/inverse golden tests;
6. require either the exact source-pinned v4 bregma/surface evidence or, for legacy v1–v3,
a passing subject calibration; never treat atlas origin as bregma; and
7. update coordinate/validation documentation with exact evidence and tolerances.

## Bridge-change checklist

- Preserve strict envelope and exact-parameter validation.
- Reject bool where a number is expected, plus NaN and infinity.
- Use stable error codes and include recoverability/suggested action in protocol v2 errors.
- Every mutation checks the expected project revision and returns the new revision.
- Long work runs off the UI thread and stale results cannot overwrite current state.
- Add Python contract tests, matching Swift Codable tests, and a production handler/capability
inventory assertion.
- Do not send full atlas volumes or platform-specific index objects across NDJSON.

## Review discipline

Before committing, inspect `git diff --check`, run the relevant focused tests, then run the full
gate in proportion to the change. Never weaken frame/provenance validation to make a test pass.
Update [Code Audit](docs/CODE_AUDIT.md) when a previously orphaned module becomes product-reachable.
Atlas volumes, vascular datasets, PDF inputs, and user projects stay outside source control.
Use `MOUSE_BRAIN_PLANNER_CONFIG_DIR`, `MOUSE_BRAIN_PLANNER_DATA_DIR`, and
`MOUSE_BRAIN_PLANNER_CACHE_DIR` for isolated development environments.
Loading