7 Raster data

For observational data at dwdbase, selectDWD is the main function to choose data to be downloaded.

For gridded data at gridbase, including data interpolated onto a 1 km raster and radar data up to the last hour, I don’t yet understand the structure of the FTP server as well.
For now, you’ll have to query gridIndex yourself, e.g. with

data(gridIndex)
head(grep("historical", gridIndex, value=TRUE))

# currently available files in a given folder:
rasterbase <- paste0(gridbase,"/seasonal/air_temperature_mean")
ftp.files <- indexFTP("/16_DJF", base=rasterbase, dir=tempdir())

# current index of all grid files (takes > 2 min, yields >30k charstrings >5MB):
gridIndexNow <- indexFTP(folder="currentgindex", base=gridbase, filename="grids")

If you send me examples of how you use it, I can then expand this in rdwd.
For files that are not yet read correctly, you can also consult the Kompositformatbeschreibung at https://www.dwd.de/DE/leistungen/radolan/radolan.html

Besides dwdbase and gridbase, there’s yet more data at ftp://ftp-cdc.dwd.de/weather.

A helper function to reduce code duplication:

ddir <- localtestdir()
tdir <- tempdir()
project_and_plot <- function(x, main1, main2, main3=NULL, ...)
  {
  par(mar=c(2,2,2.2,5), mgp=c(3,0.7,0))
  main <- paste(main1, "\n", as.character(main2), as.character(main3))
  out <- plotRadar(x, main=main, layer=1, ...)
  return(invisible(c(pp,out)))
  }
pp <- list()

The following overview will usually unzip only a few selected files for speed and memory considerations. In real life, you probably do not want to unzip to a temporary exdir. You can also remove read=FALSE in dataDWD and add the needed arguments right there, but I wanted to be explicit here.

The first line in each code block below shows for which FTP folder at gridbase this function will be called.
The last line shows what projection and extent to use in projectRasterDWD (called through plotRadar).

7.1 readDWD.raster

readDWD.raster

link <- "seasonal/air_temperature_mean/16_DJF/grids_germany_seasonal_air_temp_mean_188216.asc.gz" # 0.2 MB
file <- dataDWD(link, base=gridbase, joinbf=TRUE, dir=ddir, read=FALSE)
rad <- readDWD(file) # with dividebyten=TRUE
rad <- readDWD(file) # runs faster at second time due to skip=TRUE
pp <- project_and_plot(rad, ".raster", "", proj="seasonal", extent=rad@extent)

7.2 readDWD.nc

readDWD.nc

link <- "daily/Project_TRY/pressure/PRED_199606_daymean.nc.gz"  #  5 MB
file <- dataDWD(link, base=gridbase, joinbf=TRUE, dir=ddir, read=FALSE)
rad <- readDWD(file) # can also have interactive selection of variable
pp <- project_and_plot(rad, ".nc", rad@title, rad@z[[1]][1], proj="nc", extent="nc")

7.3 readDWD.binary (RW)

readDWD.binary

link <- "hourly/radolan/reproc/2017_002/bin/2017/RW2017.002_201712.tar.gz"  # 25 MB
file <- dataDWD(link, base=gridbase, joinbf=TRUE, dir=ddir, read=FALSE)
rad <- readDWD(file, exdir=tdir, selection=1:3)
pp <- project_and_plot(rad$dat, ".binary RW", rad$meta$date[1], extent="rw")

7.4 readDWD.binary (SF)

readDWD.binary

link <- "/daily/radolan/historical/bin/2017/SF201712.tar.gz"           # 204 MB
file <- dataDWD(link, base=gridbase, joinbf=TRUE, dir=ddir, read=FALSE)
rad <- readDWD(file, exdir=tdir, selection=1:3) # with toraster=TRUE
pp <- project_and_plot(rad$dat, ".binary SF", rad$meta$date[1])

7.5 readDWD.asc

readDWD.asc

link <- "hourly/radolan/historical/asc/2018/RW-201809.tar" # 25 mB
file <- dataDWD(link, base=gridbase, joinbf=TRUE, dir=ddir,
                dbin=TRUE, read=FALSE) # download with mode=wb!!!
rad <- readDWD(file, selection=1:3, dividebyten=TRUE)
pp <- project_and_plot(rad, ".asc", names(rad)[1])

7.6 readDWD.radar (RW)

readDWD.radar

links <- indexFTP("hourly/radolan/recent/bin", base=gridbase, dir=tdir) # 0.04 MB
file <- dataDWD(links[773], base=gridbase, joinbf=TRUE, dir=tdir, read=FALSE)
rad <- readDWD(file)
pp <- project_and_plot(rad$dat, ".radar RW", rad$meta$date)

7.7 readDWD.radar (RQ)

readDWD.radar

rqbase <- "ftp://opendata.dwd.de/weather/radar/radvor/rq"
links <- indexFTP("", base=rqbase, dir=tdir) # 0.07 MB
file <- dataDWD(links[17], base=rqbase, joinbf=TRUE, dir=tdir, read=FALSE)
rad <- readDWD(file)
pp <- project_and_plot(rad$dat, ".radar RQ", rad$meta$date)

7.8 binary file errors

Binary files must be downloaded by download.file with wb=TRUE (at least on Windows, due to CRLF issues). download.file will automatically do that for some file endings (like .gz, .zip). For others (e.g. .tar files in readDWD.asc), dataDWD has a dbin=TRUE option.
If you do not use this, your plots may look partially shifted like this and have the wrong units (image from 2020-06-16 21:30 CEST):

url <- "ftp://ftp-cdc.dwd.de/weather/radar/radolan/rw/raa01-rw_10000-latest-dwd---bin"
rw_file <- dataDWD(url, dir=tempdir(), read=FALSE, dbin=FALSE)
rw_orig <- dwdradar::readRadarFile(rw_file)
raster::plot(raster::raster(rw_orig$dat))

I’m considering to set the default dbin to TRUE but need to assess the implications yet.

7.9 PDF overview

pdf("../ExampleTests/Radartests_Vign.pdf", width=6, height=6)
par(mar=c(0,0,3,5))
dummy <- lapply(pp, function(x) plotRadar(x, xlim=c(3,16), ylim=c(47, 55), 
                                        main=x@title, project=FALSE))
dev.off()
## png 
##   2

Open the pdf at https://github.com/brry/rdwd/tree/master/misc/ExampleTests