Input data is a 2D array (timestamp, value) pairs, ordered by timestamp:
np.array([[50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66],
[ 2, 3, 5, 6, 4, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3]])
I want to find time windows where the value exceeds a threshold (eg. >=4). Seems I can do the threshold part with a boolean condition, and map back to the timestamps with np.extract():
>>> a[1] >= 4
array([False, False, True, True, True, False, False, False, False,
True, True, True, False, False, False, False, False])
>>> np.extract(a[1] >= 4, a[0])
array([52, 53, 54, 59, 60, 61])
But from that I need the first and last timestamps of each window matching the threshold (ie. [[52, 54], [59, 61]]), which is where I can't quite find the right approach.