从R中的netCDF提取一个点的时间序列(lon,lat) [英] Extract time series of a point ( lon, lat) from netCDF in R

查看:319
本文介绍了从R中的netCDF提取一个点的时间序列(lon,lat)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在R上还比较陌生. 我正在尝试从netCDF文件中获取温度数据的不同点(纬度,经度)的时间序列. 我的示例数据文件是此处

I am relatively new on R. I am trying to get time series of different points ( lat, lon) of temperature data from a netCDF file. My sample data file is here and here is the small file . I have tried netCDF package and the code i have used so far

library(ncdf)
obsdata = open.ncdf("obs.nc")

print.ncdf(obsdata) 

obsdatadates = obsdata$dim$time$vals
obsdatadates = as.Date(obsdatadates,origin = '1950-01-01') 
obsdatadates
obsoutput = get.var.ncdf(obsdata, varid = 'tasmin', start = c(1,1,1),
                         count = c(1,1,22280))
dim(obsoutput)
datafinal=merge(obsdatadates,obsoutput)

任何人都可以帮助我获取时间序列的数据帧(第一列)以及针对该数据的特定点(纬度,经度)的另一个数据值. 在这种情况下,我正在寻找特定纬度点(对于许多兴趣点重复)和给定变量(在这种情况下,数据为1950-01-01至2010-12-31的时间序列) tasmin). 您的帮助将不胜感激. 谢谢, 似乎

Can anyone help me to get a dataframe of timeseries ( first column) and value of data in another for a particular points( lat, lon) of that data. In this case I am looking for time series ( 1950-01-01 to 2010-12-31 for which the data is ) for a particular lat lon point ( and repeat for many points of interests) and for given variable(in this case tasmin). Your help would be appreciated. Thank you, aseem

推荐答案

也许使用raster包,这不适用于所有NetCDF文件,但对您的文件适用:

Perhaps use the raster package, this won't work for all NetCDF files but it does for yours:

library(raster)
## brick reads all 22280 layers
r <- brick("obs.nc", varname = "tasmin")
## extract works for all time steps
vals <- extract(r, matrix(c(-120, 52.5), ncol = 2))

dim(vals)
## [1]     1 22280

请注意,它给出了一个1行,多列的矩阵,因为我只给extract()一个点.

Note that gives a 1-row, many column matrix because I only gave a single point to extract().

(提取很简单,可以从最近的像元直接复制,使用方法="bilinear"进行插值).有关其他选项,请参见?extract.

(The extraction is simple with direct copy from the nearest cell, use method = "bilinear" to do interpolation). See ?extract for other options.

这篇关于从R中的netCDF提取一个点的时间序列(lon,lat)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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