cokriging using raster images

Respected Sir,/Ma'am,
I am working on cokring code over raster images. I am facing the issue of creating a grid and using predict command. I have two datasets one has a resolution of 70003500 meters with a lot of missing values for pixels and the other has 1000 meters resolution with mostly area covered with data values. I want to predict values for the dataset of 70003500 meters but at 1000meters resolution. This is the code I have worked upon so far.

aod3k <- raster("crop_LST.tif")
aod3k.d <- discretizeRaster(aod3k, 1000)
aod10 <- raster("crop_CH4.tif")
aod10.d <- discretizeRaster(aod10, 1000)

aod3k.pt <- aod3k.d$areaValues
aod10.pt <- aod10.d$areaValues
coordinates(aod3k.pt) = ~centx+centy
coordinates(aod10.pt) = ~centx+centy

aod3k.ev = variogram(aod3k.pt$value ~1, aod3k.pt)
aod10.ev = variogram( aod10.pt$value ~1, aod10.pt)
aod3k.mv = fit.variogram(aod3k.ev, model = vgm(psill =60,
model = "Sph",
range = 37000 ,
nugget = 0.2,
cutoff = 0))

aod10.mv = fit.variogram(aod10.ev, model = vgm(psill =40,
model = "Exp",
range = 37000 ,
nugget = 0.000005,
cutoff = 4))

g = gstat(NULL, "LST", aod3k.pt$value ~1, aod3k.pt)
g = gstat(g, "CH4", aod10.pt$value ~1, aod10.pt)
g = gstat(g, model = vgm(psill = 40, model = "Exp", range = 37000,
nugget = 0.5), fill.all = TRUE)
g.fit = fit.lmc(v, g)
g = g.fit

Then for creating a grid I am trying two ways either use the 1000meters data to use as the base for grid values:

grid.pred <- discretizeRaster(aod3k, 1000, type = "value")
unknown.pt <- grid.pred$areaValues
coordinates(unknown.pt) = ~centx+centy
gridded(unknown.pt) = FALSE
pred.ck = predict(g, unknown.pt)

But it does not produce any grid the output is points rather than cells. Thus I created a grid manually, making it into raster and then converting it to spatial pixels using this link https://stackoverflow.com/questions/43436466/create-grid-in-r-for-kriging-in-gstat.

I used the following code:
grid.pred <- discretizeRaster(aod3k, 1000, type = "value")
unknown.pt <- grid.pred$areaValues
coordinates(unknown.pt) = ~centx+centy
coordinates(unknown.pt)

The origin has been rounded to the nearest 100

x_ori <- round(coordinates(unknown.pt)[1, 1]/100) * 100
y_ori <- round(coordinates(unknown.pt)[1, 2]/100) * 100

Define how many cells for x and y axis

x_cell <- 100
y_cell <- 110

Define the resolution to be 1000 meters

cell_size <- 1000

Create the extent

ext <- extent(x_ori, x_ori + (x_cell * cell_size), y_ori, y_ori +
(y_cell * cell_size))

Initialize a raster layer

ras <- raster(ext)

Set the resolution to be

res(ras) <- c(cell_size, cell_size)
ras <- 0
proj4string(station) <- CRS("+init=epsg:3857")
gridded(ras) = FALSE

Save the raster layer

writeRaster(ras, filename = "grid.tif", format="GTiff")

Convert the raster to grid to be used for kriging

st_grid <- rasterToPoints(ras, spatial = TRUE)
gridded(st_grid)
st_grid <- as(st_grid, "SpatialPixels")
pred.ck = predict(g, st_grid)

But again when using the command gridded it shows FALSE rather than TRUE.
Also after writeRaster function, this error pops up but a raster is created.
Warning message:
In .gd_SetProject(object, ...) : NOT UPDATED FOR PROJ >= 6

Any help will be highly appreciated. Kindly let me know what am I missing or where am I going wrong with the codes.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.