detect function

Detect events in time series