scilpy.connectivity package

scilpy.connectivity.connectivity module

scilpy.connectivity.connectivity.compute_connectivity_matrices_from_hdf5(hdf5_filename, labels_img, in_label, out_label, compute_volume=True, compute_streamline_count=True, compute_length=True, similarity_directory=None, metrics_data=None, metrics_names=None, lesion_data=None, include_dps=False, weighted=False, min_lesion_vol=0)[source]
Parameters:
  • hdf5_filename (str) – Name of the hdf5 file containing the precomputed connections (bundles)

  • labels_img (np.ndarray) – Data as labels

  • in_label (str) – Name of one extremity of the bundle to analyse.

  • out_label (str) – Name of the other extremity. Current node is {in_label}_{out_label}.

  • compute_volume (bool) – If true, return ‘volume_mm3’ in the returned dictionary with the volume of the bundle.

  • compute_streamline_count (bool) – If true, return ‘streamline_count’ in the returned dictionary, with the number of streamlines in the bundle.

  • compute_length (bool) – If true, return ‘length_mm’ in the returned dictionary, with the mean length of streamlines in the bundle.

  • similarity_directory (str) – If not None, should be a directory containing nifti files that represent density maps for each connection, using the <in_label>_<out_label>.nii.gz conventions. Typically computed from a template (must be in the same space).

  • metrics_data (list[np.ndarray]) – List of 3D data with metrics to use, with the list of associated metric names. If set, the returned dictionary will contain an entry for each name, with the mean value of each metric.

  • metrics_names (list[str]) – The metrics names.

  • lesion_data (Tuple[list, np.ndarray]) – The (lesion_labels, lesion_data) for lesion load analysis. If set, the returned dictionary will contain the three entries ‘lesion_volume’: the total lesion volume, ‘lesion_streamline_count’: the number of streamlines passing through lesions, ‘lesion_count’: the number of lesions.

  • include_dps (bool) – If true, return an entry for each dps with the mean dps value.

  • weighted (bool) – If true, weight the results with the density map.

  • min_lesion_vol (float) – Minimum lesion volume for a lesion to be considered.

Returns:

final_dict

dict: {(in_label, out_label): measures_dict}

A dictionary with the node as key and as the dictionary as described above.

dps_keys: The list of keys included from dps.

Return type:

Tuple[dict, list[str]] or None

scilpy.connectivity.connectivity.compute_triu_connectivity_from_labels(tractogram, data_labels, keep_background=False, hide_labels=None)[source]

Compute a connectivity matrix.

Parameters:
  • tractogram (StatefulTractogram, or list[np.ndarray]) – Streamlines. A StatefulTractogram input is recommanded. When using directly with a list of streamlines, streamlines must be in vox space, center origin.

  • data_labels (np.ndarray) – The loaded nifti image. Must be 3D.

  • keep_background (Bool) – By default, the background (label 0) is not included in the matrix. If True, label 0 is kept.

  • hide_labels (Optional[List[int]]) – If not None, streamlines ending in a voxel with a given label are ignored (i.e. matrix is set to 0 for that label).

Returns:

  • matrix (np.ndarray) – With use_scilpy: shape (nb_labels + 1, nb_labels + 1) Else, shape (nb_labels, nb_labels)

  • ordered_labels (List) – The list of labels. Name of each row / column.

  • start_labels (List) – For each streamline, the label at starting point.

  • end_labels (List) – For each streamline, the label at ending point.

scilpy.connectivity.connectivity.multi_proc_compute_connectivity_matrices_from_hdf5(args)[source]

scilpy.connectivity.matrix_tools module

scilpy.connectivity.matrix_tools.apply_reordering(array, ordering)[source]

Apply a non-symmetric array ordering that support non-square output. The ordering can contain duplicated or discarded rows/columns.

Parameters:
  • array (ndarray (NxN)) – Sparse connectivity matrix.

  • ordering (list of lists) – First elements of the list is the permutation to apply to the rows. First elements of the list is the permutation to apply to the columns.

Returns:

tmp_array – Reordered array.

Return type:

ndarray (N,N)

scilpy.connectivity.matrix_tools.compute_olo(array)[source]

Optimal Leaf Ordering permutes a weighted matrix that has a symmetric sparsity pattern using hierarchical clustering.

Parameters:

array (ndarray (NxN)) – Connectivity matrix.

Returns:

perm – Output permutations for rows and columns.

Return type:

ndarray (N,)

scilpy.connectivity.matrix_tools.evaluate_functional_graph_measures(conn_matrix, conn_threshold, avg_node_wise)[source]
Parameters:
  • conn_matrix (np.ndarray) – 2D matrix of functional connectivity weights

  • conn_threshold (float) – 2D matrix of bundle lengths.

  • avg_node_wise (bool) – If true, return a single value for node-wise measures.

scilpy.connectivity.matrix_tools.evaluate_graph_measures(conn_matrix, len_matrix, avg_node_wise, small_world)[source]
Parameters:
  • conn_matrix (np.ndarray) – 2D matrix of connectivity weights. Typicaly a streamline count matrix.

  • len_matrix (np.ndarray) – 2D matrix of bundle lengths.

  • avg_node_wise (bool) – If true, return a single value for node-wise measures.

  • small_world (bool) – If true, compute measure related to small worldness (omega and sigma). This option is much slower.

scilpy.connectivity.matrix_tools.normalize_matrix_from_parcel(matrix, atlas_img, labels_list, parcel_from_volume)[source]
Parameters:
  • matrix (np.ndarray) – Connectivity matrix

  • atlas_img (nib.Nifti1Image) – Atlas for edge-wise division.

  • labels_list (np.ndarray) – The list of labels of interest for edge-wise division.

  • parcel_from_volume (bool) – If true, parcel from volume. Else, parcel from surface.

scilpy.connectivity.matrix_tools.normalize_matrix_from_values(matrix, norm_factor, inverse)[source]
Parameters:
  • matrix (np.ndarray) – Connectivity matrix

  • norm_factor (np.ndarray of shape ?) – Matrix used for edge-wise multiplication. Ex: length or volume of the bundles.

  • inverse (bool) – If true, divide by the matrix rather than multiply.