diff --git a/talks/matlab_vs_python/migp/python_MIGP.ipynb b/talks/matlab_vs_python/migp/python_MIGP.ipynb index 50993ca54b2b7cd9a1888a5869e4a4d63102b84b..c447f9162a0f30400cbdfef98070c14940de13ac 100644 --- a/talks/matlab_vs_python/migp/python_MIGP.ipynb +++ b/talks/matlab_vs_python/migp/python_MIGP.ipynb @@ -107,7 +107,7 @@ "random.shuffle(in_list)\n", "\n", "# load and unravel brainmask\n", - "mask = in_mask.get_fdata().ravel()\n", + "mask = in_mask.get_fdata(caching='unchanged') != 0.0\n", "\n", "# function to demean the data\n", "def demean(x):\n", @@ -118,9 +118,7 @@ " \n", " # read data\n", " print(f'Reading data file {f.get_filename()}')\n", - " grot = f.get_fdata()\n", - " grot = np.reshape(grot, [-1, grot.shape[-1]])\n", - " grot = grot[mask!=0, :].T\n", + " grot = f.get_fdata(caching='unchanged')[mask].T\n", " \n", " # demean\n", " print(f'\\tRemoving mean image')\n", @@ -143,13 +141,13 @@ " # reduce W to dPCA_int eigenvectors\n", " if W.shape[0]-10 > dPCA_int:\n", " print(f'\\tReducing data matrix to a {dPCA_int} dimensional subspace')\n", - " uu = eigs(W@W.T, dPCA_int)[1]\n", + " uu = eigs(np.dot(W, W.T), dPCA_int)[1]\n", " uu = np.real(uu)\n", - " W = uu.T @ W\n", + " W = np.dot(uu.T, W)\n", " \n", "# reshape and save\n", - "grot = np.zeros([mask.shape[0], dPCA_out])\n", - "grot[mask!=0, :] = W[:dPCA_out, :].T\n", + "grot = np.zeros([mask.size, dPCA_out])\n", + "grot[mask.ravel(), :] = W[:dPCA_out, :].T\n", "grot = np.reshape(grot, in_list[0].shape[:3] + (dPCA_out,))\n", "\n", "print(f'Save to {GO}')\n", @@ -254,6 +252,13 @@ "ics = nb.load('pymigp.gica/melodic_IC.nii.gz')\n", "fig = map_plot(ics)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {