Skip to content

Commit

Permalink
Forward cli args to MaskSaver
Browse files Browse the repository at this point in the history
[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

flake8 and mypy fixes

Fix mypy
  • Loading branch information
will-moore committed Jun 27, 2022
1 parent c2e7e34 commit 05bce56
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
10 changes: 8 additions & 2 deletions src/omero_zarr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
from zarr.hierarchy import open_group
from zarr.storage import FSStore

from .masks import MASK_DTYPE_SIZE, image_shapes_to_zarr, plate_shapes_to_zarr
from .masks import (
MASK_DTYPE_SIZE,
MaskSaver,
image_shapes_to_zarr,
plate_shapes_to_zarr,
)
from .raw_pixels import (
add_omero_metadata,
add_toplevel_metadata,
Expand Down Expand Up @@ -276,7 +281,8 @@ def _configure(self, parser: Parser) -> None:
subcommand.add_argument(
"--overlaps",
type=str,
choices=["dtype_max"],
default=MaskSaver.OVERLAPS[0],
choices=MaskSaver.OVERLAPS,
help="To allow overlapping shapes, use 'dtype_max':"
" All overlapping regions will be set to the"
" max value for the dtype",
Expand Down
26 changes: 15 additions & 11 deletions src/omero_zarr/masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ def plate_shapes_to_zarr(
n_fields = plate.getNumberOfFields()
total = n_rows * n_cols * (n_fields[1] - n_fields[0] + 1)

# If overlaps isn't 'dtype_max', an exception is thrown if any overlaps exist
check_overlaps = args.overlaps != "dtype_max"

dtype = MASK_DTYPE_SIZE[int(args.label_bits)]
saver = MaskSaver(
plate,
Expand All @@ -71,7 +68,7 @@ def plate_shapes_to_zarr(
args.label_path,
args.style,
args.source_image,
check_overlaps,
args=args,
)

count = 0
Expand Down Expand Up @@ -161,8 +158,6 @@ def image_shapes_to_zarr(
print("Boolean type makes no sense for labeled. Using 64")
dtype = MASK_DTYPE_SIZE[64]

# If overlaps isn't 'dtype_max', an exception is thrown if any overlaps exist
check_overlaps = args.overlaps != "dtype_max"
if masks:
saver = MaskSaver(
None,
Expand All @@ -171,7 +166,7 @@ def image_shapes_to_zarr(
args.label_path,
args.style,
args.source_image,
check_overlaps,
args=args,
)

if args.style == "split":
Expand All @@ -195,6 +190,8 @@ class MaskSaver:
masks to zarr groups/arrays.
"""

OVERLAPS = ["error", "dtype_max"]

def __init__(
self,
plate: Optional[omero.gateway.PlateWrapper],
Expand All @@ -203,15 +200,18 @@ def __init__(
path: str = "labels",
style: str = "labeled",
source: str = "..",
check_overlaps: bool = True,
args: argparse.Namespace = None,
) -> None:
self.dtype = dtype
self.path = path
self.style = style
self.source_image = source
self.plate = plate
self.plate_path = Optional[str]
self.check_overlaps = check_overlaps
if args is not None and args.overlaps is not None:
self.overlaps = args.overlaps
else:
self.overlaps = "error"
if image:
self.image = image
self.size_t = image.getSizeT()
Expand Down Expand Up @@ -321,7 +321,6 @@ def save(self, masks: List[omero.model.Shape], name: str) -> None:
masks,
mask_shape,
ignored_dimensions,
check_overlaps=self.check_overlaps,
)

axes = marshal_axes(self.image)
Expand Down Expand Up @@ -452,7 +451,7 @@ def masks_to_labels(
masks: List[omero.model.Mask],
mask_shape: Tuple[int, ...],
ignored_dimensions: Set[str] = None,
check_overlaps: bool = True,
check_overlaps: bool = None,
) -> Tuple[np.ndarray, Dict[int, str], Dict[int, Dict]]:
"""
:param masks [MaskI]: Iterable container of OMERO masks
Expand Down Expand Up @@ -483,6 +482,11 @@ def masks_to_labels(
sorted_roi_ids = list(set(roi_ids))
sorted_roi_ids.sort()

if check_overlaps is None:
# If overlaps isn't 'dtype_max', an exception is thrown
# if any overlaps exist
check_overlaps = self.overlaps != "dtype_max"

# label values are 1...n
max_value = len(sorted_roi_ids)
# find most suitable dtype...
Expand Down

0 comments on commit 05bce56

Please sign in to comment.