Initialisation

Function implementing the centering of the data set

Simulation of the data sets

Two data sets are simulated: - the first data set is constituted os samples randomly located within a dilated bounding box around a rotated grid - the second data set is a sampling of the nodes of the rotated grid nodes.

The first one is used to check the validity of the centering while the second one prooves that centering does not do anything when the data are alreay centered.

nech = 25
dx = c(0.05, 0.025)
nx = c(11, 23)
x0 = c(0.5, 2)
angles = c(20, 0)
delta = 0.1 # margin around the grid bounding box

# Creating the rotated grid
target = DbGrid_create(nx = nx, dx = dx, x0 = x0, angles = angles)

# In real coordinates
bb = bounding_xy(target = target, delta = delta) 
XY = as.matrix(cbind(target["x1"], target["x2"]))

# Test of the identity
UV = XY_to_UV(target, XY)
xy = UV_to_XY(target, UV)

# Simulation of uniform scattered points in the local coordinates 
# inside the bounding box
bb_uv   = bounding_uv(target, delta)
bb_xy   = bounding_xy(target, delta)
lim_uv  = bb_uv[c(1,3),]
sim_uv  = lim_uv[1,] + 
  matrix(runif(nech * 2), nrow=nech, ncol=2) %*% diag(lim_uv[2,] - lim_uv[1,])
sim_xy  = UV_to_XY(target, sim_uv)

data_ini1 = Db_createFromSamples(nech)
data_ini1["x1"] = sim_xy[,1]
data_ini1["x2"] = sim_xy[,2]
data_ini1$setLocators(c("x1", "x2"), ELoc_X())
## NULL
data_ini1["Y"] = rnorm(nech)
data_ini1$setLocators("Y", ELoc_Z())
## NULL
# Second input data set (extracted from the target grid)
data_ini2 = Db_createSamplingDb(target, number=nech, names=c("x1","x2"))
data_ini2["Y"] = rnorm(data_ini2$getSampleNumber())
data_ini2$setLocators("Y", ELoc_Z())
## NULL

Display of the first data set

ggDefaultGeographic() + 
  plot.XY(bb[,1], bb[,2], flagLine=TRUE, color='blue') + 
  plot.point(target) +
  plot.point(data_ini1, color = "grey", size=4) +
  plot.decoration(title="First Data Set")

Display of the second data set

ggDefaultGeographic() + 
  plot.point(target) +
  plot.point(data_ini2, col = "grey", size=4) + 
  plot.decoration(title = "Second Data Set")

Test of the centering

Two centering are systematically tested:

The graphic convention is the following one: - the nodes of the target grid are always represented (black dots) - the initial data set are displayed with large size grey symbols - the centered data are displayed with small red circles. - the bounding box is represented as a solid blue line (when relevant)

Scattered data

Performing the manual centering

data_man1 = data_ini1$clone()
err = manual_centering(data_man1, target)

Displaying the centered results

ggDefaultGeographic() + 
  plot.XY(bb[,1], bb[,2], flagLine=TRUE, color='blue') + 
  plot.point(target) +
  plot.point(data_ini1, col = "grey", size=4) +
  plot.point(data_man1, col='red', size=2) + 
  plot.decoration(title="First Data Set (centered manually)")

Performing the centering using gstlearn: this is done in place (coordinates have been modified).

data_auto1 = data_ini1$clone()
err = DbHelper_centerPointToGrid(data_auto1, target)

Displaying the centered results

ggDefaultGeographic() + 
  plot.XY(bb[,1], bb[,2], flagLine=TRUE, color='blue') + 
  plot.point(target) +
  plot.point(data_ini1, col = "grey", size=4) +
  plot.point(data_auto1, col='red', size=2) + 
  plot.decoration(title="First Data Set (centered by gstlearn)")

Data extracted from the target grid

Performing the manual centering

data_man2 = data_ini2$clone()
err = manual_centering(data_man2, target)

Displaying the centered results

ggDefaultGeographic() + 
  plot.point(target) +
  plot.point(data_ini2, col = "grey", size=4) +
  plot.point(data_man2, col='red', size=2) + 
  plot.decoration(title="Second Data Set (centered manually)")

Performing the centering using gstlearn: this is done in place (coordinates have been modified).

data_auto2 = data_ini2$clone()
err = DbHelper_centerPointToGrid(data_auto2, target)

Displaying the centered results

ggDefaultGeographic() + 
  plot.point(target) +
  plot.point(data_ini2, col = "grey", size=4) +
  plot.point(data_auto2, col='red', size=2) + 
  plot.decoration(title="Second Data Set (centered by gstlearn)")