Last active
February 21, 2019 19:55
-
-
Save dill/f5e3aebc9b9246c4bec46f2e61c3ea38 to your computer and use it in GitHub Desktop.
☁️🎲💻
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# generate some relaxing cloudy sky squares | |
# | |
# David Lawrence Miller (2019) | |
library(INLA) | |
library(ggplot2) | |
## function to simulate spatial fields | |
simdat <- function(n, seed, prior.range = c(5, .05), | |
prior.sigma = c(.05, .05)){ | |
sigma.u <- .1 | |
kappa <- 1 | |
range <- sqrt(8*1.5) / kappa | |
fake.locations <- as.matrix(expand.grid(seq(0, 10, length.out=n), | |
seq(0, 10, length.out=n))) | |
mesh.sim <- inla.mesh.2d(loc = fake.locations, max.n=500) | |
spde <- inla.spde2.pcmatern(mesh.sim, | |
prior.range=prior.range, | |
prior.sigma=prior.sigma) | |
Qu <- inla.spde.precision(spde, theta=c(log(range), log(sigma.u))) | |
u <- inla.qsample(n=1, Q=Qu, seed=seed) | |
u <- u[ ,1] | |
# project mesh to locations | |
A <- inla.spde.make.A(mesh=mesh.sim, fake.locations) | |
u <- drop(A %*% u) | |
# make a data object | |
dat <- data.frame(x=fake.locations[,1], | |
y=fake.locations[,2], | |
u=u) | |
return(dat) | |
} | |
cloudy_boi <- function(seed=runif(1)*1000){ | |
ggplot(simdat(200, seed)) + geom_tile(aes(x=x,y=y,fill=u)) + | |
theme_void() + coord_equal() + theme(legend.position="none") + | |
scale_fill_gradient(high = "#ffffff", low = "#56B1F7") | |
} | |
Author
dill
commented
Feb 21, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment