-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_toy.R
34 lines (30 loc) · 1.24 KB
/
generate_toy.R
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
n <- 28
message("image size set to: ", n)
tt <- 2000
message("number of time steps set to: ", tt)
d <- n / 2
dir.create("databases/data/toy/", showWarnings = FALSE, recursive = TRUE)
cube <- array(data =0, dim = c(n,n,tt))
true <- sin(1:tt / 10) + runif(tt)
hidden <- sin( 1:tt / (5 + runif(tt)))
m1 <- mean(cube[1:d, 1:d, 1])
target <-vector(mode = 'double', length = tt)
target[1] <- m1
for (t in 2:tt){
cube[1:d, 1:d, t] <- 0.5*cube[1:d, 1:d, t-1] + 0.5 * true[t-1] + runif(d*d, min = -0.1, max = 0.1)
cube[(n+1-d):n, (n+1-d):n, t] <- 0.5*cube[(n+1-d):n, (n+1-d):n, t - 1] + 0.5 * hidden[t-1] + runif(d*d, min = -0.1, max = 0.1)
}
library(raster)
library(rgdal)
message("saving target time series")
write.table(true, file = "databases/data/toy/target.txt", append = FALSE, row.names = FALSE, col.names = FALSE)
message("saving slices")
cube <- 255 * (cube - min(cube)) / (max(cube) - min(cube))
for (t in 1:tt){
writeGDAL(as(raster(cube[,,t]), Class = "SpatialPixelsDataFrame"),
fname = paste0("databases/data/toy/cube_slice",
formatC(t, width = 3, flag = "0"),".png"),
drivername = "PNG",type = "Byte")
file.remove(paste0("databases/data/toy/cube_slice", formatC(t, width = 3, flag = "0"), ".png.aux.xml"))
}
message("done")