View source: R/weatherHelper.R
read.ghcn | R Documentation |
Given a station id and start and end dates, retrieves daily
temperature data from NOAA's API. This wraps the function
read.one.ghcn, which reads data one year at a time (that's the
maximum you're allowed to get in a single query), which itself
gets raw data with the read.noaa
function.
read.ghcn(stationid, startdate, enddate)
stationid |
the identifier for the weather station |
startdate |
the first date of data requested |
enddate |
the last date of data requested. Dates should be POSIX date class or coercible to such with as.Date |
Two things to note: 1) you need a key from NOAA to access the data. This is free and you can generate one here: https://www.ncdc.noaa.gov/cdo-web/token. All weather functions in rterm look for an object in the global environment called "noaa_key". You can deal with this by taking the following line:
noaa_key <- "your_key_here"
and placing it either before the library(rterm) statement, or, preferably, in a .Rprofile. http://www.statmethods.net/interface/customizing.html
2) You need to find a weather station to use! Probably the best way to do this for now is to use the NOAA web search at http://www.ncdc.noaa.gov/cdo-web/search, where you search for "Daily Summaries" and "Stations" with the appropriate date range and a keyword. This will bring up a map where you can click on icons for weather stations and it will report an "ID" that looks something like "GHCND:US1WAKG0179"
a data frame with variables "date", "TMIN", "TMAX", and "aveTemp". Temperatures in Fahrenheit
read.noaa
stationSearch
weather <- read.ghcn("GHCND:USW00024233", "2010-01-01", "2014-12-31")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.