Wednesday, July 2, 2014

Day 31: Downsampling to a grid

Notebook

I don't know why I thought the vertices needed to be equidistant yesterday. In setup_volume_source_space,
the volume is setup over a grid. So I can downsample volumes into a grid.

In [1]:
%matplotlib inline
import numpy as np
import nibabel as nib
from mne.datasets import spm_face

# get the aseg file
data_path = spm_face.data_path()
aseg_fname = data_path + '/subjects/spm/mri/aseg.mgz'

# read aseg file using nibabel
aseg = nib.load(aseg_fname)
hdr = aseg.get_header()
dat = aseg.get_data()

# get indices to region of interest
ix = dat == 18
X, Y, Z = np.where(ix)

# create a downsampled grid (5mm spacing)
kernel = np.zeros((5, 5, 5))
kernel[0, 0, 0] = 1
n = np.ceil(256./5.)
grid = np.tile(kernel, (n, n, n))
grid = grid[:256, :256, :256]

# downsample region of interest
x, y, z = np.where(ix*grid)
/home/alan/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/mne/datasets/utils.py:190: UserWarning: The spm dataset (version 0.7) is older than mne-python (version 0.8.git). If the examples fail, you may need to update the spm dataset by using mne.datasets.spm.data_path(force_update=True)
  name=name, current=data_version, newest=mne_version))
/home/alan/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/lib/shape_base.py:834: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  return c.reshape(shape)
/home/alan/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/lib/shape_base.py:834: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  return c.reshape(shape)
/home/alan/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/lib/shape_base.py:834: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  return c.reshape(shape)

In [3]:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# plot the region of interest
ax = plt.axes(projection='3d')
ax.scatter(X, Y, Z, c='red', alpha=0.1)
ax.scatter(x, y, z, c='blue')
Out[3]:
<mpl_toolkits.mplot3d.art3d.Patch3DCollection at 0x9cc2c50>

No comments:

Post a Comment