Skip to content

Commit

Permalink
deploy: d129e5e
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-mueller committed Sep 1, 2024
1 parent f364a6c commit 4b2fce6
Show file tree
Hide file tree
Showing 15 changed files with 1,527 additions and 9 deletions.
2 changes: 1 addition & 1 deletion _sources/notebooks/metadata/key_value_pairs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"outputs": [],
"source": [
"host = 'omero-int.biotec.tu-dresden.de'\n",
"user = 'johamuel' # replace this with your username\n",
"user = '' # replace this with your username\n",
"secure = True\n",
"port = 4064\n",
"group = 'default'\n",
Expand Down
168 changes: 168 additions & 0 deletions _sources/notebooks/metadata/setting_pixel_sizes.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Setting pixel sizes of an image\n",
"\n",
"A key part of the metadata are the pixel/voxel sizes of image data. When upload processed image data to OMERO, they are by default not part of the uploaded data but a key part you wish to add to your data. Following up [this dicsussion](https://forum.image.sc/t/specifying-pixel-size-using-python-bridge-for-omero-ezomero/81729/2) on image.sc, here's how you can do it using [omero-py](https://pypi.org/project/omero-py/):"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import omero\n",
"import ezomero\n",
"\n",
"from omero.model.enums import UnitsLength"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"host = 'omero-int.biotec.tu-dresden.de'\n",
"user = '' # replace this with your username\n",
"secure = True\n",
"port = 4064\n",
"group = 'default'\n",
"\n",
"conn = ezomero.connect(host=host, user=user, secure=secure, port=port, group=group)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We first need to retrieve the remote object:"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"image_object = conn.getObject(\"Image\", 330)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If there are already pixel sizes set, you can retrieve them like this:"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pixel size X: 0.2\n",
"Pixel size Y: 0.2\n",
"Pixel size Z: 2.0\n"
]
}
],
"source": [
"print('Pixel size X: ', image_object.getPixelSizeX())\n",
"print('Pixel size Y: ', image_object.getPixelSizeY())\n",
"print('Pixel size Z: ', image_object.getPixelSizeZ())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you want to set them yourself, you can do it like this:"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"unit_x = omero.model.LengthI(0.5, UnitsLength.MICROMETER)\n",
"unit_y = omero.model.LengthI(0.5, UnitsLength.MICROMETER)\n",
"unit_z = omero.model.LengthI(3, UnitsLength.MICROMETER)\n",
"\n",
"primary_pixels_object = image_object.getPrimaryPixels()._obj\n",
"primary_pixels_object.setPhysicalSizeX(unit_x)\n",
"primary_pixels_object.setPhysicalSizeY(unit_y)\n",
"primary_pixels_object.setPhysicalSizeZ(unit_z)\n",
"\n",
"# update the image object\n",
"conn.getUpdateService().saveObject(primary_pixels_object)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can doublecheck whether this worked:"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pixel size X: 0.5\n",
"Pixel size Y: 0.5\n",
"Pixel size Z: 3.0\n"
]
}
],
"source": [
"image_object = conn.getObject(\"Image\", 330)\n",
"\n",
"print('Pixel size X: ', image_object.getPixelSizeX())\n",
"print('Pixel size Y: ', image_object.getPixelSizeY())\n",
"print('Pixel size Z: ', image_object.getPixelSizeZ())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "omero",
"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.9.19"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 4b2fce6

Please sign in to comment.