gsp1000
lacuna.utils.gsp1000
¶
Utilities for working with GSP1000 connectome data.
This module provides functions to convert GSP1000 functional data into optimized HDF5 batch files for efficient lesion network mapping.
create_connectome_batches(gsp_dir, mask_path, output_dir, subjects_per_batch=50, pattern='sub-*/func/*bld001_rest_*_finalmask.nii.gz', verbose=False)
¶
Create HDF5 batch files from GSP1000 functional data.
Scans a directory of functional NIfTI files, extracts time-series from within a brain mask, and saves the data into multiple smaller HDF5 batch files optimized for memory-efficient lesion network mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gsp_dir
|
str or Path
|
Directory containing GSP1000 subject functional data. Expected structure: sub-/func/bld001_rest_*_finalmask.nii.gz |
required |
mask_path
|
str or Path
|
Path to brain mask NIfTI file (e.g., MNI152_T1_2mm_Brain_Mask.nii.gz). Defines which voxels to extract. |
required |
output_dir
|
str or Path
|
Directory where HDF5 batch files will be saved. |
required |
subjects_per_batch
|
int
|
Number of subjects to include in each batch file. Larger batches = fewer files but more memory per batch. |
50
|
pattern
|
str
|
Glob pattern to find functional files within gsp_dir. Default matches standard GSP1000 structure. |
'sub-*/func/*bld001_rest_*_finalmask.nii.gz'
|
verbose
|
bool
|
Print progress information. |
True
|
Returns:
| Type | Description |
|---|---|
list of Path
|
Paths to created HDF5 batch files, sorted by name. |
Notes
Each HDF5 batch file contains: - 'timeseries': (n_subjects, n_timepoints, n_voxels) float32 array - 'mask_indices': (3, n_voxels) array of mask coordinates - 'mask_affine': (4, 4) affine transformation matrix - Attributes: n_subjects, n_timepoints, n_voxels, mask_shape
The batch files are designed for sequential loading during analysis, minimizing memory footprint while maintaining processing speed.
Examples:
>>> from lacuna.utils.gsp1000 import create_connectome_batches
>>> batch_files = create_connectome_batches(
... gsp_dir="/data/GSP1000",
... mask_path="/data/MNI152_T1_2mm_Brain_Mask.nii.gz",
... output_dir="/data/connectomes/gsp1000_batches",
... subjects_per_batch=100
... )
>>> print(f"Created {len(batch_files)} batch files")
Source code in src/lacuna/utils/gsp1000.py
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 87 88 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 125 126 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 170 171 | |
validate_connectome_batches(batch_dir, verbose=False)
¶
Validate integrity of HDF5 connectome batch files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_dir
|
str or Path
|
Directory containing HDF5 batch files. |
required |
verbose
|
bool
|
Print validation results. |
True
|
Returns:
| Type | Description |
|---|---|
dict
|
Validation summary with keys: n_batches, total_subjects, n_timepoints, n_voxels, mask_shape, consistent, errors |
Source code in src/lacuna/utils/gsp1000.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |