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下载单点数据。数据量大的话,这种好一点。 

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值