From f2d76ffad26c922914a288a14a384c99cb4cb467 Mon Sep 17 00:00:00 2001 From: Najib Ishaq Date: Wed, 18 Sep 2024 10:45:42 -0400 Subject: [PATCH] moved branch --- .../apply-flatfield-tool/.bumpversion.cfg | 4 +-- .../images/apply-flatfield-tool/README.md | 2 +- .../images/apply-flatfield-tool/VERSION | 2 +- .../images/apply-flatfield-tool/plugin.json | 4 +-- .../apply-flatfield-tool/pyproject.toml | 6 ++-- .../images/apply_flatfield/__init__.py | 2 +- .../images/apply_flatfield/apply_flatfield.py | 8 +++-- .../image-assembler-tool/.bumpversion.cfg | 2 +- .../images/image-assembler-tool/README.md | 2 +- .../images/image-assembler-tool/VERSION | 2 +- .../images/image-assembler-tool/plugin.json | 4 +-- .../image-assembler-tool/pyproject.toml | 8 ++--- .../images/image_assembler/__init__.py | 2 +- .../images/image_assembler/__main__.py | 30 ++++++++++--------- .../images/image_assembler/image_assembler.py | 2 +- .../image-assembler-tool/tests/test_cli.py | 2 +- .../image-calculator-tool/.bumpversion.cfg | 4 +-- .../images/image-calculator-tool/README.md | 2 +- .../images/image-calculator-tool/VERSION | 2 +- .../images/image-calculator-tool/plugin.json | 4 +-- .../image-calculator-tool/pyproject.toml | 7 +++-- .../images/image_calculator/__init__.py | 2 +- .../images/image_calculator/calculator.py | 8 +++-- 23 files changed, 60 insertions(+), 51 deletions(-) diff --git a/transforms/images/apply-flatfield-tool/.bumpversion.cfg b/transforms/images/apply-flatfield-tool/.bumpversion.cfg index a2f2fd1cf..b49e9657c 100644 --- a/transforms/images/apply-flatfield-tool/.bumpversion.cfg +++ b/transforms/images/apply-flatfield-tool/.bumpversion.cfg @@ -1,6 +1,6 @@ [bumpversion] -current_version = 2.0.1 -commit = False +current_version = 2.1.0-dev0 +commit = True tag = False parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\-(?P[a-z]+)(?P\d+))? serialize = diff --git a/transforms/images/apply-flatfield-tool/README.md b/transforms/images/apply-flatfield-tool/README.md index c2ce5d8b9..bd4614e03 100644 --- a/transforms/images/apply-flatfield-tool/README.md +++ b/transforms/images/apply-flatfield-tool/README.md @@ -1,4 +1,4 @@ -# Apply Flatfield Plugin (v2.0.1) +# Apply Flatfield Plugin (v2.1.0-dev0) This WIPP plugin applies a flatfield operation on every image in a collection. The algorithm used to apply the flatfield is as follows: diff --git a/transforms/images/apply-flatfield-tool/VERSION b/transforms/images/apply-flatfield-tool/VERSION index 38f77a65b..e967cc4d6 100644 --- a/transforms/images/apply-flatfield-tool/VERSION +++ b/transforms/images/apply-flatfield-tool/VERSION @@ -1 +1 @@ -2.0.1 +2.1.0-dev0 diff --git a/transforms/images/apply-flatfield-tool/plugin.json b/transforms/images/apply-flatfield-tool/plugin.json index 60a1bafda..80ef16874 100644 --- a/transforms/images/apply-flatfield-tool/plugin.json +++ b/transforms/images/apply-flatfield-tool/plugin.json @@ -1,6 +1,6 @@ { "name": "Apply Flatfield", - "version": "2.0.1", + "version": "2.1.0-dev0", "title": "Apply Flatfield", "description": "Apply a flatfield algorithm to a collection of images.", "author": "Nick Schaub (Nick.Schaub@nih.gov), Najib Ishaq (najib.ishaq@nih.gov)", @@ -8,7 +8,7 @@ "repository": "https://github.com/labshare/polus-plugins", "website": "https://ncats.nih.gov/preclinical/core/informatics", "citation": "", - "containerId": "polusai/apply-flatfield-tool:2.0.1", + "containerId": "polusai/apply-flatfield-tool:2.1.0-dev0", "baseCommand": [ "python3", "-m", diff --git a/transforms/images/apply-flatfield-tool/pyproject.toml b/transforms/images/apply-flatfield-tool/pyproject.toml index cf82fd99d..c72f171eb 100644 --- a/transforms/images/apply-flatfield-tool/pyproject.toml +++ b/transforms/images/apply-flatfield-tool/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "polus-images-transforms-images-apply-flatfield" -version = "2.0.1" +version = "2.1.0-dev0" description = "" authors = [ "Nick Schaub ", @@ -11,10 +11,10 @@ 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 = { version = "^0.7.0", extras = ["all"] } -numpy = "^1.24.3" +numpy = "^2.0.0" tqdm = "^4.65.0" preadator = "0.4.0-dev2" diff --git a/transforms/images/apply-flatfield-tool/src/polus/images/transforms/images/apply_flatfield/__init__.py b/transforms/images/apply-flatfield-tool/src/polus/images/transforms/images/apply_flatfield/__init__.py index ab03b2528..f8394ba88 100644 --- a/transforms/images/apply-flatfield-tool/src/polus/images/transforms/images/apply_flatfield/__init__.py +++ b/transforms/images/apply-flatfield-tool/src/polus/images/transforms/images/apply_flatfield/__init__.py @@ -3,4 +3,4 @@ from . import utils from .apply_flatfield import apply -__version__ = "2.0.1" +__version__ = "2.1.0-dev0" diff --git a/transforms/images/apply-flatfield-tool/src/polus/images/transforms/images/apply_flatfield/apply_flatfield.py b/transforms/images/apply-flatfield-tool/src/polus/images/transforms/images/apply_flatfield/apply_flatfield.py index d81ef71da..5ac394a76 100644 --- a/transforms/images/apply-flatfield-tool/src/polus/images/transforms/images/apply_flatfield/apply_flatfield.py +++ b/transforms/images/apply-flatfield-tool/src/polus/images/transforms/images/apply_flatfield/apply_flatfield.py @@ -134,7 +134,8 @@ def _unshade_batch( batch_paths: list[pathlib.Path], out_dir: pathlib.Path, ff_image: numpy.ndarray, - df_image: typing.Optional[numpy.ndarray] = None, + df_image: typing.Optional[numpy.ndarray], + dtype: numpy.dtype = numpy.float32, ) -> None: """Apply flatfield correction to a batch of images. @@ -143,6 +144,7 @@ def _unshade_batch( out_dir: directory to save the corrected images ff_image: component to be used for flatfield correction df_image: component to be used for flatfield correction + dtype: data type to use for the corrected images """ # Load images with preadator.ProcessManager( @@ -160,11 +162,11 @@ def _unshade_batch( images = [f.result() for f in load_futures] images = [img for _, img in sorted(images, key=operator.itemgetter(0))] - img_stack = numpy.stack(images, axis=0).astype(numpy.float32) + img_stack = numpy.stack(images, axis=0).astype(dtype) # Apply flatfield correction if df_image is not None: - img_stack -= df_image + img_stack -= df_image.astype(dtype) img_stack /= ff_image + 1e-8 diff --git a/transforms/images/image-assembler-tool/.bumpversion.cfg b/transforms/images/image-assembler-tool/.bumpversion.cfg index c50534710..58ec0c42f 100644 --- a/transforms/images/image-assembler-tool/.bumpversion.cfg +++ b/transforms/images/image-assembler-tool/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.4.2 +current_version = 1.5.0-dev0 commit = True tag = False parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\-(?P[a-z]+)(?P\d+))? diff --git a/transforms/images/image-assembler-tool/README.md b/transforms/images/image-assembler-tool/README.md index 3c026e219..3c6d8884f 100644 --- a/transforms/images/image-assembler-tool/README.md +++ b/transforms/images/image-assembler-tool/README.md @@ -1,4 +1,4 @@ -# Image Assembler (1.4.2) +# Image Assembler (1.5.0-dev0) This WIPP plugin assembles images into a stitched image using an image stitching vector. It can assemble 2d and z-stacked images. When assembling z-stacked images, diff --git a/transforms/images/image-assembler-tool/VERSION b/transforms/images/image-assembler-tool/VERSION index 9df886c42..a6326d4d4 100644 --- a/transforms/images/image-assembler-tool/VERSION +++ b/transforms/images/image-assembler-tool/VERSION @@ -1 +1 @@ -1.4.2 +1.5.0-dev0 diff --git a/transforms/images/image-assembler-tool/plugin.json b/transforms/images/image-assembler-tool/plugin.json index 9a1baaf00..190ac91a5 100644 --- a/transforms/images/image-assembler-tool/plugin.json +++ b/transforms/images/image-assembler-tool/plugin.json @@ -1,6 +1,6 @@ { "name": "Image Assembler", - "version": "1.4.2", + "version": "1.5.0-dev0", "title": "Image Assembler", "description": "A scalable image assembling plugin.", "author": "Nick Schaub (nick.schaub@nih.gov), Antoine Gerardin (antoine.gerardin@gmail.com)", @@ -8,7 +8,7 @@ "repository": "https://github.com/labshare/polus-plugins", "website": "https://ncats.nih.gov/preclinical/core/informatics", "citation": "", - "containerId": "polusai/image-assembler-tool:1.4.2", + "containerId": "polusai/image-assembler-tool:1.5.0-dev0", "baseCommand": [ "python3", "-m", diff --git a/transforms/images/image-assembler-tool/pyproject.toml b/transforms/images/image-assembler-tool/pyproject.toml index fa2c64847..c54e00e36 100644 --- a/transforms/images/image-assembler-tool/pyproject.toml +++ b/transforms/images/image-assembler-tool/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "polus-images-transforms-images-image-assembler" -version = "1.4.2" +version = "1.5.0-dev0" description = "A scalable image assembler plugin." authors = ["Nick Schaub ", "Antoine Gerardin "] readme = "README.md" @@ -8,11 +8,11 @@ packages = [{include = "polus", from = "src"}] [tool.poetry.dependencies] python = ">=3.9,<3.12" -bfio = {version = "2.3.3", extras = ["all"]} -filepattern = "2.0.4" +bfio = {version = "^2.4.3", extras = ["all"]} +filepattern = "^2.0.4" preadator = "0.4.0.dev2" typer = "^0.7.0" -numpy = "<2.0.0" +numpy = "^2.0.0" [tool.poetry.group.dev.dependencies] diff --git a/transforms/images/image-assembler-tool/src/polus/images/transforms/images/image_assembler/__init__.py b/transforms/images/image-assembler-tool/src/polus/images/transforms/images/image_assembler/__init__.py index 47d722f4f..55bbed50a 100644 --- a/transforms/images/image-assembler-tool/src/polus/images/transforms/images/image_assembler/__init__.py +++ b/transforms/images/image-assembler-tool/src/polus/images/transforms/images/image_assembler/__init__.py @@ -1,6 +1,6 @@ """Image Assembler Plugin.""" -__version__ = "1.4.2" +__version__ = "1.5.0-dev0" from .image_assembler import ( # noqa assemble_images, diff --git a/transforms/images/image-assembler-tool/src/polus/images/transforms/images/image_assembler/__main__.py b/transforms/images/image-assembler-tool/src/polus/images/transforms/images/image_assembler/__main__.py index 73c050ea9..6b502d555 100644 --- a/transforms/images/image-assembler-tool/src/polus/images/transforms/images/image_assembler/__main__.py +++ b/transforms/images/image-assembler-tool/src/polus/images/transforms/images/image_assembler/__main__.py @@ -1,7 +1,6 @@ """Package entrypoint for Image Assembler.""" import json import logging -import typing from os import environ from pathlib import Path @@ -38,7 +37,7 @@ def generate_preview( timeslice_naming, ) - preview: dict[str, typing.Union[list, str]] = { + preview: dict[str, list[str]] = { "outputDir": [], } @@ -57,18 +56,33 @@ def main( "-i", help="""Absolute path to the input image collection directory to be processed by this plugin.""", + exists=True, + file_okay=False, + dir_okay=True, + readable=True, + resolve_path=True, ), stitch_path: Path = typer.Option( ..., "--stitchPath", "-s", help="Absolute path to a stitching vector directory.", + exists=True, + file_okay=False, + dir_okay=True, + readable=True, + resolve_path=True, ), out_dir: Path = typer.Option( ..., "--outDir", "-o", help="Absolute path to the output collection directory.", + exists=True, + file_okay=False, + dir_okay=True, + writable=True, + resolve_path=True, ), timeslice_naming: bool = typer.Option( False, @@ -89,18 +103,6 @@ def main( logger.info(f"outDir: {out_dir}") logger.info(f"timesliceNaming: {timeslice_naming}") - if not img_path.exists(): - msg = "imgPath does not exist" - raise ValueError(msg, img_path) - - if not out_dir.exists(): - msg = "outDir does not exist" - raise ValueError(msg, out_dir) - - if not stitch_path.exists(): - msg = "stitchPath does not exist" - raise ValueError(msg, stitch_path) - # if the input image collection contains a images subdirectory, we use that # TODO this is an artifact from WIPP integration. # This should eventually be removed from the implementation. diff --git a/transforms/images/image-assembler-tool/src/polus/images/transforms/images/image_assembler/image_assembler.py b/transforms/images/image-assembler-tool/src/polus/images/transforms/images/image_assembler/image_assembler.py index 570980264..8a7f922ba 100644 --- a/transforms/images/image-assembler-tool/src/polus/images/transforms/images/image_assembler/image_assembler.py +++ b/transforms/images/image-assembler-tool/src/polus/images/transforms/images/image_assembler/image_assembler.py @@ -335,7 +335,7 @@ def assemble_chunk( chunk[ chunk_start_y : chunk_start_y + region_height, chunk_start_x : chunk_start_x + region_width, - ] = data + ] = data.astype(bw.dtype) # completed chunk is written to disk # we only write what fits in the image since that the behavior bfio expects diff --git a/transforms/images/image-assembler-tool/tests/test_cli.py b/transforms/images/image-assembler-tool/tests/test_cli.py index 7dfea1868..fb5f0e07c 100644 --- a/transforms/images/image-assembler-tool/tests/test_cli.py +++ b/transforms/images/image-assembler-tool/tests/test_cli.py @@ -82,4 +82,4 @@ def test_cli_bad_input(local_data: tuple[Path, Path, Path, Path]): ], ) - assert result.exc_info[0] is ValueError + assert result.exc_info[0] is SystemExit diff --git a/transforms/images/image-calculator-tool/.bumpversion.cfg b/transforms/images/image-calculator-tool/.bumpversion.cfg index 55e4e691e..4de40e518 100644 --- a/transforms/images/image-calculator-tool/.bumpversion.cfg +++ b/transforms/images/image-calculator-tool/.bumpversion.cfg @@ -1,6 +1,6 @@ [bumpversion] -current_version = 0.2.2 -commit = False +current_version = 0.3.0-dev0 +commit = True tag = False parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\-(?P[a-z]+)(?P\d+))? serialize = diff --git a/transforms/images/image-calculator-tool/README.md b/transforms/images/image-calculator-tool/README.md index 9388d9ddd..c8f904d8b 100644 --- a/transforms/images/image-calculator-tool/README.md +++ b/transforms/images/image-calculator-tool/README.md @@ -1,4 +1,4 @@ -# Image Calculator (v0.2.2) +# Image Calculator (v0.3.0-dev0) This plugin performs pixel-wise operations between two image collections. For example, images in one image collection can be subtracted from images in another collection. diff --git a/transforms/images/image-calculator-tool/VERSION b/transforms/images/image-calculator-tool/VERSION index ee1372d33..d89f43c7d 100644 --- a/transforms/images/image-calculator-tool/VERSION +++ b/transforms/images/image-calculator-tool/VERSION @@ -1 +1 @@ -0.2.2 +0.3.0-dev0 diff --git a/transforms/images/image-calculator-tool/plugin.json b/transforms/images/image-calculator-tool/plugin.json index 5e594b59d..3b34298dc 100644 --- a/transforms/images/image-calculator-tool/plugin.json +++ b/transforms/images/image-calculator-tool/plugin.json @@ -1,6 +1,6 @@ { "name": "Image Calculator", - "version": "0.2.2", + "version": "0.3.0-dev0", "title": "Image Calculator", "description": "Perform simple mathematical operations on images.", "author": "Nick Schaub (nick.schaub@nih.gov)", @@ -8,7 +8,7 @@ "repository": "https://github.com/labshare/polus-plugins", "website": "https://ncats.nih.gov/preclinical/core/informatics", "citation": "", - "containerId": "polusai/image-calculator-tool:0.2.2", + "containerId": "polusai/image-calculator-tool:0.3.0-dev0", "baseCommand": [ "python3", "-m", diff --git a/transforms/images/image-calculator-tool/pyproject.toml b/transforms/images/image-calculator-tool/pyproject.toml index d31f47316..c08fd0785 100644 --- a/transforms/images/image-calculator-tool/pyproject.toml +++ b/transforms/images/image-calculator-tool/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "polus-images-transforms-images-image-calculator" -version = "0.2.2" +version = "0.3.0-dev0" description = "" authors = [ "Nicholas Schaub ", @@ -11,11 +11,12 @@ packages = [{include = "polus", from = "src"}] [tool.poetry.dependencies] python = ">=3.9,<3.12" -bfio = {version = "2.3.3", extras = ["all"]} -filepattern = "2.0.4" +bfio = {version = "^2.4.3", extras = ["all"]} +filepattern = "^2.0.7" typer = "^0.7.0" tqdm = "^4.65.0" preadator = "0.4.0.dev2" +numpy = "^2.0" [tool.poetry.group.dev.dependencies] pre-commit = "^3.3.3" diff --git a/transforms/images/image-calculator-tool/src/polus/images/transforms/images/image_calculator/__init__.py b/transforms/images/image-calculator-tool/src/polus/images/transforms/images/image_calculator/__init__.py index 6649c4f2b..d5553f897 100644 --- a/transforms/images/image-calculator-tool/src/polus/images/transforms/images/image_calculator/__init__.py +++ b/transforms/images/image-calculator-tool/src/polus/images/transforms/images/image_calculator/__init__.py @@ -6,4 +6,4 @@ from .calculator import Operation from .calculator import process_image -__version__ = "0.2.2" +__version__ = "0.3.0-dev0" diff --git a/transforms/images/image-calculator-tool/src/polus/images/transforms/images/image_calculator/calculator.py b/transforms/images/image-calculator-tool/src/polus/images/transforms/images/image_calculator/calculator.py index c733846e5..061a8505a 100644 --- a/transforms/images/image-calculator-tool/src/polus/images/transforms/images/image_calculator/calculator.py +++ b/transforms/images/image-calculator-tool/src/polus/images/transforms/images/image_calculator/calculator.py @@ -89,9 +89,11 @@ def _process_chunk( # noqa: PLR0913 operation: Operation, ) -> None: """Process on chunk of the images in a thread/process.""" + left = primary_reader[y:y_max, x:x_max, z] + right = secondary_reader[y:y_max, x:x_max, z] writer[y:y_max, x:x_max, z] = operation.func()( - primary_reader[y:y_max, x:x_max, z], - secondary_reader[y:y_max, x:x_max, z], + left, + right.astype(primary_reader.dtype), ) @@ -121,6 +123,8 @@ def process_image( # Initialize the output image with bfio.BioWriter(out_path, metadata=primary_reader.metadata) as writer: + writer.dtype = primary_reader.dtype + for z in range(primary_reader.Z): for x in range(0, primary_reader.X, CHUNK_SIZE): x_max = min(x + CHUNK_SIZE, primary_reader.X)