Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated three tools to use numpy 2.0 #564

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions transforms/images/apply-flatfield-tool/.bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[bumpversion]
current_version = 2.0.1
commit = False
current_version = 2.1.0-dev0
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<dev>\d+))?
serialize =
Expand Down
2 changes: 1 addition & 1 deletion transforms/images/apply-flatfield-tool/README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion transforms/images/apply-flatfield-tool/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.1
2.1.0-dev0
4 changes: 2 additions & 2 deletions transforms/images/apply-flatfield-tool/plugin.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"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 ([email protected]), Najib Ishaq ([email protected])",
"institution": "National Center for Advancing Translational Sciences, National Institutes of Health",
"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",
Expand Down
6 changes: 3 additions & 3 deletions transforms/images/apply-flatfield-tool/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
Expand All @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from . import utils
from .apply_flatfield import apply

__version__ = "2.0.1"
__version__ = "2.1.0-dev0"
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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(
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion transforms/images/image-assembler-tool/.bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.4.2
current_version = 1.5.0-dev0
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<dev>\d+))?
Expand Down
2 changes: 1 addition & 1 deletion transforms/images/image-assembler-tool/README.md
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion transforms/images/image-assembler-tool/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.2
1.5.0-dev0
4 changes: 2 additions & 2 deletions transforms/images/image-assembler-tool/plugin.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "Image Assembler",
"version": "1.4.2",
"version": "1.5.0-dev0",
"title": "Image Assembler",
"description": "A scalable image assembling plugin.",
"author": "Nick Schaub ([email protected]), Antoine Gerardin ([email protected])",
"institution": "National Center for Advancing Translational Sciences, National Institutes of Health",
"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",
Expand Down
8 changes: 4 additions & 4 deletions transforms/images/image-assembler-tool/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[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 <[email protected]>", "Antoine Gerardin <[email protected]>"]
readme = "README.md"
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]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Image Assembler Plugin."""

__version__ = "1.4.2"
__version__ = "1.5.0-dev0"

from .image_assembler import ( # noqa
assemble_images,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Package entrypoint for Image Assembler."""
import json
import logging
import typing
from os import environ
from pathlib import Path

Expand Down Expand Up @@ -38,7 +37,7 @@ def generate_preview(
timeslice_naming,
)

preview: dict[str, typing.Union[list, str]] = {
preview: dict[str, list[str]] = {
"outputDir": [],
}

Expand All @@ -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,
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion transforms/images/image-assembler-tool/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions transforms/images/image-calculator-tool/.bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[bumpversion]
current_version = 0.2.2
commit = False
current_version = 0.3.0-dev0
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<dev>\d+))?
serialize =
Expand Down
2 changes: 1 addition & 1 deletion transforms/images/image-calculator-tool/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion transforms/images/image-calculator-tool/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.2
0.3.0-dev0
4 changes: 2 additions & 2 deletions transforms/images/image-calculator-tool/plugin.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"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 ([email protected])",
"institution": "National Center for Advancing Translational Sciences, National Institutes of Health",
"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",
Expand Down
7 changes: 4 additions & 3 deletions transforms/images/image-calculator-tool/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
from .calculator import Operation
from .calculator import process_image

__version__ = "0.2.2"
__version__ = "0.3.0-dev0"
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)


Expand Down Expand Up @@ -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)
Expand Down
Loading