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

example tiled code #16

Merged
merged 5 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .github/workflows/staging-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ env

.theia/
*.tiff
*.tif
*.tif

.env
config.py
3 changes: 3 additions & 0 deletions examples/requirements.txt
Wiebke marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jupyterlab
ipykernel
matplotlib
165 changes: 165 additions & 0 deletions examples/tiled.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Demonstration of Tiled Functionality\n",
"This notebook demonstrates how to connect to tiled using the python client. \n",
"\n",
"Not that config.py is in gitignore because it contains the api_key. It should look like:\n",
"\n",
"```\n",
"api_key=\"<key>\"\n",
"```\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# import tempfile used for on_disk cache\n",
"import ipywidgets as widgets\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib.animation as animation \n",
"from tiled.client import from_uri\n",
"from tiled.client.cache import Cache\n",
"# from tiled.client import show_logs\n",
"import config\n",
"\n",
"%matplotlib widget\n",
"\n",
"# displays details of tiled client http traffic\n",
"# it's a little wordy but often extremely useful\n",
Wiebke marked this conversation as resolved.
Show resolved Hide resolved
"# show_logs()\n",
"\n",
"####\n",
"# Setup client-side caching. Commented out because this exposed a bug in \n",
"# client caching https://github.com/bluesky/tiled/issues/471\n",
"# cache = Cache.on_disk(\n",
"# tempfile.gettempdir(),\n",
"# capacity=2e9 #2GB\n",
"# )\n",
"# cache = Cache.in_memory(capacity=2e9) # 2GB\n",
"\n",
"# create a Tiled client\n",
"client = from_uri(\n",
" \"https://mlex-segmentation.als.lbl.gov\", \n",
" api_key=config.api_key)\n",
" # cache=cache)\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data = client['data']\n",
"reconstruction = data['rec20221222_085501_looking_from_above_spiralUP_CounterClockwise_endPointAtDoor']\n",
" "
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Grab a frame!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"frame_num_text = widgets.Text(value='Hello World', disabled=True)\n",
"fig = plt.figure()\n",
"im = plt.imshow(reconstruction[0], animated=True)\n",
"\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Grab a reduced frame\n",
"This shows a very simple downcasting method. The downcasting happens in the server, saving traffic across the wire."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"frame_num_text = widgets.Text(value='Hello World', disabled=True)\n",
"fig = plt.figure()\n",
"im = plt.imshow(reconstruction[0, ::10, ::10], animated=True)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Animate across the images\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"frame_num_text = widgets.Text(value='Hello World', disabled=True)\n",
"fig = plt.figure()\n",
"im = plt.imshow(reconstruction[0, ::10, ::10], animated=True)\n",
"\n",
"# animation function \n",
"def updatefig(i):\n",
" im.set_array(reconstruction[i, ::10, ::10])\n",
" return im, \n",
"\n",
"ani = animation.FuncAnimation(fig, updatefig, frames=range(len(reconstruction)) , interval=50, blit=True)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "tiled_client",
"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.11.3"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
black==22.10.0
flake8==6.0.0
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ tifffile==2023.4.12
tzdata==2023.3
Werkzeug==2.2.3
zipp==3.15.0
black==22.10.0
flake8==6.0.0
tiled[client]==0.1.0a96
Loading