Skip to content
Open
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
370 changes: 370 additions & 0 deletions Load_FIRE.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,370 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "5da62504",
"metadata": {},
"source": [
"## Connect to IDR"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "3e1ec8b6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"from omero.gateway import BlitzGateway\n",
"HOST = 'ws://idr.openmicroscopy.org/omero-ws'\n",
"conn = BlitzGateway('public', 'public',\n",
" host=HOST, secure=True)\n",
"print(conn.connect())\n",
"conn.c.enableKeepAlive(60)"
]
},
{
"cell_type": "markdown",
"id": "46f1f8d0",
"metadata": {},
"source": [
"## Connect to IDR testing "
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "27861120",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"HOST = 'ws://idr-testing.openmicroscopy.org/omero-ws'\n",
"conn_testing = BlitzGateway('public', 'public',\n",
" host=HOST, secure=True)\n",
"print(conn_testing.connect())\n",
"conn_testing.c.enableKeepAlive(60)"
]
},
{
"cell_type": "markdown",
"id": "682a9ddb",
"metadata": {},
"source": [
"## Load an image\n",
"\n",
"We load information about the image but **not** the binary data. An image is a 5D-object\n",
"The size of a plane is 1024x1024"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "0f8964ac",
"metadata": {},
"outputs": [],
"source": [
"# For the test an image from idr0067, idr0082, idr0117 should be used.\n",
"image_id = 9846309 # idr0067 9846282->idr0082"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "3fe79a7a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"S156_HandE.ndpi [0]\n"
]
}
],
"source": [
"image = conn.getObject(\"Image\", image_id)\n",
"print(image.getName())"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "c04bbd1f",
"metadata": {},
"outputs": [],
"source": [
"image_testing = conn_testing.getObject(\"Image\", image_id)"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "639d759f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Size Z: 1, Size C: 3, Size T: 3\n"
]
}
],
"source": [
"print(\"Size Z: %s, Size C: %s, Size T: %s\" % (image.getSizeZ(), image.getSizeC(), image.getSizeC()))"
]
},
{
"cell_type": "markdown",
"id": "c564e823",
"metadata": {},
"source": [
"## Load the binary data\n",
"\n",
"To access the binary data, we need to load the `pixels` object from the image and retrieve the plane(s)"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "7901bf45",
"metadata": {},
"outputs": [],
"source": [
"def load_plane(image, z, c, t, tile=None):\n",
" pixels = image.getPrimaryPixels()\n",
" if tile is not None:\n",
" print(tile)\n",
" return pixels.getTile(z, c, t, tile)\n",
" return pixels.getPlane(z, c, t)"
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "1a47b60c",
"metadata": {},
"outputs": [],
"source": [
"tile = (0, 0, 5000, 5000)"
]
},
{
"cell_type": "code",
"execution_count": 55,
"id": "ade36464",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(0, 0, 5000, 5000)\n",
"(5000, 5000)\n",
"CPU times: user 1.81 s, sys: 179 ms, total: 1.99 s\n",
"Wall time: 4.21 s\n"
]
}
],
"source": [
"%%time\n",
"# Load from idr\n",
"plane = load_plane(image, 0, 0, 0, tile)\n",
"print(plane.shape)"
]
},
{
"cell_type": "code",
"execution_count": 56,
"id": "cd0bcf37",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(0, 0, 5000, 5000)\n",
"CPU times: user 1.81 s, sys: 162 ms, total: 1.97 s\n",
"Wall time: 4.01 s\n"
]
}
],
"source": [
"%%time\n",
"# Load from idr-testing\n",
"plane_testing = load_plane(image_testing, 0, 0, 0, tile)"
]
},
{
"cell_type": "markdown",
"id": "7494df01",
"metadata": {},
"source": [
"To load multiple planes use ``pixels.getPlanes()``"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "146e0d0b",
"metadata": {},
"outputs": [],
"source": [
"zct_list = [(0, 0, 0), (1, 0, 0)]"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "aff55fee",
"metadata": {},
"outputs": [],
"source": [
"def load_planes(image, zct_list):\n",
" pixels = image.getPrimaryPixels()\n",
" return pixels.getPlanes(zct_list)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "c77e4820",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 233 µs, sys: 26 µs, total: 259 µs\n",
"Wall time: 285 µs\n"
]
}
],
"source": [
"%%time\n",
"# Load from idr\n",
"planes = load_planes(image, zct_list)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6c53867b",
"metadata": {},
"outputs": [],
"source": [
"%%time\n",
"# Load from idr-testing\n",
"planes_testing = load_planes(image_testing, zct_list)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "1c71b06d",
"metadata": {},
"outputs": [],
"source": [
"def load_5D_array(image):\n",
" pixels = image.getPrimaryPixels()\n",
" size_z = image.getSizeZ()\n",
" size_c = image.getSizeC()\n",
" size_t = image.getSizeT()\n",
" #z, t, c = 0, 0, 0 # first plane of the image\n",
"\n",
" zct_list = []\n",
" for t in range(size_t):\n",
" for c in range(size_c): # all channels\n",
" for z in range(size_z): # get the Z-stack\n",
" zct_list.append((z, c, t))\n",
"\n",
" # Load all the planes as YX numpy array\n",
" return pixels.getPlanes(zct_list)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "efd67ee3",
"metadata": {},
"outputs": [
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"File \u001b[0;32m<timed exec>:2\u001b[0m, in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n",
"File \u001b[0;32m~/opt/anaconda3/envs/stardist/lib/python3.9/site-packages/omero/gateway/__init__.py:7466\u001b[0m, in \u001b[0;36m_PixelsWrapper.getTiles\u001b[0;34m(self, zctTileList)\u001b[0m\n\u001b[1;32m 7464\u001b[0m z, c, t, tile \u001b[38;5;241m=\u001b[39m zctTile\n\u001b[1;32m 7465\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m tile \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m-> 7466\u001b[0m rawPlane \u001b[38;5;241m=\u001b[39m \u001b[43mrawPixelsStore\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgetPlane\u001b[49m\u001b[43m(\u001b[49m\u001b[43mz\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mc\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mt\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 7467\u001b[0m planeY \u001b[38;5;241m=\u001b[39m sizeY\n\u001b[1;32m 7468\u001b[0m planeX \u001b[38;5;241m=\u001b[39m sizeX\n",
"File \u001b[0;32m~/opt/anaconda3/envs/stardist/lib/python3.9/site-packages/omero/gateway/__init__.py:4793\u001b[0m, in \u001b[0;36mOmeroGatewaySafeCallWrapper.__call__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 4791\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__call__\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 4792\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m-> 4793\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mf\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 4794\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 4795\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdebug(e\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__class__\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m, args, kwargs)\n",
"File \u001b[0;32m~/opt/anaconda3/envs/stardist/lib/python3.9/site-packages/omero_api_RawPixelsStore_ice.py:1199\u001b[0m, in \u001b[0;36mRawPixelsStorePrx.getPlane\u001b[0;34m(self, z, c, t, _ctx)\u001b[0m\n\u001b[1;32m 1198\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mgetPlane\u001b[39m(\u001b[38;5;28mself\u001b[39m, z, c, t, _ctx\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[0;32m-> 1199\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_M_omero\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapi\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mRawPixelsStore\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_op_getPlane\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minvoke\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m(\u001b[49m\u001b[43m(\u001b[49m\u001b[43mz\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mc\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mt\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m_ctx\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
],
"source": [
"%%time\n",
"# Load from idr\n",
"planes = load_5D_array(image)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c42ca39c",
"metadata": {},
"outputs": [],
"source": [
"%%time\n",
"# Load from idr-testing\n",
"planes_testing = load_5D_array(image_testing)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "65f6bd08",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:stardist]",
"language": "python",
"name": "conda-env-stardist-py"
},
"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.9.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}