Skip to content

tracts

ngtools.local.tracts

Specialized SkeletonSource that loads and serves tractography data.

TractDataSource

TractDataSource(*args, **kwargs)

Bases: LocalSkeletonDataSource

Data source for local skeletons.

info property

info

Lazy access to format-specific metadata.

local_url property

local_url

Path to url, even if file is local.

shape property

shape

Return the shape of the array (spatial dimensions first).

rank property

rank

Return the number of dimensions in the array.

dtype property

dtype

Return the data type of the array.

slope_inter property

slope_inter

Affine scaling to apply to the stored intensity.

dataobj property

dataobj

Return an array-like object pointing to the data.

nb_levels property

nb_levels

Number of pyramid levels.

input_dimensions property

input_dimensions

Input dimensions.

output_dimensions property

output_dimensions

Output dimensions.

input_bbox property

input_bbox

Bounding box, in input_dimensions space and units.

output_bbox property

output_bbox

Bounding box, in output_dimensions space and units.

input_center property

input_center

Center of the field of view in input dimensions space and units.

output_center property

output_center

Center of the field of view in output dimensions space and units.

input_bbox_size property

input_bbox_size

Center of the field of view in input dimensions space and units.

output_bbox_size property

output_bbox_size

Center of the field of view in output dimensions space and units.

output_voxel_size property

output_voxel_size

Voxel size in model space.

local_skeleton property

local_skeleton

Points to the underlying SkeletonSource, if any.

get_dataobj

get_dataobj(level=0, mode='r')

Return an array-like object pointing to a pyramid level.

quantiles

quantiles(q)

Compute data quantiles.

apply_transform

apply_transform(*args)

Apply an additional transform in model space.

TractSkeleton

TractSkeleton(fileobj, max_tracts=DEFAULT_MAX_TRACTS, format=None, **kwargs)

Bases: SkeletonSource

Local tractography source loaded into a neuroglancer skeleton.

This class reads a TRK stremalines file (using nibabel) and implements methods that allow serving and/or converting the streamlines data into neuroglancer's precomputed skeleton format.

The skeleton format was originally implemented to render skeletonized volumetric segmentations, with a relatively small number of individual objects. Since tractography (especially high-resolution tractography) can generate millions of streamlines, saving each streamline as an individual skeleton is very inefficient -- both for querying and rendering.

Instead, we combine all streamlines into a single skeleton. Still, the large number of streamlines slows down rendering quite a lot, so I currently sample MAX_TRACTS streamlines from the file to display (currently set to 10,000).

There is no "multi-scale" representation of the tracts in neuroglancer (i.e., generate tracts with a smaller or larger number of edges based on the current rendering scale). Maybe this is something that we should ask be added to neuroglancer.

If a segmentation of the tractogram is available, it would probably make sense to save the tracts belonging to each segment in a different skeleton. This would allow switching each segment on and off, and would allow segments to be displayed in different colors.

I also save a unit-norm orientation vector for each vertex. Saving this information as vertex_attribute allows using it for rendering (e.g., it can be used to render orientation-coded tracts).

The specification of the precomputed skeleton format is available here: https://github.com/google/neuroglancer/blob/master/ src/neuroglancer/datasource/precomputed/skeletons.md

Parameters:

Name Type Description Default
fileobj path or file - like

TCK or TRK file

required
max_tracts int

Maximum number of tracts to display

DEFAULT_MAX_TRACTS
format [list of] {'tck', 'trk'}

Format hint

None

__len__

__len__()

Total number of tracts.

compute_orientation classmethod

compute_orientation(tract)

Compute the orientation of a tract at each vertex.

get_skeleton

get_skeleton(i=1)

Neuroglancer Python API.

Parameters:

Name Type Description Default
i int

Segment index (should be zero in our case)

1

Returns:

Name Type Description
skel Skeleton

precomputed_prop_info

precomputed_prop_info(combined=False)

Return precomputed format's "property info" file.

https://github.com/google/neuroglancer/blob/master/
src/neuroglancer/datasource/precomputed/segment_properties.md

precomputed_skel_info

precomputed_skel_info()

Return precomputed format's "skeleton info" file.

https://github.com/google/neuroglancer/blob/master/
src/neuroglancer/datasource/precomputed/skeletons.md

precomputed_skel_data

precomputed_skel_data(id=1, combined=True)

Return precomputed format's "skeleton data" bytes.