Skip to content

Commit

Permalink
Add simulation exercise for multiple orientations
Browse files Browse the repository at this point in the history
  • Loading branch information
kaitj committed Apr 2, 2021
1 parent 666909f commit 32d994c
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions _episodes/constrained_spherical_deconvolution.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,5 +425,72 @@ References
Non-negativity constrained super-resolved spherical deconvolution",
Neuroimage, vol. 35, no. 4, pp. 1459-1472, 2007.

> ## Exercise 1
>
> In this episode, the ODF of a single fibre population (i.e. no crossing
> fibres) was visualized. Simulate what the ODF would look like given
> crossing angles of 90, 60, 45, 30, and 20 degrees. We have included
> helpful hints and code below to help you get started.
>
> Helpful hints:
> * To set the angle between tensors, use `[(0, 0), (angle, 0)]`
> * You may need to use a higher resolution sphere
> ~~~
> from dipy.sims.voxel import multi_tensor_odf
>
> # Eigenvalues for multiple orientations
> mevals = np.array(([0.0015, 0.00015, 0.00015], [0.0015, 0.00015, 0.00015]))
>
> # Set fractional value of each tensor
> fractions = [50, 50]
> ~~~
> {: .language-python}
>
> > ## Solution
> >
> > ~~~
> > import matplotlib.pyplot as plt
> >
> > import numpy as np
> >
> > from dipy.data import get_sphere
> > from dipy.viz import window, actor
> > from dipy.sims.voxel import multi_tensor_odf
> >
> > # Create output directory to stoage image
> > out_dir = '../../data/ds000221/derivatives/dwi/reconstruction/exercise/dwi/'
> >
> > if not os.path.exists(out_dir):
> > os.makedirs(out_dir)
> >
> > # Set eigenvalues for tensors
> > mevals = np.array(([0.0015, 0.00015, 0.00015], [0.0015, 0.00015, 0.00015]))
> >
> > # Set fraction for each tensor
> > fractions = [50, 50]
> >
> > fig, axes = plt.subplots(1,5, figsize=(10,10))
> >
> > # Create synthetic ODF of different angles
> > for ix, angle in enumerate([90, 60, 45, 30, 20]):
> > angles = [(0, 0), (angle, 0)]
> > odf = multi_tensor_odf(get_sphere("repulsion724").vertices, mevals, angles, fractions)
> > scene = window.Scene()
> > odf_actor = actor.odf_slicer(odf[None, None, None, :], sphere=get_sphere("repulsion724"),
> > colormap='plasma')
> > odf_actor.RotateX(90)
> > scene.add(odf_actor)
> > odf_scene_arr = window.snapshot(
> > scene, fname=os.path.join(out_dir, 'odf_%d_angle.png' % angle), size=(200, 200),
> > offscreen=True)
> >
> > axes[ix].imshow(odf_scene_arr, cmap="plasma", origin="lower")
> > axes[ix].axis("off")
> >
> > plt.show()
> > ~~~
> > {: .language-python}
> {: .solution}
{: .challenge}
{% include links.md %}

0 comments on commit 32d994c

Please sign in to comment.