Skip to content

Instantly share code, notes, and snippets.

@sckott
Last active August 29, 2015 14:00
Show Gist options
  • Save sckott/11046362 to your computer and use it in GitHub Desktop.
Save sckott/11046362 to your computer and use it in GitHub Desktop.
Example using rnoaa

Here's an example workflow for rnoaa.

Note that you can alternatively install the development version of rnoaa from Github by doing

install.packages("devtools")
library("devtools")
install_github("ropensci/rnoaa")

Load rnoaa

library("rnoaa")

Seach for stations at zip 28801

stations <- noaa_stations(locationid = "ZIP:28801")

These are stations available at that location

stations$data$id
##  [1] "COOP:310301"       "GHCND:US1NCBC0005" "GHCND:US1NCBC0033"
##  [4] "GHCND:US1NCBC0051" "GHCND:USC00310288" "GHCND:USW00013872"
##  [7] "NEXRAD:KCAE"       "NEXRAD:KGSP"       "NEXRAD:KJKL"      
## [10] "NEXRAD:KMRX"

What datasetids are available for one station

noaa_datasets(stationid = stations$data$id[1])
## $meta
## $meta$limit
## [1] 25
## 
## $meta$count
## [1] 2
## 
## $meta$offset
## [1] 1
## 
## 
## $data
##                    uid         id                 name datacoverage
## 1 gov.noaa.ncdc:C00040     ANNUAL     Annual Summaries            1
## 2 gov.noaa.ncdc:C00313 PRECIP_HLY Precipitation Hourly            1
##      mindate    maxdate
## 1 1831-02-01 2013-11-01
## 2 1900-01-01 2013-05-01
## 
## attr(,"class")
## [1] "noaa_datasets"

What datatypes are available for one station

noaa_datatypes(datasetid = "PRECIP_HLY", stationid = stations$data$id[1])
## $data
##     id                             name datacoverage    mindate    maxdate
## 1 HPCP Precipitation (100th of an inch)            1 1900-01-01 2013-05-01
## 
## $meta
##   limit count offset
## 1    25     1      1
## 
## attr(,"class")
## [1] "noaa_datatypes"

Collect data for a single station

noaa(datasetid = "PRECIP_HLY", stationid = stations$data$id[1], datatypeid = "HPCP", 
    limit = 10, startdate = "2012-01-19", enddate = "2012-02-24")
## $meta
## $meta$totalCount
## [1] 74
## 
## $meta$pageCount
## [1] 10
## 
## $meta$offset
## [1] 1
## 
## 
## $data
##        station value attributes datatype                date
## 1  COOP:310301     3       ,,HI     HPCP 2012-01-20T21:00:00
## 2  COOP:310301     2       ,,HI     HPCP 2012-01-20T22:00:00
## 3  COOP:310301     1       ,,HI     HPCP 2012-01-20T23:00:00
## 4  COOP:310301     3       ,,HI     HPCP 2012-01-21T02:00:00
## 5  COOP:310301     3       ,,HI     HPCP 2012-01-21T04:00:00
## 6  COOP:310301     3       ,,HI     HPCP 2012-01-21T06:00:00
## 7  COOP:310301     1       ,,HI     HPCP 2012-01-21T07:00:00
## 8  COOP:310301     5       ,,HI     HPCP 2012-01-21T09:00:00
## 9  COOP:310301     7       ,,HI     HPCP 2012-01-21T10:00:00
## 10 COOP:310301    14       ,,HI     HPCP 2012-01-21T11:00:00
## 
## attr(,"class")
## [1] "noaa_data"

Collect data for a zip code

noaa(datasetid = "PRECIP_HLY", locationid = "ZIP:28801", datatypeid = "HPCP", 
    limit = 10, startdate = "2012-01-19", enddate = "2012-02-24")
## $meta
## $meta$totalCount
## [1] 74
## 
## $meta$pageCount
## [1] 10
## 
## $meta$offset
## [1] 1
## 
## 
## $data
##        station value attributes datatype                date
## 1  COOP:310301     3       ,,HI     HPCP 2012-01-20T21:00:00
## 2  COOP:310301     2       ,,HI     HPCP 2012-01-20T22:00:00
## 3  COOP:310301     1       ,,HI     HPCP 2012-01-20T23:00:00
## 4  COOP:310301     3       ,,HI     HPCP 2012-01-21T02:00:00
## 5  COOP:310301     3       ,,HI     HPCP 2012-01-21T04:00:00
## 6  COOP:310301     3       ,,HI     HPCP 2012-01-21T06:00:00
## 7  COOP:310301     1       ,,HI     HPCP 2012-01-21T07:00:00
## 8  COOP:310301     5       ,,HI     HPCP 2012-01-21T09:00:00
## 9  COOP:310301     7       ,,HI     HPCP 2012-01-21T10:00:00
## 10 COOP:310301    14       ,,HI     HPCP 2012-01-21T11:00:00
## 
## attr(,"class")
## [1] "noaa_data"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment