Diagnosing the FSL data
%pylab inline
We make sure we have some useful libraries loaded:
import numpy as np # array manipulation
import matplotlib.pyplot as plt # plotting library
Set some defaults for plotting:
plt.rcParams['image.cmap'] = 'gray'
plt.rcParams['image.interpolation'] = 'nearest'
We need the library to load and analyze images:
from nipy import load_image
from nipy.core.api import Image, drop_io_dim, rollimg
from nipy.algorithms.utils.pca import pca_image
from nipy.algorithms.diagnostics import screens
Get the image to look at it:
img = load_image('fmri.nii.gz')
img.shape
print(img.metadata['header'])
t0_img = rollimg(img, 't') # Put time axis first
time_mean_array = t0_img.get_data().mean(axis=0)
plt.imshow(time_mean_array[:, :, 10])
Try PCA:
img_pca_results = pca_image(t0_img, axis='t', ncomp=10)
img_pca_results.keys()
img_pca_results['basis_vectors'].shape
fig, axes = plt.subplots(10, 1)
for i, ax in enumerate(axes):
ax.plot(img_pca_results['basis_vectors'][:, i])
pca0 = img_pca_results['basis_projections']
plt.imshow(pca0.get_data()[0, :, :, 5])
Do some more diagostic checks:
dx = screens.screen(img, slice_axis=2)
fig, axes = plt.subplots(4, 1, figsize=(12, 6))
screens.plot_tsdiffs(dx['ts_res'], axes)