【问题标题】:Era-Interim - different value in output from R and ArcGISEra-Interim - R 和 ArcGIS 的输出值不同
【发布时间】:2016-07-02 15:38:15
【问题描述】:

我是 R 语言的新手,我需要帮助 :) 因此,我从 Era-Interim 再分析中获得了温度数据(来自表面和少数模型级别),并想在 R 中打开该文件。我使用这样的代码:

library(chron)
library(RColorBrewer)
library(lattice)
library(ncdf4)
getwd()
workdir <- "C:\\Users\\Angelika\\Documents\\Reanalysis\\06\\03"
setwd(workdir)
# model levels
ncname <- "03"
ncfname <- paste(ncname, ".nc", sep = "")
dname1 <- "t"
ncin <- nc_open(ncfname)
print(ncin)
lon <- ncvar_get(ncin, "longitude")
nlon <- dim(lon)
head(lon)
lat <- ncvar_get(ncin, "latitude")
nlat <- dim(lat)
head(lat)
level <- ncvar_get(ncin, "level")
nlevel <- dim(level)
head(level)
t <- ncvar_get(ncin, "time")
tunits <- ncatt_get(ncin, "time", "units")
nt <- dim(t)
head(t)
print(c(nlon, nlat, nlevel, nt))
tmp.array1 <- ncvar_get(ncin, dname1)
dlname1 <- ncatt_get(ncin, dname1, "long_name")
dunits1 <- ncatt_get(ncin, dname1, "units")
fillvalue <- ncatt_get(ncin, dname1, "_FillValue")
dim(tmp.array1)
title <- ncatt_get(ncin, 0, "title")
institution <- ncatt_get(ncin, 0, "institution")
datasource <- ncatt_get(ncin, 0, "source")
references <- ncatt_get(ncin, 0, "references")
history <- ncatt_get(ncin, 0, "history")
conventions <- ncatt_get(ncin, 0, "Conventions")
tmp.vec.long1 <- as.vector(tmp.array1)
length(tmp.vec.long1)
tmp.mat1 <- matrix(tmp.vec.long1, nrow = nlon * nlat, ncol = nlevel)
dim(tmp.mat1)
head(na.omit(tmp.mat1)) 
tlonlat1 <- expand.grid(t,lon, lat)
tmp.df02t <- data.frame(cbind(tlonlat1, tmp.mat1))
names(tmp.df02t) <- c("t", "lon", "lat", "t39", "t40", "t41", "t42", "t43", "t44", "t45", "t46", "t47", "t48", "t49", "t50", "t51", "t52", "t53", "t54", "t55", "t56", "t57", "t58", "t59", "t60")
head(na.omit(tmp.df02t, 20))

# surface = t2m
ncname <- "03_surface"
ncfname <- paste(ncname, ".nc", sep = "")
dname3 <- "t2m"
ncin <- nc_open(ncfname)
print(ncin)
lon <- ncvar_get(ncin, "longitude")
nlon <- dim(lon)
head(lon)
lat <- ncvar_get(ncin, "latitude")
nlat <- dim(lat)
head(lat)
t <- ncvar_get(ncin, "time")
tunits <- ncatt_get(ncin, "time", "units")
nt <- dim(t)
head(t)
print(c(nlon, nlat, nt))
tmp.array3 <- ncvar_get(ncin, dname3)
dlname <- ncatt_get(ncin, dname3, "long_name")
dunits <- ncatt_get(ncin, dname3, "units")
fillvalue <- ncatt_get(ncin, dname3, "_FillValue")
dim(tmp.array3)
title <- ncatt_get(ncin, 0, "title")
institution <- ncatt_get(ncin, 0, "institution")
datasource <- ncatt_get(ncin, 0, "source")
references <- ncatt_get(ncin, 0, "references")
history <- ncatt_get(ncin, 0, "history")
conventions <- ncatt_get(ncin, 0, "Conventions")
tmp.vec.long3 <- as.vector(tmp.array3)
length(tmp.vec.long3)
tmp.mat <- matrix(tmp.vec.long3, nrow = nlon * nlat *nt)
dim(tmp.mat)
head(na.omit(tmp.mat)) 
tlonlat <- expand.grid(t,lon, lat)
tmp.df02t2m <- data.frame(cbind(tlonlat, tmp.mat))
names(tmp.df02t2m) <- c("t", "lon", "lat", "t2m")
head(na.omit(tmp.df02t2m))
table<- merge(tmp.df02t2m , tmp.df02t, by=c("t","lon", "lat"))
csvfile <- "03_data.csv"
write.table(na.omit(table), csvfile, row.names = FALSE, sep = ",")

不幸的是,插值后我得到了一些奇怪的结果。我通过在 ArcGIS 10.1 和 Python 和温度值中打开 NetCDF 再次检查它 - 有时完全不同,但仅在选定的网格和日期上(在 ArcGIS 中一切都很好)。我在 R 语言中做错了什么?为什么会出现这样的差异? 最好的问候;)

【问题讨论】:

  • 嗨,您是否设法对此进行了排序,我在 R 中遇到了类似的问题。任何指导将不胜感激

标签: python r python-2.7


【解决方案1】:

我猜想使用 na.omit() 可能是虚假平均值的原因。很可能您会以这种方式丢失部分“非 NA”数据。在 R 中,可以从包含向量或矩阵的 NA 安全地计算平均值。

【讨论】:

    猜你喜欢
    • 2016-02-09
    • 1970-01-01
    • 2019-01-18
    • 2018-10-14
    • 2012-06-29
    • 1970-01-01
    • 2019-05-29
    • 1970-01-01
    • 2017-04-25
    相关资源
    最近更新 更多