bfastmonitor_rasterEngine: Apply bfastmonitor() using rasterEngine()

Usage Arguments Examples

Usage

1
bfastmonitor_rasterEngine(x, startperiod, endperiod = NULL, dates = NULL, cpus = "max", sensor = "all", formula = response ~ trend + harmon, order = 3, lag = NULL, slag = NULL, history = c("ROC", "BP", "all"), type = "OLS-MOSUM", h = 0.25, end = 10, level = 0.05, datetype = c("16-day", "irregular"), data_multiplier = 1, filename = "")

Arguments

x
startperiod
endperiod
dates
cpus
sensor
formula
order
lag
slag
history
type
h
end
level
datetype
data_multiplier
filename

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (x, startperiod, endperiod = NULL, dates = NULL, cpus = "max", 
    sensor = "all", formula = response ~ trend + harmon, order = 3, 
    lag = NULL, slag = NULL, history = c("ROC", "BP", "all"), 
    type = "OLS-MOSUM", h = 0.25, end = 10, level = 0.05, datetype = c("16-day", 
        "irregular"), data_multiplier = 1, filename = "") 
{
    s <- getSceneinfo(names(x))
    if (sensor != "all") {
        if ("ETM+" %in% sensor) {
            sensor <- unique(c(sensor, "ETM+ SLC-on", "ETM+ SLC-off"))
        }
        x <- dropLayer(x, which(!s$sensor %in% sensor))
        s <- s[which(s$sensor %in% sensor), ]
        names(x) <- row.names(s)
    }
    bfastmonitor_array <- function(rasterTS, start, formula, 
        order, lag, slag, history, type, h, end, level, dates, 
        datetype, endperiod, data_multiplier, ...) {
        if (data_multiplier != 1) {
            rasterTS <- rasterTS * data_multiplier
        }
        rasterTS_dims <- dim(rasterTS)
        npixels <- prod(dim(rasterTS)[1:2])
        ndates <- dim(rasterTS)[3]
        dim(rasterTS) <- c(npixels, ndates)
        bfm_out <- foreach(i = seq(npixels), .packages = c("bfast"), 
            .combine = rbind) %do% {
            bfts <- bfastts(rasterTS[i, ], dates = dates, type = datetype)
            if (!is.null(endperiod)) 
                bfts <- window(bfts, end = endperiod)
            bfm <- bfastmonitor(data = bfts, start = start, formula = formula, 
                order = order, lag = lag, slag = slag, history = history, 
                type = type, h = h, end = end, level = level)
            return(c(bfm$breakpoint, bfm$magnitude))
        }
        dim(bfm_out) <- c(rasterTS_dims[1:2], 2)
        return(bfm_out)
    }
    dates <- s$date
    if (cpus == "max") {
        sfQuickInit()
    }
    else {
        sfQuickInit(cpus = cpus)
    }
    args_list <- list(dates = dates, datetype = datetype[1], 
        start = startperiod, endperiod = endperiod, formula = formula, 
        order = order, lag = lag, slag = slag, history = history, 
        type = type, h = h, end = end, level = level, data_multiplier = data_multiplier)
    if (filename == "") 
        bfastmonitor_raster <- rasterEngine(rasterTS = x, args = args_list, 
            fun = bfastmonitor_array, debugmode = FALSE)
    else bfastmonitor_raster <- rasterEngine(rasterTS = x, args = args_list, 
        fun = bfastmonitor_array, debugmode = FALSE, filename = filename)
    sfQuickStop()
    return(bfastmonitor_raster)
  }

bendv/bfastmonitor.rasterEngine documentation built on May 12, 2019, 10:58 a.m.