Rprof(memory.profile = TRUE, gc.profiling = TRUE,
      line.profiling = TRUE)
library(CSTools)
library(s2dverification)
library(stringr)
datalist <- CSTools::lonlat_data$exp
dim(datalist$data)
numcl = 4
results <- CST_EnsClustering(datalist, numclus = numcl, numpcs = 4,
                             time_moment = 'mean', cluster_dim = c('member', 'sdate'))
Rprof(NULL)
a <- summaryRprof(memory = 'both')
subset(a$by.total, total.time > 1)


Rprof()
library(s2dv)
a <- array(rnorm(1:10*10*5), c(lat = 10, lon = 10, time = 5))
b <- MeanDims(a, 'time')
PlotEquiMap(b, 1:10, 1:10)
c <- apply(a, 3, function(x){x*b})
c <- NULL
for (i in 1:5) {
  c <- c(c, abind(a[,,i] * b)
}
Rprof(NULL)
a <- summaryRprof()
subset(a$by.total, total.time > 0.2)
