8 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:
<- paste0(gridbase,"/seasonal/air_temperature_mean")
rasterbase <- indexFTP("/16_DJF", base=rasterbase, dir=tempdir())
ftp.files
# current index of all grid files (takes > 2 min, yields >30k charstrings >5MB):
<- indexFTP(folder="currentgindex", base=gridbase, filename="grids") gridIndexNow
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:
<- localtestdir()
ddir <- tempdir()
tdir <- function(x, main1, main2, main3=NULL, ...)
project_and_plot
{par(mar=c(2,2,2.2,5), mgp=c(3,0.7,0))
<- paste(main1, "\n", as.character(main2), as.character(main3))
main <- plotRadar(x, main=main, layer=1, ...)
out return(invisible(c(pp,out)))
}<- list() pp
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
).
8.1 readDWD.raster
<- "seasonal/air_temperature_mean/16_DJF/grids_germany_seasonal_air_temp_mean_188216.asc.gz" # 0.2 MB
link <- dataDWD(link, base=gridbase, joinbf=TRUE, dir=ddir, read=FALSE)
file <- readDWD(file) # with dividebyten=TRUE
rad <- readDWD(file) # runs faster at second time due to skip=TRUE
rad <- project_and_plot(rad, ".raster", "", proj="seasonal", extent=rad@extent) pp
8.2 readDWD.nc
<- "daily/Project_TRY/pressure/PRED_199606_daymean.nc.gz" # 5 MB
link <- dataDWD(link, base=gridbase, joinbf=TRUE, dir=ddir, read=FALSE)
file <- readDWD(file) # can also have interactive selection of variable
rad <- project_and_plot(rad, ".nc", rad@title, rad@z[[1]][1], proj="nc", extent="nc") pp
8.3 readDWD.binary (RW)
<- "hourly/radolan/reproc/2017_002/bin/2017/RW2017.002_201712.tar.gz" # 25 MB
link <- dataDWD(link, base=gridbase, joinbf=TRUE, dir=ddir, read=FALSE)
file <- readDWD(file, exdir=tdir, selection=1:3)
rad <- project_and_plot(rad$dat, ".binary RW", rad$meta$date[1], extent="rw") pp
8.4 readDWD.binary (SF)
<- "/daily/radolan/historical/bin/2017/SF201712.tar.gz" # 204 MB
link <- dataDWD(link, base=gridbase, joinbf=TRUE, dir=ddir, read=FALSE)
file <- readDWD(file, exdir=tdir, selection=1:3) # with toraster=TRUE
rad <- project_and_plot(rad$dat, ".binary SF", rad$meta$date[1]) pp
8.5 readDWD.asc
<- "hourly/radolan/historical/asc/2018/RW-201809.tar" # 25 mB
link <- dataDWD(link, base=gridbase, joinbf=TRUE, dir=ddir,
file dbin=TRUE, read=FALSE) # download with mode=wb!!!
<- readDWD(file, selection=1:3, dividebyten=TRUE)
rad <- project_and_plot(rad, ".asc", names(rad)[1]) pp
8.6 readDWD.radar (RW)
<- indexFTP("hourly/radolan/recent/bin", base=gridbase, dir=tdir) # 0.04 MB
links <- dataDWD(links[773], base=gridbase, joinbf=TRUE, dir=tdir, read=FALSE)
file <- readDWD(file)
rad <- project_and_plot(rad$dat, ".radar RW", rad$meta$date) pp
8.7 readDWD.radar (RQ)
<- "ftp://opendata.dwd.de/weather/radar/radvor/rq"
rqbase <- indexFTP("", base=rqbase, dir=tdir) # 0.07 MB
links <- dataDWD(links[17], base=rqbase, joinbf=TRUE, dir=tdir, read=FALSE)
file <- readDWD(file)
rad <- project_and_plot(rad$dat, ".radar RQ", rad$meta$date) pp
8.8 readDWD.grib2
readDWD.grib2
- since version 1.4.12 (2021-01-01)
<- "ftp://ftp-cdc.dwd.de/weather/nwp/cosmo-d2/grib/00/t_2m"
nwpbase <- indexFTP("", base=nwpbase, dir=tdir)
links <- dataDWD(links[6], base=nwpbase, joinbf=TRUE, dir=tdir, read=FALSE)
file <- readDWD(file)
forecast <- project_and_plot(forecast, ".grib2", Sys.Date(), project=FALSE) pp
8.9 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):
<- "ftp://ftp-cdc.dwd.de/weather/radar/radolan/rw/raa01-rw_10000-latest-dwd---bin"
url <- dataDWD(url, dir=tempdir(), read=FALSE, dbin=FALSE)
rw_file <- dwdradar::readRadarFile(rw_file)
rw_orig ::plot(raster::raster(rw_orig$dat)) raster
I’m considering to set the default dbin to TRUE but need to assess the implications yet.
8.10 PDF overview
pdf("../ExampleTests/Radartests_Vign.pdf", width=6, height=6)
par(mar=c(0,0,3,5))
<- lapply(pp, function(x) plotRadar(x, xlim=c(3,16), ylim=c(47, 55),
dummy main=x@title, project=FALSE))
dev.off()
## png
## 2
Open the pdf at https://github.com/brry/rdwd/tree/master/misc/ExampleTests