Skip to content

Instantly share code, notes, and snippets.

@rsignell-usgs
Created July 3, 2018 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsignell-usgs/2fe9f69f46c6784fb441bf37a1f32c3f to your computer and use it in GitHub Desktop.
Save rsignell-usgs/2fe9f69f46c6784fb441bf37a1f32c3f to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"N = 500\n",
"x = np.linspace(0, 10, N)\n",
"y = np.linspace(0, 10, N)\n",
"xx, yy = np.meshgrid(x, y)\n",
"z = np.sin(xx) * np.cos(yy)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from bokeh import events\n",
"from bokeh.io import show, output_notebook\n",
"from bokeh.plotting import figure\n",
"\n",
"output_notebook()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"geom = {}\n",
"global geom\n",
"\n",
"def print_event(attributes=[]):\n",
" def python_callback(event):\n",
" geom.update(event.__dict__['geometry'])\n",
"# print(event.__dict__['geometry'])\n",
" return python_callback\n",
"\n",
"\n",
"def modify_doc(doc):\n",
" p = figure(x_range=(0, 10), y_range=(0, 10), plot_height=300,\n",
" tools='reset,box_select,lasso_select,poly_select')\n",
"\n",
" p.image(image=[z], x=0, y=0, dw=10, dh=10, palette='Spectral11')\n",
"\n",
" # register Python event callbacks\n",
" p.on_event(events.SelectionGeometry, print_event(attributes=['geometry']))\n",
"\n",
" doc.add_root(p)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"notebook_url = lambda x: 'pangeo.esipfed.org/user/rsignell-usgs/proxy/{}'.format(x)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"show(modify_doc, notebook_url=notebook_url(8787))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(geom)"
]
}
],
"metadata": {
"gist": {
"data": {
"description": "bokeh_image_selector",
"public": true
},
"id": ""
},
"kernelspec": {
"display_name": "Python [conda root]",
"language": "python",
"name": "conda-root-py"
},
"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.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
@jsignell
Copy link

jsignell commented Jul 3, 2018

No!!

show(modify_doc, notebook_url=lambda x: 'pangeo.esipfed.org/user/rsignell-usgs/proxy/{}'.format(x))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment