read.ghcn: Retrive GHCN Weather Data

View source: R/weatherHelper.R

read.ghcnR Documentation

Retrive GHCN Weather Data

Description

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.

Usage

read.ghcn(stationid, startdate, enddate)

Arguments

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

Details

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"

Value

a data frame with variables "date", "TMIN", "TMAX", and "aveTemp". Temperatures in Fahrenheit

See Also

read.noaa stationSearch

Examples

weather <- read.ghcn("GHCND:USW00024233", "2010-01-01", "2014-12-31")

EcotopeResearch/rterm documentation built on Oct. 17, 2022, 4:02 p.m.