In this figure, we show the spatial distribution of the performance of the SFM model in predicting the signal.
We start by importing necessary modues:
import tempfile
from IPython.display import Image, display
import nibabel as ni
import osmosis.viz.maya as viz
import osmosis.utils as ozu
import osmosis.model.sparse_deconvolution as ssd
import osmosis.model.analysis as oza
/usr/lib/python2.7/dist-packages/nose/util.py:14: DeprecationWarning: The compiler package is deprecated and removed in Python 3.x. from compiler.consts import CO_GENERATOR
We set the path to the data-files:
import os
import osmosis as oz
import osmosis.io as oio
oio.data_path = os.path.join(oz.__path__[0], 'data')
And read the file-names to be used in the analysis:
subject = 'SUB1'
data_1k_1, data_1k_2 = oio.get_dwi_data(1000, subject)
data_2k_1, data_2k_2 = oio.get_dwi_data(2000, subject)
data_4k_1, data_4k_2 = oio.get_dwi_data(4000, subject)
A white-matter mask is used (see Methods):
wm_mask = np.zeros(ni.load(data_1k_1[0]).shape[:3])
wm_nifti = ni.load(oio.data_path + '/%s/%s_wm_mask.nii.gz'%(subject, subject)).get_data()
wm_mask[np.where(wm_nifti==1)] = 1
We have determined that these are good regularization parameters:
# This is the best according to rRMSE across bvals:
l1_ratio = 0.8
alpha = 0.0005
solver_params = dict(l1_ratio=l1_ratio, alpha=alpha, fit_intercept=False, positive=True)
The axial and radial diffusivity in each b value are read from stored values (calculated as described in Methods).
Then, a model class instance is initialized for every set of data.
ad_rd = oio.get_ad_rd(subject, 1000)
SD_1k_1 = ssd.SparseDeconvolutionModel(*data_1k_1, mask=wm_mask, params_file ='temp', axial_diffusivity=ad_rd[0]['AD'], radial_diffusivity=ad_rd[0]['RD'], solver_params=solver_params)
SD_1k_2 = ssd.SparseDeconvolutionModel(*data_1k_2, mask=wm_mask, params_file ='temp', axial_diffusivity=ad_rd[1]['AD'], radial_diffusivity=ad_rd[1]['RD'], solver_params=solver_params)
ad_rd = oio.get_ad_rd(subject, 2000)
SD_2k_1 = ssd.SparseDeconvolutionModel(*data_2k_1, mask=wm_mask, params_file ='temp', axial_diffusivity=ad_rd[0]['AD'], radial_diffusivity=ad_rd[0]['RD'], solver_params=solver_params)
SD_2k_2 = ssd.SparseDeconvolutionModel(*data_2k_2, mask=wm_mask, params_file ='temp', axial_diffusivity=ad_rd[1]['AD'], radial_diffusivity=ad_rd[1]['RD'], solver_params=solver_params)
ad_rd = oio.get_ad_rd(subject, 4000)
SD_4k_1 = ssd.SparseDeconvolutionModel(*data_4k_1, mask=wm_mask, params_file ='temp', axial_diffusivity=ad_rd[0]['AD'], radial_diffusivity=ad_rd[0]['RD'], solver_params=solver_params)
SD_4k_2 = ssd.SparseDeconvolutionModel(*data_4k_2, mask=wm_mask, params_file ='temp', axial_diffusivity=ad_rd[1]['AD'], radial_diffusivity=ad_rd[1]['RD'], solver_params=solver_params)
Loading from file: /home/arokem/usr/lib/python2.7/site-packages/osmosis/data/HT/0006_01_DWI_2mm150dir_2x_b1000_aligned_trilin.bvals Loading from file: /home/arokem/usr/lib/python2.7/site-packages/osmosis/data/HT/0006_01_DWI_2mm150dir_2x_b1000_aligned_trilin.bvecs Loading from file: /home/arokem/usr/lib/python2.7/site-packages/osmosis/data/HT/0008_01_DWI_2mm150dir_2x_b1000_aligned_trilin.bvals Loading from file: /home/arokem/usr/lib/python2.7/site-packages/osmosis/data/HT/0008_01_DWI_2mm150dir_2x_b1000_aligned_trilin.bvecs Loading from file: /home/arokem/usr/lib/python2.7/site-packages/osmosis/data/HT/0015_01_DTI_2mm_b2000_150dir_aligned_trilin.bvals Loading from file: /home/arokem/usr/lib/python2.7/site-packages/osmosis/data/HT/0015_01_DTI_2mm_b2000_150dir_aligned_trilin.bvecs Loading from file: /home/arokem/usr/lib/python2.7/site-packages/osmosis/data/HT/0017_01_DTI_2mm_b2000_150dir_aligned_trilin.bvals Loading from file: /home/arokem/usr/lib/python2.7/site-packages/osmosis/data/HT/0017_01_DTI_2mm_b2000_150dir_aligned_trilin.bvecs Loading from file: /home/arokem/usr/lib/python2.7/site-packages/osmosis/data/HT/0009_01_DWI_2mm150dir_2x_b4000_aligned_trilin.bvals Loading from file: /home/arokem/usr/lib/python2.7/site-packages/osmosis/data/HT/0009_01_DWI_2mm150dir_2x_b4000_aligned_trilin.bvecs Loading from file: /home/arokem/usr/lib/python2.7/site-packages/osmosis/data/HT/0010_01_DWI_2mm150dir_2x_b4000_aligned_trilin.bvals Loading from file: /home/arokem/usr/lib/python2.7/site-packages/osmosis/data/HT/0010_01_DWI_2mm150dir_2x_b4000_aligned_trilin.bvecs
To provide anatomical context to the display of the results, a T1-weighted was resampled to the DWI data resolution. We load it here:
vol_anat = oio.get_t1(subject, resample=ni.load(oio.data_path + '/%s/%s_wm_mask.nii.gz'%(subject, subject)))
We calculate the rRMSE between the two instances of models (the two independent data sets) in each b value
rrmse_data = [oza.cross_predict(SD_1k_1, SD_1k_2), oza.cross_predict(SD_2k_1, SD_2k_2), oza.cross_predict(SD_4k_1, SD_4k_2)]
SparseDeconvolutionModel.model_params [****************100%******************] 57819 of 57820 complete
What follows are calls to generate the visualization. This is done using 3-D visualization in Mayavi.
%gui wx
fn = []
for vol_rmse in rrmse_data:
fn.append('%s.png'%tempfile.NamedTemporaryFile().name)
viz.plot_cut_planes(vol_anat,
overlay=vol_rmse,
vmin=0.5,
vmax=1.5,
overlay_cmap="RdYlGn",
invert_cmap=True,
slice_coronal=40,
slice_saggital=15,
slice_axial=30,
view_azim=-40,
view_elev=60,
file_name=fn[-1])
Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x132059b0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x181dc170> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x181ed4d0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x181eb830> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x181fcbf0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x18208ef0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x17d75cb0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x17d81dd0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x18780350> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x1878b650> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x18796950> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x1879ec50> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x992d3b0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x99376b0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x99409b0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x994bcb0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x9955fb0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x1d0cf2f0>
for this_fn in fn:
i = Image(filename=this_fn, width=1280, height=1024)
display(i)
fn = []
for vol_rmse in rrmse_data:
fn.append('%s.png'%tempfile.NamedTemporaryFile().name)
viz.plot_cut_planes(vol_anat,
overlay=vol_rmse,
vmin=0.5,
vmax=1.5,
overlay_cmap="RdYlGn",
invert_cmap=True,
slice_coronal=40,
slice_saggital=15,
slice_axial=45,
view_azim=40,
view_elev=60,
file_name=fn[-1])
Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x1d0ed3b0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x1e2376b0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x1e23f9b0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x1e248cb0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x1e255fb0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x1e26b2f0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x1fc70a10> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x1fc79d10> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x1fc87dd0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x2058d350> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x2059c650> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x205a1950> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x205c3fb0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x21f5c3b0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x21f696b0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x21f6f9b0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x21f78cb0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x21f86fb0>
for this_fn in fn:
i = Image(filename=this_fn, width=1280, height=1024)
display(i)
viz.plot_cut_planes(vol_anat,
overlay=rrmse_data[-1],
vmin=0.5,
vmax=1.5,
overlay_cmap="RdYlGn",
invert_cmap=True,
slice_coronal=None,
slice_saggital=None,
slice_axial=45,
view_azim=0,
view_elev=0)
Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x1d0d76b0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x235c8290>
<mayavi.core.scene.Scene at 0x235bae30>
%gui wx
viz.plot_cut_planes(vol_anat,
overlay=rrmse_data[-1],
vmin=0.5,
vmax=1.5,
overlay_cmap="RdYlGn",
invert_cmap=True,
slice_coronal=None,
slice_saggital=None,
slice_axial=30,
view_azim=0,
view_elev=0)
Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x24b7eef0> Cannot set extents for <mayavi.modules.image_plane_widget.ImagePlaneWidget object at 0x24b8b1d0>
<mayavi.core.scene.Scene at 0x24b7e5f0>