visualizer
tit.plotting.nilearn.visualizer ¶
TI-Toolbox Visualization Module Provides comprehensive visualization tools for electric field distributions from TES simulations.
Features: 1. Multiple surface views (lateral, medial, left/right hemispheres) saved as high-res PDF 2. Interactive 3D visualization saved as HTML using plotly 3. Atlas contour overlays for anatomical context 4. Support for both subject-specific and MNI space visualizations
Based on: https://nilearn.github.io/dev/auto_examples/01_plotting/plot_3d_map_to_surface_projection.html
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
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 | |
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
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 531 532 | |
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
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 622 623 | |
glass_brain_to_base64
staticmethod
¶
glass_brain_to_base64(nifti_path: str, title: str = 'Electric Field', min_cutoff: float = 0.1, max_cutoff: float | None = None, cmap: str = 'hot') -> str | None
Render a glass-brain PNG and return it as a base64 string.
Intended for embedding in HTML reports via
ImageReportlet.set_base64_data().
Parameters¶
nifti_path : str Path to a NIfTI file (e.g. TI_max volume). title : str, optional Title text rendered on the figure. min_cutoff : float, optional Lower display threshold in V/m. max_cutoff : float or None, optional Upper display threshold. Defaults to the 99.9th percentile. cmap : str, optional Matplotlib colormap name.
Returns¶
str or None Base64-encoded PNG string, or None on failure.
Source code in tit/plotting/nilearn/visualizer.py
multi_slice_to_base64
staticmethod
¶
multi_slice_to_base64(nifti_path: str, title: str = 'Electric Field', min_cutoff: float = 0.1, max_cutoff: float | None = None) -> str | None
Render a multi-slice overview and return it as a base64 string.
Creates a compact 3-row (sagittal / coronal / axial) x 5-column slice grid suitable for embedding in HTML reports.
Parameters¶
nifti_path : str Path to a NIfTI file. title : str, optional Title text rendered on the figure. min_cutoff : float, optional Lower display threshold in V/m. max_cutoff : float or None, optional Upper display threshold. Defaults to the 99.9th percentile.
Returns¶
str or None Base64-encoded PNG string, or None on failure.
Source code in tit/plotting/nilearn/visualizer.py
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 | |
interactive_volume_to_html
staticmethod
¶
interactive_volume_to_html(nifti_path: str, title: str = 'Electric Field', min_cutoff: float = 0.1, max_cutoff: float | None = None, cmap: str = 'hot') -> str | None
Render an interactive volumetric stat-map viewer as HTML.
Uses nilearn.plotting.view_img to create an interactive
slice-based viewer suitable for embedding in HTML reports.
Parameters¶
nifti_path : str Path to a NIfTI file. title : str, optional Title text for the viewer. min_cutoff : float, optional Lower display threshold in V/m. max_cutoff : float or None, optional Upper display threshold. Defaults to the 99.9th percentile. cmap : str, optional Matplotlib colormap name.
Returns¶
str or None HTML string for embedding, or None on failure.
Source code in tit/plotting/nilearn/visualizer.py
interactive_surface_to_html
staticmethod
¶
interactive_surface_to_html(nifti_path: str, title: str = 'Electric Field', min_cutoff: float = 0.1, max_cutoff: float | None = None, cmap: str = 'hot') -> str | None
Render an interactive 3-D surface projection as HTML.
Uses nilearn.plotting.view_img_on_surf to project the
stat-map onto a cortical surface mesh suitable for embedding
in HTML reports.
Parameters¶
nifti_path : str Path to a NIfTI file. title : str, optional Title text for the viewer. min_cutoff : float, optional Lower display threshold in V/m. max_cutoff : float or None, optional Upper display threshold. Defaults to the 99.9th percentile. cmap : str, optional Matplotlib colormap name.
Returns¶
str or None HTML string for embedding, or None on failure.