From ec3c6f65e9e8f36d56dcced6d3e8ca1c32830519 Mon Sep 17 00:00:00 2001 From: Michiel Cottaar <MichielCottaar@gmail.com> Date: Fri, 16 Feb 2018 14:16:19 +0000 Subject: [PATCH] BUG: updated the ipython notebook files --- talks/nibabel_cifti/nibabel_cifti.ipynb | 183 ++++-------------------- talks/packages/packages.ipynb | 90 +----------- 2 files changed, 29 insertions(+), 244 deletions(-) diff --git a/talks/nibabel_cifti/nibabel_cifti.ipynb b/talks/nibabel_cifti/nibabel_cifti.ipynb index a98c7aa..890f974 100644 --- a/talks/nibabel_cifti/nibabel_cifti.ipynb +++ b/talks/nibabel_cifti/nibabel_cifti.ipynb @@ -2,18 +2,9 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/ndcn0236/miniconda3/lib/python3.6/site-packages/h5py/__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n", - " from ._conv import register_converters as _register_converters\n" - ] - } - ], + "outputs": [], "source": [ "%matplotlib nbagg\n", "import numpy as np\n", @@ -50,9 +41,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "img = nib.load('100307/T1w.nii.gz')\n", @@ -74,9 +63,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "img = nib.load('100307/fsaverage_LR32k/100307.L.white.32k_fs_LR.surf.gii')\n", @@ -87,9 +74,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "from nibabel import freesurfer\n", @@ -98,21 +83,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([2.9977965, 2.7661548, 3.0803757, ..., 2.47089 , 2.2333388,\n", - " 2.363499 ], dtype=float32)" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "thickness = nib.load('100307/fsaverage_LR32k/100307.L.thickness.32k_fs_LR.shape.gii').darrays[0].data\n", "thickness" @@ -153,9 +126,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "!pip install git+https://github.com/MichielCottaar/cifti.git" @@ -172,7 +143,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -188,9 +159,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "!wb_view 100307/fsaverage_LR32k/100307.*.32k_fs_LR.surf.gii random_ctx.dscalar.nii" @@ -198,26 +167,24 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "img = ni.load('100307/aparc+aseg.nii.gz')\n", + "img = nib.load('100307/aparc+aseg.nii.gz')\n", "cerebellum = img.get_data() == 8\n", "\n", "bm_cerebellum = cifti.BrainModel.from_mask(cerebellum, name='CerebellumLeft', affine=img.affine)\n", "bm = bm_ctx + bm_cerebellum\n", - "sc = cifti.Scalar.from_names(['random'])\n", - "arr = np.random.rand(len(bm))\n", - "cifti.write('random_ctx_cerebellum.dscalar.nii', arr[None, :], (sc, bm))" + "sc = cifti.Scalar.from_names(['random1', 'random2'])\n", + "arr = np.random.rand(2, len(bm))\n", + "cifti.write('random_ctx_cerebellum.dscalar.nii', arr, (sc, bm))" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "!wb_view 100307/fsaverage_LR32k/100307.*.32k_fs_LR.surf.gii 100307/T1w.nii.gz random_ctx_cerebellum.dscalar.nii" @@ -226,9 +193,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "arr = abs(thickness[ctx, None] - thickness[None, ctx])\n", @@ -238,9 +203,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "!wb_view 100307/fsaverage_LR32k/100307.*.32k_fs_LR.surf.gii diff_thickness.dconn.nii" @@ -255,10 +218,8 @@ }, { "cell_type": "code", - "execution_count": 7, - "metadata": { - "collapsed": true - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ "parcels = cifti.Parcels.from_brain_models([('thin', bm_ctx[thickness[ctx] < 2]),\n", @@ -266,7 +227,9 @@ " ('thick', bm_ctx[thickness[ctx] > 3]),\n", " ])\n", "scl = cifti.Scalar.from_names(['rgb'])\n", - "label = scl.to_label([{1: ('red', (1, 0, 0, 1)), 2: ('green', (0, 1, 0, 1)), 3: ('blue', (0, 0, 1, 1))}])\n", + "label = scl.to_label([{1: ('red', (1, 0, 0, 1)),\n", + " 2: ('green', (0, 1, 0, 1)),\n", + " 3: ('blue', (0, 0, 1, 1))}])\n", "arr = np.array([[1, 2, 3]])\n", "cifti.write('labels.plabel.nii', arr, (label, parcels))" ] @@ -275,109 +238,13 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Info: Resources loaded:\n", - " :/About :/Cursor :/Fonts :/HelpFiles :/LayersPanel :/PaletteSettings :/resources.qrc :/SpecFileDialog :/Splash :/ToolBar :/trolltech :/update_resources.sh\n", - "\n", - "\n", - "Info: Time to color volume data is 0.581 seconds.\n", - "\n", - "\n", - "Info: Time to read /Users/ndcn0236/Work/projects/pytreat-2018-practicals/talks/nibabel_cifti/100307/T1w.nii.gz was 1.06257 seconds.\n", - "\n", - "\n", - "Info: Time to read /Users/ndcn0236/Work/projects/pytreat-2018-practicals/talks/nibabel_cifti/100307/fsaverage_LR32k/100307.L.inflated.32k_fs_LR.surf.gii was 0.111264 seconds.\n", - "\n", - "\n", - "Info: Time to read /Users/ndcn0236/Work/projects/pytreat-2018-practicals/talks/nibabel_cifti/100307/fsaverage_LR32k/100307.L.midthickness.32k_fs_LR.surf.gii was 0.019432 seconds.\n", - "\n", - "\n", - "Info: Time to read /Users/ndcn0236/Work/projects/pytreat-2018-practicals/talks/nibabel_cifti/100307/fsaverage_LR32k/100307.L.pial.32k_fs_LR.surf.gii was 0.019506 seconds.\n", - "\n", - "\n", - "Info: Time to read /Users/ndcn0236/Work/projects/pytreat-2018-practicals/talks/nibabel_cifti/100307/fsaverage_LR32k/100307.L.very_inflated.32k_fs_LR.surf.gii was 0.019134 seconds.\n", - "\n", - "\n", - "Info: Time to read /Users/ndcn0236/Work/projects/pytreat-2018-practicals/talks/nibabel_cifti/100307/fsaverage_LR32k/100307.L.white.32k_fs_LR.surf.gii was 0.018743 seconds.\n", - "\n", - "\n", - "Info: Time to read /Users/ndcn0236/Work/projects/pytreat-2018-practicals/talks/nibabel_cifti/100307/fsaverage_LR32k/100307.R.inflated.32k_fs_LR.surf.gii was 0.087767 seconds.\n", - "\n", - "\n", - "Info: Time to read /Users/ndcn0236/Work/projects/pytreat-2018-practicals/talks/nibabel_cifti/100307/fsaverage_LR32k/100307.R.midthickness.32k_fs_LR.surf.gii was 0.019677 seconds.\n", - "\n", - "\n", - "Info: Time to read /Users/ndcn0236/Work/projects/pytreat-2018-practicals/talks/nibabel_cifti/100307/fsaverage_LR32k/100307.R.pial.32k_fs_LR.surf.gii was 0.019088 seconds.\n", - "\n", - "\n", - "Info: Time to read /Users/ndcn0236/Work/projects/pytreat-2018-practicals/talks/nibabel_cifti/100307/fsaverage_LR32k/100307.R.very_inflated.32k_fs_LR.surf.gii was 0.019656 seconds.\n", - "\n", - "\n", - "Info: Time to read /Users/ndcn0236/Work/projects/pytreat-2018-practicals/talks/nibabel_cifti/100307/fsaverage_LR32k/100307.R.white.32k_fs_LR.surf.gii was 0.018397 seconds.\n", - "\n", - "\n", - "Info: Time to read /Users/ndcn0236/Work/projects/pytreat-2018-practicals/talks/nibabel_cifti/labels.plabel.nii was 0.651135 seconds.\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "!wb_view 100307/fsaverage_LR32k/100307.*.32k_fs_LR.surf.gii 100307/T1w.nii.gz labels.plabel.nii" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] } ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.2" - }, - "toc": { - "colors": { - "hover_highlight": "#DAA520", - "running_highlight": "#FF0000", - "selected_highlight": "#FFD700" - }, - "moveMenuLeft": true, - "nav_menu": { - "height": "176px", - "width": "252px" - }, - "navigate_menu": true, - "number_sections": true, - "sideBar": true, - "threshold": 4, - "toc_cell": false, - "toc_section_display": "block", - "toc_window_display": false - } - }, + "metadata": {}, "nbformat": 4, "nbformat_minor": 2 } diff --git a/talks/packages/packages.ipynb b/talks/packages/packages.ipynb index 0c2b66f..84bc379 100644 --- a/talks/packages/packages.ipynb +++ b/talks/packages/packages.ipynb @@ -32,7 +32,10 @@ "source": [ "Numpy includes support for:\n", "- N-dimensional arrays with various datatypes\n", - "- basic functions (e.g., polynomials)\n", + " - masked arrays\n", + " - matrices\n", + " - structured/record array\n", + "- basic functions (e.g., sin, log, arctan, polynomials)\n", "- basic linear algebra\n", "- random number generation\n", "\n", @@ -513,91 +516,6 @@ "## Neuroimage packages\n", "The [nipy](http://nipy.org/) ecosystem covers most of these.\n", "\n", - "### [CIFTI](https://github.com/MichielCottaar/cifti): easy creation/manipulation" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import nibabel\n", - "thickness = nibabel.load('100307/fsaverage_LR32k/100307.L.thickness.32k_fs_LR.shape.gii').darrays[0].data\n", - "thickness" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import cifti\n", - "ctx = thickness != 0\n", - "arr = np.random.rand(ctx.sum())\n", - "\n", - "bm_ctx = cifti.BrainModel.from_mask(ctx, name='CortexLeft')\n", - "sc = cifti.Scalar.from_names(['random'])\n", - "cifti.write('random_ctx.dscalar.nii', arr[None, :], (sc, bm_ctx))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "!wb_view 100307/fsaverage_LR32k/100307.*.32k_fs_LR.surf.gii random_ctx.dscalar.nii" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "img = nibabel.load('100307/aparc+aseg.nii.gz')\n", - "cerebellum = img.get_data() == 8\n", - "\n", - "bm = bm_ctx + cifti.BrainModel.from_mask(cerebellum, name='CerebellumLeft', affine=img.affine)\n", - "sc = cifti.Scalar.from_names(['random'])\n", - "arr = np.random.rand(len(bm))\n", - "cifti.write('random_ctx_cerebellum.dscalar.nii', arr[None, :], (sc, bm))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "!wb_view 100307/fsaverage_LR32k/100307.*.32k_fs_LR.surf.gii 100307/aparc+aseg.nii.gz random_ctx_cerebellum.dscalar.nii" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "arr = abs(thickness[ctx, None] - thickness[None, ctx])\n", - "cifti.write('diff_thickness.dconn.nii', arr, (bm_ctx, bm_ctx))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "!wb_view 100307/fsaverage_LR32k/100307.*.32k_fs_LR.surf.gii diff_thickness.dconn.nii" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ "## [networkx](https://networkx.github.io/): graph theory\n", "\n", "## GUI\n", -- GitLab