systole.utils.norm_bad_segments#
- systole.utils.norm_bad_segments(bad_segments) List[Tuple[int, int]][source]#
- Normalize bad segments. Return a list of tuples and merge overlapping intervals. - Parameters
- bad_segments
- The time stamps of the bad segments. Can be a boolean 1d numpy array where True is a bad segment (will be rejected), or a list of tuples such as (start_idx, end_idx) in signal samples or milliseconds when intervals are provided. 
 
- Returns
- bad_segments_tuples
- The merged bad segments as tuples such as (start_idx, end_idx) indicate when each bad segment starts and ends. 
 
- Raises
- ValueError
- If bad_segments is not a tuple or a np.ndarray. 
 
 - Examples - Get a list of tuples such as [(start_idx, end_idx)] from a boolean vector that is of the same length that the associated signal and where True is a bad segment/sample. - >>> import numpy as np >>> from systole.utils import norm_bad_segments >>> bool_bad_segments = np.zeros(100, dtype=bool) >>> bool_bad_segments[10:20] = True >>> bool_bad_segments[50:60] = True >>> new_segments = norm_bad_segments(bool_bad_segments) >>> new_segments `[(10, 20), (50, 60)]` - From a list of tuples such as [(start_idx, end_idx)], where some intervals are overlapping, get a clean version of these bad segments by merging the overlapping intervals. - >>> bad_segments = [(100, 200), (150, 250)] >>> new_segments = norm_bad_segments(bad_segments) >>> assert new_segments `[(100, 250)]`