1

所以我一直在 R 中使用以下教程来习惯 NetCDF(我使用 netcdf4 包):http ://geog.uoregon.edu/bartlein/courses/geog607/Rmd/netCDF_01.htm

但是,我无法在我的数据集中为任何特定年份创建漂亮的图像,可以在这里找到:https ://www.ncdc.noaa.gov/paleo-search/study/19419

这是我的代码,我在其中尝试获取公元 100 年的地图:

library(lattice)
library(ncdf4)
library(chron)
library(RColorBrewer)
setwd('/Users/Nikki/Dropbox/Europe/Drought Maps')
ncname <- "owda"
ncfname <- paste(ncname,".nc",sep="")
dname <- "pdsi"
ncin <- nc_open(ncfname)
print(ncin)

lon <- ncvar_get(ncin, "lon")
nlon <- dim(lon)
head(lon)

lat <- ncvar_get(ncin, "lat", verbose = F)
nlat <- dim(lat)
head(lat)

print(c(nlon, nlat))

t <- ncvar_get(ncin, "time")
nt <- dim(t)
head(t)

drought.array <- ncvar_get(ncin, dname)
dlname <- ncatt_get(ncin, dname, "long_name")
dunits <- ncatt_get(ncin, dname, "units")
fillvalue <- ncatt_get(ncin, dname, "_FillValue")
dim(drought.array)

creation_date <- ncatt_get(ncin, 0, "creation_date")
Description <- ncatt_get(ncin, 0, "Description")

nc_close(ncin)


m <- 100
drought.slice <- drought.array[m,,]
image(lon, lat, drought.slice, col = rev(brewer.pal(10, "RdBu")))

特别是,当我尝试运行最后一行时,我收到以下错误消息:

image.default(lon,lat,drried.slice,col = rev(brewer.pal(10,:z 的尺寸不是长度(x)(-1)乘以长度(y)(-1))中的错误

有人可以解释我做错了什么吗?

顺便说一句,为了让您对我的数据结构有所了解,请看:

>print(ncin)
File owda.nc (NC_FORMAT_NETCDF4_CLASSIC):
 1 variables (excluding dimension variables):
    double pdsi[time,lat,lon]   
        longname: Palmer Drought Severity Index
        units: unitless

 3 dimensions:
    time  Size:2013
    lat  Size:88
        longname: latitude
        units: degrees
    lon  Size:114
        longname: longitude
        units: degrees

2 global attributes:
    creation_date: 10-Mar-2015 15:53:08
    Description: Reconstructed PDSI for Europe-Mediterranean Region (OWDA v1.0)
4

1 回答 1

2

看起来您的图像需要旋转:

rotate <- function(x) t(apply(x, 2, rev))
image(lon, lat, rotate(drought.slice), col = rev(brewer.pal(10, "RdBu")))

为我工作。

于 2018-04-05T00:04:33.820 回答