Skip to content

Commit

Permalink
final notebook updates
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmje committed Nov 12, 2020
1 parent b456044 commit d333535
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 43 deletions.
70 changes: 30 additions & 40 deletions docs/dwi/02-intro_dmri.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
"# Introduction to Diffusion MRI"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import warnings\n",
"warnings.filterwarnings(\"ignore\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -66,32 +76,14 @@
"In addition to the acquired diffusion images, two files are collected as part of the diffusion dataset. These files correspond to the gradient amplitude (b-values) and directions (b-vectors) of the diffusion measurement and are named with the extensions `.bval` and `.bvec` respectively. The b-value is the diffusion-sensitizing factor, and reflects the timing & strength of the gradients used to acquire the diffusion-weighted images. The b-vector corresponds to the direction of the diffusion sensitivity. Together these two files define the diffusion MRI measurement as a set of gradient directions and corresponding amplitudes."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from dipy.io.gradients import read_bvals_bvecs\n",
"from dipy.core.gradients import gradient_table"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### FSL format\n",
"\n",
"This format consists of a pair of ASCII text files, typically named `.bvec` & `.bval`. The bvals file consists of a single row of space-separated floating-point values, all in one row, with one value per volume in the DWI dataset. The bvecs file consists of 3 rows of space-separated floating-point values, with the first row corresponding to the x-component of the DW gradient vectors, one value per volume in the dataset; the second row corresponding to the y-component, and the third row to the z-component. A typical pair of FSL format DW gradient files might look like:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the example data below, we see that 2 b-values were chosen for this scanning sequence. The first few images were acquired with a b-value of 0 and are typically referred to as b=0 images. In these images, no DW gradient vector is applied either. These images don't hold any diffusion information and are used as a reference since they aren't subject to the same types of scanner artefacts that affect diffusion-weighted images. \n",
"\n",
"All of the remaining images have a b-value of 1000 and have a DW gradient vector associated with them. In these images, you can assess the diffusion of water in different directions based on the gradient vector that is applied."
"The bvals consists a single row of space-separated floating-point values with one value per volume in the DWI dataset. \n",
"The bvecs file consists of 3 rows of space-separated floating-point values. The first row corresponds to the x-component of the DW gradient vectors, one value per volume in the dataset; the second row corresponding to the y-component, and the third row to the z-component. A typical `.bval` and `.bvec` file are shown below:"
]
},
{
Expand Down Expand Up @@ -120,7 +112,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"After reading the `.bval` and `.bvec` files with the `read_bvals_bvecs()` function, we get both in a numpy array. Notice that the `.bvec` file has been transposed so that the x, y, and z-components are in column format."
"In the example data above, we see that 2 b-values were chosen for this scanning sequence. The first few images were acquired with a b-value of 0 and are typically referred to as b=0 images. In these images, no DW gradient vector is applied either. These images don't hold any diffusion information and are used as a reference since they aren't subject to the same types of scanner artefacts that affect diffusion-weighted images. \n",
"\n",
"All of the remaining images have a b-value of 1000 and have a DW gradient vector associated with them. In these images, you can assess the diffusion of water in different directions based on the gradient vector that is applied."
]
},
{
Expand All @@ -129,17 +123,24 @@
"metadata": {},
"outputs": [],
"source": [
"gt_bvals, gt_bvecs = read_bvals_bvecs(bval, bvec)"
"from dipy.io.gradients import read_bvals_bvecs"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"After reading the `.bval` and `.bvec` files with the `read_bvals_bvecs()` function, we get both in a numpy array. Notice that the `.bvec` file has been transposed so that the x, y, and z-components are in column format."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"gt_bvals, gt_bvecs = read_bvals_bvecs(bval, bvec)\n",
"\n",
"print(\"bvals:\\n\", gt_bvals, \"\\n\\nbvecs:\\n\", gt_bvecs)"
]
},
Expand All @@ -163,18 +164,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"It is important to note that in this format, the gradient vectors are provided with respect to the image axes, not in real or scanner coordinates. Simply reformatting the image from sagittal to axial will effectively rotate the b-vectors, since this operation changes the image axes. Thus, a particular bvals/bvecs pair is only valid for the particular image that it corresponds to."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### RASB+ format\n",
"\n",
"Inspired by MRtrix3 and the [BIDS spec](https://github.com/bids-standard/bids-specification/issues/349).\n",
"### `.bval` and `.bvec` handling in `dMRIPRep`\n",
"\n",
"One row per DWI volume, with each row consisting of 4 space-separated floating-point values; these correspond to [x y z b], where [x y z] are the components of the gradient vector, and b is the b-value in units of s/mm2."
"`dMRIPrep` includes a Python class called `DiffusionGradientTable` that does a lot of heavy lifting."
]
},
{
Expand Down Expand Up @@ -207,12 +199,10 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"gtab.gradients"
"Now, let's take a look at another dwi sequence. This one has multiple b-values."
]
},
{
Expand Down
10 changes: 10 additions & 0 deletions docs/dwi/03-issue_solution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
"# Issue Solution: Determining the number of shells"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import warnings\n",
"warnings.filterwarnings(\"ignore\")"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
dmriprep==0.3.0
flake8
ghp-import
jupyter-book==0.8.3
jupyter-book
jupytext
pytest
nbdime

0 comments on commit d333535

Please sign in to comment.