Skip to content

Commit bb94850

Browse files
Commit suggestion from review comments
Co-authored-by: Peter Somhorst <127968566+psomhorst@users.noreply.github.com>
1 parent fbc5bd7 commit bb94850

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

eitprocessing/roi/filter_by_size.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,20 @@ def __post_init__(self):
4545
) # required with frozen objects
4646

4747
def _parse_connectivity(self, connectivity: int | np.ndarray) -> np.ndarray:
48-
if isinstance(connectivity, int):
49-
if connectivity not in (1, 2):
48+
match connectivity:
49+
case np.ndarray():
50+
return connectivity
51+
case 1 | 2:
52+
return ndi.generate_binary_structure(2, connectivity)
53+
case int(): # another integer
5054
msg = (
5155
f"Unsupported connectivity value: {connectivity}."
5256
" Must be 1 or 2, or input a custom structure as array."
5357
)
5458
raise ValueError(msg)
55-
return ndi.generate_binary_structure(2, connectivity)
56-
if isinstance(connectivity, np.ndarray):
57-
return connectivity
58-
msg = f"Unsupported connectivity type: {type(connectivity)}. Must be an integer or numpy array."
59-
raise ValueError(msg)
59+
case _:
60+
msg = f"Unsupported connectivity type: {type(connectivity)}. Must be an integer or numpy array."
61+
raise ValueError(msg)
6062

6163
def apply(self, mask: PixelMask) -> PixelMask:
6264
"""Identify connected regions in a PixelMask, filter them by size, and return a combined mask.

0 commit comments

Comments
 (0)