|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "metadata": { |
| 7 | + "scrolled": false |
| 8 | + }, |
| 9 | + "outputs": [ |
| 10 | + { |
| 11 | + "name": "stderr", |
| 12 | + "output_type": "stream", |
| 13 | + "text": [ |
| 14 | + "/Users/janfreyberg/anaconda3/envs/py36/lib/python3.6/site-packages/h5py/__init__.py:36: 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", |
| 15 | + " from ._conv import register_converters as _register_converters\n" |
| 16 | + ] |
| 17 | + } |
| 18 | + ], |
| 19 | + "source": [ |
| 20 | + "from niwidgets.niwidget_volume import VolumeWidget, NiftiWidget\n", |
| 21 | + "from niwidgets.exampledata import examplet1\n", |
| 22 | + "from IPython import display\n" |
| 23 | + ] |
| 24 | + }, |
| 25 | + { |
| 26 | + "cell_type": "markdown", |
| 27 | + "metadata": {}, |
| 28 | + "source": [ |
| 29 | + "The new volume widget works slightly differently: It doesn't rely on `widgets.interact`, and therefore allows more control over the interactive elements, and what happens when they change. For example, we can make cool play buttons to move through the brain smoothly.\n", |
| 30 | + "\n", |
| 31 | + "You also don't need to call a plotter / rendering function anymore (although you can)." |
| 32 | + ] |
| 33 | + }, |
| 34 | + { |
| 35 | + "cell_type": "code", |
| 36 | + "execution_count": 3, |
| 37 | + "metadata": { |
| 38 | + "scrolled": false |
| 39 | + }, |
| 40 | + "outputs": [ |
| 41 | + { |
| 42 | + "data": { |
| 43 | + "application/vnd.jupyter.widget-view+json": { |
| 44 | + "model_id": "7932ddd4bdcd4fd883497ad46026882a", |
| 45 | + "version_major": 2, |
| 46 | + "version_minor": 0 |
| 47 | + }, |
| 48 | + "text/plain": [ |
| 49 | + "VBox(children=(Box(children=(PlaySlider(children=(Label(value='X: '), Play(value=45, interval=300, max=90), In…" |
| 50 | + ] |
| 51 | + }, |
| 52 | + "metadata": {}, |
| 53 | + "output_type": "display_data" |
| 54 | + } |
| 55 | + ], |
| 56 | + "source": [ |
| 57 | + "widget = VolumeWidget(examplet1, colormap='viridis')\n", |
| 58 | + "\n", |
| 59 | + "widget # equivalent to widget.render()" |
| 60 | + ] |
| 61 | + }, |
| 62 | + { |
| 63 | + "cell_type": "markdown", |
| 64 | + "metadata": {}, |
| 65 | + "source": [ |
| 66 | + "Amongst other things, you can now choose whether to follow radiological standards (left-right mirror images). Turned on by default, you can either untick the checkbox, or pass it as an argument to the widget:" |
| 67 | + ] |
| 68 | + }, |
| 69 | + { |
| 70 | + "cell_type": "code", |
| 71 | + "execution_count": 4, |
| 72 | + "metadata": {}, |
| 73 | + "outputs": [ |
| 74 | + { |
| 75 | + "data": { |
| 76 | + "application/vnd.jupyter.widget-view+json": { |
| 77 | + "model_id": "b7df1220e0104e8f9bd32971155cfe17", |
| 78 | + "version_major": 2, |
| 79 | + "version_minor": 0 |
| 80 | + }, |
| 81 | + "text/plain": [ |
| 82 | + "VBox(children=(Box(children=(PlaySlider(children=(Label(value='X: '), Play(value=45, interval=300, max=90), In…" |
| 83 | + ] |
| 84 | + }, |
| 85 | + "metadata": {}, |
| 86 | + "output_type": "display_data" |
| 87 | + } |
| 88 | + ], |
| 89 | + "source": [ |
| 90 | + "widget = VolumeWidget(examplet1, orient_radiology=False)\n", |
| 91 | + "\n", |
| 92 | + "widget" |
| 93 | + ] |
| 94 | + }, |
| 95 | + { |
| 96 | + "cell_type": "markdown", |
| 97 | + "metadata": {}, |
| 98 | + "source": [ |
| 99 | + "In addition, composing the widget from scratch means that the control elements and plots can re-flow if the page isn't large enough. Try shrinking your browser window, or adjusting the figure size:" |
| 100 | + ] |
| 101 | + }, |
| 102 | + { |
| 103 | + "cell_type": "code", |
| 104 | + "execution_count": 5, |
| 105 | + "metadata": { |
| 106 | + "scrolled": false |
| 107 | + }, |
| 108 | + "outputs": [ |
| 109 | + { |
| 110 | + "data": { |
| 111 | + "application/vnd.jupyter.widget-view+json": { |
| 112 | + "model_id": "883c5edfafd747fcaa8427d5c0926ba0", |
| 113 | + "version_major": 2, |
| 114 | + "version_minor": 0 |
| 115 | + }, |
| 116 | + "text/plain": [ |
| 117 | + "VBox(children=(Box(children=(PlaySlider(children=(Label(value='X: '), Play(value=45, interval=300, max=90), In…" |
| 118 | + ] |
| 119 | + }, |
| 120 | + "metadata": {}, |
| 121 | + "output_type": "display_data" |
| 122 | + } |
| 123 | + ], |
| 124 | + "source": [ |
| 125 | + "widget = VolumeWidget(examplet1, figsize=(6, 6))\n", |
| 126 | + "\n", |
| 127 | + "widget" |
| 128 | + ] |
| 129 | + }, |
| 130 | + { |
| 131 | + "cell_type": "markdown", |
| 132 | + "metadata": {}, |
| 133 | + "source": [ |
| 134 | + "Lastly, making the control elements part of the class means you can interact with it more like a normal python object, e.g. get and set the elements of the graph as python attributes:" |
| 135 | + ] |
| 136 | + }, |
| 137 | + { |
| 138 | + "cell_type": "code", |
| 139 | + "execution_count": 6, |
| 140 | + "metadata": {}, |
| 141 | + "outputs": [ |
| 142 | + { |
| 143 | + "name": "stdout", |
| 144 | + "output_type": "stream", |
| 145 | + "text": [ |
| 146 | + "[45, 54, 45]\n", |
| 147 | + "viridis\n", |
| 148 | + "summer\n" |
| 149 | + ] |
| 150 | + } |
| 151 | + ], |
| 152 | + "source": [ |
| 153 | + "print(widget.indices)\n", |
| 154 | + "print(widget.colormap)\n", |
| 155 | + "widget.colormap = 'summer'\n", |
| 156 | + "print(widget.colormap)" |
| 157 | + ] |
| 158 | + } |
| 159 | + ], |
| 160 | + "metadata": { |
| 161 | + "kernelspec": { |
| 162 | + "display_name": "Python 3", |
| 163 | + "language": "python", |
| 164 | + "name": "python3" |
| 165 | + }, |
| 166 | + "language_info": { |
| 167 | + "codemirror_mode": { |
| 168 | + "name": "ipython", |
| 169 | + "version": 3 |
| 170 | + }, |
| 171 | + "file_extension": ".py", |
| 172 | + "mimetype": "text/x-python", |
| 173 | + "name": "python", |
| 174 | + "nbconvert_exporter": "python", |
| 175 | + "pygments_lexer": "ipython3", |
| 176 | + "version": "3.6.3" |
| 177 | + }, |
| 178 | + "toc": { |
| 179 | + "nav_menu": {}, |
| 180 | + "number_sections": true, |
| 181 | + "sideBar": true, |
| 182 | + "skip_h1_title": false, |
| 183 | + "toc_cell": false, |
| 184 | + "toc_position": {}, |
| 185 | + "toc_section_display": "block", |
| 186 | + "toc_window_display": false |
| 187 | + } |
| 188 | + }, |
| 189 | + "nbformat": 4, |
| 190 | + "nbformat_minor": 2 |
| 191 | +} |
0 commit comments