如何从netcdf文件可视化地图?

sac*_*cvf 5 dictionary r netcdf ggplot2

我有一个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"
Run Code Online (Sandbox Code Playgroud)

似乎我必须将纬度与经度以及地面点连接起来以获得土壤深度的地图.我真的很困惑.任何人都可以帮助我处理这类数据.

Pau*_*tra 11

我更喜欢使用ggplot2包进行可视化.使用@plannapus的优秀解决方案:

require(reshape)
require(ggplot2); theme_set(theme_bw())
land_df = melt(land)
ggplot(aes(x = X1, y = X2, fill = value), data = land_df) + 
  geom_raster() + coord_equal() + 
  scale_fill_continuous(na.value = "transparent")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


如果要更改轴的标题,请不要更改变量名称aes.这些值是指列中的数据,并改变它们导致你得到的错误,没有轴命名Xland_df.如果要更改轴上的名称:

ggplot(aes(x = X1, y = X2, fill = value), data = land_df) + 
  geom_raster() + coord_equal() + 
  scale_fill_continuous(na.value = "transparent") + 
  scale_x_continuous("X")
Run Code Online (Sandbox Code Playgroud)


pla*_*pus 10

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
Run Code Online (Sandbox Code Playgroud)

正如您在netcdf文件的摘要中所说的那样,变量仅SoilDepth取决于维度land而不取决于x,y因此我不确定在绘制此数据集时会给您留下什么.

编辑

事实证明,有一个键链接x,yland:

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
Run Code Online (Sandbox Code Playgroud)

所以为了绘图:

# 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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • 如果您遇到新问题,请发布一个新问题. (2认同)

Pop*_*Pop 5

你想用R来形象化吗?

如果不是与其他软件进行可视化的问题,你可以使用ncBrowse,可在这里,或一整套,更复杂的一个,由美国航天局提供的,您可以donwload 这里.

如果您想使用R,您可以使用ncdf包.借助该get.var.ncdf功能,您将能够提取数据.您可以通过sp包和spplot功能绘制它,或使用rgl包(或其他scatterplot).