rm(list=ls())
library(gstlearn)
library(ggplot2)
library(ggpubr)
Defining some essential parameters:
ndim = 2
defineDefaultSpace(ESpaceType_RN(), ndim);
## NULL
nbsimu = 20
nbcc = 4
cmap = c('red', 'blue', 'yellow')
Downloading the data base (from the distribution Exdemo_PGS.db) and creating the output Grid, the Model (Cubic) and the Neighborhood (Unique):
dlfile = "https://soft.minesparis.psl.eu/gstlearn/data/PluriGaussian/Data.NF"
fileNF = "Scotland_Temperatures.NF"
download.file(dlfile, fileNF)
data = Db_createFromNF(fileNF)
grid = DbGrid_create(nx=c(110,110))
model = Model_createFromParam(type=ECov_CUBIC(), ranges=c(50,30))
neigh = NeighUnique()
Defining the internal function plot.dat used to visualize the data set with convenient color representation:
# TODO: Utiliser CMAP
plot.setDefaultGeographic(dims=c(6,6))
p = ggDefaultGeographic()
p = p + plot(data, name_color="facies", name_size="connect")
# edgecolors='black', sizmin=40, cmap=cmap)
p = p + plot.decoration(title="Conditioning Information")
ggPrint(p)
props = dbStatisticsFacies(data)
rule = Rule_createFromNames(c("S","S","F1","F2","F3"))
# TODO: utiliser cmap
p = ggplot()
p = p + plot(rule, proportions = props, maxG=3)
p = p + plot.decoration(title="Lithotype Rule")
ggPrint(p)
Calculate the Experimental Variogram of the Underlying Gaussian Random Function and fit the Model (used in PGS).
varioparam = VarioParam_createOmniDirection(dpas=5, npas=20)
ruleprop = RuleProp_createFromRule(rule, props)
vario = variogram_pgs(data, varioparam, ruleprop)
model_gaus = Model()
err = model_gaus$fit(vario, types=ECov_fromKeys(c("CUBIC")),
constraints=Constraints(1.))
ggplot() + plot.varmod(vario, model_gaus, asCov=TRUE)
err = simpgs(dbin=data, dbout=grid, ruleprop=ruleprop, model1=model_gaus,
neigh=neigh, nbsimu=nbsimu,
namconv = NamingConvention("SimuPGS"))
p1 = ggDefaultGeographic()
p1 = p1 + plot(grid, "SimuPGS.1")
p1 = p1 + plot(data, name_color="facies", name_size="connect")
p2 = ggDefaultGeographic()
p2 = p2 + plot(grid, "SimuPGS.2")
p2 = p2 + plot(data, name_color="facies", name_size="connect")
p3 = ggDefaultGeographic()
p3 = p3 + plot(grid, "SimuPGS.3")
p3 = p3 + plot(data, name_color="facies", name_size="connect")
p4 = ggDefaultGeographic()
p4 = p4 + plot(grid, "SimuPGS.4")
p4 = p4 + plot(data, name_color="facies", name_size="connect")
ggarrange(p1,p2,p3,p4, nrow=2, ncol=2)