Skip to main content

Dynamical Neural Spatiotemporal Representations.

Project description

Dynamical Neuroimaging Spatiotemporal Representations

DyNeuSR is a Python visualization library for topological representations of neuroimaging data.

DyNeuSR was designed specifically for working with shape graphs produced by the Mapper algorithm from topological data analysis (TDA), as described in the papers "Generating dynamical neuroimaging spatiotemporal representations (DyNeuSR) using topological data analysis" (Geniesse et al., 2019) and "Towards a new approach to reveal dynamical organization of the brain using topological data analysis" (Saggar et al., 2018). Check out this blog post for more about the initial work that inspired the development of DyNeuSR.

Developed with neuroimaging data analysis in mind, DyNeuSR connects existing implementations of Mapper (e.g. KeplerMapper) with network analysis tools (e.g. NetworkX) and other neuroimaging data visualization libraries (e.g. Nilearn) and provides a high-level interface for interacting with and manipulating shape graph representations of neuroimaging data and relating these representations back to neurophysiology.

DyNeuSR also provides an interactive web interface for visualizing and exploring shape graphs. To see this visual interface in action, check out the demos.

Demos

References

If you find DyNeuSR useful, please consider citing:

Geniesse, C., Sporns, O., Petri, G., & Saggar, M. (2019). Generating dynamical neuroimaging spatiotemporal representations (DyNeuSR) using topological data analysis. Network Neuroscience. Advance publication. doi:10.1162/netn_a_00093

For more information about the Mapper approach, please see:

Saggar, M., Sporns, O., Gonzalez-Castillo, J., Bandettini, P.A., Carlsson, G., Glover, G., & Reiss, A.L. (2018). Towards a new approach to reveal dynamical organization of the brain using topological data analysis. Nature Communications, 9(1). doi:10.1038/s41467-018-03664-4

API Usage & Examples

DyNeuSR provides a Python API for working with and visualizing shape graphs generated by Mapper. This repository includes several examples that introduce DyNeuSR's API and highlight different aspects of analysis with DyNeuSR. For more detailed tutorials, check out dyneusr-notebooks.

Shape Graph Visualization (trefoil knot)

from dyneusr import DyNeuGraph
from dyneusr.datasets import make_trefoil
from dyneusr.tools import visualize_mapper_stages
from kmapper import KeplerMapper

# Generate synthetic dataset
dataset = make_trefoil(size=100)
X = dataset.data
y = dataset.target

# Generate shape graph using KeplerMapper
mapper = KeplerMapper(verbose=1)
lens = mapper.fit_transform(X, projection=[0])
graph = mapper.map(lens, X, nr_cubes=6, overlap_perc=0.2)

# Visualize the shape graph using DyNeuSR's DyNeuGraph                          
dG = DyNeuGraph(G=graph, y=y)
dG.visualize('dyneusr_output.html')

Mapper Parameter Comparison (trefoil knot)

# Define projections to compare
projections = ([0], [0,1], [1,2], [0, 2])

# Compare different sets of columns as lenses
for projection in projections:

	# Generate shape graph using KeplerMapper
	mapper = KeplerMapper(verbose=1)
	lens = mapper.fit_transform(X, projection=projection)
	graph = mapper.map(lens, X, nr_cubes=4, overlap_perc=0.3)

	# Visualize the stages of Mapper
	fig, axes = visualize_mapper_stages(
		dataset, lens=lens, graph=graph, cover=mapper.cover, 
		layout="spectral")

Neuroimaging Applications (haxby decoding)

import numpy as np 
import pandas as pd

from nilearn.datasets import fetch_haxby
from nilearn.input_data import NiftiMasker

from kmapper import KeplerMapper, Cover
from sklearn.manifold import TSNE
from sklearn.cluster import DBSCAN

# Fetch dataset, extract time-series from ventral temporal (VT) mask
dataset = fetch_haxby()
masker = NiftiMasker(
    dataset.mask_vt[0], 
    standardize=True, detrend=True, smoothing_fwhm=4.0,
    low_pass=0.09, high_pass=0.008, t_r=2.5,
    memory="nilearn_cache")
X = masker.fit_transform(dataset.func[0])

# Encode labels as integers
df = pd.read_csv(dataset.session_target[0], sep=" ")
target, labels = pd.factorize(df.labels.values)
y = pd.DataFrame({l:(target==i).astype(int) for i,l in enumerate(labels)})

# Generate shape graph using KeplerMapper
mapper = KeplerMapper(verbose=1)
lens = mapper.fit_transform(X, projection=TSNE(2))
graph = mapper.map(lens, X, cover=Cover(20, 0.5), clusterer=DBSCAN(eps=20.))

# Visualize the shape graph using DyNeuSR's DyNeuGraph                          
dG = DyNeuGraph(G=graph, y=y)
dG.visualize('dyneusr_output.html')

Setup

Dependencies

Python 3.6

Required Python Packages

For a full list of packages and required versions, see requirements.txt and requirements-versions.txt.

Install with PIP

To install with pip:

pip install dyneusr

To install from source:

git clone https://github.com/braindynamicslab/dyneusr.git
cd dyneusr

pip install -r requirements.txt
pip install -e .

pytest

Install with Conda

If your default environment is Python 2, we recommend that you install dyneusr in a separate Python 3 environment. You can find more information about creating a separate environment for Python 3 here.

If you don't have conda, or if you are new to scientific python, we recommend that you download the Anaconda scientific python distribution.

To create a new conda environment and install from source:

conda create -n dyneusr python=3.6
conda activate dyneusr

git clone https://github.com/braindynamicslab/dyneusr.git
cd dyneusr

conda install --file requirements-conda.txt
pip install -e .

pytest

This creates a new conda environment dyneusr and installs in it the dependencies that are needed. To access it, use the conda activate dyneusr command (if your conda version >= 4.4) and use source activate dyneusr command (if your conda version < 4.4).

Support

Please feel free to report any issues, request new features, or propose improvements. You can also contact Caleb Geniesse at geniesse [at] stanford [dot] edu.

If you contribute to DyNeuSR, please feel free to add your name to the list of contributors.

Citation

Geniesse, C., Sporns, O., Petri, G., & Saggar, M. (2019). Generating dynamical neuroimaging spatiotemporal representations (DyNeuSR) using topological data analysis. Network Neuroscience. Advance publication. doi:10.1162/netn_a_00093

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dyneusr-0.3.2.tar.gz (52.2 kB view details)

Uploaded Source

Built Distribution

dyneusr-0.3.2-py3-none-any.whl (59.3 kB view details)

Uploaded Python 3

File details

Details for the file dyneusr-0.3.2.tar.gz.

File metadata

  • Download URL: dyneusr-0.3.2.tar.gz
  • Upload date:
  • Size: 52.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2

File hashes

Hashes for dyneusr-0.3.2.tar.gz
Algorithm Hash digest
SHA256 3c0f5d1ce14190f8cd8c83322fe4e2af92bd9dbcf53530bbe2adbe458e70fb30
MD5 65c5a16265351c7edecee02e3f3c2f36
BLAKE2b-256 d7f52469ad6e0f93029f40012a146f11eae225287c4fa612ad7ac9f585ca24b3

See more details on using hashes here.

File details

Details for the file dyneusr-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: dyneusr-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 59.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2

File hashes

Hashes for dyneusr-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c8609e23ab8c2a104769ba7bcc2d8f49ce428251c33ccd1eba07c208b45bd2ed
MD5 70bd3d255b778e10d3d219ee9f373352
BLAKE2b-256 35a005b434f47193d3bff47582a8ad04716c4fa0ead364540f3d96bc0ddc512c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page