get_forecasts: Extract DWD MOSMIX Forecast Data

Description Usage Arguments Details Value Author(s) See Also Examples

Description

This is the reason this package exists. Extracts the DWD MOSMIX forecasts for a specific station/location.

Usage

1
2
3
4
5
get_forecasts(station, doc, datetime, meta, parameter = NULL,
  as.zoo = TRUE)

## S3 method for class 'dwdforecast'
print(x, ...)

Arguments

station

character or factor containing the name of the station (e.g., "11120", "06660"). The name has to match the name as provided by the XML file (see get_station_information).

doc

an XMLInternalDocument object as returned by xmlParse (XML package).

datetime

vector of time stamps for which the forecasts are valid as returned by get_datetime.

meta

object of class dwdmeta as returned by get_meta_info.

parameter

can be NULL, character, or a vector of character. If not set (parameter = NULL) all forecast parameters will be returned containing data. If set, only a subset will be returned (see 'Details' section).

as.zoo

logical, default TRUE. If FALSE a data.frame instead of a zoo object will be returned.

x

an object of class dwdforecast as returned by get_forecasts.

...

forwarded to S3 methods. Unused for now.

Details

Extracts the forecasted values for a given location. If as.zoo = FALSE a data.frame will be returned containing the date/time for which the forecasts are valid in the first column (datetime).

If as.zoo = TRUE a zoo object is returned. In this case the datetime column (see above) will be removed.

The parameter input argument allows to subset the data. If parameter = NULL all parameters will be returned which provide at least one valid value. Columns containing missing values only will be removed automatically. parameter can be used to subset the data. Only the user specified columns will be returned. Note that this could result in an empty object if no values are available given the parmaeter specification!

Value

Returns a data.frame or zoo object (depending on input as.zoo) with the DWD MOSMIX forecasts.

Author(s)

Reto Stauffer

Reto Stauffer

See Also

get_station_information, get_meta_info, get_datetime, parameter_description.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Latest L-type DWD MOSMIX forecast file for Innsbruck Airport
url <- "https://opendata.dwd.de/weather/local_forecasts/mos/MOSMIX_L/single_stations/11120/kml/MOSMIX_L_LATEST_11120.kmz"

# Download and extract file
kmz   <- tempfile("mosmix_demo_", fileext = ".kmz")
check <- download.file(url, kmz)
if ( inherits(check, "try-error") ) stop("Problems downloading the file!")
kml   <- unzip(kmz)

# Parsing the unzipped kml file (XML format)
# And extract required datetime and meta information.
doc <- XML::xmlParse(kml)
datetime <- get_datetime(doc)
meta     <- get_meta_info(doc)
stations <- get_station_information(doc)

# Extracting forecasts now
# - parameter = NULL:    extracts all parameters
# - as.zoo = TRUE:       returns a time series object.
fcst1 <- get_forecasts("11120", doc, datetime, meta)
print(fcst1)
print(class(fcst1))
print(head(fcst1[,1:5]))

# Extracting forecasts now
# - parameter = NULL:    extracts all parameters
# - as.zoo = FALSE:      returns a data.frame
fcst2 <- get_forecasts("11120", doc, datetime, meta, as.zoo = FALSE)
print(fcst2)
print(class(fcst2))
print(head(fcst2[,1:5]))

# Extracting forecasts now
# - parameter is set:    return 2m temperature and 2m dewpoint
#                        temperature only (see parameter_description method)
# - as.zoo = TRUE:       returns a time series object.
fcst3 <- get_forecasts("11120", doc, datetime, meta, parameter = c("TTT", "Td"))
print(fcst3)
print(class(fcst3))
print(head(fcst3))
zoo::plot.zoo(fcst3 - 273.15, screen = 1, col = c("red", "green"),
     xlab = "date/time", ylab = "TTT/Td [degrees Celsius]",
     main = "DWD MOSMIX Forecasts for Station Innsbruck Airport (11120)")

# Remove kmz and kml file
file.remove(kmz, kml)

retostauffer/Rmosmix documentation built on May 22, 2019, 2:45 p.m.