Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker voila #226

Merged
merged 21 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,7 @@ dmypy.json
*.code-workspace

# Local History for Visual Studio Code
.history/
.history/

# NWB streaming cache
*/nwb-cache
16 changes: 16 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.10

RUN cd ..
COPY requirements.txt .
RUN pip install --upgrade pip \
&& pip install -r requirements.txt \
&& pip install git+https://github.com/NeurodataWithoutBorders/nwbwidgets.git

COPY notebook.ipynb .
RUN mkdir nwb-cache

EXPOSE 8866
CMD ["voila", "notebook.ipynb", "--port=8866", "--Voila.ip=0.0.0.0", "--enable_nbextensions=True", "--autoreload=True", "--no-browser"]

# EXPOSE 8888
# CMD ["jupyter", "notebook", "notebook.ipynb", "--port=8888", "--ip=0.0.0.0", "--no-browser", "--allow-root", "--NotebookApp.token=''"]
23 changes: 23 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Build Docker Image

From `/docker` directory, run:
```bash
$ docker build -t nwbwidgets-voila .
```

## Run Docker Image

To run with `Panel`:
```bash
$ docker run -p 8866:8866 nwbwidgets-voila
```

By default, the Panel will run with `enable_local_source=False` (see [Panel](https://nwb-widgets.readthedocs.io/en/latest/contents/quickstart.html#basic-usage-with-panel)). To allow for local files browsering, run the container with:
```bash
$ docker run -p 8866:8866 -e ENABLE_LOCAL_SOURCE=True nwbwidgets-voila
```

To run for a specific NWB file, pass the s3 url as an ENV variable to the container:
```bash
$ docker run -p 8866:8866 -e S3_URL_NWBFILE=<s3_url_to_nwb_file> nwbwidgets-voila
```
Binary file added docker/favicon.ico
Binary file not shown.
74 changes: 74 additions & 0 deletions docker/notebook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"\n",
"s3_url = os.getenv(\"S3_URL_NWBFILE\", None)\n",
"enable_local_source = bool(os.getenv(\"ENABLE_LOCAL_SOURCE\", False))\n",
"\n",
"if s3_url:\n",
" from pynwb import NWBHDF5IO\n",
" from nwbwidgets import nwb2widget\n",
" from dandi.dandiapi import DandiAPIClient\n",
" import h5py\n",
" import fsspec\n",
" from fsspec.implementations.cached import CachingFileSystem\n",
" \n",
" # Create a virtual filesystem based on the http protocol and use caching to save accessed data to RAM.\n",
" fs = CachingFileSystem(\n",
" fs=fsspec.filesystem(\"http\"),\n",
" cache_storage=\"nwb-cache\", # Local folder for the cache\n",
" )\n",
" f = fs.open(s3_url, \"rb\")\n",
" file = h5py.File(f)\n",
" io = NWBHDF5IO(file=file, load_namespaces=True)\n",
" nwbfile = io.read()\n",
" w = nwb2widget(nwbfile)\n",
"else:\n",
" from nwbwidgets import Panel\n",
" w = Panel(enable_local_source=enable_local_source)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"w"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.5 ('base')",
"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.8.5"
},
"vscode": {
"interpreter": {
"hash": "698d109e506a444d1bfd677c8f66adf4920b11c19b28ee52fae9b02c95d46a98"
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
35 changes: 35 additions & 0 deletions docker/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pynwb>=2.2.0
dandi>=0.46.6
# nwbwidgets>=0.9.2
ndx-grayscalevolume==0.0.2
ndx-icephys-meta==0.1.0
ndx-spectrum==0.2.2
voila==0.3.6
numpy==1.23.3
matplotlib==3.6.1
scikit-image==0.19.3
plotly==5.10.0
ipydatagrid==1.1.13
ipydatawidgets==4.3.2
ipytree==0.2.2
ipyvolume==0.6.0a10
ipyvue==1.8.0
ipyvuetify==1.8.4
ipywebrtc==0.6.0
ipywidgets==7.7.2
ipykernel==6.16.0
ipympl==0.9.2
jupyter_client==7.4.2
jupyter_core==4.11.1
jupyter-server==1.21.0
jupyterlab==3.4.8
jupyterlab-pygments==0.2.2
jupyterlab_server==2.15.2
jupyterlab-widgets==1.1.1
tqdm>=4.36.0
zarr==2.13.3
aiohttp==3.8.3
tifffile==2022.10.10
trimesh==3.15.4
importlib-metadata<5.0
fsspec==2022.8.2
7 changes: 6 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## Build documentation

From `/docs` run:
To run auto-doc for the API, from `/docs` run:
```bash
$ sphinx-apidoc -f -o ./source/api_reference ../nwbwidgets
```

To build the HTML, from `/docs` run:
```bash
$ sphinx-build -b html ./source ./build
```
Binary file added docs/source/_static/panel.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/source/_static/quickstart/panel_fsspec.gif
Binary file not shown.
8 changes: 8 additions & 0 deletions docs/source/api_reference/nwbwidgets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ nwbwidgets.ophys module
:undoc-members:
:show-inheritance:

nwbwidgets.panel module
-----------------------

.. automodule:: nwbwidgets.panel
:members:
:undoc-members:
:show-inheritance:

nwbwidgets.spectrum module
--------------------------

Expand Down
8 changes: 8 additions & 0 deletions docs/source/api_reference/nwbwidgets.utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ nwbwidgets.utils.cmaps module
:undoc-members:
:show-inheritance:

nwbwidgets.utils.dandi module
-----------------------------

.. automodule:: nwbwidgets.utils.dandi
:members:
:undoc-members:
:show-inheritance:

nwbwidgets.utils.dynamictable module
------------------------------------

Expand Down
11 changes: 9 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# Insert the project root dir as the first element in the PYTHONPATH.
# This lets us ensure that the source package is imported, and that its
# version is used.
sys.path.insert(0, os.path.join(project_root, 'src'))
sys.path.insert(0, os.path.join(project_root, '../../nwbwidgets'))



Expand Down Expand Up @@ -61,4 +61,11 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
html_static_path = ['_static']


# TODO - not working- Include arguments with typehints from classes
# ref: https://stackoverflow.com/questions/5599254/how-to-use-sphinxs-autodoc-to-document-a-classs-init-self-method
# ref: https://stackoverflow.com/questions/63957326/sphinx-does-not-show-class-instantiation-arguments-for-generic-classes-i-e-par
autoclass_content = 'both'
autodoc_typehints = 'signature'
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Quickstart
# Running NWB widgets on Jupyter

## Basic usage with `Panel`
## Using `Panel`

The easiest way to use NWB widgets is with the interactive `Panel`:
```python
Expand All @@ -10,13 +10,25 @@ from nwbwidgets.panel import Panel
Panel()
```

![panel](../_static/quickstart/panel_fsspec.gif)
![panel](../_static/panel.gif)

With `Panel` you can easily browser through local files as well as stream remote datasets from DANDI archive.
For data streaming the default mode is [fsspec](https://pynwb.readthedocs.io/en/stable/tutorials/advanced_io/streaming.html#streaming-method-2-fsspec). If you would like to use [ROS3](https://pynwb.readthedocs.io/en/stable/tutorials/advanced_io/streaming.html#streaming-method-1-ros3) instead, you can do so with `Panel(stream_mode='ros3')`.
For data streaming the default mode is [fsspec](https://pynwb.readthedocs.io/en/stable/tutorials/advanced_io/streaming.html#streaming-method-2-fsspec). If you would like to use [ROS3](https://pynwb.readthedocs.io/en/stable/tutorials/advanced_io/streaming.html#streaming-method-1-ros3) instead, you can do so with:
```python
Panel(stream_mode='ros3')
```

If you intend to you `Panel` only for local storage (no streaming), you can instantiate it as:
```python
Panel(enable_dandi_source=False, enable_s3_source=False)
```

If you intend to you `Panel` only for streaming data (no local storage), you can instantiate it as:
```python
Panel(enable_local_source=False)
```

## Basic usage with `nwb2widget`
## Using `nwb2widget`

If you're working with a nwb file object in your Jupyter notebook, you can also explore it with NWB Widgets using `nwb2widget`:
```python
Expand Down
32 changes: 32 additions & 0 deletions docs/source/contents/running_remotely.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Running NWB widgets remotely

## Using Docker
You can easily deploy a webapp for visualizing NWB files using NWB widgets, [Voila](https://voila.readthedocs.io/en/stable/using.html) and Docker. Start by cloning the repository:
```bash
$ git clone https://github.com/NeurodataWithoutBorders/nwbwidgets.git
$ cd nwbwidgets/docker
```

Build a Docker image:
```bash
$ docker build -t nwbwidgets-voila .
```

Finally, run a container:
```bash
$ docker run -p 8866:8866 nwbwidgets-voila
```

By default, the Panel will run with `enable_local_source=False` (see [Panel](https://nwb-widgets.readthedocs.io/en/latest/contents/quickstart.html#basic-usage-with-panel)). To allow for local files browsering, run the container with:
```bash
$ docker run -p 8866:8866 -e ENABLE_LOCAL_SOURCE=True nwbwidgets-voila
```

If you want to skip the default Panel and instead run it for a specific NWB file, pass the s3 url as an ENV variable to the container:
```bash
$ docker run -p 8866:8866 -e S3_URL_NWBFILE=<s3_url_to_nwb_file> nwbwidgets-voila
```


## Using Binder

3 changes: 2 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ NWB Widgets is a library of widgets for visualization NWB data in a Jupyter note
:caption: Contents:

contents/installation
contents/quickstart
contents/running_on_jupyter
contents/running_remotely
contents/developer_guide

.. toctree::
Expand Down
Loading