简体   繁体   English

使用akima双线性函数进行插值

[英]Using the akima bilinear function for interpolation

I am using the akima package and bilinear function to interpolate z values (temperatures) from a coarse coordinate grid (2.5° x 2.5°) to a finer grid (0.5° x 0.5°). 我正在使用akima软件包和双线性函数将z值(温度)从粗坐标网格(2.5°x 2.5°)插值到较细的网格(0.5°x 0.5°)。 The bilinear function works as follows: 双线性函数的工作原理如下:

Usage 用法

bilinear(x, y, z, x0, y0) 双线性的(x,y,z,x0,y0)

Arguments 争论

xa vector containing the x coordinates of the rectangular data grid. x包含矩形数据网格的x坐标的向量。

ya vector containing the y coordinates of the rectangular data grid. 包含矩形数据网格的y坐标的ya向量。

za matrix containing the z[i,j] data values for the grid points (x[i],y[j]). 包含矩阵点(x [i],y [j])的z [i,j]数据值的za矩阵。

x0 vector of x coordinates used to interpolate at. x坐标的x0向量,用于在处进行插值。

y0 vector of y coordinates used to interpolate at. y坐标的y0向量,用于在处进行插值。

Value

This function produces a list of interpolated points: 此函数生成内插点列表:

x vector of x coordinates. x坐标的x向量。

y vector of y coordinates. y坐标的y向量。

z vector of interpolated data z. 内插数据z的z向量。

Given the following data: 给定以下数据:

# coarse grid longitudes     x -> c(0, 2.5, 5, 7.5, 10)
# coarse grid latitudes      y -> c(50, 55, 60, 65, 70)
# temperatures               z -> c(10.5, 11.1, 12.4, 9.8, 10.6)
# fine grid longitudes       x0 -> c(0, 0.5, 1, 1.5, 2)
# fine grid latitudes        y0 -> c(50, 50.5, 51, 51.5, 52)

I tried the function: 我尝试了该功能:

bilinear -> (x=x, y=y, z=z, x0=x0, y0=y0)

But I get the following: 但是我得到以下信息:

Error in if (dim(z)[1] != nx) stop("dim(z)[1] and length of x differs!") : 
argument is of length zero

I clearly don't fully understand how this function works and would really appreciate any suggestions if somebody knows what I'm doing wrong? 我显然不完全了解此功能的工作原理,如果有人知道我做错了什么,我将不胜感激。 I'm open to an alternative solution using a different package also. 我也欢迎使用其他软件包的替代解决方案。

Read carefully the description of the function, z need to be a matrix with dimension x,y: 仔细阅读该函数的说明,z必须是维为x,y的矩阵

library(akima)
x <- c(0, 2.5, 5, 7.5, 10)
y <- c(50, 55, 60, 65, 70)
z <- matrix(rnorm(25), 5, 5)
x0 <- seq(0, 10, .5)
y0 <- seq(50, 70, length = length(x0))

> bilinear(x, y, z, x0, y0)
$x
[1]  0.0  0.5  1.0  1.5  2.0  2.5  3.0  3.5  4.0  4.5  5.0  5.5  6.0  6.5  7.0
[16]  7.5  8.0  8.5  9.0  9.5 10.0

$y
[1] 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

$z
[1]  1.14880762  1.08789150  0.88252672  0.53271328  0.03845118 -0.60025959
[7] -0.13758256  0.17947029  0.35089894  0.37670342  0.25688371 -0.06736752
[13] -0.42197570 -0.80694083 -1.22226291 -1.66794194 -1.38940279 -1.08889523
[19] -0.76641923 -0.42197481 -0.05556197

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM