Skip to content

Instantly share code, notes, and snippets.

@klarh
Last active July 26, 2019 17:46
Show Gist options
  • Save klarh/a924c3f698897c9e41a01cf6a9fc99bb to your computer and use it in GitHub Desktop.
Save klarh/a924c3f698897c9e41a01cf6a9fc99bb to your computer and use it in GitHub Desktop.
Docker images to test vispy jupyter notebook backend installation

This gist holds a docker recipe for testing vispy's jupyter integration. It can be run like:

docker run -p 127.0.0.1:8899:8888 -it --rm mspells/vispy_notebook_tests /bin/bash 
# (setup vispy)
# jupyter notebook --ip 0.0.0.0 --port 8888 --allow-root 
#!/bin/sh
set -e
OWNER=mspells
PACKAGE=vispy_notebook_tests
TAG=$(date +%Y%m%d)
core_tag="${OWNER}/${PACKAGE}:${TAG}"
latest_tag="${OWNER}/${PACKAGE}:latest"
docker build -f Dockerfile -t "${core_tag}" .
docker tag "${core_tag}" "${latest_tag}"
#docker push "${core_tag}"
#docker push "${latest_tag}"
FROM ubuntu:latest
RUN apt-get update && apt-get install -y \
build-essential \
cython3 \
git \
npm \
python3-fontconfig \
python3-pip \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y nano && rm -rf /var/lib/apt/lists/* && \
npm install -g npm@latest && \
pip3 install --no-cache-dir --upgrade pip setuptools
RUN pip3 install --no-cache-dir jupyter plato-draw && \
jupyter nbextension enable --py --sys-prefix widgetsnbextension
COPY *.ipynb /
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import vispy, vispy.app\n",
"vispy.app.use_app('ipynb_webgl')\n",
"import plato\n",
"import plato.draw.vispy as draw\n",
"import itertools\n",
"import rowan\n",
"import numpy as np\n",
"import IPython"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def example_vector_field(N):\n",
" xs = np.linspace(-N/2, N/2, N)\n",
" positions = np.array(list(itertools.product(xs, xs, xs)), dtype=np.float32)\n",
" positions = positions.reshape((-1, 3))\n",
"\n",
" thetas = np.arctan2(positions[:, 1], positions[:, 0])\n",
" circle = np.array([-np.sin(thetas), np.cos(thetas), np.zeros_like(thetas)]).T\n",
"\n",
" rotated = np.cross(positions, circle)\n",
" rotated /= np.linalg.norm(rotated, axis=-1, keepdims=True)\n",
" rotated[np.logical_not(np.all(np.isfinite(rotated), axis=-1))] = (1, 0, 0)\n",
"\n",
" return positions, rotated"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"features = dict(ambient_light=.4)\n",
"(positions, units) = example_vector_field(5)\n",
"\n",
"normalized_z = positions[:, 2].copy()\n",
"normalized_z -= np.min(normalized_z)\n",
"normalized_z /= np.max(normalized_z)\n",
"\n",
"colors = plato.cmap.cubehelix(normalized_z, h=1.4)\n",
"colors[:, :3] = .5*(colors[:, :3] +\n",
" plato.cmap.cubeellipse(np.arctan2(positions[:, 1], positions[:, 0])))\n",
"\n",
"orientations = rowan.vector_vector_rotation([(1, 0, 0)], units)\n",
"prim = draw.Ellipsoids(\n",
" positions=positions, orientations=orientations, colors=colors,\n",
" a=.5, b=.125, c=.125)\n",
"\n",
"rotation = [ 0.8126942 , 0.35465172, -0.43531808, 0.15571932]\n",
"scene = draw.Scene(\n",
" prim, zoom=4, features=features, rotation=rotation)\n",
"scene.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment