From ca7230f926e569455991d5cb65a11e74ae19e375 Mon Sep 17 00:00:00 2001 From: Dylan McReynolds Date: Fri, 23 Jun 2023 15:08:52 -0700 Subject: [PATCH 1/4] example tiled code --- .gitignore | 5 +- examples/requirements.txt | 3 + examples/tiled.ipynb | 165 ++++++++++++++++++++++++++++++++++++++ requirements-dev.txt | 2 + requirements.txt | 3 +- 5 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 examples/requirements.txt create mode 100644 examples/tiled.ipynb create mode 100644 requirements-dev.txt diff --git a/.gitignore b/.gitignore index 92ee895b..5c76df5d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,7 @@ env .theia/ *.tiff -*.tif \ No newline at end of file +*.tif + +.env +config.py \ No newline at end of file diff --git a/examples/requirements.txt b/examples/requirements.txt new file mode 100644 index 00000000..d731fc12 --- /dev/null +++ b/examples/requirements.txt @@ -0,0 +1,3 @@ +jupyterlab +ipykernel +matplotlib diff --git a/examples/tiled.ipynb b/examples/tiled.ipynb new file mode 100644 index 00000000..17d1385f --- /dev/null +++ b/examples/tiled.ipynb @@ -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=\"\"\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", + "# 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 +} diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 00000000..d43a9d74 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,2 @@ +black==22.10.0 +flake8==6.0.0 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index f764739e..937fad57 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 From b014cfc4ff67a70104f8d2fe05d6df7ae9dad7e4 Mon Sep 17 00:00:00 2001 From: Dylan McReynolds Date: Fri, 23 Jun 2023 15:18:37 -0700 Subject: [PATCH 2/4] update actions --- .github/workflows/staging-deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml index e1899487..ae02b28d 100644 --- a/.github/workflows/staging-deploy.yml +++ b/.github/workflows/staging-deploy.yml @@ -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 From 0ed1f03f4be13d696bc6075da1b0badd5791a475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiebke=20K=C3=B6pp?= Date: Thu, 6 Jul 2023 15:05:48 -0700 Subject: [PATCH 3/4] Add ipympl to requirements for tiled example --- examples/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/requirements.txt b/examples/requirements.txt index d731fc12..3cb642a4 100644 --- a/examples/requirements.txt +++ b/examples/requirements.txt @@ -1,3 +1,4 @@ jupyterlab ipykernel +ipympl matplotlib From a2f597f7dadb3543f16dffc4d97d02c6efc4a9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiebke=20K=C3=B6pp?= Date: Thu, 6 Jul 2023 15:06:06 -0700 Subject: [PATCH 4/4] Split cells in tiled example notebook --- examples/tiled.ipynb | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/examples/tiled.ipynb b/examples/tiled.ipynb index 17d1385f..3437b6f8 100644 --- a/examples/tiled.ipynb +++ b/examples/tiled.ipynb @@ -8,7 +8,7 @@ "# 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", + "Note that config.py is in gitignore because it contains the api_key. It should look like:\n", "\n", "```\n", "api_key=\"\"\n", @@ -30,12 +30,26 @@ "# from tiled.client import show_logs\n", "import config\n", "\n", - "%matplotlib widget\n", - "\n", + "%matplotlib widget" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "# displays details of tiled client http traffic\n", "# it's a little wordy but often extremely useful\n", - "# show_logs()\n", - "\n", + "# show_logs()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "####\n", "# Setup client-side caching. Commented out because this exposed a bug in \n", "# client caching https://github.com/bluesky/tiled/issues/471\n", @@ -49,9 +63,7 @@ "client = from_uri(\n", " \"https://mlex-segmentation.als.lbl.gov\", \n", " api_key=config.api_key)\n", - " # cache=cache)\n", - "\n", - "\n" + " # cache=cache)" ] }, { @@ -81,8 +93,7 @@ "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" + "im = plt.imshow(reconstruction[0], animated=True)" ] }, {