ENH Visualize HCP fs_LR 32k data and resample to fsaverage (cortex.hcp)#655
ENH Visualize HCP fs_LR 32k data and resample to fsaverage (cortex.hcp)#655mvdoc wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new hcp module to interface with HCP fs_LR 32k data, allowing direct visualization and resampling to fsaverage using spherical barycentric interpolation. It also refactors the Freesurfer surface-to-surface mapping to use a direct geometry-based implementation instead of the previous regression-based approach, alongside formatting cleanups and new tests. The review feedback suggests enhancing the robustness of the new HCP functions by supporting arbitrary leading dimensions (N-D arrays) for timeseries data, adding shape validation, and accepting standard hemisphere names ('lh'/'rh') alongside 'L'/'R'.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Add a `cortex.hcp` module for working with HCP fs_LR 32k data in pycortex: - download_fs_lr(): fetch the prebuilt 32k_fs_LR pycortex subject (registered with download_subject) for native fs_LR rendering. - cifti_to_surface()/get_cifti_vertex_indices(): expand CIFTI cortical grayordinates to the full 64984-vertex fs_LR surface (NaN medial wall); supports N-D inputs and hemispherically split files. - project_fslr_to_fsaverage()/to_fsaverage(): resample fs_LR 32k data to fsaverage5/6/fsaverage via a pure-python spherical-barycentric matrix built from the HCP standard-mesh spheres. Matches `wb_command -metric-resample ... BARYCENTRIC`, so Connectome Workbench is not required at runtime. Also make upsample_to_fsaverage() FreeSurfer-free for the common cases: the per-vertex nearest-neighbor mapping is a fixed property of the fsaverage tessellation, so ship precomputed neighbor tables for fsaverage5/6 (0.68 MB) and fall back to computing from the sphere (and caching) for other orders. Output is numerically identical to the previous sphere-based implementation. Add examples/hcp/plot_hcp_fs_lr.py (renders both the native and the resampled flatmaps) and tests in cortex/tests/test_hcp.py plus FreeSurfer-free upsample_to_fsaverage tests. Also fixes a pre-existing "Unkown" typo in utils.get_cmap flagged by codespell. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019z37ML4wsmosg5Xvvq6ENN
28ae968 to
8adc530
Compare
Adds a
cortex.hcpmodule to visualize HCP fs_LR 32k data with pycortex — natively on the HCP template and resampled to fsaverage.What's new
cortex.hcpdownload_fs_lr()— fetch the prebuilt32k_fs_LRpycortex subject (registered withdownload_subject) for native fs_LR rendering via the usualcortex.Vertex(...)/quickshowpath.cifti_to_surface()/get_cifti_vertex_indices()— expand CIFTI cortical grayordinates (59412) to the full 64984-vertex fs_LR surface, NaN medial wall (tolerates hemispherically split files).project_fslr_to_fsaverage()/to_fsaverage()— resample fs_LR 32k data to fsaverage5/6/fsaverage using a pure-python spherical-barycentric matrix built from the HCP standard-mesh spheres. This matcheswb_command -metric-resample ... BARYCENTRIC, so Connectome Workbench is not required at runtime.FreeSurfer-free
upsample_to_fsaveragecortex/data/upsample_fsaverage_neighbors.npz, 0.68 MB), with a compute-from-sphere (+cache) fallback for other orders. Output is numerically identical to the previous implementation;$SUBJECTS_DIRis no longer needed for the common cases.Example + tests
examples/hcp/plot_hcp_fs_lr.pyrenders both the native and the resampled flatmaps (runs on CI with no FreeSurfer).cortex/tests/test_hcp.py(barycentric matrix math, CIFTI expansion,wb_commandvalidation when available) and new FreeSurfer-freeupsample_to_fsaveragetests.Notes
32k_fs_LRsubject is derived from HCP S1200 group-average Open Access surfaces and redistributed under the WU-Minn HCP Consortium Open Access Data Use Terms (with the required acknowledgment); its download URL is registered indownload_subject..npzships in the built wheel and loads from the installed package.🤖 Generated with Claude Code
https://claude.ai/code/session_019z37ML4wsmosg5Xvvq6ENN