我有一个netcdf文件,我只想可视化土壤深度图
[1] "file C:\\Users\\SoilDepth-gswp.nc has 3 dimensions:"
[1] "x Size: 360"
[1] "y Size: 150"
[1] "land Size: 15238"
[1] "------------------------"
[1] "file C:\\SoilDepth-gswp.nc has 3 variables:"
[1] "float nav_lon[x,y] Longname:Longitude Missval:1e+30"
[1] "float nav_lat[x,y] Longname:Latitude Missval:1e+30"
[1] "float SoilDepth[land] Longname:Soil depth Missval:1.00000002004088e+20"
似乎我必须将纬度和经度以及陆地点联系起来才能获得土壤深度的 map 。我真的很困惑。任何人都可以通过这种数据来帮助我。
最佳答案
library(ncdf)
# I'm assuming this is the netcdf file you are working with:
download.file("http://dods.ipsl.jussieu.fr/gswp/Fixed/SoilDepth.nc", destfile="SoilDepth.nc")
soil <- open.ncdf("SoilDepth.nc")
#The way to extract a variable is as following:
soil$var[[3]] -> var3 # here, as shown in your question, SoilDepth is the 3rd variable
get.var.ncdf(soil, var3) -> SoilDepth
dim(SoilDepth)
[1] 15238
就像在您的netcdf文件的摘要中所说的那样,变量
SoilDepth
仅取决于维度land
,而不取决于x
和y
,因此,我不确定在绘制此数据集时会离开哪里。编辑
事实证明,有一个链接
x
,y
和land
的键:download.file("http://dods.ipsl.jussieu.fr/gswp/Fixed/landmask_gswp.nc", destfile="landmask.nc")
landmask <- open.ncdf("landmask.nc")
landmask$var[[3]] -> varland
get.var.ncdf(landmask, varland) -> land
sum(land==1)
[1] 15238
因此,为了绘制:
# The values where stored in an expected order, hence the transpose
land = t(land)
land[land==1] <- SoilDepth
land[land==0] <- NA
land = t(land)
image(land)
关于r - 如何从netcdf文件可视化 map ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12285120/