ghcnd: Get all GHCND data from a single weather site

Description Usage Arguments Details Value File storage Author(s) See Also Examples

View source: R/ghcnd.R

Description

This function uses ftp to access the Global Historical Climatology Network daily weather data from NOAA's FTP server for a single weather site. It requires the site identification number for that site and will pull the entire weather dataset for the site.

Usage

1
ghcnd(stationid, ...)

Arguments

stationid

A character string giving the identification of the weather station for which the user would like to pull data. To get a full and current list of stations, the user can use the ghcnd_stations function. To identify stations within a certain radius of a location, the user can use the meteo_nearby_stations function.

...

Additional curl options to pass through to GET.

Details

This function saves the full set of weather data for the queried site locally in the directory specified by the path argument.

You can access the path for the cached file via attr(x, "source")

Value

A tibble (data.frame) which contains data pulled from NOAA's FTP server for the queried weather site. A README file with more information about the format of this file is available from NOAA (http://www1.ncdc.noaa.gov/pub/data/ghcn/daily/readme.txt). This file is formatted so each line of the file gives the daily weather observations for a single weather variable for all days of one month of one year. In addition to measurements, columns are included for certain flags, which add information on observation sources and quality and are further explained in NOAA's README file for the data.

File storage

We use rappdirs to store files, see user_cache_dir for how we determine the directory on your machine to save files to, and run rappdirs::user_cache_dir("rnoaa/ghcnd") to get that directory.

Note that between versions of rnoaa you may want to clear your cache of ghcnd files IF there are changes in ghcnd functions. See ghcnd_clear_cache or you can do so manually.

Author(s)

Scott Chamberlain myrmecocystus@gmail.com, Adam Erickson adam.erickson@ubc.ca

See Also

To generate a weather dataset for a single weather site that has been cleaned to a tidier weather format, the user should use the ghcnd_search function, which calls ghcnd and then processes the output, or meteo_tidy_ghcnd, which wraps the ghcnd_search function to output a tidy dataframe. To pull GHCND data from multiple monitors, see meteo_pull_monitors.

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
28
## Not run: 
# Get data
ghcnd(stationid = "AGE00147704")

stations <- ghcnd_stations()
ghcnd(stations$id[40])
ghcnd(stations$id[4000])
ghcnd(stations$id[10000])
ghcnd(stations$id[80000])
ghcnd(stations$id[80300])

library("dplyr")
ghcnd(stations$id[80300]) %>% select(id, element) %>% slice(1:3)

# manipulate data
## using built in fxns
dat <- ghcnd(stationid = "AGE00147704")
(alldat <- ghcnd_splitvars(dat))
library("ggplot2")
ggplot(subset(alldat$tmax, tmax >= 0), aes(date, tmax)) + geom_point()

## using dplyr
library("dplyr")
dat <- ghcnd(stationid = "AGE00147704")
dat %>%
 filter(element == "PRCP", year == 1909)

## End(Not run)

leighseverson/rnoaa documentation built on May 21, 2019, 3:06 a.m.