From c8d9b4fc3ed26089385162dfef613fb5d9d1bb96 Mon Sep 17 00:00:00 2001 From: Hamdah Shafqat Abbasi Date: Wed, 18 Sep 2024 15:54:40 -0400 Subject: [PATCH 1/7] =?UTF-8?q?Bump=20version:=200.3.2=20=E2=86=92=200.3.3?= =?UTF-8?q?-dev1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- formats/ome-converter-tool/.bumpversion.cfg | 2 +- formats/ome-converter-tool/README.md | 2 +- formats/ome-converter-tool/VERSION | 2 +- formats/ome-converter-tool/plugin.json | 4 ++-- formats/ome-converter-tool/pyproject.toml | 2 +- .../src/polus/images/formats/ome_converter/__init__.py | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/formats/ome-converter-tool/.bumpversion.cfg b/formats/ome-converter-tool/.bumpversion.cfg index bf31b9cf5..6b1edaaaa 100644 --- a/formats/ome-converter-tool/.bumpversion.cfg +++ b/formats/ome-converter-tool/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.3.2 +current_version = 0.3.3-dev1 commit = True tag = False parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\-(?P[a-z]+)(?P\d+))? diff --git a/formats/ome-converter-tool/README.md b/formats/ome-converter-tool/README.md index 3fbcc8491..cd791af33 100644 --- a/formats/ome-converter-tool/README.md +++ b/formats/ome-converter-tool/README.md @@ -1,4 +1,4 @@ -# OME Converter (v0.3.2) +# OME Converter (v0.3.3-dev1) This WIPP plugin converts BioFormats supported data types to the OME Zarr or OME TIF file format. This is not a complete implementation, rather it implements a file diff --git a/formats/ome-converter-tool/VERSION b/formats/ome-converter-tool/VERSION index d15723fbe..1487b3ba8 100644 --- a/formats/ome-converter-tool/VERSION +++ b/formats/ome-converter-tool/VERSION @@ -1 +1 @@ -0.3.2 +0.3.3-dev1 diff --git a/formats/ome-converter-tool/plugin.json b/formats/ome-converter-tool/plugin.json index b00ef8446..0dd9fec56 100644 --- a/formats/ome-converter-tool/plugin.json +++ b/formats/ome-converter-tool/plugin.json @@ -1,6 +1,6 @@ { "name": "OME Converter", - "version": "0.3.2", + "version": "0.3.3-dev1", "title": "OME Converter", "description": "Convert Bioformats supported format to OME Zarr or OME TIF", "author": "Nick Schaub (nick.schaub@nih.gov), Hamdah Shafqat Abbasi (hamdahshafqat.abbasi@nih.gov)", @@ -8,7 +8,7 @@ "repository": "https://github.com/PolusAI/polus-plugins", "website": "https://ncats.nih.gov/preclinical/core/informatics", "citation": "", - "containerId": "polusai/ome-converter-tool:0.3.2", + "containerId": "polusai/ome-converter-tool:0.3.3-dev1", "baseCommand": [ "python3", "-m", diff --git a/formats/ome-converter-tool/pyproject.toml b/formats/ome-converter-tool/pyproject.toml index ef070ca62..55cb9e366 100644 --- a/formats/ome-converter-tool/pyproject.toml +++ b/formats/ome-converter-tool/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "polus-images-formats-ome-converter" -version = "0.3.2" +version = "0.3.3-dev1" description = "Convert BioFormats datatypes to ome.tif or ome.zarr file format" authors = [ "Nick Schaub ", diff --git a/formats/ome-converter-tool/src/polus/images/formats/ome_converter/__init__.py b/formats/ome-converter-tool/src/polus/images/formats/ome_converter/__init__.py index 601dd3281..d5e163467 100644 --- a/formats/ome-converter-tool/src/polus/images/formats/ome_converter/__init__.py +++ b/formats/ome-converter-tool/src/polus/images/formats/ome_converter/__init__.py @@ -1,6 +1,6 @@ """Ome Converter.""" -__version__ = "0.3.2" +__version__ = "0.3.3-dev1" from .image_converter import batch_convert from .image_converter import convert_image From dcdb6b10b830070ed12ccddbe602da6191b34f8f Mon Sep 17 00:00:00 2001 From: Hamdah Shafqat Abbasi Date: Thu, 26 Sep 2024 08:35:18 -0400 Subject: [PATCH 2/7] fix endian and remove fileExtension input argument --- formats/ome-converter-tool/.bumpversion.cfg | 2 + formats/ome-converter-tool/Dockerfile | 2 +- formats/ome-converter-tool/README.md | 8 +- formats/ome-converter-tool/ict.yaml | 76 ++++---- formats/ome-converter-tool/omeconverter.cwl | 6 +- formats/ome-converter-tool/plugin.json | 22 +-- formats/ome-converter-tool/pyproject.toml | 2 +- formats/ome-converter-tool/run-plugin.sh | 7 +- .../images/formats/ome_converter/__main__.py | 14 +- .../formats/ome_converter/image_converter.py | 163 ++++++++++-------- formats/ome-converter-tool/tests/conftest.py | 2 +- formats/ome-converter-tool/tests/test_main.py | 3 - 12 files changed, 141 insertions(+), 166 deletions(-) diff --git a/formats/ome-converter-tool/.bumpversion.cfg b/formats/ome-converter-tool/.bumpversion.cfg index 6b1edaaaa..cb010b29c 100644 --- a/formats/ome-converter-tool/.bumpversion.cfg +++ b/formats/ome-converter-tool/.bumpversion.cfg @@ -24,6 +24,8 @@ replace = version = "{new_version}" [bumpversion:file:VERSION] +[bumpversion:file:ict.yaml] +[bumpversion:file:omeconverter.cwl] [bumpversion:file:README.md] [bumpversion:file:src/polus/images/formats/ome_converter/__init__.py] diff --git a/formats/ome-converter-tool/Dockerfile b/formats/ome-converter-tool/Dockerfile index 088c8b643..527b0a45d 100644 --- a/formats/ome-converter-tool/Dockerfile +++ b/formats/ome-converter-tool/Dockerfile @@ -1,4 +1,4 @@ -FROM polusai/bfio:2.3.3 +FROM polusai/bfio:2.4.3 # environment variables defined in polusai/bfio ENV EXEC_DIR="/opt/executables" diff --git a/formats/ome-converter-tool/README.md b/formats/ome-converter-tool/README.md index cd791af33..d6936b6a3 100644 --- a/formats/ome-converter-tool/README.md +++ b/formats/ome-converter-tool/README.md @@ -23,12 +23,16 @@ contents of `plugin.json` into the pop-up window and submit. ## Options -This plugin takes 3 input arguments and 1 output argument: +This plugin takes 2 input arguments and 1 output argument: | Name | Description | I/O | Type | |------------------|--------------------------------------------------------------|--------|-------------| | `--inpDir` | Input generic data collection to be processed by this plugin | Input | genericData | | `--filePattern` | A filepattern, used to select data for conversion | Input | string | -| `--fileExtension`| A desired file format for conversion | Input | enum | | `--outDir` | Output collection | Output | genericData | | `--preview` | Generate a JSON file with outputs | Output | JSON | + +## Docker Command + +```bash +docker run -e POLUS_IMG_EXT=".ome.zarr" -v /Users/abbasih2/:/Users/abbasih2/ polusai/ome-converter-tool:0.3.3-dev1 --inpDir=/Users/path/to/Images/ --filePattern=".*.tif" --outDir=/Users/path/to/outputs diff --git a/formats/ome-converter-tool/ict.yaml b/formats/ome-converter-tool/ict.yaml index 63658d64c..a67cf8ec1 100644 --- a/formats/ome-converter-tool/ict.yaml +++ b/formats/ome-converter-tool/ict.yaml @@ -1,55 +1,41 @@ author: -- Nick Schaub -- Hamdah Shafqat + - Nick Schaub + - Hamdah Shafqat contact: nick.schaub@nih.gov -container: polusai/ome-converter-tool:0.3.2-dev0 +container: polusai/ome-converter-tool:0.3.3-dev1 description: Convert Bioformats supported format to OME Zarr or OME TIF entrypoint: python3 -m polus.images.formats.ome_converter inputs: -- description: Input generic data collection to be processed by this plugin - format: - - genericData - name: inpDir - required: true - type: path -- description: A filepattern, used to select data to be converted - format: - - string - name: filePattern - required: true - type: string -- description: Type of data conversion - format: - - enum - name: fileExtension - required: true - type: string + - description: Input generic data collection to be processed by this plugin + format: + - genericData + name: inpDir + required: true + type: path + - description: A filepattern, used to select data to be converted + format: + - string + name: filePattern + required: true + type: string name: polusai/OMEConverter outputs: -- description: Output collection - format: - - genericData - name: outDir - required: true - type: path -repository: https://github.com/PolusAI/polus-plugins + - description: Output collection + format: + - genericData + name: outDir + required: true + type: path +repository: https://github.com/PolusAI/image-tools specVersion: 1.0.0 title: OME Converter ui: -- description: Input generic data collection to be processed by this plugin - key: inputs.inpDir - title: Input generic collection - type: path -- description: A filepattern, used to select data for conversion - key: inputs.filePattern - title: Filepattern - type: text -- description: Type of data conversion - fields: - - .ome.tif - - .ome.zarr - - default - key: inputs.fileExtension - title: fileExtension - type: select -version: 0.3.2-dev0 + - description: Input generic data collection to be processed by this plugin + key: inputs.inpDir + title: Input generic collection + type: path + - description: A filepattern, used to select data for conversion + key: inputs.filePattern + title: Filepattern + type: text +version: 0.3.3-dev1 diff --git a/formats/ome-converter-tool/omeconverter.cwl b/formats/ome-converter-tool/omeconverter.cwl index e242d5409..e09b50bf8 100644 --- a/formats/ome-converter-tool/omeconverter.cwl +++ b/formats/ome-converter-tool/omeconverter.cwl @@ -1,10 +1,6 @@ class: CommandLineTool cwlVersion: v1.2 inputs: - fileExtension: - inputBinding: - prefix: --fileExtension - type: string filePattern: inputBinding: prefix: --filePattern @@ -24,7 +20,7 @@ outputs: type: Directory requirements: DockerRequirement: - dockerPull: polusai/ome-converter-tool:0.3.2-dev0 + dockerPull: polusai/ome-converter-tool:0.3.3-dev1 InitialWorkDirRequirement: listing: - entry: $(inputs.outDir) diff --git a/formats/ome-converter-tool/plugin.json b/formats/ome-converter-tool/plugin.json index 0dd9fec56..ca7444412 100644 --- a/formats/ome-converter-tool/plugin.json +++ b/formats/ome-converter-tool/plugin.json @@ -5,7 +5,7 @@ "description": "Convert Bioformats supported format to OME Zarr or OME TIF", "author": "Nick Schaub (nick.schaub@nih.gov), Hamdah Shafqat Abbasi (hamdahshafqat.abbasi@nih.gov)", "institution": "National Center for Advancing Translational Sciences, National Institutes of Health", - "repository": "https://github.com/PolusAI/polus-plugins", + "repository": "https://github.com/PolusAI/image-tools", "website": "https://ncats.nih.gov/preclinical/core/informatics", "citation": "", "containerId": "polusai/ome-converter-tool:0.3.3-dev1", @@ -26,20 +26,6 @@ "type": "string", "description": "A filepattern, used to select data to be converted", "required": true - }, - { - "name": "fileExtension", - "type": "enum", - "description": "Type of data conversion", - "default": "default", - "options": { - "values": [ - ".ome.tif", - ".ome.zarr", - "default" - ] - }, - "required": true } ], "outputs": [ @@ -59,12 +45,6 @@ "key": "inputs.filePattern", "title": "Filepattern", "description": "A filepattern, used to select data for conversion" - }, - { - "key": "inputs.fileExtension", - "title": "fileExtension", - "description": "Type of data conversion", - "default": ".ome.tif" } ] } diff --git a/formats/ome-converter-tool/pyproject.toml b/formats/ome-converter-tool/pyproject.toml index 55cb9e366..a64414c03 100644 --- a/formats/ome-converter-tool/pyproject.toml +++ b/formats/ome-converter-tool/pyproject.toml @@ -12,7 +12,7 @@ packages = [{include = "polus", from = "src"}] [tool.poetry.dependencies] python = ">=3.9,<3.12" -bfio = {version = "^2.3.3", extras = ["all"]} +bfio = {version = "^2.4.3", extras = ["all"]} filepattern = "^2.0.4" typer = "^0.7.0" tqdm = "^4.64.1" diff --git a/formats/ome-converter-tool/run-plugin.sh b/formats/ome-converter-tool/run-plugin.sh index 154496d8b..b579515f9 100755 --- a/formats/ome-converter-tool/run-plugin.sh +++ b/formats/ome-converter-tool/run-plugin.sh @@ -12,12 +12,11 @@ fileExtension=".ome.zarr" outDir=/data/output # Show the help options -docker run polusai/ome-converter-plugin:${version} +# docker run polusai/ome-converter-plugin:${version} # Run the plugin -docker run --mount type=bind,source=${datapath},target=/data/ \ - polusai/ome-converter-plugin:${version} \ +docker run -e POLUS_IMG_EXT=${fileExtension} --mount type=bind,source=${datapath},target=/data/ \ + polusai/ome-converter-tool:${version} \ --inpDir ${inpDir} \ --filePattern ${filePattern} \ - --fileExtension ${fileExtension} \ --outDir ${outDir} diff --git a/formats/ome-converter-tool/src/polus/images/formats/ome_converter/__main__.py b/formats/ome-converter-tool/src/polus/images/formats/ome_converter/__main__.py index 7c4c36559..969c803ff 100644 --- a/formats/ome-converter-tool/src/polus/images/formats/ome_converter/__main__.py +++ b/formats/ome-converter-tool/src/polus/images/formats/ome_converter/__main__.py @@ -11,7 +11,6 @@ import preadator import typer from polus.images.formats.ome_converter.image_converter import NUM_THREADS -from polus.images.formats.ome_converter.image_converter import Extension from polus.images.formats.ome_converter.image_converter import convert_image from tqdm import tqdm @@ -24,6 +23,7 @@ ) logger = logging.getLogger("polus.images.formats.ome_converter") logger.setLevel(os.environ.get("POLUS_LOG", logging.INFO)) +POLUS_IMG_EXT = os.environ.get("POLUS_IMG_EXT", ".ome.tif") @app.command() @@ -43,11 +43,6 @@ def main( "--filePattern", help="A filepattern defining the images to be converted", ), - file_extension: Extension = typer.Option( - Extension, - "--fileExtension", - help="Type of data conversion", - ), out_dir: pathlib.Path = typer.Option( ..., "--outDir", @@ -68,7 +63,6 @@ def main( logger.info(f"inpDir = {inp_dir}") logger.info(f"outDir = {out_dir}") logger.info(f"filePattern = {pattern}") - logger.info(f"fileExtension = {file_extension}") fps = fp.FilePattern(inp_dir, pattern) @@ -79,7 +73,7 @@ def main( "outDir": [], } for file in fps(): - out_name = str(file[1][0].name.split(".")[0]) + file_extension + out_name = str(file[1][0].name.split(".")[0]) + POLUS_IMG_EXT out_json["outDir"].append(out_name) json.dump(out_json, jfile, indent=2) return @@ -93,14 +87,14 @@ def main( for files in fps(): file = files[1][0] threads.append( - executor.submit_process(convert_image, file, file_extension, out_dir), + executor.submit_process(convert_image, file, POLUS_IMG_EXT, out_dir), ) for f in tqdm( as_completed(threads), total=len(threads), mininterval=5, - desc=f"converting images to {file_extension}", + desc=f"converting images to {POLUS_IMG_EXT}", initial=0, unit_scale=True, colour="cyan", diff --git a/formats/ome-converter-tool/src/polus/images/formats/ome_converter/image_converter.py b/formats/ome-converter-tool/src/polus/images/formats/ome_converter/image_converter.py index 8bc5f174a..f0c39b019 100644 --- a/formats/ome-converter-tool/src/polus/images/formats/ome_converter/image_converter.py +++ b/formats/ome-converter-tool/src/polus/images/formats/ome_converter/image_converter.py @@ -1,14 +1,15 @@ """Ome Converter.""" -import enum + import logging import os import pathlib from concurrent.futures import as_completed -from multiprocessing import cpu_count +from itertools import product from sys import platform from typing import Optional import filepattern as fp +import numpy as np import preadator from bfio import BioReader from bfio import BioWriter @@ -20,25 +21,52 @@ TILE_SIZE = 2**13 -if platform == "linux" or platform == "linux2": +if platform.startswith("linux"): NUM_THREADS = len(os.sched_getaffinity(0)) // 2 # type: ignore else: - NUM_THREADS = max(cpu_count() // 2, 1) + NUM_THREADS = os.cpu_count() # type: ignore -POLUS_IMG_EXT = os.environ.get("POLUS_IMG_EXT", ".ome.tif") +def write_image( + image: np.ndarray, + out_path: pathlib.Path, + max_workers: int, +) -> None: + """Write an image to OME-TIFF or OME-ZARR format using BioFormats. -class Extension(str, enum.Enum): - """Extension types to be converted.""" + This function converts a given image to the OME-TIFF or OME-ZARR format, + ensuring that the data type is compatible and handling any necessary + byte order adjustments. It utilizes the BioWriter for writing the image + and manages channel names based on the provided BioReader. - OMETIF = ".ome.tif" - OMEZARR = ".ome.zarr" - Default = POLUS_IMG_EXT + Args: + c: The index of the channel in the image. + br: An instance of BioReader containing metadata for the image. + image: The image data to be written. + out_path: Path to an output image. + max_workers: The maximum number of worker threads to use for writing. + """ + if image.dtype == ">u2": + image = image.byteswap().newbyteorder("<") + + with BioWriter( + out_path, + max_workers, + ) as bw: + # Handling of parsing channels when channels names are not provided. + # if bw.channel_names != [None]: + bw.C = 1 + bw.T = 1 + bw.Z = 1 + bw.X = image.shape[1] + bw.Y = image.shape[0] + bw.dtype = image.dtype + bw[:] = image def convert_image( inp_image: pathlib.Path, - file_extension: Extension, + file_extension: str, out_dir: pathlib.Path, ) -> None: """Convert bioformats supported datatypes to ome.tif or ome.zarr file format. @@ -48,78 +76,67 @@ def convert_image( file_extension: Type of data conversion. out_dir: Path to output directory. """ - with BioReader(inp_image, max_workers=2) as br: - # Loop through timepoints - for t in range(br.T): - # Loop through channels - for c in range(br.C): - extension = "".join( - [ - suffix - for suffix in inp_image.suffixes[-2:] - if len(suffix) < 6 # noqa: PLR2004 - ], + # Loop through timepoints, channels and z-slices + with BioReader(inp_image, max_workers=NUM_THREADS) as br: + for t, c, z in product(range(br.T), range(br.C), range(br.Z)): + extension = "".join( + [ + suffix + for suffix in inp_image.suffixes[-2:] + if len(suffix) < 6 # noqa: PLR2004 + ], + ) + + out_path = out_dir.joinpath( + inp_image.name.replace(extension, file_extension), + ) + if br.C > 1: + out_path = out_dir.joinpath( + out_path.name.replace( + file_extension, + f"_c{c}" + file_extension, + ), + ) + if br.T > 1: + out_path = out_dir.joinpath( + out_path.name.replace( + file_extension, + f"_t{t}" + file_extension, + ), ) + if br.Z > 1: out_path = out_dir.joinpath( - inp_image.name.replace(extension, file_extension), + out_path.name.replace( + file_extension, + f"_z{z}" + file_extension, + ), + ) + + # Process each tile in the image using itertools.product + for y, x in product(range(0, br.Y, TILE_SIZE), range(0, br.X, TILE_SIZE)): + y_max = min(br.Y, y + TILE_SIZE) + x_max = min(br.X, x + TILE_SIZE) + + image = br[ + y:y_max, + x:x_max, + z, + c, + t, + ] + write_image( + image=image, + out_path=out_path, + max_workers=NUM_THREADS, ) - if br.C > 1: - out_path = out_dir.joinpath( - out_path.name.replace( - file_extension, - f"_c{c}" + file_extension, - ), - ) - if br.T > 1: - out_path = out_dir.joinpath( - out_path.name.replace( - file_extension, - f"_t{t}" + file_extension, - ), - ) - - with BioWriter( - out_path, - max_workers=2, - metadata=br.metadata, - ) as bw: - bw.C = 1 - bw.T = 1 - - # Handling of parsing channels when channels names are not provided. - if bw.channel_names != [None]: - bw.channel_names = [br.channel_names[c]] - - # Loop through z-slices - for z in range(br.Z): - # Loop across the length of the image - for y in range(0, br.Y, TILE_SIZE): - y_max = min([br.Y, y + TILE_SIZE]) - - # Loop across the depth of the image - for x in range(0, br.X, TILE_SIZE): - x_max = min([br.X, x + TILE_SIZE]) - bw[ - y:y_max, - x:x_max, - z : z + 1, - 0, - 0, - ] = br[ - y:y_max, - x:x_max, - z : z + 1, - c, - t, - ] def batch_convert( inp_dir: pathlib.Path, out_dir: pathlib.Path, file_pattern: Optional[str], - file_extension: Extension, + file_extension: str, ) -> None: """Convert bioformats supported datatypes in batches to ome.tif or ome.zarr. diff --git a/formats/ome-converter-tool/tests/conftest.py b/formats/ome-converter-tool/tests/conftest.py index 4b1931a57..15a37ec7e 100644 --- a/formats/ome-converter-tool/tests/conftest.py +++ b/formats/ome-converter-tool/tests/conftest.py @@ -53,7 +53,7 @@ def synthetic_images( syn_dir = pathlib.Path(tempfile.mkdtemp(suffix="_syn_data")) images: list[numpy.ndarray] = [] - for i in range(10): + for i in range(5): # Create images blobs: numpy.ndarray = skimage.data.binary_blobs( length=size, diff --git a/formats/ome-converter-tool/tests/test_main.py b/formats/ome-converter-tool/tests/test_main.py index 027a4a1a6..8e91d9480 100644 --- a/formats/ome-converter-tool/tests/test_main.py +++ b/formats/ome-converter-tool/tests/test_main.py @@ -59,7 +59,6 @@ def test_image_converter_omezarr( def test_cli( synthetic_images: tuple[list[np.ndarray], pathlib.Path], output_directory: pathlib.Path, - file_extension: str, ) -> None: """Test Cli.""" _, inp_dir = synthetic_images @@ -71,8 +70,6 @@ def test_cli( inp_dir, "--filePattern", ".+", - "--fileExtension", - file_extension, "--outDir", output_directory, ], From dc3f63434f8a3332da746270d5fa2a0eb05138d2 Mon Sep 17 00:00:00 2001 From: Hamdah Shafqat Abbasi Date: Mon, 30 Sep 2024 16:35:49 -0400 Subject: [PATCH 3/7] updated bfio dependency and tests --- formats/ome-converter-tool/Dockerfile | 2 +- formats/ome-converter-tool/pyproject.toml | 2 +- .../formats/ome_converter/image_converter.py | 9 +++++++-- formats/ome-converter-tool/tests/conftest.py | 18 ++++++++++-------- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/formats/ome-converter-tool/Dockerfile b/formats/ome-converter-tool/Dockerfile index 527b0a45d..53a844554 100644 --- a/formats/ome-converter-tool/Dockerfile +++ b/formats/ome-converter-tool/Dockerfile @@ -1,4 +1,4 @@ -FROM polusai/bfio:2.4.3 +FROM polusai/bfio:2.4.4 # environment variables defined in polusai/bfio ENV EXEC_DIR="/opt/executables" diff --git a/formats/ome-converter-tool/pyproject.toml b/formats/ome-converter-tool/pyproject.toml index a64414c03..e120015c0 100644 --- a/formats/ome-converter-tool/pyproject.toml +++ b/formats/ome-converter-tool/pyproject.toml @@ -12,7 +12,7 @@ packages = [{include = "polus", from = "src"}] [tool.poetry.dependencies] python = ">=3.9,<3.12" -bfio = {version = "^2.4.3", extras = ["all"]} +bfio = {version = "^2.4.4", extras = ["all"]} filepattern = "^2.0.4" typer = "^0.7.0" tqdm = "^4.64.1" diff --git a/formats/ome-converter-tool/src/polus/images/formats/ome_converter/image_converter.py b/formats/ome-converter-tool/src/polus/images/formats/ome_converter/image_converter.py index f0c39b019..a939a02f4 100644 --- a/formats/ome-converter-tool/src/polus/images/formats/ome_converter/image_converter.py +++ b/formats/ome-converter-tool/src/polus/images/formats/ome_converter/image_converter.py @@ -28,6 +28,8 @@ def write_image( + br: BioReader, + c: int, image: np.ndarray, out_path: pathlib.Path, max_workers: int, @@ -40,8 +42,8 @@ def write_image( and manages channel names based on the provided BioReader. Args: - c: The index of the channel in the image. br: An instance of BioReader containing metadata for the image. + c: The index of the channel in the image. image: The image data to be written. out_path: Path to an output image. max_workers: The maximum number of worker threads to use for writing. @@ -54,7 +56,8 @@ def write_image( max_workers, ) as bw: # Handling of parsing channels when channels names are not provided. - # if bw.channel_names != [None]: + if bw.channel_names != [None]: + bw.channel_names = [br.channel_names[c]] bw.C = 1 bw.T = 1 bw.Z = 1 @@ -126,6 +129,8 @@ def convert_image( t, ] write_image( + br=br, + c=c, image=image, out_path=out_path, max_workers=NUM_THREADS, diff --git a/formats/ome-converter-tool/tests/conftest.py b/formats/ome-converter-tool/tests/conftest.py index 15a37ec7e..b3dc8a7b9 100644 --- a/formats/ome-converter-tool/tests/conftest.py +++ b/formats/ome-converter-tool/tests/conftest.py @@ -10,7 +10,6 @@ import pytest import requests import skimage.data -import skimage.io import skimage.measure @@ -52,15 +51,18 @@ def synthetic_images( size, extension = get_params syn_dir = pathlib.Path(tempfile.mkdtemp(suffix="_syn_data")) + images: list[numpy.ndarray] = [] - for i in range(5): - # Create images - blobs: numpy.ndarray = skimage.data.binary_blobs( - length=size, - volume_fraction=0.05, - blob_size_fraction=0.05, + # Create a random number generator + rng = numpy.random.default_rng() + + for i in range(3): + syn_img: numpy.ndarray = rng.integers( + low=0, + high=256, + size=(size, size), + dtype=numpy.uint8, ) - syn_img: numpy.ndarray = skimage.measure.label(blobs) outname = f"syn_image_{i}{extension}" # Save image From 4d99387b20ffbd522a2ae78fc02bdf1b0d5c6c51 Mon Sep 17 00:00:00 2001 From: Hamdah Shafqat Abbasi Date: Thu, 3 Oct 2024 13:11:58 -0400 Subject: [PATCH 4/7] =?UTF-8?q?Bump=20version:=200.3.3-dev1=20=E2=86=92=20?= =?UTF-8?q?0.3.3-dev2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- formats/ome-converter-tool/.bumpversion.cfg | 4 +++- formats/ome-converter-tool/README.md | 4 ++-- formats/ome-converter-tool/VERSION | 2 +- formats/ome-converter-tool/ict.yaml | 4 ++-- formats/ome-converter-tool/omeconverter.cwl | 2 +- formats/ome-converter-tool/plugin.json | 4 ++-- formats/ome-converter-tool/pyproject.toml | 2 +- .../src/polus/images/formats/ome_converter/__init__.py | 2 +- 8 files changed, 13 insertions(+), 11 deletions(-) diff --git a/formats/ome-converter-tool/.bumpversion.cfg b/formats/ome-converter-tool/.bumpversion.cfg index cb010b29c..4a3ec8e3d 100644 --- a/formats/ome-converter-tool/.bumpversion.cfg +++ b/formats/ome-converter-tool/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.3.3-dev1 +current_version = 0.3.3-dev2 commit = True tag = False parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\-(?P[a-z]+)(?P\d+))? @@ -25,7 +25,9 @@ replace = version = "{new_version}" [bumpversion:file:VERSION] [bumpversion:file:ict.yaml] + [bumpversion:file:omeconverter.cwl] + [bumpversion:file:README.md] [bumpversion:file:src/polus/images/formats/ome_converter/__init__.py] diff --git a/formats/ome-converter-tool/README.md b/formats/ome-converter-tool/README.md index d6936b6a3..2caa8c3e4 100644 --- a/formats/ome-converter-tool/README.md +++ b/formats/ome-converter-tool/README.md @@ -1,4 +1,4 @@ -# OME Converter (v0.3.3-dev1) +# OME Converter (v0.3.3-dev2) This WIPP plugin converts BioFormats supported data types to the OME Zarr or OME TIF file format. This is not a complete implementation, rather it implements a file @@ -35,4 +35,4 @@ This plugin takes 2 input arguments and 1 output argument: ## Docker Command ```bash -docker run -e POLUS_IMG_EXT=".ome.zarr" -v /Users/abbasih2/:/Users/abbasih2/ polusai/ome-converter-tool:0.3.3-dev1 --inpDir=/Users/path/to/Images/ --filePattern=".*.tif" --outDir=/Users/path/to/outputs +docker run -e POLUS_IMG_EXT=".ome.zarr" -v /Users/abbasih2/:/Users/abbasih2/ polusai/ome-converter-tool:0.3.3-dev2 --inpDir=/Users/path/to/Images/ --filePattern=".*.tif" --outDir=/Users/path/to/outputs diff --git a/formats/ome-converter-tool/VERSION b/formats/ome-converter-tool/VERSION index 1487b3ba8..7e8afea56 100644 --- a/formats/ome-converter-tool/VERSION +++ b/formats/ome-converter-tool/VERSION @@ -1 +1 @@ -0.3.3-dev1 +0.3.3-dev2 diff --git a/formats/ome-converter-tool/ict.yaml b/formats/ome-converter-tool/ict.yaml index a67cf8ec1..a83b94af0 100644 --- a/formats/ome-converter-tool/ict.yaml +++ b/formats/ome-converter-tool/ict.yaml @@ -2,7 +2,7 @@ author: - Nick Schaub - Hamdah Shafqat contact: nick.schaub@nih.gov -container: polusai/ome-converter-tool:0.3.3-dev1 +container: polusai/ome-converter-tool:0.3.3-dev2 description: Convert Bioformats supported format to OME Zarr or OME TIF entrypoint: python3 -m polus.images.formats.ome_converter inputs: @@ -38,4 +38,4 @@ ui: key: inputs.filePattern title: Filepattern type: text -version: 0.3.3-dev1 +version: 0.3.3-dev2 diff --git a/formats/ome-converter-tool/omeconverter.cwl b/formats/ome-converter-tool/omeconverter.cwl index e09b50bf8..f642bf318 100644 --- a/formats/ome-converter-tool/omeconverter.cwl +++ b/formats/ome-converter-tool/omeconverter.cwl @@ -20,7 +20,7 @@ outputs: type: Directory requirements: DockerRequirement: - dockerPull: polusai/ome-converter-tool:0.3.3-dev1 + dockerPull: polusai/ome-converter-tool:0.3.3-dev2 InitialWorkDirRequirement: listing: - entry: $(inputs.outDir) diff --git a/formats/ome-converter-tool/plugin.json b/formats/ome-converter-tool/plugin.json index ca7444412..a8258471a 100644 --- a/formats/ome-converter-tool/plugin.json +++ b/formats/ome-converter-tool/plugin.json @@ -1,6 +1,6 @@ { "name": "OME Converter", - "version": "0.3.3-dev1", + "version": "0.3.3-dev2", "title": "OME Converter", "description": "Convert Bioformats supported format to OME Zarr or OME TIF", "author": "Nick Schaub (nick.schaub@nih.gov), Hamdah Shafqat Abbasi (hamdahshafqat.abbasi@nih.gov)", @@ -8,7 +8,7 @@ "repository": "https://github.com/PolusAI/image-tools", "website": "https://ncats.nih.gov/preclinical/core/informatics", "citation": "", - "containerId": "polusai/ome-converter-tool:0.3.3-dev1", + "containerId": "polusai/ome-converter-tool:0.3.3-dev2", "baseCommand": [ "python3", "-m", diff --git a/formats/ome-converter-tool/pyproject.toml b/formats/ome-converter-tool/pyproject.toml index e120015c0..147db9bf2 100644 --- a/formats/ome-converter-tool/pyproject.toml +++ b/formats/ome-converter-tool/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "polus-images-formats-ome-converter" -version = "0.3.3-dev1" +version = "0.3.3-dev2" description = "Convert BioFormats datatypes to ome.tif or ome.zarr file format" authors = [ "Nick Schaub ", diff --git a/formats/ome-converter-tool/src/polus/images/formats/ome_converter/__init__.py b/formats/ome-converter-tool/src/polus/images/formats/ome_converter/__init__.py index d5e163467..d81521526 100644 --- a/formats/ome-converter-tool/src/polus/images/formats/ome_converter/__init__.py +++ b/formats/ome-converter-tool/src/polus/images/formats/ome_converter/__init__.py @@ -1,6 +1,6 @@ """Ome Converter.""" -__version__ = "0.3.3-dev1" +__version__ = "0.3.3-dev2" from .image_converter import batch_convert from .image_converter import convert_image From a420976e231e188dea8e5197da6f9c54c1de0e0f Mon Sep 17 00:00:00 2001 From: Hamdah Shafqat Abbasi Date: Tue, 8 Oct 2024 15:21:24 -0400 Subject: [PATCH 5/7] =?UTF-8?q?Bump=20version:=200.3.3-dev2=20=E2=86=92=20?= =?UTF-8?q?0.3.3-dev3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- formats/ome-converter-tool/.bumpversion.cfg | 2 +- formats/ome-converter-tool/README.md | 4 ++-- formats/ome-converter-tool/VERSION | 2 +- formats/ome-converter-tool/ict.yaml | 4 ++-- formats/ome-converter-tool/omeconverter.cwl | 2 +- formats/ome-converter-tool/plugin.json | 4 ++-- formats/ome-converter-tool/pyproject.toml | 2 +- .../src/polus/images/formats/ome_converter/__init__.py | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/formats/ome-converter-tool/.bumpversion.cfg b/formats/ome-converter-tool/.bumpversion.cfg index 4a3ec8e3d..c2255d773 100644 --- a/formats/ome-converter-tool/.bumpversion.cfg +++ b/formats/ome-converter-tool/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.3.3-dev2 +current_version = 0.3.3-dev3 commit = True tag = False parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\-(?P[a-z]+)(?P\d+))? diff --git a/formats/ome-converter-tool/README.md b/formats/ome-converter-tool/README.md index 2caa8c3e4..01531c084 100644 --- a/formats/ome-converter-tool/README.md +++ b/formats/ome-converter-tool/README.md @@ -1,4 +1,4 @@ -# OME Converter (v0.3.3-dev2) +# OME Converter (v0.3.3-dev3) This WIPP plugin converts BioFormats supported data types to the OME Zarr or OME TIF file format. This is not a complete implementation, rather it implements a file @@ -35,4 +35,4 @@ This plugin takes 2 input arguments and 1 output argument: ## Docker Command ```bash -docker run -e POLUS_IMG_EXT=".ome.zarr" -v /Users/abbasih2/:/Users/abbasih2/ polusai/ome-converter-tool:0.3.3-dev2 --inpDir=/Users/path/to/Images/ --filePattern=".*.tif" --outDir=/Users/path/to/outputs +docker run -e POLUS_IMG_EXT=".ome.zarr" -v /Users/abbasih2/:/Users/abbasih2/ polusai/ome-converter-tool:0.3.3-dev3 --inpDir=/Users/path/to/Images/ --filePattern=".*.tif" --outDir=/Users/path/to/outputs diff --git a/formats/ome-converter-tool/VERSION b/formats/ome-converter-tool/VERSION index 7e8afea56..f3f8731e3 100644 --- a/formats/ome-converter-tool/VERSION +++ b/formats/ome-converter-tool/VERSION @@ -1 +1 @@ -0.3.3-dev2 +0.3.3-dev3 diff --git a/formats/ome-converter-tool/ict.yaml b/formats/ome-converter-tool/ict.yaml index a83b94af0..f6b3688de 100644 --- a/formats/ome-converter-tool/ict.yaml +++ b/formats/ome-converter-tool/ict.yaml @@ -2,7 +2,7 @@ author: - Nick Schaub - Hamdah Shafqat contact: nick.schaub@nih.gov -container: polusai/ome-converter-tool:0.3.3-dev2 +container: polusai/ome-converter-tool:0.3.3-dev3 description: Convert Bioformats supported format to OME Zarr or OME TIF entrypoint: python3 -m polus.images.formats.ome_converter inputs: @@ -38,4 +38,4 @@ ui: key: inputs.filePattern title: Filepattern type: text -version: 0.3.3-dev2 +version: 0.3.3-dev3 diff --git a/formats/ome-converter-tool/omeconverter.cwl b/formats/ome-converter-tool/omeconverter.cwl index f642bf318..42340d71b 100644 --- a/formats/ome-converter-tool/omeconverter.cwl +++ b/formats/ome-converter-tool/omeconverter.cwl @@ -20,7 +20,7 @@ outputs: type: Directory requirements: DockerRequirement: - dockerPull: polusai/ome-converter-tool:0.3.3-dev2 + dockerPull: polusai/ome-converter-tool:0.3.3-dev3 InitialWorkDirRequirement: listing: - entry: $(inputs.outDir) diff --git a/formats/ome-converter-tool/plugin.json b/formats/ome-converter-tool/plugin.json index a8258471a..9089f13f1 100644 --- a/formats/ome-converter-tool/plugin.json +++ b/formats/ome-converter-tool/plugin.json @@ -1,6 +1,6 @@ { "name": "OME Converter", - "version": "0.3.3-dev2", + "version": "0.3.3-dev3", "title": "OME Converter", "description": "Convert Bioformats supported format to OME Zarr or OME TIF", "author": "Nick Schaub (nick.schaub@nih.gov), Hamdah Shafqat Abbasi (hamdahshafqat.abbasi@nih.gov)", @@ -8,7 +8,7 @@ "repository": "https://github.com/PolusAI/image-tools", "website": "https://ncats.nih.gov/preclinical/core/informatics", "citation": "", - "containerId": "polusai/ome-converter-tool:0.3.3-dev2", + "containerId": "polusai/ome-converter-tool:0.3.3-dev3", "baseCommand": [ "python3", "-m", diff --git a/formats/ome-converter-tool/pyproject.toml b/formats/ome-converter-tool/pyproject.toml index 147db9bf2..4866564cb 100644 --- a/formats/ome-converter-tool/pyproject.toml +++ b/formats/ome-converter-tool/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "polus-images-formats-ome-converter" -version = "0.3.3-dev2" +version = "0.3.3-dev3" description = "Convert BioFormats datatypes to ome.tif or ome.zarr file format" authors = [ "Nick Schaub ", diff --git a/formats/ome-converter-tool/src/polus/images/formats/ome_converter/__init__.py b/formats/ome-converter-tool/src/polus/images/formats/ome_converter/__init__.py index d81521526..941a41f60 100644 --- a/formats/ome-converter-tool/src/polus/images/formats/ome_converter/__init__.py +++ b/formats/ome-converter-tool/src/polus/images/formats/ome_converter/__init__.py @@ -1,6 +1,6 @@ """Ome Converter.""" -__version__ = "0.3.3-dev2" +__version__ = "0.3.3-dev3" from .image_converter import batch_convert from .image_converter import convert_image From 25c694cf51fe6261d27de81659be014d5b553454 Mon Sep 17 00:00:00 2001 From: Hamdah Shafqat Abbasi Date: Wed, 9 Oct 2024 16:15:57 -0400 Subject: [PATCH 6/7] fix writing tiled large images --- .../formats/ome_converter/image_converter.py | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/formats/ome-converter-tool/src/polus/images/formats/ome_converter/image_converter.py b/formats/ome-converter-tool/src/polus/images/formats/ome_converter/image_converter.py index a939a02f4..825df42b9 100644 --- a/formats/ome-converter-tool/src/polus/images/formats/ome_converter/image_converter.py +++ b/formats/ome-converter-tool/src/polus/images/formats/ome_converter/image_converter.py @@ -116,6 +116,9 @@ def convert_image( ), ) + # Initialize the complete_image if not done yet + final_image = np.zeros((br.Y, br.X, 1, 1, 1), dtype=br.dtype) + # Process each tile in the image using itertools.product for y, x in product(range(0, br.Y, TILE_SIZE), range(0, br.X, TILE_SIZE)): y_max = min(br.Y, y + TILE_SIZE) @@ -128,13 +131,16 @@ def convert_image( c, t, ] - write_image( - br=br, - c=c, - image=image, - out_path=out_path, - max_workers=NUM_THREADS, - ) + # Place the tile into the correct position in the complete image + final_image[y:y_max, x:x_max, z, c, t] = image + + write_image( + br=br, + c=c, + image=final_image, + out_path=out_path, + max_workers=NUM_THREADS, + ) def batch_convert( From 3474e7d3cb937fdfe4462c2887ba3a8c6e350fd8 Mon Sep 17 00:00:00 2001 From: Hamdah Shafqat Abbasi Date: Wed, 9 Oct 2024 18:14:43 -0400 Subject: [PATCH 7/7] updated doc --- formats/ome-converter-tool/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/formats/ome-converter-tool/README.md b/formats/ome-converter-tool/README.md index 01531c084..1eb47cbab 100644 --- a/formats/ome-converter-tool/README.md +++ b/formats/ome-converter-tool/README.md @@ -35,4 +35,4 @@ This plugin takes 2 input arguments and 1 output argument: ## Docker Command ```bash -docker run -e POLUS_IMG_EXT=".ome.zarr" -v /Users/abbasih2/:/Users/abbasih2/ polusai/ome-converter-tool:0.3.3-dev3 --inpDir=/Users/path/to/Images/ --filePattern=".*.tif" --outDir=/Users/path/to/outputs +docker run -e POLUS_IMG_EXT=".ome.zarr" -v /Users/username/:/Users/username/ polusai/ome-converter-tool:0.3.3-dev3 --inpDir=/Users/path/to/Images/ --filePattern=".*.tif" --outDir=/Users/path/to/outputs