From f532597af7b42cb2df6e585288cf407dba67d7f0 Mon Sep 17 00:00:00 2001 From: Riccardo Massei <118002526+rmassei@users.noreply.github.com> Date: Fri, 22 Nov 2024 10:36:36 +0000 Subject: [PATCH 1/2] Correct dysfunctional test cases --- oryx-build-commands.txt | 2 + test_cases/image_metadata_reading.ipynb | 69 ++++++++++++++++++++ test_cases/read_ome_xml_from_ome_tiff.ipynb | 71 +++++++++++++++++++++ test_cases/tiff_metadata_reading.ipynb | 71 +++++++++++++++++++++ 4 files changed, 213 insertions(+) create mode 100644 oryx-build-commands.txt create mode 100644 test_cases/image_metadata_reading.ipynb create mode 100644 test_cases/read_ome_xml_from_ome_tiff.ipynb create mode 100644 test_cases/tiff_metadata_reading.ipynb diff --git a/oryx-build-commands.txt b/oryx-build-commands.txt new file mode 100644 index 0000000..d647bdf --- /dev/null +++ b/oryx-build-commands.txt @@ -0,0 +1,2 @@ +PlatformWithVersion=Python +BuildCommands=conda env create --file environment.yml --prefix ./venv --quiet diff --git a/test_cases/image_metadata_reading.ipynb b/test_cases/image_metadata_reading.ipynb new file mode 100644 index 0000000..0da39aa --- /dev/null +++ b/test_cases/image_metadata_reading.ipynb @@ -0,0 +1,69 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "initial_id", + "metadata": {}, + "outputs": [], + "source": [ + "def image_metadata_reading(image):\n", + " \"\"\"\n", + " Read image shape and data type object from a tiff file. \n", + " Write then the results into a dictionary \n", + " \"\"\"\n", + " import imageio.v3 as iio\n", + " props = iio.improps(image)\n", + " meta_dict = { \"Shape\" : f\"{props.shape}\", \"dtype\" : f\"{props.dtype}\"}\n", + " return meta_dict" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "859ceed62dbcbd1c", + "metadata": {}, + "outputs": [], + "source": [ + "def check(candidate):\n", + " img_path = \"example_data/noise.tif\"\n", + " meta_dict_result = candidate(img_path)\n", + "\n", + " meta_dict_expected = {'Shape': '(20, 10)', 'dtype': 'uint8'}\n", + " \n", + " assert meta_dict_result == meta_dict_expected" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "fb8581fe6d7b73e3", + "metadata": {}, + "outputs": [], + "source": [ + "check(image_metadata_reading)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.12.0" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/test_cases/read_ome_xml_from_ome_tiff.ipynb b/test_cases/read_ome_xml_from_ome_tiff.ipynb new file mode 100644 index 0000000..ae94bbf --- /dev/null +++ b/test_cases/read_ome_xml_from_ome_tiff.ipynb @@ -0,0 +1,71 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "initial_id", + "metadata": {}, + "outputs": [], + "source": [ + "def read_ome_metadata_from_ome_tiff(img_path):\n", + " \"\"\"\n", + " Read the ome.xml header from an ome.tiff\n", + " \"\"\"\n", + " from ome_types import from_tiff, to_xml\n", + " ome = from_tiff(img_path)\n", + " return to_xml(ome)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "47041db4eac2b5dd", + "metadata": {}, + "outputs": [], + "source": [ + "def check(candidate):\n", + " img_path = \"example_data/example.ome.tif\"\n", + " ome_string_result = candidate(img_path)\n", + " \n", + " with open(\"example_data/ome_xml_example.xml\", 'r', encoding='utf-8') as file:\n", + " ome_string_expected = file.read()\n", + " \n", + " ome_string_result = ome_string_result.strip()\n", + " ome_string_expected = ome_string_expected.strip() \n", + "\n", + " assert ome_string_result == ome_string_expected" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "38283683630e2522", + "metadata": {}, + "outputs": [], + "source": [ + "check(read_ome_metadata_from_ome_tiff)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.12.0" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/test_cases/tiff_metadata_reading.ipynb b/test_cases/tiff_metadata_reading.ipynb new file mode 100644 index 0000000..0e6b25c --- /dev/null +++ b/test_cases/tiff_metadata_reading.ipynb @@ -0,0 +1,71 @@ +{ + "cells": [ + { + "metadata": {}, + "cell_type": "code", + "source": [ + "def image_metadata_reading(image_filename):\n", + " \"\"\"\n", + " Read image metadata from tiff file and convert it into a dictionary.\n", + " Ensure that the dictionary only contains a single entry \"shape\" with image dimensions as tuple.\n", + " Return the dictionary.\n", + " \"\"\"\n", + " import json\n", + " \n", + " from bioio import BioImage\n", + " import bioio_tifffile\n", + " img = BioImage(image_filename, reader=bioio_tifffile.Reader)\n", + " metadata = json.loads(img.metadata)\n", + " return metadata" + ], + "id": "initial_id", + "outputs": [], + "execution_count": null + }, + { + "cell_type": "code", + "id": "22fa850f66ddba30", + "metadata": {}, + "source": [ + "def check(candidate):\n", + " result_metadata = candidate(\"example_data/blobs.tif\") \n", + " expected_metadata = {\"shape\": [254, 256]}\n", + " \n", + " assert result_metadata == expected_metadata" + ], + "outputs": [], + "execution_count": null + }, + { + "cell_type": "code", + "id": "d8b1eb3c6d32e7ab", + "metadata": {}, + "source": [ + "check(image_metadata_reading)" + ], + "outputs": [], + "execution_count": null + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.12.0" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 767e8a808b5de64d327d21fff358b3ddcebb3e18 Mon Sep 17 00:00:00 2001 From: Riccardo Massei <118002526+rmassei@users.noreply.github.com> Date: Fri, 22 Nov 2024 14:01:26 +0000 Subject: [PATCH 2/2] removed strange oryx file --- oryx-build-commands.txt | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 oryx-build-commands.txt diff --git a/oryx-build-commands.txt b/oryx-build-commands.txt deleted file mode 100644 index d647bdf..0000000 --- a/oryx-build-commands.txt +++ /dev/null @@ -1,2 +0,0 @@ -PlatformWithVersion=Python -BuildCommands=conda env create --file environment.yml --prefix ./venv --quiet