projection API
yabplot.projection.project_vol2surf(nii_path, bmesh='midthickness', mask_medial_wall=True, interpolation='linear')
Projects a 3D NIfTI volume onto 2D cortical surface vertices.
It maps volumetric data directly onto surface meshes by converting real-world coordinates using the image affine and sampling the data array at those exact points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nii_path
|
str
|
absolute path to the 3D or 4D NIfTI volume. if 4D, only the first volume/timepoint is used. |
required |
bmesh
|
str, dict, or pyvista.PolyData
|
background mesh to use for projection coordinates. accepts a standard string (e.g., 'midthickness') or a dictionary of custom pyvista meshes {'L': mesh, 'R': mesh}. default is 'midthickness'. |
'midthickness'
|
mask_medial_wall
|
bool
|
whether to automatically set the medial wall vertices to NaN to prevent
subcortical signal from bleeding onto the cortical surface.
Note: only supported if |
True
|
interpolation
|
(linear, nearest)
|
interpolation method for sampling the volume. 'linear' performs trilinear interpolation (smoother, good for continuous t-stats), while 'nearest' snaps to the closest voxel center (strictly required for p-values or atlases). default is 'linear'. |
'linear'
|
Returns:
| Name | Type | Description |
|---|---|---|
lh_data |
ndarray
|
1D array of projected values for the left hemisphere vertices. |
rh_data |
ndarray
|
1D array of projected values for the right hemisphere vertices. |
Source code in yabplot/projection.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
yabplot.projection.project_vol2tract_atlas(nii_path, atlas='xtract_tiny', custom_atlas_path=None, interpolation='linear')
Samples a 3D volume across all tracts in a specific atlas.
This is a convenience function around project_vol2tract that automatically
resolves the atlas paths, loops through all available tractograms, and returns
a dictionary ready to be passed directly to plot_tracts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nii_path
|
str
|
absolute path to the 3D nifti volume (e.g., FA or MD map). |
required |
atlas
|
str
|
name of the standard tract atlas. default is 'xtract_tiny'. |
'xtract_tiny'
|
custom_atlas_path
|
str
|
path to a custom directory of .trk files. |
None
|
interpolation
|
(linear, nearest)
|
trilinear interpolation (default) blends nearby voxels for a smooth map. |
'linear'
|
Returns:
| Type | Description |
|---|---|
dict
|
dictionary mapping tract names to their 1D sampled data arrays. |
Source code in yabplot/projection.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
yabplot.projection.project_vol2tract(trk_path, nii_path, interpolation='linear')
Samples a 3D volume natively at every vertex of a tractogram. Maps the streamline coordinates directly into the volumetric voxel space using the image affine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trk_path
|
str
|
absolute path to the .trk or .tck tractography file. |
required |
nii_path
|
str
|
absolute path to the 3D nifti volume (e.g., FA or MD map). |
required |
interpolation
|
(linear, nearest)
|
trilinear interpolation (default) blends nearby voxels for a smooth map. |
'linear'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
1D array of sampled values corresponding exactly to the flattened points of the tractogram, ready to be injected into plot_tracts. |
Source code in yabplot/projection.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |