【问题标题】:extract time series weather forecast data from Netcdf to csv将时间序列天气预报数据从 Netcdf 提取到 csv
【发布时间】:2016-01-02 15:30:32
【问题描述】:

我想使用 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) ... (Sep 2015)] N= 187 pts :grid

以月为单位的预测交货时间 网格:/L(月)按 1.0 N = 4 pts 排序(1.0 个月)到(4.0 个月):grid 经度(经度)

grid: /X (degree_east) 周期性 (178.75W) 到 (178.75E) 2.5 N= 144 pts :grid 纬度(纬度)

grid: /Y (degree_north) 以 2.5 N= 72 pts 排序 (88.75N) 到 (88.75S) :grid

【问题讨论】:

  • 你试过包ncdf吗?
  • 使用 matlab,您可以使用库 ncdf 读取 netcdf,然后使用 csvwrite 将结果导出为 .csv

标签: r matlab csv netcdf weather


【解决方案1】:

你可以使用 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=",")

【讨论】:

  • 欢迎来到 Stack Overflow 并感谢您的贡献!如果您仍然可以将几个印尼语单词翻译成英语,那就太好了。谢谢!
猜你喜欢
  • 2015-03-05
  • 1970-01-01
  • 2012-11-01
  • 2019-10-11
  • 1970-01-01
  • 2012-11-25
  • 2019-06-10
  • 2011-05-16
  • 2017-06-25
相关资源
最近更新 更多