|
43 | 43 | "import os\n",
|
44 | 44 | "import pandas as pd\n",
|
45 | 45 | "\n",
|
46 |
| - "data_dir = '/home/Desktop/MAIN_tutorial/'\n", |
| 46 | + "data_dir = '/home/emdupre/Desktop/MAIN_tutorial/'\n", |
47 | 47 | "participants = 'participants.tsv'\n",
|
48 | 48 | "phenotypic_data = pd.read_csv(os.path.join(data_dir, participants), sep='\\t')\n",
|
49 |
| - "phenotypic.head()" |
| 49 | + "phenotypic_data.head()" |
50 | 50 | ]
|
51 | 51 | },
|
52 | 52 | {
|
|
229 | 229 | "print(fmri_masked.shape)"
|
230 | 230 | ]
|
231 | 231 | },
|
| 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 | + "\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 | + }, |
232 | 267 | {
|
233 | 268 | "cell_type": "markdown",
|
234 | 269 | "metadata": {},
|
|
281 | 316 | "print(fmri_matrix.shape)"
|
282 | 317 | ]
|
283 | 318 | },
|
| 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 | + }, |
284 | 330 | {
|
285 | 331 | "cell_type": "code",
|
286 | 332 | "execution_count": null,
|
|
292 | 338 | "correlation_measure"
|
293 | 339 | ]
|
294 | 340 | },
|
| 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 | + }, |
295 | 365 | {
|
296 | 366 | "cell_type": "code",
|
297 | 367 | "execution_count": null,
|
|
0 commit comments