我正在使用R中的gstat包执行IDW插值。我的代码运行正常,但是花费了太多时间。我想并行化gstat :: idw函数。
我已经按照下面提到的链接进行了尝试,但是失败了 https://gis.stackexchange.com/questions/237672/how-to-achieve-parallel-kriging-in-r-to-speed-up-the-process
library("raster")
library("rgdal")
library("maptools")
library("sp")
library("gstat")
new_f = read.csv("1.csv")
new_f$Lat = as.numeric(as.character(new_f$Lat))
new_f$Long = as.numeric(as.character(new_f$Long))
new_f$Rainfall = as.numeric(as.character(new_f$Rainfall))
coordinates(new_f) <- ~Lat + Long
my_sp <- sp::SpatialPointsDataFrame(coords = data.frame(new_x1$Long, new_x1$Lat), data = data.frame(new_x1$Rainfall), proj4string = CRS("+init=epsg:4326"))
x_range <- as.numeric(c(min(my_sp@coords[,1]),max(my_sp@coords[,1]))) # min/max longitude of the interpolation area
y_range <- as.numeric(c(min(my_sp@coords[,2]),max(my_sp@coords[,2]))) # min/max latitude of the interpolation area
# create an empty grid of values ranging from the xmin-xmax, ymin-ymax
grd <- expand.grid(x = seq(from = x_range[1],
to = x_range[2],
by = 0.05),
y = seq(from = y_range[1], to = y_range[2],
by = 0.05)) # expand points to grid
# Convert grd object to a matrix and then turn into a spatial
# points object
coordinates(grd) <- ~x + y
# turn into a spatial pixels object
gridded(grd) <- TRUE
fullgrid(grd) <- TRUE
proj4string(grd) <- proj4string(my_sp)
idw_pow2 <- gstat::idw(formula = new_x1.Rainfall ~ 1,
locations = my_sp,
newdata = grd,
nmax = 12,
idp = 2)
r = raster(idw_pow2)
extent(r) = extent(my_sp)
请帮助我减少运行代码所需的时间。
csv文件的链接在下面给出。
https://drive.google.com/file/d/1qim5bJm5-jao3-ijwapZJ-UkOf_AeAza/view?usp=sharing