R语言提取单点的cru格点数据

以下以提取降水的cru格点数据为例,温度的数据类似。

inputpath <- 'data/cru_ts4.05.1901.2020.pre.dat.nc'  #文件存储路径

library(ncdf4) # package for netcdf manipulation

nc_data <- nc_open(inputpath)

print(nc_data)
# Save the print(nc) dump to a text file
{
  sink('ncdata.txt')
  print(nc_data)
  sink()
}

lon <- ncvar_get(nc_data, "lon")
lat <- ncvar_get(nc_data, "lat", verbose = F)
t <- ncvar_get(nc_data, "time")
ticount <- length(t)

head(lon) # look at the first few entries in the longitude vector

###裁剪数据
#boundary = c(36.75,97.75,36.75,97.75)
#lon_scope= which(lon >= boundary[1] & lon <= boundary[2])
#lat_scope = which(lat >= boundary[3] & lat <= boundary[4])
#lon_number=length(lon_scope)
#lat_number = length(lat_scope)

###提取单点数据
lon_scope= which(lon == 97.75)
lat_scope = which(lat == 36.75)
start = c(lon_scope,lat_scope,1)
count = c(1,1,ticount)
stride1 = c(1,1,1)


data.array <- ncvar_get(nc_data,"pre",start,count) # store the data in a 3-dimensional
write.csv(data.array,'data.csv') 

另外,当然也可以用Google Earth下载单点数据。数据量大的话,这种好一点。 

 

上一篇:C# Post 使用(multipart/form-data)请求数据


下一篇:vue 导出execl