Learn R Programming

chillR (version 0.75)

handle_dwd: List, download or convert to chillR format data from the Deutscher Wetterdienst database

Description

This function accesses the Deutscher Wetterdienst database and allows to:

  • 2) obtain weather data for one or more weather stations through the station ID

  • 3) 'clean' and 'format' downloaded data, so the records can easily be used in other chillR functions

Usage

handle_dwd(
  action,
  location = NA,
  time_interval = c(19160101, Date2YEARMODA(Sys.Date())),
  station_list = NULL,
  stations_to_choose_from = 25,
  drop_most = TRUE,
  end_at_present = TRUE,
  add.DATE = FALSE,
  quiet = FALSE,
  add_station_name = FALSE
)

Value

If action = 'list_stations', the function returns a data frame with 'stations_to_choose_from' rows and 9 columns. This data frame contains information about the weather stations (Latitude, Longitude, among others). If action = 'download_weather', the function returns a list of length according to the length of the location parameter. Each list elements is a data frame containing the data downloaded from the database. If the action is provided with the list generated by the function in the downloading mode, the function will return a list of data frames structured according to the chillR format. If drop_most is set to TRUE, the function will keep only the most relevant variables for standard chillR analyses.

Arguments

action

is a character string to decide on 3 modes of action for the function.

  • 'list_stations' returns a data frame with the information on weather stations that are to the location defined by number_of_stations and location parameters.

  • 'download_weather' retrieves the records for one or more weather stations defined in the location parameter.

  • If the input is a data frame previously downloaded with the mode 'download_weather', the function will format the data frame using the chillR structure.

location

accepts a numeric vector with two or three elements representing the longitude, latitude, and elevation of a given place or a vector of character strings representing the ID of the weather stations of interest. If action = 'list_stations', location requires the coordinates of the place and optionally the elevation. This vector can be named or not. Valid names are: 'y', 'Y', 'latitude', 'lat', 'Latitude', 'Lat', 'LATITUDE', 'LAT' for latitude, 'x', 'X', 'longitude', 'long', 'Longitude', 'Long', 'LONGITUDE', 'LONG' for longitude, and 'z', 'Z', 'elevation', 'elev', 'Elevation', 'Elev', 'ELEVATION', 'ELEV' for elevation. If action = 'download_weather', location accepts the ID of the station as character string.

time_interval

numeric vector with two elements, specifying the start and end date of the period of interest. Only required when running in 'list_stations' or 'download_weather' mode. Unlike other functions from the handle family, handle_dwd allows specifying the date in YEARMODA format. Default is set to 19160101 (the earliest date on record) and the current date.

station_list

accepts a data frame if the list of weather stations has already been downloaded. The list can be passed to the function through this argument. This can save a bit of time, since it can take a bit of time to download the list, which can have several MB.

stations_to_choose_from

if the location is specified by geographic coordinates, this argument determines the number of nearby stations in the list that is returned.

drop_most

boolean variable indicating if most columns should be dropped from the file if a list of data frames is provided to the action argument. If set to TRUE (the default), only essential columns for running chillR functions are retained.

end_at_present

boolean variable indicating whether the interval of interest should end on the present day, rather than extending until the end of the year specified under time_interval[2] (if time_interval[2] is the current year). DEPRECATED in this function since time_interval already allows specifying the present day.

add.DATE

is a boolean parameter to be passed to make_all_day_table if action is a collection of outputs (in the form of list) from the function in the downloading format.

quiet

is a boolean parameter to be passed to download.file if action = "download_weather".

add_station_name

is a boolean parameter to include the name of the respective weather station in the resulting data frame in case the function is used in the downloading or formatting mode.

Author

Eduardo Fernandez and Eike Luedeling

References

Fernandez, E., Whitney, C., and Luedeling, E. 2020. The importance of chill model selection - A multi-site analysis. European Journal Of Agronomy 119: 126103

Examples

Run this code

# The following lines may take longer than required to pass the
# CRAN checks. Please, un-comment them to run the example

# stations <- handle_dwd(action = "list_stations", 
#                        location = c(latitude = 53.5373, longitude = 9.6397),
#                        time_interval = c(20000101, 20101231),
#                        stations_to_choose_from = 25)
                     
# data <- handle_dwd(action = "download_weather",
#                     location = stations[1 : 3, "Station_ID"],
#                     time_interval = c(20000101, 20020601),
#                     stations_to_choose_from = 25,
#                     station_list = stations,
#                     drop_most = TRUE, 
#                     add.DATE = FALSE,
#                     quiet = TRUE,
#                     add_station_name = FALSE)

# data_modified <- handle_dwd(data, add.DATE = TRUE, drop_most = TRUE)
           

Run the code above in your browser using DataLab