Spaces:
Sleeping
Sleeping
Deploy Python probe API
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- .gitattributes+3-32
- .gitignoreAdded+4
- README.md+3-46
- app.py+157-110
- mindVisualizer/data/brain_alignment.jsonAdded+28
- mindVisualizer/data/extra_parcellation/README.mdAdded+53
- mindVisualizer/data/roi_flow/mdn_training_all_points.npy → mindVisualizer/data/extra_parcellation/combined_atlas.nii.gzRenamed+2-2
- mindVisualizer/data/extra_parcellation/combined_atlas_labels.jsonAdded+129
- mindVisualizer/data/label_grid_cache.keys.jsonAdded+1
- mindVisualizer/data/roi_flow/probe_embed.npy → mindVisualizer/data/label_grid_cache.npzRenamed+2-2
- mindVisualizer/data/roi_flow/mdn_universal_all_grid64_entropy.bin → mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_entropy.binRenamed+2-2
- mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_mean_xyz3.binAdded+3
- mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_meta.jsonAdded+1
- mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_mu1_xyz3.binAdded+3
- mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_mu2_xyz3.binAdded+3
- mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_mu3_xyz3.binAdded+3
- mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_mu4_xyz3.binAdded+3
- mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_mu5_xyz3.binAdded+3
- mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_mu6_xyz3.binAdded+3
- mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_pi_xyz6.binAdded+3
- mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_training_points.npyAdded+3
- mindVisualizer/data/roi_flow/mdn_universal_all_grid64_mean_xyz3.bin → mindVisualizer/data/meshes_obj/10153.objRenamed+2-2
- mindVisualizer/data/meshes_obj/10154.objAdded+3
- mindVisualizer/data/meshes_obj/10155.objAdded+3
- mindVisualizer/data/meshes_obj/10156.objAdded+3
- mindVisualizer/data/roi_flow/mdn_universal_all_grid64_mu1_xyz3.bin → mindVisualizer/data/meshes_obj/10157.objRenamed+2-2
- mindVisualizer/data/meshes_obj/10158.objAdded+3
- mindVisualizer/data/meshes_obj/10159.objAdded+3
- mindVisualizer/data/meshes_obj/10292.objAdded+3
- mindVisualizer/data/meshes_obj/10306.objAdded+3
- mindVisualizer/data/roi_flow/probe_roi_centers.npy → mindVisualizer/data/meshes_obj/10307.objRenamed+2-2
- mindVisualizer/data/meshes_obj/10308.objAdded+3
- mindVisualizer/data/meshes_obj/10311.objAdded+3
- mindVisualizer/data/meshes_obj/10313.objAdded+3
- mindVisualizer/data/meshes_obj/10327.objAdded+3
- mindVisualizer/data/meshes_obj/10329.objAdded+3
- mindVisualizer/data/meshes_obj/10330.objAdded+3
- mindVisualizer/data/meshes_obj/10331.objAdded+3
- mindVisualizer/data/meshes_obj/10332.objAdded+3
- mindVisualizer/data/meshes_obj/10333.objAdded+3
- mindVisualizer/data/meshes_obj/10334.objAdded+3
- mindVisualizer/data/meshes_obj/10335.objAdded+3
- mindVisualizer/data/meshes_obj/10336.objAdded+3
- mindVisualizer/data/meshes_obj/10337.objAdded+3
- mindVisualizer/data/meshes_obj/10338.objAdded+3
- mindVisualizer/data/meshes_obj/10339.objAdded+3
- mindVisualizer/data/meshes_obj/10342.objAdded+3
- mindVisualizer/data/meshes_obj/10343.objAdded+3
- mindVisualizer/data/meshes_obj/10344.objAdded+3
- mindVisualizer/data/meshes_obj/10346.objAdded+3
1234567891011121314151617181920212223242526272829303132333435*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text123456*.bin filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.obj filter=lfs diff=lfs merge=lfs -text*.nii filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text
1234.git__pycache__*.pyc.env1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253---title: MindVisualizer APIsdk: dockerapp_port: 7860pinned: false---# MindVisualizer Python APISmall FastAPI adapter for the hosted web page.The GitHub Pages frontend renders particles locally. This backend is only for algorithm-sensitive operations:- recomputing probe trajectories with the original Python `TriLinearSampler`- mapping a trajectory to ROI vectors with the original `ManifoldToROIKNN`- building the original `ROIFlowAnalyzer` context- optionally calling the original `ROIFlowLLM` if `OPENAI_API_KEY` is configured## Cheapest hosting shapeUse a free Python container host and keep the service public:1. Bundle the minimal `mindVisualizer` source/data folder into the Space as `/app/mindVisualizer`.2. Deploy this directory as a Docker/FastAPI service.3. Set `MINDVIS_REPO=/app/mindVisualizer`.4. Set `CORS_ORIGINS=https://pixedar.github.io,http://localhost:3000`.5. In the GitHub Pages build, set `NEXT_PUBLIC_MINDVIS_API_URL=https://your-backend-url`.6. Optional: set `OPENAI_API_KEY` as a Space secret and `OPENAI_MODEL` as a Space variable.Current Space:- https://huggingface.co/spaces/Pixedar/mindvisualizer-api- https://pixedar-mindvisualizer-api.hf.spaceDo not install the full `mindVisualizer` `pyproject.toml` on a tiny free host; it pulls desktop/VTK dependencies. This adapter uses `PYTHONPATH` and installs only the packages needed for the API path.## Local run```bashcd backend/mindvis-apipython -m venv .venv.venv\Scripts\activatepip install -r requirements.txt$env:MINDVIS_REPO="C:\Users\assas\PycharmProjects\mindVisualizer"uvicorn app:app --reload --port 7860```Then build/run the web page with:```bash$env:NEXT_PUBLIC_MINDVIS_API_URL="http://localhost:7860"pnpm dev```12345678910---title: MindVisualizer APIsdk: dockerapp_port: 7860pinned: false---# MindVisualizer APIPython-backed probe trajectory and explanation service.
12346 unmodified lines11121314151617181920212223242526272829309 unmodified lines4041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878816 unmodified lines1051061071081091101111121131145 unmodified lines1201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601614 unmodified lines166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209import jsonimport osimport sysfrom functools import lru_cache6 unmodified linesfrom pydantic import BaseModel, FieldFieldMode = Literal["mean", "gated", "mu1", "mu2"]class TrajectoryRequest(BaseModel):seed: list[float] = Field(default_factory=lambda: [0.5, 0.5, 0.5], min_length=3, max_length=3)fieldMode: FieldMode = "gated"steps: int = Field(default=220, ge=8, le=1200)dt: float = Field(default=0.018, gt=0, le=0.1)speedScale: float = Field(default=0.48, gt=0, le=4)class ExplainRequest(BaseModel):trajectory: list[list[float]] = Field(min_length=2)fieldMode: FieldMode = "gated"callLlm: bool = True9 unmodified lines@lru_cache(maxsize=1)def services():repo = mindvis_repo()from src.field_loader import TriLinearSampler, load_fieldfrom src.roi_flow import ManifoldToROIKNN, ROIFlowAnalyzerdata = repo / "data"flow = load_field(data / "roi_flow" / "mdn_universal_raw_grid64_meta.json")mean = flow["mean"]mu1 = flow["mus"][0]mu2 = flow["mus"][1]pi = flow["pi"]gated = np.where(np.argmax(pi, axis=-1)[..., None] == 0, mu1, mu2).astype(np.float32)samplers = {"mean": TriLinearSampler(mean, flow["amin"], flow["amax"]),"gated": TriLinearSampler(gated, flow["amin"], flow["amax"]),"mu1": TriLinearSampler(mu1, flow["amin"], flow["amax"]),"mu2": TriLinearSampler(mu2, flow["amin"], flow["amax"]),}embed = np.load(data / "roi_flow" / "probe_embed.npy").astype(np.float32)roi = np.load(data / "roi_flow" / "probe_roi.npy").astype(np.float32)centers = np.load(data / "roi_flow" / "probe_roi_centers.npy").astype(np.float32)structures = json.loads((data / "structures.json").read_text(encoding="utf-8"))names = []for idx in range(roi.shape[1]):item = structures[idx] if idx < len(structures) else {}names.append(item.get("name") or item.get("acronym") or f"ROI {idx + 1}")mapper = ManifoldToROIKNN(embed, roi, k=256)analyzer = ROIFlowAnalyzer(names, centers[: len(names)])return {"amin": flow["amin"],"amax": flow["amax"],"span": flow["amax"] - flow["amin"],"samplers": samplers,"mapper": mapper,"analyzer": analyzer,}app = FastAPI(title="MindVisualizer API", version="0.1.0")origins = [origin.strip() for origin in os.environ.get("CORS_ORIGINS", "*").split(",") if origin.strip()]app.add_middleware(16 unmodified lines@app.post("/api/mindvis/trajectory")def trajectory(req: TrajectoryRequest):svc = services()path = integrate_path(req.seed, req.fieldMode, req.steps, req.dt, req.speedScale)return {"fieldMode": req.fieldMode,"trajectory": normalized(path, svc["amin"], svc["span"]).tolist(),}5 unmodified linesraise HTTPException(status_code=400, detail="trajectory must be an array of [x,y,z] points")world = denormalized(np.clip(traj, 0.0, 1.0), svc["amin"], svc["span"])mapper = svc["mapper"]analyzer = svc["analyzer"]start_roi = mapper.query(world[0])end_roi = mapper.query(world[-1])delta = analyzer.compute_delta(start_roi, end_roi)context = analyzer.build_llm_context(delta)text = ""if req.callLlm and os.environ.get("OPENAI_API_KEY"):text = call_openai_interpreter(context)if not text:analysis = analyzer.analyze_flow_pattern(delta)text = (f"Pattern: {analysis['pattern_type']}. "f"Bulk direction: {analysis['bulk_direction']}. "f"Positive ROIs: {analysis['n_significant_positive']}; "f"negative ROIs: {analysis['n_significant_negative']}.")return {"text": text, "context": context}def integrate_path(seed: list[float], field_mode: FieldMode, steps: int, dt: float, speed_scale: float) -> np.ndarray:svc = services()p = denormalized(np.asarray(seed[:3], dtype=np.float32)[None, :], svc["amin"], svc["span"])sampler = svc["samplers"][field_mode]path = np.empty((steps, 3), dtype=np.float32)for idx in range(steps):path[idx] = p[0]v = sampler.sample_vec(p)p = p + v * (dt * speed_scale)p = ((p - svc["amin"]) % svc["span"]) + svc["amin"]return pathdef denormalized(points: np.ndarray, amin: np.ndarray, span: np.ndarray) -> np.ndarray:4 unmodified linesreturn (points.astype(np.float32) - amin[None, :]) / span[None, :]def call_openai_interpreter(context: str) -> str:from openai import OpenAImodel = os.environ.get("OPENAI_MODEL", "gpt-4o-mini")instructions = ("You are a neuroscientist interpreting brain state dynamics from a ""manifold flow simulation. The user traced a path through a learned ""neural manifold. You are given how each ROI's contribution changed ""along this path.\n\n""The delta values do not mean simple activation. They measure how each ""ROI's contribution to the overall brain state shifted. Positive means ""the region became a stronger contributor; negative means it became a ""weaker contributor.\n\n""Do not list every ROI. Synthesize the spatial pattern, directionality, ""and network shift into one coherent interpretation. Keep the response ""to 2 concise paragraphs.")try:client = OpenAI(timeout=60.0)if hasattr(client, "responses"):response = client.responses.create(model=model,instructions=instructions,input=context,max_output_tokens=900,)return (response.output_text or "").strip()response = client.chat.completions.create(model=model,messages=[{"role": "system", "content": instructions},{"role": "user", "content": context},],max_tokens=900,temperature=0.3,)return (response.choices[0].message.content or "").strip()except Exception as exc:return f"[GPT ERROR] {exc}"1236 unmodified lines10111213141516171819202122232425262728299 unmodified lines3940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711816 unmodified lines1351361371381391401411421431441451461471481491505 unmodified lines1561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362374 unmodified lines242243244245246247248249250251252253254255256import osimport sysfrom functools import lru_cache6 unmodified linesfrom pydantic import BaseModel, FieldFieldMode = Literal["mean", "gated", "mu1", "mu2", "mu3", "mu4", "mu5", "mu6"]class TrajectoryRequest(BaseModel):seed: list[float] = Field(default_factory=lambda: [0.5, 0.5, 0.5], min_length=3, max_length=3)fieldMode: FieldMode = "mean"steps: int = Field(default=700, ge=8, le=1600)dt: float = Field(default=1.0, gt=0, le=8.0)speedScale: float = Field(default=1.0, gt=0, le=8.0)class ExplainRequest(BaseModel):trajectory: list[list[float]] = Field(min_length=2)fieldMode: FieldMode = "mean"callLlm: bool = True9 unmodified lines@lru_cache(maxsize=1)def services():repo = mindvis_repo()data = repo / "data"from src.field_loader import TriLinearSampler, load_fieldfrom src.mesh_overlay import FlowMeshOverlayflow = load_field(data / "mdn" / "mdn_particles_rdcim_teacher_edge_hq_grid125_meta.json")mean = flow["mean"]mus = flow["mus"]pi = flow["pi"]ent = flow["ENT"]amin = flow["amin"]amax = flow["amax"]span = amax - amindiag = float(np.linalg.norm(span))target_step = 0.01 * max(diag, 1e-6)winner = np.argmax(pi, axis=-1)gated = np.zeros_like(mean, dtype=np.float32)for idx, mu in enumerate(mus):gated += mu * (winner[..., None] == idx).astype(np.float32)fields = {"mean": mean, "gated": gated}fields.update({f"mu{idx + 1}": mu for idx, mu in enumerate(mus)})samplers = {name: TriLinearSampler(field, amin, amax) for name, field in fields.items()}def vmax(field):mag = np.linalg.norm(field.reshape(-1, 3), axis=1)nz = mag[mag > 0]return float(np.percentile(nz, 100.0)) if nz.size else 1.0vmax_by_name = {name: vmax(field) for name, field in fields.items()}# The original Python app uses FlowMeshOverlay + its cached label grid for# probe interpretation. This API intentionally reuses that path.import vtkren = vtk.vtkRenderer()win = vtk.vtkRenderWindow()win.OffScreenRenderingOn()win.AddRenderer(ren)mesh = FlowMeshOverlay(ren=ren, win=win, mesh_dir=data / "meshes", alignment_file=data / "brain_alignment.json")cache = data / "label_grid_cache.npz"if not mesh.load_label_grid(cache):raise RuntimeError("Python label_grid_cache is missing; run setup_brain_data.py in mindVisualizer first.")# Optional finer parcellation, exactly as the desktop flow mode auto-detects.try:from src.extra_parcellation import ExtraParcellationatlas = data / "extra_parcellation" / "combined_atlas.nii.gz"labels = data / "extra_parcellation" / "combined_atlas_labels.json"if atlas.exists():extra = ExtraParcellation(atlas, labels if labels.exists() else None)if extra.load():mesh.set_extra_parcellation(extra)except Exception as exc:print(f"[extra-parcellation] disabled: {exc}")ent_sampler = TriLinearSampler(mean, amin, amax) if ent is not None else Nonereturn {"amin": amin,"amax": amax,"span": span,"samplers": samplers,"vmax": vmax_by_name,"target_step": target_step,"mesh": mesh,"entropy": ent,"entropy_sampler": ent_sampler,}app = FastAPI(title="MindVisualizer API", version="1.0.0")origins = [origin.strip() for origin in os.environ.get("CORS_ORIGINS", "*").split(",") if origin.strip()]app.add_middleware(16 unmodified lines@app.post("/api/mindvis/trajectory")def trajectory(req: TrajectoryRequest):svc = services()world, mags, stopped = integrate_probe(req, svc)transitions = analyze_regions(world, mags, req.callLlm if hasattr(req, "callLlm") else False)return {"fieldMode": req.fieldMode,"trajectory": normalized(world, svc["amin"], svc["span"]).tolist(),"worldTrajectory": world.tolist(),"fieldMagnitudes": mags.tolist(),"stopped": stopped,"transitions": transitions,"regionText": format_transition_text(transitions),}5 unmodified linesraise HTTPException(status_code=400, detail="trajectory must be an array of [x,y,z] points")world = denormalized(np.clip(traj, 0.0, 1.0), svc["amin"], svc["span"])sampler = svc["samplers"].get(req.fieldMode, svc["samplers"]["mean"])mags = np.linalg.norm(sampler.sample_vec(world), axis=1).astype(np.float32)transitions = analyze_regions(world, mags, req.callLlm)text = format_transition_text(transitions)if req.callLlm:from src.region_analyzer import analyze_with_gpttext = analyze_with_gpt(transitions,use_rag=os.environ.get("MINDVIS_USE_RAG", "0") == "1",model=os.environ.get("OPENAI_MODEL", "gpt-5.4-mini"),debug=os.environ.get("MINDVIS_DEBUG", "0") == "1",)return {"text": text, "transitions": transitions, "regionText": format_transition_text(transitions)}def integrate_probe(req: TrajectoryRequest, svc: dict) -> tuple[np.ndarray, np.ndarray, bool]:p = denormalized(np.asarray(req.seed[:3], dtype=np.float32)[None, :], svc["amin"], svc["span"])sampler = svc["samplers"].get(req.fieldMode, svc["samplers"]["mean"])step = req.dt * req.speedScale * (svc["target_step"] / max(svc["vmax"].get(req.fieldMode, 1.0), 1e-9))path = []mags = []stopped = Falsefor _ in range(req.steps):path.append(p[0].copy())velocity = sampler.sample_vec(p)[0]mags.append(float(np.linalg.norm(velocity)))new_pos = np.clip(p[0] + velocity * step, svc["amin"], svc["amax"])# Original probe boundary behavior: if a step leaves labelled brain# space, try half-step; otherwise stop instead of wrapping.if not is_valid_probe_position(new_pos, svc["mesh"]):half = np.clip(p[0] + velocity * step * 0.5, svc["amin"], svc["amax"])if is_valid_probe_position(half, svc["mesh"]):new_pos = halfelse:stopped = Truebreakif np.linalg.norm(new_pos - p[0]) < 1e-5:stopped = Truebreakp[0] = new_pos.astype(np.float32)return np.asarray(path, dtype=np.float32), np.asarray(mags, dtype=np.float32), stoppeddef is_valid_probe_position(point: np.ndarray, mesh) -> bool:key = mesh.get_region_at_point(point)if key is None:key = mesh.find_nearest_region(point, search_radius=2, max_distance_mm=5.0)return key is not Nonedef analyze_regions(world: np.ndarray, mags: np.ndarray, call_llm: bool) -> list[dict]:svc = services()from src.region_analyzer import analyze_probe_pathtransitions = analyze_probe_path(world,svc["mesh"],sample_every=5,field_mags=mags,entropy_sampler=svc["entropy_sampler"],entropy_field=svc["entropy"],)return make_json_safe(transitions)def format_transition_text(transitions: list[dict]) -> str:from src.region_analyzer import format_transitions_textreturn format_transitions_text(transitions)def denormalized(points: np.ndarray, amin: np.ndarray, span: np.ndarray) -> np.ndarray:4 unmodified linesreturn (points.astype(np.float32) - amin[None, :]) / span[None, :]def make_json_safe(value):if isinstance(value, np.ndarray):return value.tolist()if isinstance(value, np.generic):return value.item()if isinstance(value, dict):return {str(k): make_json_safe(v) for k, v in value.items() if not str(k).startswith("_")}if isinstance(value, list):return [make_json_safe(v) for v in value]if isinstance(value, tuple):return [make_json_safe(v) for v in value]return value
12345678910111213141516171819202122232425262728{ "matrix": [ [ -0.03483789662196803, -0.1654855793300339, 0.9305766368497694, -68.4377205759064 ], [ -0.9422190580860553, -0.06752555868994387, -0.047281905216520856, 106.73199000287599 ], [ 0.0747101104018069, -0.9287770749837014, -0.16236864674663903, 115.80117022013123 ], [ 0.0, 0.0, 0.0, 1.0 ] ]}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253# Extra Parcellation Data
Provides fine-grained subregion labels alongside the primary Allen atlas meshes.
## Setup (recommended)
Run the setup script to build the combined atlas automatically:
```bashpython scripts/setup_extra_parcellation.py```
This downloads and merges three complementary MNI-space atlases via nilearn:
| Layer | Source | Regions | Role ||-------|--------|---------|------|| 1 | Harvard-Oxford Cortical | 48 | Broad cortical coverage || 2 | Harvard-Oxford Subcortical | 17 | Thalamus, putamen, caudate, hippocampus, amygdala, etc. || 3 | **Julich-Brain** (highest priority) | 62 | Cytoarchitectonic: motor BA4a/4p, somatosensory BA1-3, visual V1-V5, auditory, Broca's, hippocampal subfields |
**Total: 127 labeled regions**, Julich-Brain labels override coarser Harvard-Oxfordwhere available.
Output files (auto-detected by flow mode):- `combined_atlas.nii.gz` — NIfTI volume (~700KB)- `combined_atlas_labels.json` — label ID to name map
## How it works
The combined atlas is in MNI152 1mm space. The Allen atlas scene space isapproximately MNI-aligned, so probe coordinates can be used directly for lookups.When the exact voxel is unlabeled, a nearby-search fallback finds the closestlabeled region within a few mm.
When both the primary Allen mesh and the extra parcellation cover a probe position,both are highlighted: the Allen mesh in red, the extra parcellation subregion inorange. The subregion name is included in the LLM context as additional detail.
## Custom atlas
You can also provide any NIfTI atlas in MNI space:
```bashpython examples/flow_probe_example.py \ --extra-parcellation my_atlas.nii.gz \ --extra-parcellation-labels my_atlas_labels.json```
## Requirements
```bashpip install nilearn nibabel scikit-image```123version https://git-lfs.github.com/spec/v1oid sha256:bf047435bda457ab7eb4d59940ae8463555bb92cffadaed9d13aad234123887fsize 223208123version https://git-lfs.github.com/spec/v1oid sha256:68b7dbb0b9949e0e3021d60db9d6f1499615560cba955e0a2f6ab2e41962d25asize 693799
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129{ "1": "Frontal Pole", "2": "Insular Cortex", "3": "Superior Frontal Gyrus", "4": "Middle Frontal Gyrus", "5": "Inferior Frontal Gyrus, pars triangularis", "6": "Inferior Frontal Gyrus, pars opercularis", "7": "Precentral Gyrus", "8": "Temporal Pole", "9": "Superior Temporal Gyrus, anterior division", "10": "Superior Temporal Gyrus, posterior division", "11": "Middle Temporal Gyrus, anterior division", "12": "Middle Temporal Gyrus, posterior division", "13": "Middle Temporal Gyrus, temporooccipital part", "14": "Inferior Temporal Gyrus, anterior division", "15": "Inferior Temporal Gyrus, posterior division", "16": "Inferior Temporal Gyrus, temporooccipital part", "17": "Postcentral Gyrus", "18": "Superior Parietal Lobule", "19": "Supramarginal Gyrus, anterior division", "20": "Supramarginal Gyrus, posterior division", "21": "Angular Gyrus", "22": "Lateral Occipital Cortex, superior division", "23": "Lateral Occipital Cortex, inferior division", "24": "Intracalcarine Cortex", "25": "Frontal Medial Cortex", "26": "Juxtapositional Lobule Cortex (formerly Supplementary Motor Cortex)", "27": "Subcallosal Cortex", "28": "Paracingulate Gyrus", "29": "Cingulate Gyrus, anterior division", "30": "Cingulate Gyrus, posterior division", "31": "Precuneous Cortex", "32": "Cuneal Cortex", "33": "Frontal Orbital Cortex", "34": "Parahippocampal Gyrus, anterior division", "35": "Parahippocampal Gyrus, posterior division", "36": "Lingual Gyrus", "37": "Temporal Fusiform Cortex, anterior division", "38": "Temporal Fusiform Cortex, posterior division", "39": "Temporal Occipital Fusiform Cortex", "40": "Occipital Fusiform Gyrus", "41": "Frontal Opercular Cortex", "42": "Central Opercular Cortex", "43": "Parietal Opercular Cortex", "44": "Planum Polare", "45": "Heschl's Gyrus (includes H1 and H2)", "46": "Planum Temporale", "47": "Supracalcarine Cortex", "48": "Occipital Pole", "103": "Left Lateral Ventricle", "104": "Left Thalamus", "105": "Left Caudate", "106": "Left Putamen", "107": "Left Pallidum", "108": "Brain-Stem", "109": "Left Hippocampus", "110": "Left Amygdala", "111": "Left Accumbens", "114": "Right Lateral Ventricle", "115": "Right Thalamus", "116": "Right Caudate", "117": "Right Putamen", "118": "Right Pallidum", "119": "Right Hippocampus", "120": "Right Amygdala", "121": "Right Accumbens", "201": "Amygdala_centromedial group", "202": "Amygdala_laterobasal group", "203": "Amygdala_superficial group", "204": "Anterior intra-parietal sulcus hIP1", "205": "Anterior intra-parietal sulcus hIP2", "206": "Anterior intra-parietal sulcus hIP3", "207": "Broca's area BA44", "208": "Broca's area BA45", "209": "Hippocampus cornu ammonis", "210": "Hippocampus dentate gyrus", "211": "Hippocampus entorhinal cortex", "212": "Hippocampus hippocampal-amygdaloid transition area", "213": "Hippocampus subiculum", "214": "Inferior parietal lobule PF", "215": "Inferior parietal lobule PFcm", "216": "Inferior parietal lobule PFm", "217": "Inferior parietal lobule PFop", "218": "Inferior parietal lobule PFt", "219": "Inferior parietal lobule PGp", "220": "Inferior parietal lobule Pga", "221": "Insula Id1", "222": "Insula Ig1", "223": "Insula Ig2", "224": "Lateral geniculate body", "225": "Mamillary body", "226": "Medial geniculate body", "227": "Premotor cortex BA6", "228": "Primary auditory cortex TE1.0", "229": "Primary auditory cortex TE1.1", "230": "Primary auditory cortex TE1.2", "231": "Primary motor cortex BA4a", "232": "Primary motor cortex BA4p", "233": "Primary somatosensory cortex BA1", "234": "Primary somatosensory cortex BA2", "235": "Primary somatosensory cortex BA3a", "236": "Primary somatosensory cortex BA3b", "237": "Secondary somatosensory cortex / Parietal operculum OP1", "238": "Secondary somatosensory cortex / Parietal operculum OP2", "239": "Secondary somatosensory cortex / Parietal operculum OP3", "240": "Secondary somatosensory cortex / Parietal operculum OP4", "241": "Superior parietal lobule 5Ci", "242": "Superior parietal lobule 5L", "243": "Superior parietal lobule 5M", "244": "Superior parietal lobule 7A", "245": "Superior parietal lobule 7M", "246": "Superior parietal lobule 7P", "247": "Superior parietal lobule 7PC", "248": "Visual cortex V1 BA17", "249": "Visual cortex V2 BA18", "250": "Visual cortex V3V", "251": "Visual cortex V4", "252": "Visual cortex V5", "253": "WM: Acoustic radiation", "254": "WM: Callosal body", "255": "WM: Cingulum", "256": "WM: Corticospinal tract", "257": "WM: Fornix", "258": "WM: Inferior occipito-frontal fascicle", "259": "WM: Optic radiation", "260": "WM: Superior longitudinal fascicle", "261": "WM: Superior occipito-frontal fascicle", "262": "WM: Uncinate fascicle"}1["", "10159", "10292", "10306", "10307", "10308", "10311", "10313", "10327", "10329", "10330", "10331", "10332", "10333", "10334", "10335", "10336", "10337", "10338", "10339", "10342", "10343", "10344", "10346", "10349", "10361", "10383", "10384", "10389", "10390", "10465", "10466", "10467", "10595", "10596", "10597", "10598", "10599", "10600", "10602", "10648", "10649", "10650", "10651", "10653", "10654", "10655", "10656", "10657", "10658", "10659", "10660", "10661", "10662", "10669", "12114", "12115", "12116", "12117", "12118", "12119", "12121", "12122", "12123", "12124", "12125", "12126", "12127", "12132", "12133", "12136", "12137", "12138", "12140", "12142", "12143", "12144", "12145", "12146", "12147", "12148", "12149", "12150", "12151", "12152", "12153", "12154", "12155", "12156", "12157", "12158", "12159", "12160", "12162", "12163", "12164", "12165", "12166", "12170", "12171", "12173", "12174", "12176", "12177", "12178", "12179", "12181", "12195", "12291", "12292", "12305", "12330", "12354", "12369", "12384", "12390", "12405", "12416", "12535", "12538", "12805", "12826", "13229", "13230", "146034872", "146034876", "146034884", "146034888", "266441657"]123version https://git-lfs.github.com/spec/v1oid sha256:baecae7d26b1d76bace68d96f005b0dfc0e737dd83383345e819b669259b5af1size 113384123version https://git-lfs.github.com/spec/v1oid sha256:ab71af20799b4cefb9986791337fcb609105b4653141cde9285d486cbfaa4791size 101223
123version https://git-lfs.github.com/spec/v1oid sha256:5ef8fb7dace16f77b06b262e09dbbbd0070c21d5ac71e49b280a4af5e34fee2esize 1048576123version https://git-lfs.github.com/spec/v1oid sha256:2dc61d9b05f915dad3e8ade5e5d9e5f1df27983cbeaf34c0232010ab7e0008d7size 7812500
123version https://git-lfs.github.com/spec/v1oid sha256:34525f6bf4a68ac06f87801aa180b57cfea10c8c8559ea67d23d66ea54865109size 234375001{"grid":125,"axis_min":[-69.5,-104.5625,-54.25],"axis_max":[70.0625,76.09375,81.8125],"files":{"mean_xyz3":"mdn_particles_rdcim_teacher_edge_hq_grid125_mean_xyz3.bin","pi":"mdn_particles_rdcim_teacher_edge_hq_grid125_pi_xyz6.bin","entropy":"mdn_particles_rdcim_teacher_edge_hq_grid125_entropy.bin","mu1_xyz3":"mdn_particles_rdcim_teacher_edge_hq_grid125_mu1_xyz3.bin","mu2_xyz3":"mdn_particles_rdcim_teacher_edge_hq_grid125_mu2_xyz3.bin","mu3_xyz3":"mdn_particles_rdcim_teacher_edge_hq_grid125_mu3_xyz3.bin","mu4_xyz3":"mdn_particles_rdcim_teacher_edge_hq_grid125_mu4_xyz3.bin","mu5_xyz3":"mdn_particles_rdcim_teacher_edge_hq_grid125_mu5_xyz3.bin","mu6_xyz3":"mdn_particles_rdcim_teacher_edge_hq_grid125_mu6_xyz3.bin"},"dtype":"float32","layout":"C-order (x,y,z,3) for *_xyz3; (x,y,z,K) for pi_xyzK; (x,y,z) for entropy","endianness":"little","mixture_mean_field":true,"model":{"quality":"hq","components":6},"mdn_source":"particles/rdcim_teacher_edge","bounds_mode":"full_brain","mode":"field","notes":"Trained on teacher segments (XYZ→ΔS) with optional rDCM conditioning and ROI embeddings","training_points_npy":"mdn_particles_rdcim_teacher_edge_hq_training_points.npy"}123version https://git-lfs.github.com/spec/v1oid sha256:44c45d1ccd4c2afb936d7a4622493b1d363df9664f6ce53cb26cd5bd892b79e8size 23437500123version https://git-lfs.github.com/spec/v1oid sha256:2f1b9505a5ae611528425d57b09387e35dd921c20377a3b232a4267133b19bafsize 23437500123version https://git-lfs.github.com/spec/v1oid sha256:53b0999649dfccf31f8726695c4d5a738009f408389a16954144be89d2a58c87size 23437500123version https://git-lfs.github.com/spec/v1oid sha256:afd81e6a49823e2ddb42f8e4256f2bf58f268f5fbf83d95fbf0dc0f0eedef559size 23437500123version https://git-lfs.github.com/spec/v1oid sha256:68c1f5eceb934435f58ea77c3b623abb114256cfc23affaa2dba1a202139a4aasize 23437500123version https://git-lfs.github.com/spec/v1oid sha256:9827f9f7a923994c84e1a44773fc2fe88dd91fd7905e718083dc752d24a31f4dsize 23437500123version https://git-lfs.github.com/spec/v1oid sha256:ffb8a88b783e3a9aefeb8b7c14cd925769fcd3b4ef7d9ca029e4a8f71cd25265size 46875000123version https://git-lfs.github.com/spec/v1oid sha256:0f4ac819327e772ab01ed85b81150d2a28111df1ba4ebd9b2b3af200a011849bsize 14400128123version https://git-lfs.github.com/spec/v1oid sha256:4157011b84e35e0a861730baa16de6a97b40ca42b5a0001356760d02a4cddaefsize 3145728123version https://git-lfs.github.com/spec/v1oid sha256:03245194c13e6081c41f81bfafb018f9aa819af57642f1729d6830db236912cbsize 9316827
123version https://git-lfs.github.com/spec/v1oid sha256:0026eafd072ba11e02f3f4eab7f768ebcf89f32f5a0144fa38d8774576a1baffsize 13523828123version https://git-lfs.github.com/spec/v1oid sha256:89e07d4dc266bd9c69404da5b1ce8a1ea23dd2a41560e30f350b3c49a23e4c65size 13523828123version https://git-lfs.github.com/spec/v1oid sha256:8dd907bcc3ed5f654395b9b2bec702f2f00355d6e7a9d208e18e01766f2782ebsize 12090622123version https://git-lfs.github.com/spec/v1oid sha256:0e64c8f46eaa1c0d3fa269440687f9ff24b561567feaa7fdbb7f4d1aa259976fsize 3145728123version https://git-lfs.github.com/spec/v1oid sha256:c1432ccc092ed2e7b1495e506a11179420fcfb0919519824bb35329ee8171002size 3291242
123version https://git-lfs.github.com/spec/v1oid sha256:be09e3ec39b5cacb24af0e9f7d8e69086fd35853899daea7729bf7f048bb5c6dsize 1992516123version https://git-lfs.github.com/spec/v1oid sha256:aa7c48344b0af6f41f069450f319e9c360ef8b45fe8f36dded24cb45e7ba0aefsize 149484123version https://git-lfs.github.com/spec/v1oid sha256:2c4b4771c184c4512cfadef75b152e0bcbe9d816a62102d7b93349c967d0d955size 112083123version https://git-lfs.github.com/spec/v1oid sha256:aef8de5471788784415bdd77b44e5c532cabc79f5fc3f3c4be37e9dd6c5222e8size 112083123version https://git-lfs.github.com/spec/v1oid sha256:8a64ab89787f423cb3d4ac4e953a5fe056c4be9a7b3fe4738be529d14fac7b6bsize 12128123version https://git-lfs.github.com/spec/v1oid sha256:25a071fd3a955681fcd64f6d28fd917c921e9558b792f622649f93ebace11aa6size 19205
123version https://git-lfs.github.com/spec/v1oid sha256:83c6c01f3d02a6980403f340692930dbe47339c03784b4c6a41d6cc8bcf45dd2size 28542123version https://git-lfs.github.com/spec/v1oid sha256:6e94088b6a00b31e0077ecb75f28d21621f8b8f4ae1a033b76756713b66737fesize 57711123version https://git-lfs.github.com/spec/v1oid sha256:22a69c74d7c982a8372ac63c49df436bf8bc0fc1edb401710c4939c85fd9866fsize 48263123version https://git-lfs.github.com/spec/v1oid sha256:61602d7e56749544c6773467d7b8af22aa7788de7640de8c0b18e6fc9630239asize 48263123version https://git-lfs.github.com/spec/v1oid sha256:f145efd0531e791a5f2059f89a4c649a83b12ffee4bd06648569cc36396bbd3csize 17345123version https://git-lfs.github.com/spec/v1oid sha256:8d96c21416298bac87134b1f41f762ac122854cd66a93f53bd97a8d833f7b99csize 36168123version https://git-lfs.github.com/spec/v1oid sha256:1e092fe926797259b4568d792ea0439daf36297ab5c9946a689892abe4c3b9aasize 1853173123version https://git-lfs.github.com/spec/v1oid sha256:c5030b54f80cad2316a5cc57db2649ac44e38d31d61677bda1710ebb29e1418fsize 1027691123version https://git-lfs.github.com/spec/v1oid sha256:df7e6a6ae97116b644f5090984b56ddcf5da574b5387c22bb8c554f9fff089cesize 949235123version https://git-lfs.github.com/spec/v1oid sha256:a16d8d4d1fcb2cc0ac4be610e5f200c6efd910b3de982492432f563c39f6c2b9size 498360123version https://git-lfs.github.com/spec/v1oid sha256:6f4c64f991bb22248463cf2415ab33c6cf89235bb85fa26425672958c6362708size 225016123version https://git-lfs.github.com/spec/v1oid sha256:88b46eb320fe5c91aa1da562277d436caaabace45b0547a1b0d71e13cfa86d81size 157144123version https://git-lfs.github.com/spec/v1oid sha256:f60b0f68b013cfca7c50fc2afd63db26e64098d8e6476990d7cbc339613d68ebsize 162134123version https://git-lfs.github.com/spec/v1oid sha256:0a913a6bd57ddc20209c2a7d0c873705c234eb0f116ae0dfbb7fa88a7074d017size 374785123version https://git-lfs.github.com/spec/v1oid sha256:0521f9f55fd1c10d2d9560fff80cb2385a6a9fab003bea1c524e4db1a154bcbbsize 74905123version https://git-lfs.github.com/spec/v1oid sha256:0864087632dbee936a66dd7d0ab48f208db7fc57118bdef6a1b37e0dbe38b162size 142593123version https://git-lfs.github.com/spec/v1oid sha256:8c02b9faf662b97b9275ec64a0da4818c28d5c60f0c7299b0f02212b1f0cf2easize 121130123version https://git-lfs.github.com/spec/v1oid sha256:bf6753d2b9f64cd0f2d6aa8202d6bcdddea7faf10fc4daf6e7c30892c89a2c45size 53546123version https://git-lfs.github.com/spec/v1oid sha256:2af0bc2a2c14637a896b13b5ccee911dd9f0d214353ed87aaebbe4b686cdc3d0size 396936.gitattributes+3-32
.gitignoreAdded+4
README.md+3-46
app.py+157-110
mindVisualizer/data/brain_alignment.jsonAdded+28
mindVisualizer/data/extra_parcellation/README.mdAdded+53
mindVisualizer/data/roi_flow/mdn_training_all_points.npy → mindVisualizer/data/extra_parcellation/combined_atlas.nii.gzRenamed+2-2
mindVisualizer/data/extra_parcellation/combined_atlas_labels.jsonAdded+129
mindVisualizer/data/label_grid_cache.keys.jsonAdded+1
mindVisualizer/data/roi_flow/probe_embed.npy → mindVisualizer/data/label_grid_cache.npzRenamed+2-2
mindVisualizer/data/roi_flow/mdn_universal_all_grid64_entropy.bin → mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_entropy.binRenamed+2-2
mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_mean_xyz3.binAdded+3
mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_meta.jsonAdded+1
mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_mu1_xyz3.binAdded+3
mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_mu2_xyz3.binAdded+3
mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_mu3_xyz3.binAdded+3
mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_mu4_xyz3.binAdded+3
mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_mu5_xyz3.binAdded+3
mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_mu6_xyz3.binAdded+3
mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_grid125_pi_xyz6.binAdded+3
mindVisualizer/data/mdn/mdn_particles_rdcim_teacher_edge_hq_training_points.npyAdded+3
mindVisualizer/data/roi_flow/mdn_universal_all_grid64_mean_xyz3.bin → mindVisualizer/data/meshes_obj/10153.objRenamed+2-2
mindVisualizer/data/meshes_obj/10154.objAdded+3
mindVisualizer/data/meshes_obj/10155.objAdded+3
mindVisualizer/data/meshes_obj/10156.objAdded+3
mindVisualizer/data/roi_flow/mdn_universal_all_grid64_mu1_xyz3.bin → mindVisualizer/data/meshes_obj/10157.objRenamed+2-2
mindVisualizer/data/meshes_obj/10158.objAdded+3
mindVisualizer/data/meshes_obj/10159.objAdded+3
mindVisualizer/data/meshes_obj/10292.objAdded+3
mindVisualizer/data/meshes_obj/10306.objAdded+3
mindVisualizer/data/roi_flow/probe_roi_centers.npy → mindVisualizer/data/meshes_obj/10307.objRenamed+2-2
mindVisualizer/data/meshes_obj/10308.objAdded+3
mindVisualizer/data/meshes_obj/10311.objAdded+3
mindVisualizer/data/meshes_obj/10313.objAdded+3
mindVisualizer/data/meshes_obj/10327.objAdded+3
mindVisualizer/data/meshes_obj/10329.objAdded+3
mindVisualizer/data/meshes_obj/10330.objAdded+3
mindVisualizer/data/meshes_obj/10331.objAdded+3
mindVisualizer/data/meshes_obj/10332.objAdded+3
mindVisualizer/data/meshes_obj/10333.objAdded+3
mindVisualizer/data/meshes_obj/10334.objAdded+3
mindVisualizer/data/meshes_obj/10335.objAdded+3
mindVisualizer/data/meshes_obj/10336.objAdded+3
mindVisualizer/data/meshes_obj/10337.objAdded+3
mindVisualizer/data/meshes_obj/10338.objAdded+3
mindVisualizer/data/meshes_obj/10339.objAdded+3
mindVisualizer/data/meshes_obj/10342.objAdded+3
mindVisualizer/data/meshes_obj/10343.objAdded+3
mindVisualizer/data/meshes_obj/10344.objAdded+3
mindVisualizer/data/meshes_obj/10346.objAdded+3