@author: [email protected] """ import os, glob import numpy as np import matplotlib.pyplot as plt from nilearn.plotting import plot_stat_map, plot_roi from nilearn.image import index_img from fetch_data import fetch_adni_masks, array_to_niis, array_to_nii from scipy.ndimage import label from matplotlib import cm import nibabel as nib from fetch_data import set_cache_base_dir from joblib import Parallel, delayed base_dir = os.path.join(set_cache_base_dir(), 'decomposition') mask = fetch_adni_masks()['mask_petmr'] mask_shape = nib.load(mask).shape mask_affine = nib.load(mask).get_affine() np_files = os.listdir(base_dir) def extract_region_i(maps, i): """ Extract ROIs and plot """ m = maps[i, ...] th_value = np.percentile(m, 100. - (100. / 42.)) data = np.absolute(array_to_nii(m, mask).get_data()) data[data <= th_value] = 0 data[data > th_value] = 1 data_lab = label(data)[0]
import os import numpy as np from scipy import stats, linalg from sklearn.covariance import GraphLassoCV, LedoitWolf, OAS, \ ShrunkCovariance from sklearn.datasets.base import Bunch from sklearn.base import BaseEstimator, TransformerMixin from nilearn.input_data import NiftiLabelsMasker, NiftiMapsMasker import nibabel as nib from joblib import Parallel, delayed from nilearn.datasets import fetch_msdl_atlas from fetch_data import set_cache_base_dir from embedding import CovEmbedding, vec_to_sym CACHE_DIR = set_cache_base_dir() def atlas_rois_to_coords(atlas_name, rois): """Returns coords of atlas ROIs """ atlas = fetch_atlas(atlas_name) affine = nib.load(atlas).get_affine() data = nib.load(atlas).get_data() centroids = [] if len(data.shape) == 4: for i in range(data.shape[-1]): voxels = np.where(data[..., i] > 0) centroid = np.mean(voxels, axis=1) dvoxels = data[..., i]