Skip to content

Commit 250f695

Browse files
authored
Merge pull request #134 from oesteban/docs/comment-notebooks-2
ENH: Add more comprehensive comments to notebook
2 parents d02db15 + 1d5e510 commit 250f695

File tree

1 file changed

+65
-11
lines changed

1 file changed

+65
-11
lines changed

docs/notebooks/02_afni_deoblique.ipynb

+65-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@
99
"This notebook explores the implementation of *deobliquing* operations in AFNI, in order to be able to correctly manipulate transforms generated by the tool, and to produce transforms that can be correctly applied with AFNI.\n",
1010
"Most of the preparation comes from the previous notebook.\n",
1111
"\n",
12-
"### Preparation"
12+
"This notebook is the test bed for resolving [issue #45](https://github.com/poldracklab/nitransforms/issues/45)"
13+
]
14+
},
15+
{
16+
"cell_type": "markdown",
17+
"metadata": {},
18+
"source": [
19+
"### Preamble\n",
20+
"Prepare a Python environment and use a temporal directory for the outputs. After that, fetch the actual file from NiBabel documentation."
1321
]
1422
},
1523
{
@@ -72,6 +80,14 @@
7280
"!wget https://nipy.org/nibabel/_downloads/62985f4c43f499609fa65cb2eb955b79/someones_anatomy.nii.gz"
7381
]
7482
},
83+
{
84+
"cell_type": "markdown",
85+
"metadata": {},
86+
"source": [
87+
"### Load in the image\n",
88+
"Let's first visualize the example image, and retain some copies of the original header and affine."
89+
]
90+
},
7591
{
7692
"cell_type": "code",
7793
"execution_count": 78,
@@ -109,6 +125,14 @@
109125
"nii.orthoview()"
110126
]
111127
},
128+
{
129+
"cell_type": "markdown",
130+
"metadata": {},
131+
"source": [
132+
"### Generating variants\n",
133+
"Playing with the affine header and the data array ordering of axes and elements we generate several versions of the dataset with different orientations (LAS, LPS, oblique, LPS oblique)."
134+
]
135+
},
112136
{
113137
"cell_type": "code",
114138
"execution_count": 79,
@@ -148,6 +172,14 @@
148172
"lpsnew.to_filename('someones_anatomy_lpsrot.nii.gz')"
149173
]
150174
},
175+
{
176+
"cell_type": "markdown",
177+
"metadata": {},
178+
"source": [
179+
"### Print affines of interest\n",
180+
"Output some affines that we will want to compare to their counterparts generated by AFNI and stored in the NIfTI header"
181+
]
182+
},
151183
{
152184
"cell_type": "code",
153185
"execution_count": 194,
@@ -208,7 +240,8 @@
208240
"cell_type": "markdown",
209241
"metadata": {},
210242
"source": [
211-
"### Run `3dWarp -deoblique`"
243+
"### Run `3dWarp -deoblique`\n",
244+
"Generate one example image after \"deobliquing\", to then see if we can generate equivalent composite transforms"
212245
]
213246
},
214247
{
@@ -260,6 +293,15 @@
260293
"Warp(in_file='someones_anatomy_rot.nii.gz', deoblique=True, verbose=True, out_file='deob.nii.gz').run()"
261294
]
262295
},
296+
{
297+
"cell_type": "markdown",
298+
"metadata": {},
299+
"source": [
300+
"### Generating AFNI's \"deobliquing\" matrices\n",
301+
"\n",
302+
"Based on the image's information, we need to reconstruct AFNI's `WARPDRIVE_MATVEC_FOR_000000` affine, and then check that the results of applying such a matrix ends in the same outcome with AFNI and NiTransforms tools."
303+
]
304+
},
263305
{
264306
"cell_type": "code",
265307
"execution_count": 204,
@@ -302,7 +344,10 @@
302344
"cell_type": "markdown",
303345
"metadata": {},
304346
"source": [
305-
"### Inspecting affines and headers"
347+
"### Inspecting affines and headers\n",
348+
"Generate a rotation affine to apply on the original affine of an image, and try to reconstruct the inverse of it as AFNI calculates it.\n",
349+
"\n",
350+
"The following cells are just prior information useful for when we arrive to the next section"
306351
]
307352
},
308353
{
@@ -1043,7 +1088,8 @@
10431088
"cell_type": "markdown",
10441089
"metadata": {},
10451090
"source": [
1046-
"### Reverse-engineering matrix compositions of oblique datasets"
1091+
"### Reverse-engineering matrix compositions of oblique datasets\n",
1092+
"Calculating AFNI's affines based on the oblique image information"
10471093
]
10481094
},
10491095
{
@@ -1098,6 +1144,14 @@
10981144
"print(R)"
10991145
]
11001146
},
1147+
{
1148+
"cell_type": "markdown",
1149+
"metadata": {},
1150+
"source": [
1151+
"### Visually test whether we correctly apply dual transforms with both tools\n",
1152+
"Load images generated with AFNI and with NiTransforms to check whether NiTransforms is operating as expected"
1153+
]
1154+
},
11011155
{
11021156
"cell_type": "code",
11031157
"execution_count": 195,
@@ -1152,6 +1206,13 @@
11521206
"# nb.load('moved-affine-oblique-inv-T-for-master.nii.gz').orthoview()"
11531207
]
11541208
},
1209+
{
1210+
"cell_type": "markdown",
1211+
"metadata": {},
1212+
"source": [
1213+
"If both derivatives are resampled in the same space, the following figure should be almost (or fully) blank."
1214+
]
1215+
},
11551216
{
11561217
"cell_type": "code",
11571218
"execution_count": 196,
@@ -1184,13 +1245,6 @@
11841245
"deob = nb.load('deob.nii.gz')\n",
11851246
"nb.Nifti1Image(np.abs(deob.get_fdata() - nb.load('deob-for2.nii.gz').get_fdata()), deob.affine, deob.header).orthoview()"
11861247
]
1187-
},
1188-
{
1189-
"cell_type": "code",
1190-
"execution_count": null,
1191-
"metadata": {},
1192-
"outputs": [],
1193-
"source": []
11941248
}
11951249
],
11961250
"metadata": {

0 commit comments

Comments
 (0)