From 00da10e482baf3680be08248ed4e40c3c90a4365 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Tue, 9 Jan 2024 20:28:53 +0200 Subject: [PATCH] feat(ai): add `holes` --- src/ai/heuristics/holes.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ai/heuristics/holes.py b/src/ai/heuristics/holes.py index 0aa01b3..f2a28aa 100644 --- a/src/ai/heuristics/holes.py +++ b/src/ai/heuristics/holes.py @@ -4,4 +4,19 @@ import numpy as np def holes( field: np.ndarray[int, np.dtype[np.uint8]], ) -> int: - return 0 + """ + Calculate the number of holes in each column of the given field. + + Args: + field: The signal field. + peaks: Array containing peak indices. If not provided, it will be computed from the field. + + Returns: + The total number of holes in the field. + """ + + first_nonzero_indices = np.argmax(field != 0, axis=0) + + mask = (field == 0) & (np.arange(field.shape[0])[:, np.newaxis] > first_nonzero_indices) + + return int(np.sum(mask))