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

Description Usage Arguments Details Value Note Author(s) References Examples

View source: R/handle_wunderground.R


This function can do three things related to the Weather Underground ("Wunderground") airport database: 1. it can list stations that are close to a specified position (geographic coordinates) 2. it can retrieve weather data for a named weather station 3. it can 'clean' downloaded data, so that they can easily be used in chillR Which of these functions is carried out depends on the action argument.


handle_wunderground(action, location = NA, time_interval = NA,
  station_list = NULL, stations_to_choose_from = 25, drop_most = TRUE,
  end_at_present = TRUE)



if this is the character string "list_stations", the function will return a list of the weather stations from the database that are closest to the geographic coordinates specified by location. if this is the character string "download_weather", the function will attempt to download weather data from the database for the station named by the location argument, which should then be a character string corresponding to the chillRcode of the station (which you can get by running this function in 'list_stations mode) if this is a downloaded weather file (downloaded by running this function in 'download weather' mode), the function cleans the file and makes it ready for use in chillR. If the input is just a dataframe (not a list, as produced with this function), you have to specify the database name with the database argument


either a vector of geographic coordinates (for the 'list_stations' mode), or the 'chillRcode' of a weather station in the specified database (for the 'download_weather' mode. When running this function for data cleaning only, this is not needed.


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


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.


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


boolean variable indicating if most columns should be dropped from the file. If set to TRUE (default), only essential columns for running chillR functions are retained.


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).


This function can run independently, but it is also called by the get_weather and weather2chillR functions, which some users might find a bit easier to handle.

the Weather underground database is described here: http://www.wunderground.com/ Note that I didn't find a comprehensive listing of all their airport weather stations, so I retrieved a list of airports from somewhere else. Weather underground doesn't have data for all the airports listed. There is also no information on the time periods that are covered. So finding the right airport to work with is a bit of trial and error. Weather underground has more stations, but I haven't been able to access them (for free).

under the 'list_stations' mode, several formats are possible for specifying the location vector, which can consist of either two or three coordinates (it can include elevation). Possible formats include c(1,2,3), c(1,2), c(x=1,y=2,z=3), c(lat=2,long=1,elev=3). If elements of the vector are not names, they are interpreted as c(Longitude, Latitude, Elevation).

The 'chillRCode' is generated by this function, when it is run with geographic coordinates as location inputs. In the list of nearby stations that is returned then, the chillRCode is provided and can then be used as input for running the function in 'downloading' mode. For downloading the data, use the same call as before but replace the location argument with the chillRCode. In this case this is the airport ICAO code.


The output depends on the action argument. If it is 'list_stations', the function returns a list of station_to_choose_from weather stations that are close to the specified location. This list also contains information about how far away these stations are (in km), how much the elevation difference is (if elevation is specified; in m) and how much overlap there is between the data contained in the database and the time period specified by time_interval. If action is 'download_weather' the output is a list of two elements: 1. database="Wunderground" 2. the downloaded weather record, extended to the full duration of the specified time interval. If action is a weather data.frame or a weather record downloaded with this function (in 'download_weather' mode), the output is the same data in a format that is easy to use in chillR. If drop_most was set to TRUE, most columns are dropped.


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

I'm not aware of a real list of Weather Underground stations, but since historic records are available for many airports, a list of airports with airport codes gived a good indication. However, this means that there's a good chance that for many stations in the list, there is no data. It is also difficult to know before starting a download what years data are available for. In the database, records are available by month (or by day), which means that a separate file has to be downloaded for each month of the interval requested. This can mean quite a lot of files have to be accessed.


Eike Luedeling


The chillR package:

Luedeling E, Kunz A and Blanke M, 2013. Identification of chilling and heat requirements of cherry trees - a statistical approach. International Journal of Biometeorology 57,679-689.


#tr<-tempResponse(stack_hourly_temps(weather),Start_JDay = 300,End_JDay = 30)

chillR documentation built on Jan. 7, 2018, 1:05 a.m.