handle_dwd: List, download or convert to chillR format data from the...

Description Usage Arguments Value Note Author(s) References Examples

View source: R/handle_dwd.R

Description

This function accesses the Deutscher Wetterdienst database and allows to:

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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
)

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.

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, is a list of two elements; a data frame containing the data downloaded from the database and character string representing the respective database ('dwd'). 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 relevant variables.

Note

Many databases have data quality flags, which may sometimes indicate that data aren't reliable. These are not considered by this function!

Author(s)

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# 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)
           

chillR documentation built on Jan. 11, 2022, 5:07 p.m.