CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-dipy

Comprehensive Python library for diffusion MRI analysis including tensor imaging, tractography, and visualization

Pending
Overview
Eval results
Files

data-access.mddocs/

Data Access and Management

Comprehensive data loading, example datasets, and I/O operations for diffusion MRI data. DIPY provides extensive example datasets for testing and learning, along with utilities for handling various neuroimaging file formats.

Capabilities

Example Data Loading

Access to curated example datasets for testing and educational purposes, including diffusion MRI data from various research institutions and phantom data.

def read_stanford_hardi():
    """
    Load Stanford HARDI dataset.
    
    Returns:
        tuple: (img, gtab) - NiBabel image and gradient table
    """

def read_sherbrooke_3shell():
    """
    Load Sherbrooke 3-shell dataset.
    
    Returns:
        tuple: (img, gtab) - Multi-shell diffusion data
    """

def read_taiwan_ntu_dsi():
    """
    Load Taiwan NTU DSI dataset.
    
    Returns:
        tuple: (img, gtab) - Diffusion spectrum imaging data
    """

def read_isbi2013_2shell():
    """
    Load ISBI 2013 2-shell challenge dataset.
    
    Returns:
        tuple: (img, gtab) - Two-shell diffusion data
    """

def read_ivim():
    """
    Load IVIM (Intravoxel Incoherent Motion) dataset.
    
    Returns:
        tuple: (img, gtab) - IVIM diffusion data
    """

Dataset Fetching

Functions to download and cache datasets from various sources, providing access to larger research datasets.

def fetch_stanford_hardi():
    """
    Fetch Stanford HARDI dataset from remote source.
    
    Returns:
        tuple: File paths to downloaded data
    """

def fetch_hcp():
    """
    Fetch Human Connectome Project data.
    
    Returns:
        tuple: Paths to HCP diffusion data
    """

def fetch_bundles_2_subjects():
    """
    Fetch streamline bundles from 2 subjects.
    
    Returns:
        tuple: Paths to bundle data files
    """

def fetch_bundle_atlas_hcp842():
    """
    Fetch bundle atlas from HCP 842 subjects.
    
    Returns:
        str: Path to atlas files
    """

def fetch_mni_template():
    """
    Fetch MNI brain template.
    
    Returns:
        str: Path to template file
    """

Gradient Table Management

Creation and manipulation of gradient tables that define the diffusion sensitization directions and strengths.

def gradient_table(bvals, bvecs=None, *, big_delta=None, small_delta=None, b0_threshold=50, atol=1e-2):
    """
    Create gradient table from b-values and b-vectors.
    
    Parameters:
        bvals (array): b-values in s/mm²
        bvecs (array): gradient directions (3 x N or N x 3)
        big_delta (float): diffusion time parameter
        small_delta (float): gradient duration parameter  
        b0_threshold (float): threshold for b=0 images
        atol (float): tolerance for b-value comparison
        
    Returns:
        GradientTable: Container with gradient information
    """

class GradientTable:
    """Container for diffusion gradient information."""
    def __init__(self, bvals, bvecs=None, **kwargs): ...
    
    @property
    def bvals(self):
        """array: b-values in s/mm²"""
    
    @property 
    def bvecs(self):
        """array: normalized gradient directions"""
    
    @property
    def b0s_mask(self):
        """array: boolean mask for b=0 images"""
    
    @property
    def gradients(self):
        """array: gradient directions scaled by b-values"""

File I/O Operations

Reading and writing various neuroimaging file formats including b-values, b-vectors, and streamline data.

def read_bvals_bvecs(fbvals, fbvecs):
    """
    Read b-values and b-vectors from files.
    
    Parameters:
        fbvals (str): path to b-values file
        fbvecs (str): path to b-vectors file
        
    Returns:
        tuple: (bvals, bvecs) arrays
    """

def save_pickle(fname, dix):
    """
    Save object using pickle serialization.
    
    Parameters:
        fname (str): output filename
        dix (object): object to save
    """

def load_pickle(fname):
    """
    Load object from pickle file.
    
    Parameters:
        fname (str): pickle file path
        
    Returns:
        object: deserialized object
    """

class Dpy:
    """DIPY's native streamline format handler."""
    def __init__(self, fname, mode='r'): ...
    
    def read_streamlines(self):
        """Read streamlines from file."""
    
    def write_streamlines(self, streamlines):
        """Write streamlines to file."""
    
    def close(self):
        """Close file handle."""

Simulation Data

Generate synthetic diffusion data for testing and validation purposes.

def get_sim_voxels(*, name="fib1"):
    """
    Provide simulated voxel data for testing.
    
    Parameters:
        name (str): simulation type ('fib0', 'fib1', 'fib2')
        
    Returns:
        dict: Dictionary with 'data', 'fibres', 'gradients', 'bvals', 'snr'
    """

def dsi_voxels():
    """
    DSI dataset for testing.
    
    Returns:
        tuple: (data, gtab) synthetic DSI data
    """

Sphere Utilities

Access to predefined spherical sampling schemes used in spherical harmonics and directional analysis.

def get_sphere(name='symmetric724'):
    """
    Get pre-built sphere objects.
    
    Parameters:
        name (str): sphere configuration name
        
    Returns:
        Sphere: sphere object with vertices and faces
    """

Usage Examples

# Load example data
from dipy.data import read_stanford_hardi
from dipy.core.gradients import gradient_table

# Read diffusion data
img, gtab = read_stanford_hardi()
data = img.get_fdata()

# Create custom gradient table
import numpy as np
bvals = np.array([0, 1000, 1000, 2000, 2000])
bvecs = np.random.randn(5, 3)
bvecs[0] = 0  # b=0 has no direction
gtab = gradient_table(bvals, bvecs)

print(f"Number of gradients: {len(gtab.bvals)}")
print(f"Number of b=0 images: {gtab.b0s_mask.sum()}")

# Load streamline data using Dpy format
from dipy.io.streamline import Dpy

# Read streamlines
with Dpy('streamlines.dpy', 'r') as dpy:
    streamlines = dpy.read_streamlines()

# Access simulation data
from dipy.data import get_sim_voxels

sim_data = get_sim_voxels(name='fib1')
print(f"Simulation data shape: {sim_data['data'].shape}")
print(f"Number of fibers: {sim_data['fibres']}")

Install with Tessl CLI

npx tessl i tessl/pypi-dipy

docs

core-utilities.md

data-access.md

image-processing.md

index.md

neural-networks.md

registration.md

segmentation.md

signal-reconstruction.md

simulations.md

statistics.md

tractography.md

visualization.md

workflows.md

tile.json