As background to my question, please allow me to explain the problem I am trying to solve. I have a sensor that is collecting pressure data. I am collecting this data into a pandas dataframe, structured like this:
DateTime Transmission Line PSI
2021-02-18 11:55:34 3.760
2021-02-18 11:55:49 3.359
2021-02-18 11:56:04 3.142
2021-02-18 11:56:19 3.009
2021-02-18 11:56:34 2.938
... ...
2021-02-19 12:05:06 3.013
2021-02-19 12:05:21 3.011
2021-02-19 12:05:36 3.009
2021-02-19 12:05:51 3.009
2021-02-19 12:06:06 3.007
I can plot the dataframe with pyplot and see visually when the compressor that feeds the system is running, how often, and how long it takes to pressurize the system. Plot of pressure data:
As is evident from the image, the cycles on the left side of the plot are radically shorter than those on the right.
The problem I am trying to solve is I want to programmatically calculate the max pressure, min pressure, period length, and duty cycle of the last complete on-off cycle. A bonus would be to programmatically calculate the total run time for a 24-hour period.
I figured that I would need to take the derivative of the pressure series, and I am using the solution found at python pandas: how to calculate derivative/gradient.
Plot of the derivative series:
The derivative series will then show numerically when the compressor is running (positive numbers) and not (zero or negative numbers). I was thinking that I could then find all of the maxima and minima of the individual peaks and from there get the timedeltas between them.
However, the problem I'm running into is any solutions I've found so far require me to know in advance how large a window to use (for example, the order argument when using SciPy argrelextrema https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.argrelextrema.html).
But my data series features cycles as short as minutes, and ideally (if we didn't have leaks!) cycles should stretch into hours or longer. Using short windows will cause me to have false maxima and minima in longer cycles, and longer windows will cause me to miss many maxima and minima on the shorter ones.
Any ideas for seeing programmatically what is plain to the eye in the above plot?