How to visualize a map from a netcdf file?

I have a netcdf file that I would just like to visualize a soil depth map

   [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"

It seems that I need to associate latitudes with longitudes, as well as points of the earth, in order to get a map of the depth of the soil. I'm really confused. Can anyone help me with such data.

+5
source share
4 answers
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

As mentioned in the summary for your netcdf file, the variable SoilDepthdepends only on the dimension land, not on xand y, so I'm not sure where it stays for you when it comes to build this dataset.

Edit

It turns out there is a key that binds x, yand 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

So, to build a graph:

# 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)

enter image description here

+10

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")

enter image description here


, aes. , , , X land_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")
+11

R?

, ncBrowse, Panoply, , NASA, .

If you want to work with R, you can use the package ncdf. You can extract your data thanks to the function get.var.ncdf. You can build it thanks to the package spand spplotor use the package rgl(or scatterplot).

+5
source

For quick browsing of files you can use ncview. Maps are not particularly good, but very functional to get an idea of ​​how a given file looks. It also works easily on remote servers.

See here: http://meteora.ucsd.edu/~pierce/ncview_home_page.html

+4
source

All Articles