Flask application to serve data via CloudVolume.
This is currently a one-trick pony! The one thing it does is provide an API endpoint to query multiple x/y/z locations at once.
- CloudVolume:
pip install cloud-volume - Gunicorn:
pip install gunicorn - flask:
pip install flask - numpy:
pip install numpy - pandas:
pip install pandas
-
Clone this repository on your server
-
Install above dependencies
-
Edit
config.pyand minimally add the path to the volume:CloudVolumeKwargs = { cloudpath="file:///fafbz/fafb14/segmentation/" }
-
Test if Gunicorn can start the workers - from within the repository run:
gunicorn --workers 1 --bind 0.0.0.0:6000 -m 007 wsgi:app --log-level debug
If all works well, CTRL-C to stop.
-
Add Gunicorn to
systemd:sudo nano /etc/systemd/system/cloudvolumeserver.service
Then copy paste this (make sure to replace
YOURUSERandPATH/TO/REPOSITORY)[Unit] Description=Gunicorn instance to serve the CloudVolumeServer After=network.target [Service] User=YOURUSER Group=www-data WorkingDirectory=PATH/TO/REPOSITORY/CloudVolumeServer ExecStart=/usr/local/bin/gunicorn --workers 3 --bind 0.0.0.0:6000 -m 007 wsgi:app [Install] WantedBy=multi-user.targetNote that you can also bind Gunicorn to a sock instead of a port but that didn't work in my hands.
You can now start the Gunicorn service by running:
sudo systemctl start cloudvolumeserver sudo systemctl enable cloudvolumeserver -
Setup your nginx server and add the following server block to the config file in
/etc/nginx/sites-available:location /seg/ { include proxy_params; proxy_pass http://localhost:6000/; } -
Restart your nginx:
sudo systemctl restart nginx -
All done. Check if the site is running by visiting
http://your-server.url/seg/.
For more details: the configuration steps roughly follow this tutorial.
import requests
# Some random locations
# Please note that we need to query pixel coordinates, not native coordinates
coords = [[58695, 28631, 696],
[58688, 28632, 691],
[58691, 28635, 698]]
url = 'http://your-server.url/seg/'
resp = requests.post(url, json=coords)
print('Segment IDs:', resp.json())This code is published under a BSD 2-Clause License.