readDWD.nc: read dwd netcdf data

View source: R/readDWD.R

readDWD.ncR Documentation

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 = rdwdquiet(),
  ...
)

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 terra::rast()? All further arguments will be ignored. Specify e.g. var through ... as varname. DEFAULT: TRUE

quiet

Logical: Suppress time conversion failure warning? DEFAULT: FALSE through rdwdquiet()

...

Further arguments passed to terra::rast() or ncdf4::nc_open()

Value

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

Author(s)

Berry Boessenkool, berry-b@gmx.de, Aug 2019

See Also

readDWD()

Examples

## 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=locdir(), read=FALSE)
nc <- readDWD(file)
ncp <- plotRadar(nc, main=paste(terra::longnames(nc), terra::time(nc)), layer=1:3,
                 col=seqPal(), proj="nc", extent="nc")

str(terra::values(nc[[1]])) # obtain actual values into memory

terra::plot(nc[[1]]) # axes 0:938 / 0:720, the number of grid cells
terra::plot(ncp[[1]])# properly projected, per default onto latlon

rng <- range(terra::global(nc[[1:6]], "range", na.rm=TRUE))
terra::plot(nc, col=seqPal(), zlim=rng, maxnl=6)

# Array instead of terra rast:
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, toraster=FALSE, var="-") # commented out to not block automated tests
str(nc$var)

## End(Not run)

rdwd documentation built on July 9, 2023, 5:24 p.m.