group
tit.analyzer.group ¶
Multi-subject group analysis.
Runs per-subject ROI analyses in-process via :class:Analyzer, aggregates the
results into a summary CSV with an AVERAGE row, and produces a 2x2 comparison
bar-chart saved as PDF.
Public API¶
GroupResult Container for multi-subject group analysis outcomes. run_group_analysis Run the same ROI analysis across multiple subjects and summarise.
See Also¶
tit.analyzer.analyzer : Single-subject analyzer used per-subject.
GroupResult
dataclass
¶
GroupResult(subject_results: dict[str, AnalysisResult], summary_csv_path: Path, comparison_plot_path: Path | None)
Outcome of a multi-subject group analysis.
Attributes¶
subject_results : dict of str to AnalysisResult
Mapping of subject ID to its
:class:~tit.analyzer.analyzer.AnalysisResult.
summary_csv_path : pathlib.Path
Path to the summary CSV (one row per subject plus an AVERAGE row).
comparison_plot_path : pathlib.Path or None
Path to the 2x2 comparison bar-chart PDF, or None if plotting
failed.
See Also¶
run_group_analysis : Factory function that produces this result. AnalysisResult : Per-subject analysis container.
run_group_analysis ¶
run_group_analysis(subject_ids: list[str], simulation: str, space: str = 'mesh', tissue_type: str = 'GM', analysis_type: str = 'spherical', center: tuple[float, float, float] | None = None, radius: float | None = None, coordinate_space: str = 'subject', spheres: Sequence[tuple[float, float, float, float]] | None = None, atlas: str | None = None, region: str | list[str] | None = None, visualize: bool = False, output_dir: str | Path | None = None, field: str | None = None, mask_path: str | None = None) -> GroupResult
Run the same ROI analysis across multiple subjects and summarise.
Dispatches to analyze_sphere or analyze_cortex on each subject,
builds a summary CSV (with an AVERAGE row), and generates a 2x2
comparison bar-chart PDF.
Parameters¶
subject_ids : list of str
Subject identifiers (without sub- prefix).
simulation : str
Simulation (montage) folder name, shared by all subjects.
space : str, optional
"mesh" or "voxel". Default "mesh".
tissue_type : str, optional
"GM", "WM", or "both" (voxel only). Default "GM".
analysis_type : str, optional
"spherical", "cortical", "subcortical" or "mask".
Default "spherical".
center : tuple of float or None, optional
(x, y, z) sphere centre; required when analysis_type is
"spherical".
radius : float or None, optional
Sphere radius in mm; required when analysis_type is
"spherical".
coordinate_space : str, optional
"subject" or "MNI" (spherical, subcortical and mask): the
space of the sphere centre, the volume atlas or the mask. Default
"subject"; a group spherical or mask analysis requires "MNI"
(one target for every subject).
spheres : sequence of tuple of float or None, optional
One (x, y, z, r) per sphere, unioned into a single ROI
(spherical only). Takes precedence over center/radius.
atlas : str or None, optional
Atlas name (cortical and subcortical).
region : str, list of str, or None, optional
Region name or list of region names (cortical and subcortical).
visualize : bool, optional
Generate per-subject visualization artifacts. Default False.
output_dir : str, pathlib.Path, or None, optional
Override output directory. If None, each run writes to its own
derivatives/ti-toolbox/group_analysis/<simulation>_<space>_<target>[_<field>][_<tissue>]_<timestamp>/
(the field and tissue suffixes as :func:group_run_name adds them; a second
run of the same name started in the same second gets _2, _3, ...). The
per-subject analyses always go to each subject's own default folder.
field : str or None, optional
Field to analyze (constants.FIELD_REGISTRY name, e.g.
"TI_max", "TI_normal", "hf_peak"). Default None
resolves the TI_max/mTI_max envelope per subject.
mask_path : str or None, optional
MNI-space NIfTI mask (analysis_type="mask" only).
Returns¶
GroupResult
Per-subject results, the summary CSV path
(group_summary.csv), and the comparison plot path.
Raises¶
KeyError
If analysis_type is not "spherical", "cortical",
"subcortical" or "mask"; or if a subject's atlas lacks a
region, and then the message starts with sub-<id>:.
ValueError
If coordinate_space is not "subject"/"MNI"; if
analysis_type="mask" or "spherical" with a non-MNI
coordinate_space, or an unreadable mask_path; if a sphere is
missing or lacks a finite centre or a positive, finite radius
(checked once, before any subject); or if a
subject's analysis is refused (for example its ROI is empty), and
then the message starts with sub-<id>:.
FileNotFoundError
If a subject has no field file for simulation in space.
Examples¶
from tit.analyzer import run_group_analysis res = run_group_analysis( ... subject_ids=["ernie", "101"], simulation="L_Insula", space="voxel", ... analysis_type="spherical", center=(-35.0, 5.0, 5.0), radius=10.0, ... coordinate_space="MNI", ... ) # doctest: +SKIP res.summary_csv_path.name, sorted(res.subject_results) # doctest: +SKIP ('group_summary.csv', ['101', 'ernie']) run_group_analysis(["ernie", "101"], "L_Insula", space="mesh", ... analysis_type="cortical", atlas="DK40", ... region="lh.insula") # doctest: +SKIP
See Also¶
Analyzer : Single-subject analyzer used internally per subject. GroupResult : Container for the returned outcomes.
Source code in tit/analyzer/group.py
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 172 173 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 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
group_run_name ¶
group_run_name(simulation: str, space: str, analysis_type: str, *, center=None, radius=None, coordinate_space: str = 'subject', spheres=None, region=None, mask_path=None, field: str | None = None, tissue_type: str | None = None) -> str
<simulation>_<space>_<target>[_<field>][_<tissue>]: what a group run is named by.
The target as :func:_target_label words it, then the field and tissue the way an
analysis folder carries them (:meth:PathManager.analysis_variant_suffix), so a
TI_max and an hf_peak run of one ROI are told apart by name too.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
str
|
Simulation folder name shared by the subjects. |
required |
space
|
str
|
|
required |
analysis_type
|
str
|
|
required |
center
|
Sphere centre |
None
|
|
radius
|
Sphere radius in mm (spherical). |
None
|
|
coordinate_space
|
str
|
|
'subject'
|
spheres
|
One |
None
|
|
region
|
Region name or names (cortical, subcortical). |
None
|
|
mask_path
|
Mask file (mask). |
None
|
|
field
|
str | None
|
The analysed field; |
None
|
tissue_type
|
str | None
|
Voxel tissue; |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The run name, before :func: |
str
|
stamps it, e.g. |
Source code in tit/analyzer/group.py
group_output_dir ¶
The folder a group run writes its summary into (not created).
Shared with the plan, which previews the folder a run started now would name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str | Path | None
|
The run's explicit output folder, used verbatim when set. |
required |
run_name
|
str
|
:func: |
required |
stamp
|
str | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
str
|
output_dir, or |