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-04-27) 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
# 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
#> 580 grids_germany/hourly/radolan/historical/bin/2021/RW202109.tar.gz
#> 581 grids_germany/hourly/radolan/historical/bin/2021/RW202110.tar.gz
#> 582 grids_germany/hourly/radolan/historical/bin/2021/RW202111.tar.gz
#> 583 grids_germany/hourly/radolan/historical/bin/2021/RW202112.tar.gz
#> 584 grids_germany/hourly/radolan/historical/bin/BESCHREIBUNG_gridsgermany-hourly-radolan-historical-bin_de.pdf
#> 585 grids_germany/hourly/radolan/historical/bin/DESCRIPTION_gridsgermany-hourly-radolan-historical-bin_en.pdf
#> isdir size permissions modification_time user group links
#> 580 FALSE 22516914 -rw-r--r-- 2022-03-17 13:59 9261 15101 1
#> 581 FALSE 33268966 -rw-r--r-- 2022-03-17 13:59 9261 15101 1
#> 582 FALSE 29952317 -rw-r--r-- 2022-03-17 13:59 9261 15101 1
#> 583 FALSE 35160103 -rw-r--r-- 2022-03-17 13:59 9261 15101 1
#> 584 FALSE 134365 -rw-r--r-- 2021-07-19 00:00 9261 15101 1
#> 585 FALSE 129857 -rw-r--r-- 2021-07-19 00:00 9261 15101 1
#> path
#> 580 hourly/radolan/historical/bin/2021/RW202109.tar.gz
#> 581 hourly/radolan/historical/bin/2021/RW202110.tar.gz
#> 582 hourly/radolan/historical/bin/2021/RW202111.tar.gz
#> 583 hourly/radolan/historical/bin/2021/RW202112.tar.gz
#> 584 hourly/radolan/historical/bin/BESCHREIBUNG_gridsgermany-hourly-radolan-historical-bin_de.pdf
#> 585 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 <- "~/Downloads/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]])