nilearn
tit.plotting.nilearn ¶
Nilearn-based plotting helpers for TI-Toolbox.
This package provides neuroimaging visualization utilities built on
nilearn <https://nilearn.github.io/>_, including multi-slice PDF
exports, glass-brain PNG exports, and interactive HTML surface views.
Public API¶
NilearnVisualizer High-level class combining PDF, HTML, and glass-brain workflows. create_pdf_entry_point / create_pdf_entry_point_group CLI-oriented helpers for multi-slice PDF generation. create_glass_brain_entry_point / create_glass_brain_entry_point_group CLI-oriented helpers for glass-brain PNG generation. create_html_entry_point CLI-oriented helper for interactive HTML surface reports.
See Also¶
tit.plotting.ti_metrics : TI-specific metric plots (histograms, scatter). tit.blender : Blender-based 3-D visualizations.
NilearnVisualizer ¶
NilearnVisualizer(subject_id: str | None = None)
Main visualization class for electric field distributions.
Provides methods for creating both static PDF visualizations and interactive HTML plots. Uses PathManager for consistent path handling and supports multiple atlas overlays.
Parameters¶
subject_id : str or None, optional Subject identifier. When None, PathManager auto-detection is used instead.
Attributes¶
pm : PathManager Resolved path-manager instance. subject_id : str or None Subject identifier passed at construction time. output_dir : str Directory where visualizations are saved.
See Also¶
tit.plotting.nilearn.img_slices : Convenience entry-points for PDF creation. tit.plotting.nilearn.img_glass : Convenience entry-points for glass-brain PNGs. tit.plotting.nilearn.html_report : Convenience entry-point for HTML reports.
Create a new visualizer instance.
Parameters¶
subject_id : str or None, optional Subject identifier. When None, PathManager auto-detection is used instead.
Source code in tit/plotting/nilearn/visualizer.py
create_pdf_visualization ¶
create_pdf_visualization(subject_id: str, simulation_name: str, min_cutoff: float = 0.3, max_cutoff: float = None, atlas_name: str = 'harvard_oxford_sub', selected_regions: list[int] | None = None) -> str | None
Create a multi-slice PDF with atlas contours for a single subject.
Generates sagittal, coronal, and axial slice rows with the electric field overlaid as a hot colormap and optional atlas contour lines.
Parameters¶
subject_id : str
Subject identifier (e.g. '070').
simulation_name : str
Name of the simulation folder.
min_cutoff : float, optional
Lower display threshold in V/m. Default is 0.3.
max_cutoff : float or None, optional
Upper display threshold in V/m. When None the 99.9th
percentile of non-zero voxels is used.
atlas_name : str, optional
Nilearn atlas key. One of 'harvard_oxford',
'harvard_oxford_sub', 'aal', 'schaefer_2018'.
selected_regions : list of int or None, optional
0-indexed region indices to include in the atlas overlay.
When None, all regions are shown.
Returns¶
str or None Path to the saved PDF, or None on failure.
Source code in tit/plotting/nilearn/visualizer.py
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 | |
create_html_visualization ¶
create_html_visualization(subject_id: str, simulation_name: str, min_cutoff: float = 0.3) -> str | None
Create an interactive HTML surface visualization.
Uses nilearn.plotting.view_img_on_surf to project the
electric-field map onto the cortical surface and saves the result
as a self-contained HTML file.
Parameters¶
subject_id : str
Subject identifier.
simulation_name : str
Name of the simulation folder.
min_cutoff : float, optional
Lower display threshold in V/m. Default is 0.3.
Returns¶
str or None Path to the saved HTML file, or None on failure.
Source code in tit/plotting/nilearn/visualizer.py
create_pdf_visualization_group ¶
create_pdf_visualization_group(averaged_img, base_filename: str, output_dir: str, min_cutoff: float = 0.3, max_cutoff: float = None, atlas_name: str = 'harvard_oxford_sub', selected_regions: list[int] | None = None) -> str | None
Create a multi-slice PDF from a pre-averaged group NIfTI image.
Identical layout to :meth:create_pdf_visualization but accepts
an already-averaged nibabel.Nifti1Image instead of looking up
a per-subject simulation file.
Parameters¶
averaged_img : nibabel.Nifti1Image
Pre-averaged electric-field image.
base_filename : str
Base filename for output (without extension).
output_dir : str
Directory where the PDF will be saved.
min_cutoff : float, optional
Lower display threshold in V/m. Default is 0.3.
max_cutoff : float or None, optional
Upper display threshold in V/m. When None the 99.9th
percentile of non-zero voxels is used.
atlas_name : str, optional
Nilearn atlas key.
selected_regions : list of int or None, optional
0-indexed region indices for the atlas overlay.
Returns¶
str or None Path to the saved PDF, or None on failure.
Source code in tit/plotting/nilearn/visualizer.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | |
create_glass_brain_visualization ¶
create_glass_brain_visualization(subject_id: str, simulation_name: str, min_cutoff: float = 0.3, max_cutoff: float = None, cmap: str = 'hot') -> str | None
Create a glass-brain PNG for a single subject simulation.
Uses nilearn.plotting.plot_glass_brain to render a
maximum-intensity projection of the electric-field map.
Parameters¶
subject_id : str
Subject identifier.
simulation_name : str
Name of the simulation folder.
min_cutoff : float, optional
Lower display threshold in V/m. Default is 0.3.
max_cutoff : float or None, optional
Upper display threshold in V/m. When None the 99.9th
percentile of non-zero voxels is used.
cmap : str, optional
Matplotlib colormap name. Default is 'hot'.
Returns¶
str or None Path to the saved PNG file, or None on failure.
Source code in tit/plotting/nilearn/visualizer.py
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | |
create_pdf_entry_point ¶
create_pdf_entry_point(subject_id: str, simulation_name: str, min_cutoff: float = 0.3, max_cutoff: float = None, atlas_name: str = 'harvard_oxford_sub', selected_regions: list = None, output_callback=None)
Entry point for PDF visualization creation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject_id
|
str
|
Subject ID |
required |
simulation_name
|
str
|
Simulation name |
required |
min_cutoff
|
float
|
Minimum cutoff for visualization (V/m) |
0.3
|
max_cutoff
|
float
|
Maximum cutoff for visualization (V/m), if None uses 99.9th percentile |
None
|
atlas_name
|
str
|
Atlas name for contours |
'harvard_oxford_sub'
|
selected_regions
|
list
|
List of region indices to include (0-indexed), if None includes all |
None
|
output_callback
|
Optional callback function for output (for GUI integration) |
None
|
Source code in tit/plotting/nilearn/img_slices.py
create_pdf_entry_point_group ¶
create_pdf_entry_point_group(averaged_img, base_filename: str, output_dir: str, min_cutoff: float = 0.3, max_cutoff: float = None, atlas_name: str = 'harvard_oxford_sub', selected_regions: list = None, output_callback=None)
Entry point for PDF visualization creation with pre-averaged nifti data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
averaged_img
|
Pre-averaged nibabel Nifti1Image |
required | |
base_filename
|
str
|
Base filename for output (without extension) |
required |
output_dir
|
str
|
Output directory path |
required |
min_cutoff
|
float
|
Minimum cutoff for visualization (V/m) |
0.3
|
max_cutoff
|
float
|
Maximum cutoff for visualization (V/m), if None uses 99.9th percentile |
None
|
atlas_name
|
str
|
Atlas name for contours |
'harvard_oxford_sub'
|
selected_regions
|
list
|
List of region indices to include (0-indexed), if None includes all |
None
|
output_callback
|
Optional callback function for output (for GUI integration) |
None
|
Source code in tit/plotting/nilearn/img_slices.py
create_glass_brain_entry_point ¶
create_glass_brain_entry_point(subject_id: str, simulation_name: str, min_cutoff: float = 0.3, max_cutoff: float = None, cmap: str = 'hot', output_callback=None)
Entry point for glass brain visualization creation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject_id
|
str
|
Subject ID |
required |
simulation_name
|
str
|
Simulation name |
required |
min_cutoff
|
float
|
Minimum cutoff for visualization (V/m) |
0.3
|
max_cutoff
|
float
|
Maximum cutoff for visualization (V/m), if None uses 99.9th percentile |
None
|
cmap
|
str
|
Colormap name for visualization |
'hot'
|
output_callback
|
Optional callback function for output (for GUI integration) |
None
|
Source code in tit/plotting/nilearn/img_glass.py
create_glass_brain_entry_point_group ¶
create_glass_brain_entry_point_group(averaged_img, base_filename: str, output_dir: str, min_cutoff: float = 0.3, max_cutoff: float = None, cmap: str = 'hot', output_callback=None)
Entry point for glass brain visualization creation with pre-averaged nifti data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
averaged_img
|
Pre-averaged nibabel Nifti1Image |
required | |
base_filename
|
str
|
Base filename for output (without extension) |
required |
output_dir
|
str
|
Output directory path |
required |
min_cutoff
|
float
|
Minimum cutoff for visualization (V/m) |
0.3
|
max_cutoff
|
float
|
Maximum cutoff for visualization (V/m), if None uses 99.9th percentile |
None
|
cmap
|
str
|
Colormap name for visualization |
'hot'
|
output_callback
|
Optional callback function for output (for GUI integration) |
None
|
Source code in tit/plotting/nilearn/img_glass.py
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 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 | |
create_html_entry_point ¶
Entry point for HTML visualization creation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject_id
|
str
|
Subject ID |
required |
simulation_name
|
str
|
Simulation name |
required |
min_cutoff
|
float
|
Minimum cutoff for visualization (V/m) |
0.3
|
Source code in tit/plotting/nilearn/html_report.py
render_fsaverage_map ¶
render_fsaverage_map(values, spacing: int = 5, *, title: str | None = None, threshold: float | None = None, cmap: str = 'cold_hot', symmetric_cbar: bool | str = 'auto', out_path: str | None = None)
Paint a (n_vertices,) fsaverage map on the inflated cortex.
Parameters¶
values : array-like
Per-vertex values in [lh; rh] order, length _FSAVG_NODES[spacing].
spacing : int
fsaverage subdivision factor (5, 6, or 7).
title : str, optional
Figure suptitle.
threshold : float, optional
Hide |value| < threshold (e.g. to show only significant vertices).
cmap : str
Matplotlib/nilearn colormap. cold_hot suits signed t/r maps;
use a sequential map (e.g. "inferno") for magnitude fields.
symmetric_cbar : bool or "auto"
Passed to nilearn; keep signed maps symmetric about zero.
out_path : str, optional
If given, save the figure there and return the path; else return the
Matplotlib figure.
Returns¶
str or matplotlib.figure.Figure The saved path (when out_path is given) or the figure.
Source code in tit/plotting/nilearn/surface.py
render_surface_stats_result ¶
Render a :mod:tit.stats.surface surface_maps.npz to PDFs.
Paints the effect map (signed r if present, else t) and the
thresholded significant-cluster mask onto the inflated cortex. spacing is
inferred from the array length when not given.
Returns¶
list of str Paths of the figures written into out_dir.