Skip to content

Commit

Permalink
Merge pull request #1292 from jasongrout/annotation
Browse files Browse the repository at this point in the history
Deprecate using function annotations to specify interactive controls.
  • Loading branch information
jasongrout authored Apr 17, 2017
2 parents 69ae4b1 + 6804023 commit fcf61ec
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 778 deletions.
63 changes: 0 additions & 63 deletions docs/source/examples/Image Processing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -345,69 +345,6 @@
"interact(edit_image, image=fixed(img), sigma=(0.0, 10.0, 0.1), \n",
" R=lims, G=lims, B=lims);"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"## Python 3 only: Function annotations and unicode identifiers"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"In Python 3, we can use the new function annotation syntax to describe widgets for interact, as well as unicode names for variables such as sigma. Note how this syntax also lets us define default values for each control in a convenient (if slightly awkward looking) form: `var:descriptor=default`."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/scorlay/dev/ipython/traitlets/traitlets/traitlets.py:565: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.\n",
" silent = bool(old_value == new_value)\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "dd1f614410fd4c6b816ede23dda7cd70"
}
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"lims = (0.0, 1.0, 0.01)\n",
"\n",
"@interact\n",
"def edit_image(image: fixed(img), σ:(0.0, 10.0, 0.1)=0, \n",
" R:lims=1.0, G:lims=1.0, B:lims=1.0):\n",
" new_image = filters.gaussian_filter(image, sigma=σ, multichannel=True)\n",
" if new_image.ndim == 3:\n",
" new_image[:,:,0] = R*new_image[:,:,0]\n",
" new_image[:,:,1] = G*new_image[:,:,1]\n",
" new_image[:,:,2] = B*new_image[:,:,2]\n",
" else:\n",
" new_image = G*new_image\n",
" return arr2img(new_image)"
]
}
],
"metadata": {
Expand Down
Loading

0 comments on commit fcf61ec

Please sign in to comment.