cubnm.utils

Utility functions

avail_gpus()

Get the number of available GPUs

is_jupyter()

This function checks if the current environment is a Jupyter notebook.

fc_norm_euclidean(x, y)

Calculates Euclidean distance of two FC arrays

get_bw_params(src)

Get Balloon-Windkessel model parameters

calculate_fc(bold[, exc_interhemispheric, return_tril])

Calculates functional connectivity matrix

calculate_fcd(bold, window_size, window_step[, ...])

Calculates functional connectivity dynamics matrix

cubnm.utils.avail_gpus()

Get the number of available GPUs

Returns

int

Number of available GPUs

cubnm.utils.is_jupyter()

This function checks if the current environment is a Jupyter notebook.

Returns:

bool: True if the current environment is a Jupyter notebook, False otherwise.

cubnm.utils.fc_norm_euclidean(x, y)

Calculates Euclidean distance of two FC arrays divided by their maximum possible distance, equal to the distance of np.ones(n_pairs) and -np.ones(n_pairs) or 2 * np.sqrt(n_pairs)

Parameters

x, y: np.ndarray

FC arrays. Shape: (n_pairs,)

Returns

float

Normalized Euclidean distance

cubnm.utils.get_bw_params(src)

Get Balloon-Windkessel model parameters

Parameters

src: {‘friston2003’, ‘heinzle2016-3T’}
  • ‘friston2003’: Friston et al. 2003

  • ‘heinzle2016-3T’: Heinzle et al. 2016, 3T parameters

Returns

dict

Balloon-Windkessel model parameters

cubnm.utils.calculate_fc(bold, exc_interhemispheric=False, return_tril=True)

Calculates functional connectivity matrix

Parameters

bold: np.ndarray

cleaned and parcellated empirical BOLD time series. Shape: (nodes, volumes) Motion outliers should either be excluded or replaced with zeros.

exc_interhemispheric: bool, optional

exclude interhemispheric connections

return_tril: bool, optional

return only the lower triangular part of the FCD matrix

Returns

fc: np.ndarray

FC dynamics matrix. Shape: (nodes, nodes) or (n_node_pairs,) if return_tril is True

cubnm.utils.calculate_fcd(bold, window_size, window_step, drop_edges=True, outlier_threshold=0.5, exc_interhemispheric=False, return_tril=True, return_dfc=False)

Calculates functional connectivity dynamics matrix and dynamic functional connectivity matrices

Parameters

bold: np.ndarray

cleaned and parcellated empirical BOLD time series. Shape: (nodes, volumes) Motion outliers should either be excluded (not recommended as it disrupts the temporal structure) or replaced with zeros.

window_size: int, optional

dynamic FC window size (in TR) Must be even. The actual window size is +1 (including center).

window_step: int, optional

dynamic FC window step (in TR)

drop_edges: bool, optional

drop edge windows which have less than window_size volumes

outlier_threshold: float, optional

threshold for the proportion of motion outliers in a window that would lead to discarding the window

exc_interhemispheric: bool, optional

exclude interhemispheric connections

return_tril: bool, optional

return only the lower triangular part of the FCD matrix

return_dfc: bool, optional

return dynamic FCs as well

Returns

fcd_matrix: np.ndarray

FC dynamics matrix. Shape: (n_windows, n_windows) or (n_window_pairs,) if return_tril is True

window_fcs: np.ndarray

dynamic FCs. Shape: (nodes, nodes, n_windows) Returned only if return_dfc is True