【问题标题】:Determining the duration of an exceedance确定超出的持续时间
【发布时间】:2014-10-24 06:55:56
【问题描述】:

我正在使用 R 分析 SCADA 数据。

我需要解决的问题是分析 SCADA 提要并确定测量值超过某个限制超过 15 分钟的频率。

我可以解决这个问题的唯一方法是使用 for 循环,这会使过程非常缓慢,因为现实生活中的应用程序将有数千个点。

有什么建议吗?

简单示例:

set.seed(666)
upper_limit =1.5
sims <- 50
turb <- abs(rnorm(sims))
time <- seq.POSIXt(as.POSIXct(Sys.Date()-1), by=30, length.out=sims)
plot(time,turb, type="l")
abline(h=upper_limit, col="red", lwd=2)

见:http://rpubs.com/pprevos/scada

这个例子的答案是:8 次超标,我还需要知道每个超标的持续时间。

【问题讨论】:

    标签: r time-series scada


    【解决方案1】:

    如果您的时间序列是 1 分钟的时间序列(即:具有 1 分钟周期的时间序列),使用rle 很容易获得超过某个阈值的间隔长度:

     xx = rle(turb >1.5)
     sum(xx$values==TRUE & xx$lengths >=15)
    

    所以这里为了得到这个时间序列,一种解决方案是对其进行近似以创建一个更准确的新时间序列。

    library(xts)
    xx = xts(turb,time)
    yy = na.approx(merge(xts(,seq.POSIXt(min(time),max(time),by=1)),
          xx))
    ## optional plot the new and the old time series
    plot(x = yy, xlab = "Time",  minor.ticks = FALSE, col = "red")
    points(x = xx, col = "darkgreen",pch=20)
    

    然后我计算上面解释的间隔数:

    xx = rle(as.vector(coredata(yy>1.5)))
    sum(xx$values==TRUE & xx$lengths >=15)
    [1] 6
    

    注意:这里我发现只有 6 个区间..

    【讨论】:

    • 感谢您的解决方案。这将帮助我们使水处理厂生产更安全的饮用水:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-15
    • 2015-05-11
    • 1970-01-01
    • 2020-09-12
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    相关资源
    最近更新 更多