Learn R Programming

rdwd (version 0.7.0)

selectDWD: Select data from the DWD CDC FTP Server

Description

Select files for downloading with dataDWD. All arguments (except for mindex, findex and base) can be a vecor and will be recycled to the maximum length of all arguments. If that length > 1, the output is a list of filenames (or vector with outvec=TRUE). If station name is given, but id is empty (""), id is inferred via mindex. If res/var/per are given and valid (existing in findex), they are pasted together to form a path. Here is an overview of the behaviour in each case of availability:

case | id | path | output
1 | "" | "" | base (and some warnings)
2 | "xx" | "" | All file names (across paths) for station id
3 | "" | "xx" | The zip file names at path
4 | "xx" | "xx" | Regular single data file name

For case 3 and 4 (path given), you can set meta=TRUE. Then selectDWD will return the name of the station description file at path. This is why case 3 with meta=FALSE only returns the data file names (ending in .zip).

Usage

selectDWD(name = "", exactmatch = TRUE, mindex = metaIndex,
  id = findID(name, exactmatch = exactmatch, mindex = mindex),
  base = "ftp://ftp-cdc.dwd.de/pub/CDC/observations_germany/climate",
  res = "", var = "", per = "", findex = fileIndex, current = FALSE,
  meta = FALSE, outvec = FALSE, ...)

Arguments

name

Char: station name(s) passed to findID, along with the next two arguments. All ignored if id is given. DEFAULT: ""

exactmatch

Logical passed to findID: match name with ==)? Else with grepl. DEFAULT: TRUE

mindex

Single object: Index with metadata passed to findID. DEFAULT: rdwd:::metaIndex

id

Char/Number: station ID with or without leading zeros, e.g. "00614" or 614. Is internally converted to an integer, because some DWD meta data files also contain no leading zeros. DEFAULT: findID(name)

base

Single char: main directory of DWD ftp server, defaulting to observed climatic records. Must be the same base used to create findex. DEFAULT: ftp://ftp-cdc.dwd.de/pub/CDC/observations_germany/climate

res

Char: temporal resolution available at base, usually one of c("hourly","daily","monthly"), see rdwd. res/var/per together form the path. DEFAULT: ""

var

Char: weather variable of interest, see rdwd. Usually one of c("air_temperature", "cloudiness", "precipitation", "pressure", "sun", "wind") (only in hourly), c("soil_temperature", "solar") (in hourly and daily), or c("kl", "more_precip") (in daily and monthly). See more in View(rdwd:::fileIndex). DEFAULT: ""

per

Char: desired time period. One of "recent" (data from the last year, up to date usually within a few days) or "historical" (long time series). Can be abbreviated (if the first letter is "r" or "h", full names are used). To get both datasets, use per="hr" or per="rh" (and outvec=TRUE). per is set to "" if var=="solar". DEFAULT: ""

findex

Single object: Index used to select filename, as returned by createIndex.To use a current / custom index, use myIndex <- createIndex(indexDWD("/daily/solar")) (with desired path, of course). DEFAULT: rdwd:::fileIndex

current

Single logical for case 3/4 with given path: instead of findex, use a list of the currently available files at base/res/var/per? This will call indexDWD, thus requires availability of the RCurl package. DEFAULT: FALSE

meta

Logical: return metadata txt file name instead of climate data zip file? Relevant only in case 4 (path and id given). DEFAULT: FALSE

outvec

Single logical: if path or ID length > 1, instead of a list, return a vector? (via unlist). DEFAULT: FALSE

Further arguments passed to indexDWD if current=TRUE, like dir, quiet

Value

Character string with file path and name(s) in the format "base/res/var/per/filename.zip"

See Also

dataDWD, ../doc/mapDWD.html, NA

Examples

Run this code
# Give weather station name (must be existing in metaIndex):
findID("Potsdam", exactmatch=FALSE)
selectDWD("Potsdam", res="daily", var="kl", per="historical")
# all files for all stations matching "Koeln":
selectDWD("Koeln", exactmatch=FALSE)
findID("Koeln", FALSE)

# or directly give station ID:
selectDWD(id="00386", res="daily", var="kl", per="historical")
selectDWD(id=386, res="daily", var="kl", per="historical")
# period abbreviatable:
selectDWD(id="00386", res="daily", var="kl", per="h")
selectDWD(id="00386", res="daily", var="kl", per="h", meta=TRUE)

# vectorizable:
selectDWD(id="01050", res="daily", var="kl", per=c("r","h"))
selectDWD(id="01050", res="daily", var="kl", per="rh", outvec=TRUE)
selectDWD(id="01050", res=c("daily","monthly"), var="kl", per="r")
# vectorization gives not the outer product, but elementwise comparison:
selectDWD(id="01050", res=c("daily","monthly"), var="kl", per="hr")

# all zip files in all paths matching id:
selectDWD(id=c(1050, 386))
# all zip files in a given path (if ID is empty):
head(  selectDWD(id="", res="daily", var="kl", per="recent")   )

# See if warnings come as expected and are informative:
selectDWD()
selectDWD(7777)
selectDWD(id=7777)
selectDWD(id="", res="dummy", var="dummy")
selectDWD(res="dummy")
selectDWD(res="daily", per="r")
selectDWD(res="daily", var="kl")
selectDWD(id="01050", res=c("daily","monthly"), var="kl") # needs 'per'
selectDWD(id="00386", meta=TRUE)

selectDWD("Potsdam", res="daily", var="solar")
# should be an error:
berryFunctions::is.error(  selectDWD(id="Potsdam", res="daily", var="solar"), TRUE)
berryFunctions::is.error(  selectDWD(id="", current=TRUE) , tell=TRUE, force=TRUE)


Run the code above in your browser using DataLab