r语言 - 提取时间序列天气预报数据从Netcdf到csv



我想使用R在每个位置(X和Y)从Netcdf数据集提取时间序列数据并将其转换为csv文件。这是我第一次处理NetCDF数据。谁能告诉我使用R或Matlab的相关代码?

以下是我的数据描述:

IRI FD Seasonal_Forecast Precipitation prob: Tercile Probability data

自变量(网格):

Tercile类grid:/C (ids) unordered [(Below_Normal) (Normal) (Above_Normal)]:grid发布月度预测

grid:/F (months since 1960-01-01) ordered [(Sep 1997) (Dec 1997) (Mar 1998)…(2015年9月)]N= 187点:栅格

预测交货时间(以月为单位)网格:/L(月)订购(1.0个月)到(4.0个月)按1.0 N= 4分:网格经度(经度)

grid:/X (degree_east) periodic (178.75W) to (178.75E) by 2.5 N= 144 pts:grid纬度(纬度)

grid:/Y (degree_north) ordered (88.75N) to (88.75S) by 2.5 N= 72 pts:grid

可以使用netcdf4包

library(ncdf4)
setwd("E:\KKIM_2017\DES\")
nc = nc_open("MTS_IR_201612010000.nc")       #open ncdf and read variables
lon = ncvar_get(nc,"longitude")              # Lon lat and time
lat = ncvar_get(nc,"latitude")
time = ncvar_get(nc, "time")
dname = "IR"  #variable
variabel = ncvar_get(nc,dname)
lonlat = as.matrix(expand.grid(lon,lat))
var_vektor = as.vector(variabel)
datanya = data.frame(cbind(lonlat,var_vektor))
names(datanya) = c("lon","lat",paste(dname,as.character(), sep="_"))
head(na.omit(datanya))
csvpath = "E:\"  #directory to save file
csvname = "hasil_1v2.csv" #file_output
csvfile = paste(csvpath, csvname, sep="")
write.table(na.omit(datanya),csvfile, row.names=FALSE, sep=",")

最新更新