从“预磨"的表面创建曲面点数 [英] Create a surface from "pre-gridded" points

查看:100
本文介绍了从“预磨"的表面创建曲面点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的data.frame,其中有3个变量LongitudeLatitudeTemp.

I have a large data.frame which has 3 variables Longitude, Latitudeand Temp.

对数据进行排列,以使其在1/4度的网格"上有规律地间隔开-以便dput(head(dat))给出:

The data is arranged so that it is regularly spaced on a "grid" of 1/4 degree - so that dput(head(dat)) gives:

structure(list(Longitude = c(0.125, 0.375, 0.625, 0.875, 1.125, 
1.375), Latitude = c(0.125, 0.125, 0.125, 0.125, 0.125, 0.125
), Temp = c(25.2163, 25.1917, 25.1593, 25.125, 25.0908, 25.0612
)), .Names = c("Longitude", "Latitude", "Temp"), row.names = c(NA, 
6L), class = "data.frame").

我在将其重新排列为所需格式时遇到问题.

I am having problems re-arranging it to the required format.

我想创建一个常规曲面对象(通常是一个列表),其中x和y是网格值,z是该表面的对应矩阵.这是perspcontourimage等使用的常用格式.

I would like to create a regular surface object (typically a list), where x and y are the grid values and z is a corresponding matrix of the surface. This is the usual format used by persp, contour, imageetc.

使用这个表面对象,我将能够使用fields包中的interp.surf轻松地将其插值到位置矩阵.

Using this surface object I will could then be able to easily interpolate to a matrix of locations using interp.surffrom the fieldspackage.

任何建议都会很棒.

推荐答案

假设您的数据就像

set.seed(123)
d <- data.frame(lon=rep(seq(0,1,0.25), times=5),
           lat=rep(seq(0,1,0.25), each=5),
           temp=sample(1:25, 25, replace=TRUE))
head(d, 8)
#    lon  lat temp
# 1 0.00 0.00    8
# 2 0.25 0.00   20
# 3 0.50 0.00   11
# 4 0.75 0.00   23
# 5 1.00 0.00   24
# 6 0.00 0.25    2
# 7 0.25 0.25   14
# 8 0.50 0.25   23

我们创建一个z矩阵,该矩阵表示网格中每个点的值.然后,我们将网格线(xy)的位置以及z一起放入列表.

We create a z matrix that represent the values for each point in the grid. We then put the locations of the grid lines (x and y) into a list, together with z.

library(reshape2)
z <- acast(d, lat~lon, value.var="temp")
X <- list(x=sort(unique(d$lon)), 
          y=sort(unique(d$lat)), 
          z=z)

image(X, col=gray.colors(25))
with(d, text(lon, lat, labels=temp))

另请参见更改纬度& Lon向量到R 中的矩阵.

这篇关于从“预磨"的表面创建曲面点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆