get_weatherdata: Get weatherdata of a city for a specific time period

Description Usage Arguments Value References Examples

View source: R/get_weatherdata.R

Description

get_weatherdata allows the user to get weather data for a specified:

  1. data_type - Type of weather data. e.g. Temperature average/min/max (TAVG/TMIN/TMAX), snowfall (SNOW), precipitation (PRCP), etc. Refer here for detailed documentation about available data types.

  2. city_ID: should be taken as per the output of get_cities function

  3. start_date (in the format "YYYY-MM-DD")

  4. end_date (in the format "YYYY-MM-DD")

Usage

1
get_weatherdata(data_type, city_ID, start_date, end_date, check = TRUE)

Arguments

data_type

Character, data type (refer documentation for supported types)

city_ID

Character, valid city ID

start_date

Character, valid date (in YYYY-MM-DD format)

end_date

Character, valid date (in YYYY-MM-DD format)

check

Boolean, whether city_ID, start_date, end_date must be validated. Can be skipped by passing check=FALSE which improves performance.

Value

Weather data from all the stations in the specified city and the soecified time period are returned. Consider using simplify_weatherdata function to aggregate and simplify this result to an easy-to-use daily data format. The data contains the following columns:

References

NOAA GHCN-D Documentation - https://docs.opendata.aws/noaa-ghcn-pds/readme.html
API Reference - https://www.ncdc.noaa.gov/cdo-web/webservices/v2#data

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
## Not run: 

# First get your API-token here: https://www.ncdc.noaa.gov/cdo-web/token
# Then, set it as system variable (as character variable):
Sys.setenv("NOAA_TOKEN" = "YOUR_TOKEN_GOES_IN_HERE")

# Get location data to select the city_IDs we are interested in
cities = get_cities()

# Get weatherdata for Link<c3><b6>ping (only September)
head(cities[which(cities$country == "SW"), ]) # Pick SW000006 (Link<c3><b6>ping)
weatherdata = get_weatherdata("TAVG", "SW000006", "2018-09-01", "2018-09-23")

# Get weatherdata for Berlin (only September)
head(cities[which(cities$country == "GM"), ]) # Pick GM000001 (Berlin)
weatherdata = get_weatherdata("TAVG", "GM000001", "2018-09-01", "2018-09-23")

# If you want to download data for several years, you need to do it year by year
weatherdata_2018 = get_weatherdata("TAVG", "SW000006", "2018-01-01", "2018-08-31", check = FALSE)
weatherdata_2017 = get_weatherdata("TAVG", "SW000006", "2017-01-01", "2017-12-31", check = FALSE)
weatherdata_17to18 = rbind(weatherdata_2017, weatherdata_2018)
plot(x = as.Date(weatherdata_17to18$date), y = weatherdata_17to18$value/10, 
     main = "Avg. Temperature in Link<c3><b6>ping, Sweden [2017-2018]", 
     xlab = "Date", ylab= "Temperature in C")
     

## End(Not run)

harihp12/cdoapi documentation built on May 28, 2019, 7:29 a.m.