Skip to content

Commit

Permalink
Improve notebook and update environment.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Nov 28, 2018
1 parent a8d1403 commit 7372506
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 79 deletions.
2 changes: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ channels:
dependencies:
- xeus-python=0.0.1
- notebook
- ipywidgets>=7.4
- itkwidgets
141 changes: 62 additions & 79 deletions notebooks/xeus-python.ipynb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"from ipywidgets import IntSlider"
"<center>\n",
" <img src=\"xeus-python.png\" width=\"50%\">\n",
" <h1>Python kernel based on xeus</h1>\n",
"</center>"
]
},
{
Expand All @@ -15,25 +16,8 @@
"metadata": {},
"outputs": [],
"source": [
"slider = IntSlider()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"slider"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"slider.value"
"a = 3\n",
"a"
]
},
{
Expand All @@ -42,7 +26,7 @@
"metadata": {},
"outputs": [],
"source": [
"slider"
"a"
]
},
{
Expand All @@ -51,7 +35,7 @@
"metadata": {},
"outputs": [],
"source": [
"slider.value = 36"
"a += 6"
]
},
{
Expand All @@ -60,9 +44,7 @@
"metadata": {},
"outputs": [],
"source": [
"from ipywidgets import Video\n",
"video = Video.from_file(\"Big.Buck.Bunny.mp4\")\n",
"video"
"print(a)"
]
},
{
Expand All @@ -71,8 +53,7 @@
"metadata": {},
"outputs": [],
"source": [
"from ipywidgets import Widget\n",
"Widget.close_all()"
"a"
]
},
{
Expand All @@ -81,9 +62,12 @@
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import Image\n",
"im = Image(url=\"marie.png\")\n",
"im"
"b = 89\n",
"\n",
"def sq(x):\n",
" return x * x\n",
"\n",
"sq(b)"
]
},
{
Expand All @@ -92,13 +76,7 @@
"metadata": {},
"outputs": [],
"source": [
"from bqplot import pyplot as plt\n",
"import numpy as np\n",
"\n",
"plt.figure()\n",
"n= 100\n",
"plt.plot(np.arange(n), np.cumsum(np.random.randn(n) * 100.))\n",
"plt.show(display_toolbar=True)"
"sq(4)"
]
},
{
Expand All @@ -107,8 +85,7 @@
"metadata": {},
"outputs": [],
"source": [
"a = 3\n",
"a"
"print(a)"
]
},
{
Expand All @@ -117,7 +94,7 @@
"metadata": {},
"outputs": [],
"source": [
"a"
"import missing_module"
]
},
{
Expand All @@ -126,7 +103,7 @@
"metadata": {},
"outputs": [],
"source": [
"a += 6"
"b = {\"a\": 2, \"b\": 3}"
]
},
{
Expand All @@ -135,7 +112,7 @@
"metadata": {},
"outputs": [],
"source": [
"print(a)"
"b"
]
},
{
Expand All @@ -144,7 +121,7 @@
"metadata": {},
"outputs": [],
"source": [
"a"
"print(b[\"a\"])"
]
},
{
Expand All @@ -153,7 +130,11 @@
"metadata": {},
"outputs": [],
"source": [
"?"
"import time\n",
"\n",
"for x in range(5):\n",
" print(x)\n",
" time.sleep(1)"
]
},
{
Expand All @@ -162,23 +143,16 @@
"metadata": {},
"outputs": [],
"source": [
"b = 89\n",
"\n",
"display(im)\n",
"\n",
"def test(x):\n",
" return x * 2\n",
"import sys\n",
"\n",
"test(b)"
"print(\"Error !!\", file=sys.stderr)"
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"test(4)"
"# Widgets support"
]
},
{
Expand All @@ -187,7 +161,7 @@
"metadata": {},
"outputs": [],
"source": [
"print(a)"
"from ipywidgets import IntSlider"
]
},
{
Expand All @@ -196,7 +170,7 @@
"metadata": {},
"outputs": [],
"source": [
"import missing_module"
"slider = IntSlider()"
]
},
{
Expand All @@ -205,7 +179,7 @@
"metadata": {},
"outputs": [],
"source": [
"b = {\"a\": 2, \"b\": 3}"
"slider"
]
},
{
Expand All @@ -214,7 +188,7 @@
"metadata": {},
"outputs": [],
"source": [
"b"
"slider.value"
]
},
{
Expand All @@ -223,7 +197,7 @@
"metadata": {},
"outputs": [],
"source": [
"from ipywidgets import IntSlider"
"slider"
]
},
{
Expand All @@ -232,16 +206,14 @@
"metadata": {},
"outputs": [],
"source": [
"IntSlider()"
"slider.value = 36"
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"print(b[\"a\"])"
"## Binary buffers support for widgets"
]
},
{
Expand All @@ -250,20 +222,16 @@
"metadata": {},
"outputs": [],
"source": [
"print(b[\"c\"])"
"from ipywidgets import Video\n",
"video = Video.from_file(\"Big.Buck.Bunny.mp4\")\n",
"video"
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"import time\n",
"\n",
"for x in range(10):\n",
" print(x)\n",
" time.sleep(1)"
"## Higher-level widgets libraries support"
]
},
{
Expand All @@ -272,9 +240,24 @@
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"try:\n",
" from urllib.request import urlretrieve\n",
"except ImportError:\n",
" from urllib import urlretrieve\n",
"import os\n",
"\n",
"print(\"Error !!\", file=sys.stderr)"
"import itk\n",
"\n",
"from itkwidgets import view\n",
"\n",
"# Download data\n",
"file_name = '005_32months_T2_RegT1_Reg2Atlas_ManualBrainMask_Stripped.nrrd'\n",
"if not os.path.exists(file_name):\n",
" url = 'https://data.kitware.com/api/v1/file/564a5b078d777f7522dbfaa6/download'\n",
" urlretrieve(url, file_name)\n",
"\n",
"image = itk.imread(file_name)\n",
"view(image)"
]
},
{
Expand Down
Binary file added notebooks/xeus-python.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7372506

Please sign in to comment.