{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# itk-jupyter-widgets\n", "\n", "## Interactive 3D and 2D Visualization in Jupyter\n", "\n", "TriPython March 2018 Meeting\n", "\n", "Matthew McCormick, PhD\n", "\n", "Kitware, Inc\n", "\n", "[](https://github.com/InsightSoftwareConsortium/itk-jupyter-widgets)\n", "\n", "[](http://trizpug.org/)\n", "\n", "[](https://creativecommons.org/share-your-work/public-domain/cc0/)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "from itkwidgets import view\n", "\n", "import requests\n", "import itk\n", "\n", "import shutil\n", "import os\n", "\n", "# Download data\n", "fileName = '005_32months_T2_RegT1_Reg2Atlas_ManualBrainMask_Stripped.nrrd'\n", "if not os.path.exists(fileName):\n", " response = requests.get('https://data.kitware.com/api/v1/file/564a5b078d777f7522dbfaa6/download', stream=True)\n", " with open(fileName, 'wb') as fp:\n", " response.raw.decode_content = True\n", " shutil.copyfileobj(response.raw, fp)\n", " \n", "# Download data\n", "brainFileName = 'brainweb165a10f17.mha'\n", "if not os.path.exists(brainFileName):\n", " response = requests.get('https://data.kitware.com/api/v1/file/588271308d777f4f3f3072e2/download', stream=True)\n", " with open(brainFileName, 'wb') as fp:\n", " response.raw.decode_content = True\n", " shutil.copyfileobj(response.raw, fp)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "from itkwidgets import view\n", "import itk\n", "image = itk.imread(fileName)\n", "#view(image)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Agenda\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "### Where have we come from? Where are we going?" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "### What is the problem we are solving?" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "### What technical approaches are required for this problem?" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "### How do I use this tool?" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "### What are the next steps?" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Where have we come from?\n", "\n", "## Where are we going?" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "*with interactive scientific computing in the SciPy ecosystem*" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### IPython Shell\n", "\n", "Original author: Fernando PĂ©rez\n", "\n", "\n", "Image source\n", "\n", "Initial release: 2001" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### IPython Shell\n", "\n", "IPython 0.7.2 released June 6, 2006\n", "\n", "\n", "[Image source](https://en.wikipedia.org/wiki/IPython)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "- Interactive: **tab completion**\n", "- Accessible: Matlab $\\rightarrow$ **Scientific Python**\n", "- Brings powerful programming tools together: **matplotlib** integration" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### IPython Notebook\n", "\n", "IPython 0.12.0 released December 18, 2011\n", "\n", "\n", "[Image source](http://pgbovine.net/ipython-notebook-first-impressions.htm)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "- Interactive: creates *a tool for open, collaborative, reproducible scientific computing*\n", "- Accessible: Terminal $\\rightarrow$ **Web browser**\n", "- Brings powerful programming tools together: Literate programming: Markdown + $\\LaTeX$ **prose**, IPython shell **code** cells, and matplotlib **visualizations**" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### Jupyter Notebook\n", "\n", "Fernando announces Project Jupyter at SciPy 2014\n", "\n", "\n", "[Image source](https://jupyter.org/)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "- Interactive: Adds a file browser, browser-based terminal, and browser-based text editor\n", "- Accessible: Open standards for interative computing to enabled customized applications: Notebook Document Format, Interactive Computing Protocol, The Kernel\n", "- Brings powerful programming tools together: Expands support for programming language kernels **other than Python**" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### JupyterLab\n", "\n", "[\"JupyterLab is Ready for Users\"](https://blog.jupyter.org/jupyterlab-is-ready-for-users-5a6f039b8906) - February 20, 2018\n", "\n", "\n", "[Image source](https://blog.jupyter.org/jupyterlab-is-ready-for-users-5a6f039b8906)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "- Interactive: Browser-based **window management**, customized viewers for different file types\n", "- Accessible: Drag and drop cells, easy deploy with *Docker-based* JupyterHub\n", "- Brings powerful programming tools together: Made with **community-developed extensions** in mind" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### The Future\n", "\n", "\n", "[Image source](https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript)\n", "\n", "\"To start developing a JupyterLab extension, see the JupyterLab Extension Developer Guide and the **TypeScript** or **JavaScript** extension templates. JupyterLab itself is co-developed on top of **PhosphorJS**, a new **Javascript** library for **building extensible, high-performance, desktop-style web applications**. We use **modern JavaScript technologies** such as **TypeScript, React, Lerna, Yarn, and webpack**.\"" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "- Interactive: **Browser-based application**\n", "- Accessible: **Zero-install**, works on **all platforms**\n", "- Brings powerful programming tools together: **JavaScript**, **WebGL**, **WebAssembly**" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## What is the problem we are solving?\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "*Interactive visualization to support multi-dimensional spatial analysis*" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### ipyleaflet\n", "\n", "*A Jupyter / Leaflet bridge enabling interactive maps in the Jupyter notebook.*\n", "\n", "\n", "\n", "[Image source](https://github.com/ellisonbg/ipyleaflet)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### GeoNotebook\n", "\n", "*GeoNotebook is an application that provides client/server environment with interactive visualization and analysis capabilities using Jupyter, GeoJS and other open source tools.*\n", "\n", "\n", "\n", "[Image source](https://github.com/OpenGeoscience/geonotebook)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### ipyvolume\n", "\n", "*3d plotting for Python in the Jupyter notebook based on IPython widgets using WebGL.*\n", "\n", "\n", "\n", "[Image source](https://github.com/maartenbreddels/ipyvolume)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### pythreejs\n", "\n", "*A Python / ThreeJS bridge utilizing the Jupyter widget infrastructure.*\n", "\n", "\n", "\n", "[Image source](https://github.com/jovyan/pythreejs)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### itk-jupyter-widgets\n", "\n", "These widgets are designed to support spatial analysis with the [Insight Toolkit (ITK)](https://www.itk.org), but they also work with other spatial analysis tools in the scientific Python ecosystem.\n", "\n", "These widgets are built on [itk.js](https://github.com/InsightSoftwareConsortium/itk-js) and [vtk.js](https://github.com/Kitware/vtk-js).\n", "\n", "[](https://github.com/InsightSoftwareConsortium/itk-jupyter-widgets)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "- 2D or 3D images\n", "- Excellent volume rendering\n", "- Slicing\n", "- Data probe\n", "- Histogram and opacity transfer function editor" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2a4b246dbfda407293d46d95f4b74206", "version_major": 2, "version_minor": 0 }, "text/html": [ "
Failed to display Jupyter Widget of type Viewer
.
\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "
\n", "\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "
\n" ], "text/plain": [ "Viewer(image=Failed to display Jupyter Widget of type Viewer
.
\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "
\n", "\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "
\n" ], "text/plain": [ "Viewer(image=Failed to display Jupyter Widget of type Viewer
.
\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "
\n", "\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "
\n" ], "text/plain": [ "Viewer(image=