Skip to content

Commit 21978b4

Browse files
committed
[enh] update tutorial with more links, pictures
1 parent 4e04c6a commit 21978b4

File tree

1 file changed

+72
-2
lines changed

1 file changed

+72
-2
lines changed

MAIN_tutorial_intro_to_nilearn.ipynb

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
"import os\n",
4444
"import pandas as pd\n",
4545
"\n",
46-
"data_dir = '/home/Desktop/MAIN_tutorial/'\n",
46+
"data_dir = '/home/emdupre/Desktop/MAIN_tutorial/'\n",
4747
"participants = 'participants.tsv'\n",
4848
"phenotypic_data = pd.read_csv(os.path.join(data_dir, participants), sep='\\t')\n",
49-
"phenotypic.head()"
49+
"phenotypic_data.head()"
5050
]
5151
},
5252
{
@@ -229,6 +229,41 @@
229229
"print(fmri_masked.shape)"
230230
]
231231
},
232+
{
233+
"cell_type": "markdown",
234+
"metadata": {},
235+
"source": [
236+
"One way to think about what just happened is to look at it visually:\n",
237+
"\n",
238+
"![](http://nilearn.github.io/_images/masking.jpg)\n",
239+
"\n",
240+
"There are many other strategies in Nilearn [for masking data and for generating masks](http://nilearn.github.io/manipulating_images/manipulating_images.html#computing-and-applying-spatial-masks). I'd encourage you to spend some time exploring the documentation for these !"
241+
]
242+
},
243+
{
244+
"cell_type": "markdown",
245+
"metadata": {},
246+
"source": [
247+
"We can also [display this time series](http://nilearn.github.io/auto_examples/03_connectivity/plot_adhd_spheres.html#display-time-series) to get an intuition of how the whole brain signal is changing over time.\n",
248+
"\n",
249+
"We'll display the first three voxels by slicing the matrix using the colon-notation. You can also find more information on [how to slice arrays here](https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.indexing.html#basic-slicing-and-indexing)."
250+
]
251+
},
252+
{
253+
"cell_type": "code",
254+
"execution_count": null,
255+
"metadata": {},
256+
"outputs": [],
257+
"source": [
258+
"import matplotlib.pyplot as plt\n",
259+
"plt.plot(fmri_masked[:, :3])\n",
260+
"\n",
261+
"plt.title('Voxel Time Series')\n",
262+
"plt.xlabel('Scan number')\n",
263+
"plt.ylabel('Normalized signal')\n",
264+
"plt.tight_layout()"
265+
]
266+
},
232267
{
233268
"cell_type": "markdown",
234269
"metadata": {},
@@ -281,6 +316,17 @@
281316
"print(fmri_matrix.shape)"
282317
]
283318
},
319+
{
320+
"cell_type": "markdown",
321+
"metadata": {},
322+
"source": [
323+
"### [Compute and display a correlation matrix](http://nilearn.github.io/auto_examples/03_connectivity/plot_signal_extraction.html#compute-and-display-a-correlation-matrix)\n",
324+
"\n",
325+
"Now that we have a matrix, we'd like to create a _connectome_. A connectome is a map of the connections in the brain. Since we're working with functional data, however, we don't have access to actual connections. Instead, we'll use a measure of statistical dependency to infer the (possible) presence of a connection.\n",
326+
"\n",
327+
"Here, we'll use Pearson's correlation as our statistical dependency and compare how all of our ROIs from our chosen parcellation relate to one another."
328+
]
329+
},
284330
{
285331
"cell_type": "code",
286332
"execution_count": null,
@@ -292,6 +338,30 @@
292338
"correlation_measure"
293339
]
294340
},
341+
{
342+
"cell_type": "code",
343+
"execution_count": null,
344+
"metadata": {},
345+
"outputs": [],
346+
"source": [
347+
"correlation_matrix = correlation_measure.fit_transform([fmri_matrix])\n",
348+
"correlation_matrix"
349+
]
350+
},
351+
{
352+
"cell_type": "code",
353+
"execution_count": null,
354+
"metadata": {},
355+
"outputs": [],
356+
"source": [
357+
"import numpy as np\n",
358+
"\n",
359+
"correlation_matrix = correlation_matrix[0]\n",
360+
"# Mask the main diagonal for visualization:\n",
361+
"# np.fill_diagonal(correlation_matrix, 0)\n",
362+
"plotting.plot_matrix(correlation_matrix)"
363+
]
364+
},
295365
{
296366
"cell_type": "code",
297367
"execution_count": null,

0 commit comments

Comments
 (0)