pythonearthpy

Detecting custom events in time series data in Python


I'm looking for a neat way to detect particular events in time series data.

In my case, an event might consist of a value changing by more than a certain amount from one sample to the next, or it might consist of a sample being (for example) greater than a threshold while another parameter is less than another threshold.

e.g. imagine a time series list in which I've got three parameters; a timestamp, some temperature data and some humidity data:

time_series = []
#                  time, temp, humidity
time_series.append([0.0, 12.5, 87.5])
time_series.append([0.1, 12.8, 92.5])
time_series.append([0.2, 12.9, 95.5])

Obviously a useful time series would be much longer than this.

I can obviously loop through this data checking each row (and potentially the previous row) to see if it meets my criteria, but I'm wondering if there's a neat library or technique that I can use to search time series data for particular events - especially where an event might be defined as a function of a number of contiguous samples, or a function of samples in more than one column.

Does anyone know of such a library or technique?


Solution

  • You might like to investigate pandas, which includes time series tools see this pandas doc.

    I think that what you are trying to do is take "slices" through the data. [This link on earthpy.org] (http://earthpy.org/pandas-basics.html) has a nice introduction to using time series data with pandas, and if you follow down through the examples it shows how to take out slices, which I think would correspond to pulling out parameters that exceed thresholds, etc. in your data.