rdwd (version 1.2.0)

readDWD.nc: read dwd netcdf data

Description

Read netcdf data. Intended to be called via readDWD. Note that R.utils and ncdf4 must be installed to unzip and read the .nc.gz files.

Usage

readDWD.nc(file, gargs = NULL, var = "", toraster = TRUE,
  quiet = FALSE, ...)

Arguments

file

Name of file on harddrive, like e.g. DWDdata/grids_germany/daily/Project_TRY/humidity/RH_199509_daymean.nc.gz

gargs

Named list of arguments passed to R.utils::gunzip, see readDWD.raster. DEFAULT: NULL

var

if toraster=FALSE: Charstring with name of variable to be read with ncdf4::ncvar_get. If not available, an interactive selection is presented. DEFAULT: "" (last variable)

toraster

Read file with raster::brick? All further arguments will be ignored. Specify e.g. var through …. DEFAULT: TRUE

quiet

Logical: Suppress time conversion failure warning? DEFAULT: FALSE

Further arguments passed to raster::brick or ncdf4::nc_open

Value

raster::brick object. Alternatively, if toraster=FALSE, a list with time, lat, lon, var, varname, file and cdf. cdf is the output of ncdf4::nc_open.

See Also

readDWD

Examples

Run this code
# NOT RUN {
 # Excluded from CRAN checks, but run in localtests

library(berryFunctions) # for seqPal and colPointsLegend

url <- "daily/Project_TRY/pressure/PRED_199606_daymean.nc.gz"  #  5 MB
url <- "daily/Project_TRY/humidity/RH_199509_daymean.nc.gz"    # 25 MB
file <- dataDWD(url, base=gridbase, joinbf=TRUE, dir=localtestdir(), read=FALSE)
nc <- readDWD(file)
ncp <- projectRasterDWD(nc, proj="nc", extent="nc")
raster::plot(ncp[[1]], col=seqPal(), main=paste(nc@title, nc@z$"Date/time"[1]))
addBorders()
str(nc, max.level=2)

rng <- range(raster::cellStats(nc[[1:6]], "range"))
raster::plot(nc, col=seqPal(), zlim=rng, maxnl=6)

# Array instead of raster brick:
nc <- readDWD(file, toraster=FALSE)
image(nc$var[,,1], col=seqPal(), asp=1.1)
colPointsLegend(nc$var[,,1], title=paste(nc$varname, nc$time[1]))

# interactive selection of variable:
# nc <- readDWD(file, var="-") # uncommented to not block automated tests 
str(nc$var)
# }

Run the code above in your browser using DataCamp Workspace