torch_ecg.utils.get_mask

torch_ecg.utils.get_mask(shape: int | Sequence[int], critical_points: ndarray, left_bias: int, right_bias: int, return_fmt: str = 'mask') ndarray | list[source]

Get the mask around the given critical points.

Parameters:
  • shape (int or Sequence[int]) – Shape of the mask (and the original data).

  • critical_points (numpy.ndarray) – Indices (of the last dimension) of the points around which to be masked (value 1).

  • left_bias (int) – Bias to the left of the critical points for the mask, non-negative.

  • right_bias (int) – Bias to the right of the critical points for the mask, non-negative.

  • return_fmt ({"mask", "intervals"}) – Format of the return values, by default “mask”. “mask” stands for the usual mask, while “intervals” means a list of intervals of the form [start, end].

Returns:

The mask array or the list of intervals.

Return type:

numpy.ndarray or list

Examples

>>> mask = get_mask((12, 5000), np.arange(250, 5000 - 250, 400), 50, 50)
>>> mask.shape
(12, 5000)
>>> mask.sum(axis=1)
array([1200, 1200, 1200, 1200, 1200, 1200, 1200, 1200, 1200, 1200, 1200, 1200])
>>> intervals = get_mask((12, 5000), np.arange(250, 5000 - 250, 400), 50, 50, return_fmt="intervals")
>>> intervals
[[200, 300], [600, 700], [1000, 1100], [1400, 1500], [1800, 1900], [2200, 2300], [2600, 2700], [3000, 3100], [3400, 3500], [3800, 3900], [4200, 4300], [4600, 4700]]