首页 > 解决方案 > 将(IDW)空间数据插入栅格的最佳方法是什么?[R]

问题描述

我正在使用实习生 2D 模型进行洪水预测和分析,该模型给出了特定的水位输出,看起来不是很好,也不能与网格器一起使用。

今天我使用“SMS”一个来自 AQUAVEO 的网格器,它可以在网格上插入数据。它可以读取我从模型结果中提取的数据(CSV 文件,看起来像:X、Y、Z),用于我想查看的每个时间步:

> head(h)
    X       Y            Z
1 1005527 6280606 0.0029385281
2 1005537 6280614 0.0008433110
3 1005546 6280603 0.0009996744
4 1005552 6280620 0.0244638187
5 1005554 6280610 0.0008433110
6 1005556 6280594 0.0009992988

要恢复,我有 n 个水位时间步长的文件。

网格器没有可以组装时间步并制作动画的模块。

所以上下文结束!我希望制作一个可以插入数据并制作结果动画的工具。现在我将 R 与gstat包一起使用:

library(gstat)
library(raster)
library(sf)
library(sp)

h <- read.csv('Hmax.txt',sep = '',header = F,dec = '.',numerals = "no.loss")
crs <- "+init=EPSG:2154" #France
names(h) <- c("X","Y","Z")

bbox <- c(
  "xmin" = min(h$X),
  "xmax" = max(h$X),
  "ymin" = min(h$Y),
  "ymax" = max(h$Y)
)
sf_h <- st_as_sf(h, coords = c("X", "Y"), crs = CRS(crs))
nrows <- bbox["ymax"]-bbox["ymin"]
ncols <- bbox["xmax"]-bbox["xmin"]

h_rst <- raster(nrows = nrows, ncols = ncols,
                xmn = bbox["xmin"],ymx = bbox["ymax"],
                xmx = bbox["xmax"],ymn = bbox["ymin"], crs = CRS(crs))

fit_IDW <- gstat::gstat(
    formula = Z ~ 1,
    data = as(sf_h, "Spatial"),
    nmax = 16, nmin = 5,
    set = list(idp = i)
  )
  
  interp_IDW <- interpolate(h_rst,fit_IDW)

它运作良好!但我的模型有 78 000 分!时间步长需要 5 分钟。(我知道如何制作动画)

你知道一种让它更快的方法吗?也许用Python?

标签: pythonranimationinterpolationgstat

解决方案


推荐阅读