Install this package
# If required, install the remotes package from CRAN
# install.packages("remotes")
# Install kwb.dwd from GitHub
remotes::install_github("KWB-R/kwb.dwd")
# Install the current development version
remotes::install_github("KWB-R/kwb.dwd@dev")
List files available on DWD’s FTP server
This package contains a function that lists the files that are available on an FTP server. It allows for recursive listing, i.e. listing the files in folders and subfolders. For example, to list all historical RADOLAN files, do:
# Define the URL to the historical RADOLAN files
url <- kwb.dwd:::ftp_path_cdc("grids_germany/daily/radolan/historical")
# List all historical RADOLAN files
urls <- kwb.dwd::list_url(url, recursive = TRUE)
It takes about six seconds to get the file list. All file paths and
file names (as they were listed on 2022-09-17) are also contained in the
data frame dwd_files
that is available in the package. You
can browse through this data frame to find the files that you are
looking for:
# Get data frame of all files
dwd_files <- kwb.dwd::dwd_files
#> Please note that rgdal will be retired during October 2023,
#> plan transition to sf/stars/terra functions using GDAL and PROJ
#> at your earliest convenience.
#> See https://r-spatial.org/r/2023/05/15/evolution4.html and https://github.com/r-spatial/evolution
#> rgdal: version: 1.6-7, (SVN revision 1203)
#> Geospatial Data Abstraction Library extensions to R successfully loaded
#> Loaded GDAL runtime: GDAL 3.8.5, released 2024/04/02
#> Path to GDAL shared files: /Users/runner/work/_temp/Library/sf/gdal
#> GDAL does not use iconv for recoding strings.
#> GDAL binary built with GEOS: TRUE
#> Loaded PROJ runtime: Rel. 9.4.0, March 1st, 2024, [PJ_VERSION: 940]
#> Path to PROJ shared files: /Users/runner/Library/Application Support/proj:/usr/local/Cellar/proj/9.4.0/share/proj:/usr/local/Cellar/proj/9.4.0/share/proj
#> PROJ CDN enabled: FALSE
#> Linking to sp version:2.1-3
#> To mute warnings of possible GDAL/OSR exportToProj4() degradation,
#> use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal.
# Filter for historical RADOLAN files
radolan_files <- dwd_files[grep("radolan/historical", dwd_files$file), ]
# Shorten the path for better display
radolan_files$path <- gsub("^grids_germany/", "", radolan_files$file)
# Show the first file paths
head(kwb.utils::resetRowNames(radolan_files))
#> file isdir
#> 1 grids_germany/daily/radolan/historical/bin/2006/SF-200610.tar.gz FALSE
#> 2 grids_germany/daily/radolan/historical/bin/2006/SF-200611.tar.gz FALSE
#> 3 grids_germany/daily/radolan/historical/bin/2006/SF-200612.tar.gz FALSE
#> 4 grids_germany/daily/radolan/historical/bin/2007/SF-200701.tar.gz FALSE
#> 5 grids_germany/daily/radolan/historical/bin/2007/SF-200702.tar.gz FALSE
#> 6 grids_germany/daily/radolan/historical/bin/2007/SF-200703.tar.gz FALSE
#> size permissions modification_time user group links
#> 1 7451505 -rw-r--r-- 2020-03-30 00:00 9261 15101 1
#> 2 53109545 -rw-r--r-- 2020-03-30 00:00 9261 15101 1
#> 3 138991915 -rw-r--r-- 2020-03-30 00:00 9261 15101 1
#> 4 228995524 -rw-r--r-- 2020-03-30 00:00 9261 15101 1
#> 5 174957194 -rw-r--r-- 2020-03-30 00:00 9261 15101 1
#> 6 186723651 -rw-r--r-- 2020-03-30 00:00 9261 15101 1
#> path
#> 1 daily/radolan/historical/bin/2006/SF-200610.tar.gz
#> 2 daily/radolan/historical/bin/2006/SF-200611.tar.gz
#> 3 daily/radolan/historical/bin/2006/SF-200612.tar.gz
#> 4 daily/radolan/historical/bin/2007/SF-200701.tar.gz
#> 5 daily/radolan/historical/bin/2007/SF-200702.tar.gz
#> 6 daily/radolan/historical/bin/2007/SF-200703.tar.gz
# Show the last file paths
tail(kwb.utils::resetRowNames(radolan_files))
#> file
#> 616 grids_germany/hourly/radolan/historical/bin/2022/RW202209.tar.gz
#> 617 grids_germany/hourly/radolan/historical/bin/2022/RW202210.tar.gz
#> 618 grids_germany/hourly/radolan/historical/bin/2022/RW202211.tar.gz
#> 619 grids_germany/hourly/radolan/historical/bin/2022/RW202212.tar.gz
#> 620 grids_germany/hourly/radolan/historical/bin/BESCHREIBUNG_gridsgermany-hourly-radolan-historical-bin_de.pdf
#> 621 grids_germany/hourly/radolan/historical/bin/DESCRIPTION_gridsgermany-hourly-radolan-historical-bin_en.pdf
#> isdir size permissions modification_time user group links
#> 616 FALSE 51665082 -rw-r--r-- 2023-03-07 10:55 9261 15101 1
#> 617 FALSE 30032972 -rw-r--r-- 2023-03-07 10:55 9261 15101 1
#> 618 FALSE 36983533 -rw-r--r-- 2023-03-07 10:55 9261 15101 1
#> 619 FALSE 39932083 -rw-r--r-- 2023-03-07 10:55 9261 15101 1
#> 620 FALSE 134365 -rw-r--r-- 2021-07-19 00:00 9261 15101 1
#> 621 FALSE 129857 -rw-r--r-- 2021-07-19 00:00 9261 15101 1
#> path
#> 616 hourly/radolan/historical/bin/2022/RW202209.tar.gz
#> 617 hourly/radolan/historical/bin/2022/RW202210.tar.gz
#> 618 hourly/radolan/historical/bin/2022/RW202211.tar.gz
#> 619 hourly/radolan/historical/bin/2022/RW202212.tar.gz
#> 620 hourly/radolan/historical/bin/BESCHREIBUNG_gridsgermany-hourly-radolan-historical-bin_de.pdf
#> 621 hourly/radolan/historical/bin/DESCRIPTION_gridsgermany-hourly-radolan-historical-bin_en.pdf
Download zipped RADOLAN files from DWD’s FTP server
# Set the target directory
export_dir <- kwb.dwd:::download_dir("radolan")
# Create required directories
kwb.utils::createDirectory(file.path(export_dir, "daily/historical"))
# Download corresponding RADOLAN files from DWD's FTP server
kwb.dwd::download_radolan(
resolution = "daily",
export_dir = export_dir,
start_daily = "2018-07",
end_daily = "2018-08"
)
The output should look like this:
Download: 'daily' historical radolan data ...
Download: "daily, historical" and save to ~/Downloads/radolan/daily/historical/SF201807.tar.gz ...
versuche URL 'ftp://opendata.dwd.de/climate_environment/CDC/grids_germany/daily/radolan/historical/bin/2018/SF201807.tar.gz'
downloaded 132.2 MB
ok. (1.48s)
Download: "daily, historical" and save to ~/Downloads/radolan/daily/historical/SF201808.tar.gz ...
versuche URL 'ftp://opendata.dwd.de/climate_environment/CDC/grids_germany/daily/radolan/historical/bin/2018/SF201808.tar.gz'
downloaded 173.5 MB
ok. (1.97s)
ok. (3.45s)
Unzip the downloaded files
# Get the paths to the zipped files
files <- dir(export_dir, "\\.tar\\.gz", recursive = TRUE, full.names = TRUE)
# Unzip all files to the export directory
lapply(files, untar, exdir = path.expand(export_dir))
Read the binary Radolan files
# Get the paths to all binary Radolan files in the export directory
files_bin <- dir(export_dir, "---bin$", full.names = TRUE)
# Read all Radolan files as raster objects
raster_objects <- lapply(files_bin, function(file) kwb.utils::catAndRun(
paste("Reading", file),
kwb.dwd::read_binary_radolan_file(file)
))
# Plot the contents of one file
raster::plot(raster_objects[[1]])