Plot cifti from ROIs#

import nibabel as nib
import pandas as pd
import numpy as np
from neurotools.plotting import plot
from neurotools.loading import load
from neurotools.transform import SurfLabels
import matplotlib.pyplot as plt

The first step is loading some set of rois for an example subject just as a 1D numpy array, in this case w/ length 379.

rois = pd.read_csv('ex_rois.csv', header=None)
rois = np.squeeze(np.array(rois))

Next, we need to load the parcellation label file in a simmilar way, i.e., as just a flat 1D array.

parcel = nib.load('HCP2016FreeSurferSubcortical_dparc.dlabel.nii')
parcel_labels = np.array(parcel.get_fdata()).squeeze()

Then, we initialize a SurfLabels object based off the parcel labels file - which we can use to inverse transform the ROIs back into the space of the dlabel file

sl_transformer = SurfLabels(parcel_labels, background_label=0)
data = sl_transformer.inverse_transform(rois)
plot(data, vol_plot_type='stat', title='My Data')
/home/sage/anaconda3/envs/bpt/lib/python3.9/site-packages/nilearn/plotting/ FutureWarning: Default resolution of the MNI template will change from 2mm to 1mm in version 0.10.0
  anat_img = load_mni152_template()
# You can also plot the parcellation
# with the same command! Wowza