Skip to main content

🧠 hippunfold_surf

This package provides plotting functions for hippocampal surface maps from HippUnfold (https://github.com/khanlab/hippunfold), wrapping the Nilearn (https://nilearn.github.io) plotting functions (matplotlib engine) to achieve this.

Note: these plotting functions are distinct from those in HippoMaps (https://github.com/MICA-MNI/hippomaps), which use VTK wrappers and have a number of limitations therein.

This package is new and still under active development so suggestions and pull-requests are welcome!

📦 Installation

To install the package, simply run:

pip install hippunfold_plot

🚀 Usage

Here are some examples of how to use the plot_hipp_surf function to visualize hippocampal surface maps.

Example 1: Plot Both Hemispheres

from hippunfold_plot.plotting import plot_hipp_surf
from hippunfold_plot.utils import get_resource_path

#get subfields for demonstrating plotting
label_gii = get_resource_path('tpl-avg_label-hippdentate_density-{density}_subfields.label.gii')
density = '1mm'

# Plot dorsal view
fig = plot_hipp_surf(label_gii.format(density=density), hemi=None, density=density, view='dorsal')

# Plot ventral view
fig = plot_hipp_surf(label_gii.format(density=density), hemi=None, density=density, view='ventral')

png png

Example 2: Plot Left and Right Hemispheres Separately

from hippunfold_plot.plotting import plot_hipp_surf
from hippunfold_plot.utils import get_resource_path

#get subfields for demonstrating plotting
label_gii = get_resource_path('tpl-avg_label-hippdentate_density-{density}_subfields.label.gii')
density = '1mm'

# Plot left hemisphere
fig = plot_hipp_surf(label_gii.format(density=density), hemi='left', density=density, view='dorsal')

# Plot right hemisphere
fig = plot_hipp_surf(label_gii.format(density=density), hemi='right', density=density, view='dorsal')

png png

Example 3: Plot unfolded and canonical space separately

from hippunfold_plot.plotting import plot_hipp_surf
from hippunfold_plot.utils import get_resource_path

#get subfields for demonstrating plotting
label_gii = get_resource_path('tpl-avg_label-hippdentate_density-{density}_subfields.label.gii')
density = '1mm'

# Plot left hemisphere in unfolded space
fig = plot_hipp_surf(label_gii.format(density=density), space='unfold', density=density, view='dorsal')

# Plot left hemisphere in canonical space
fig = plot_hipp_surf(label_gii.format(density=density), space='canonical', density=density, view='dorsal')

png png

🛠️ Functions

plot_hipp_surf

Plot hippocampal surface map.

This function plots a surface map of the hippocampus, which can be a label-hippdentate shape.gii, func.gii, or a Vx1 array (where V is the number of vertices in the hippocampus and dentate). Any arguments that can be supplied to nilearn's plot_surf() can also be applied here, overriding the defaults set below.

Parameters
  • surf_map (str or array-like): The surface map to plot. This can be a file path to a .gii file or a Vx1 array.
  • density (str, optional): The density of the surface map. Can be 'unfoldiso', '0p5mm', '1mm', or '2mm'. Default is '0p5mm'.
  • hemi (str, optional): The hemisphere to plot. Can be 'left', 'right', or None (in which case both are plotted). Default is 'left'.
  • space (str, optional): The space of the surface map. Can be 'canonical', 'unfold', or None (in which case both are plotted). Default is None.
  • figsize (tuple, optional): The size of the figure. Default is (12, 8).
  • dpi (int, optional): The resolution of the figure in dots per inch. Default is 300.
  • vmin (float, optional): The minimum value for the color scale. Default is None.
  • vmax (float, optional): The maximum value for the color scale. Default is None.
  • colorbar (bool, optional): Whether to display a colorbar. Default is False.
  • colorbar_shrink (float, optional): The shrink factor for the colorbar. Default is 0.25.
  • cmap (str or colormap, optional): The colormap to use. Default is None.
  • view (str, optional): The view of the surface plot. Default is 'dorsal'.
  • avg_method (str, optional): The method to average the data. Default is 'median'.
  • bg_on_data (bool, optional): Whether to display the background on the data. Default is True.
  • alpha (float, optional): The alpha transparency level. Default is 0.1.
  • darkness (float, optional): The darkness level of the background. Default is 2.
  • axes (matplotlib.axes.Axes or list of matplotlib.axes.Axes, optional): Axes to plot on. If None, new axes will be created. If a single axis is provided, it will be used for a single plot. If multiple plots are to be made, a list of axes should be provided.
  • figure (matplotlib.figure.Figure, optional): The figure to plot on. If None, a new figure will be created.
  • **kwargs (dict): Additional arguments to pass to nilearn's plot_surf().
Returns
  • figure (matplotlib.figure.Figure): The figure object.
Notes

By default, this function will plot one hemisphere (left by default) in both canonical and unfolded space. Both surfaces can be plotted with hemi=None, but the same surf_map will be plotted on both.

🧪 Testing

To run the tests, including unit tests and docstring tests, use the following command:

python -m unittest discover -s . -p "test_*.py"

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

🙌 Contributing

We welcome contributions! Please see our CONTRIBUTING guidelines for more details.

📞 Contact

If you have any questions or feedback, feel free to reach out or post an issue!


Happy plotting! 🎉

Metadata

Release files for hippunfold_plot 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hippunfold_plot 0.1.2
File Size Uploaded
hippunfold_plot-0.1.2.tar.gz 2.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for hippunfold_plot 0.1.2
File Interpreter ABI Platform
hippunfold_plot-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 4.7 MB

Release files / hippunfold_plot-0.1.2.tar.gz

Download URL hippunfold_plot-0.1.2.tar.gz
Size 2.3 MB
Tags Source
SHA-256 checksum
How to use checksums
62cdc9d8f29580ac3d3e35ef09c842c6ba7246adc3c411789be6b0ee00a5cabe
BLAKE2b-256 checksum
How to use checksums
5f2d3cbeb3c0a4f741512e223b7be3370a8c9547da65cec705a1facb17c4e03c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.1

Release files / hippunfold_plot-0.1.2-py3-none-any.whl

Download URL hippunfold_plot-0.1.2-py3-none-any.whl
Size 2.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
98da4747ef250b5fcd714eeedd1af470147cd8be7405f29532f2de2951b352b0
BLAKE2b-256 checksum
How to use checksums
a2636071fdf501bfcbaa72d7c6d04bfd4568186231e836332fd50b85cb3a0576
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.1

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page