Skip to content

Commit 4ff5e43

Browse files
committed
UPD: Fix mypy issues
1 parent 8f7a3e7 commit 4ff5e43

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

tiatoolbox/utils/postproc_defs.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class MultichannelToRGB:
1313

1414
def __init__(
1515
self: MultichannelToRGB,
16-
color_dict: dict[str : tuple[float, float, float]] | None = None,
16+
color_dict: dict[str, tuple[float, float, float]] | None = None,
1717
) -> None:
1818
"""Initialize the MultichannelToRGB converter.
1919
@@ -40,6 +40,10 @@ def validate(self: MultichannelToRGB, n: int) -> None:
4040
n (int): Number of channels
4141
4242
"""
43+
if self.colors is None:
44+
msg = "Colors must be initialized before validation."
45+
raise ValueError(msg)
46+
4347
n_colors = len(self.colors)
4448
if n_colors == n:
4549
self.is_validated = True
@@ -49,10 +53,11 @@ def validate(self: MultichannelToRGB, n: int) -> None:
4953
self.colors = self.colors[:n]
5054
self.channels = [c for c in self.channels if c < n]
5155
self.is_validated = True
52-
warnings.warn(
53-
"""Number of channels in image is one less than number of channels in
56+
msg = """Number of channels in image is one less than number of channels in
5457
dict. Assuming last channel is background autofluorescence and ignoring
55-
it. If this is not the case please provide a manual color_dict.""",
58+
it. If this is not the case please provide a manual color_dict."""
59+
warnings.warn(
60+
msg,
5661
stacklevel=2,
5762
)
5863
return
@@ -97,6 +102,9 @@ def __call__(self: MultichannelToRGB, image: np.ndarray) -> np.ndarray:
97102
if not self.is_validated:
98103
self.validate(n)
99104

105+
if self.channels is None:
106+
self.channels = list(range(n))
107+
100108
if image.dtype == np.uint16:
101109
image = (image / 256).astype(np.uint8)
102110

@@ -117,7 +125,7 @@ def __call__(self: MultichannelToRGB, image: np.ndarray) -> np.ndarray:
117125
def __setattr__(
118126
self: MultichannelToRGB,
119127
name: str,
120-
value: dict[str, tuple[int, int, int]] | None,
128+
value: dict[str, tuple[float, float, float]] | None,
121129
) -> None:
122130
"""Ensure that colors is updated if color_dict is updated."""
123131
if name == "color_dict" and value is not None:

0 commit comments

Comments
 (0)