Skip to content

Commit

Permalink
Move serializer registration to __init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kbvw committed Aug 29, 2024
1 parent e7b80ee commit 09a154a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 25 deletions.
6 changes: 1 addition & 5 deletions docs/tutorials/ball-and-stick-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1065,13 +1065,9 @@
"metadata": {},
"outputs": [],
"source": [
"import bokeh.plotting as plt\n",
"from bokeh.core.serialization import Serializer\n",
"from bokeh.io import output_notebook\n",
"import bokeh.plotting as plt\n",
"\n",
"Serializer.register(\n",
" h.Vector, lambda obj, serializer: [serializer.encode(item) for item in obj]\n",
")\n",
"output_notebook()"
]
},
Expand Down
20 changes: 0 additions & 20 deletions docs/tutorials/scripting-neuron-basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -789,26 +789,6 @@
"output_notebook()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We also need to register a custom serialization function with Bokeh in order to plot Hoc vectors directly:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from bokeh.core.serialization import Serializer\n",
"\n",
"Serializer.register(\n",
" h.Vector, lambda obj, serializer: [serializer.encode(item) for item in obj]\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
10 changes: 10 additions & 0 deletions share/lib/python/neuron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1836,3 +1836,13 @@ def _mview_html_tree(hlist, inside_mechanisms_in_use=0):
if _get_ipython() is not None:
html_formatter = _get_ipython().display_formatter.formatters["text/html"]
html_formatter.for_type(hoc.HocObject, _hocobj_html)

# in case Bokeh is installed, register a serialization function for hoc.Vector
try:
from bokeh.core.serialization import Serializer

Serializer.register(
h.Vector, lambda obj, serializer: [serializer.encode(item) for item in obj]
)
except ImportError:
pass

0 comments on commit 09a154a

Please sign in to comment.