rnoaa (version 0.8.4)

ghcnd: Get all GHCND data from a single weather site

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

ghcnd(stationid, refresh = FALSE, ...)

ghcnd_read(path, ...)

Arguments

stationid

(character) 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.

refresh

(logical) If TRUE force re-download of data. Default: FALSE

...

In the case of ghcnd additional curl options to pass through to HttpClient. In the case of ghcnd_read further options passed on to read.csv

path

(character) a path to a file with a .dly extension - already downloaded on your computer

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.

Using refresh = TRUE you can force a re-download of the data file.

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")

You can access the last modified time for the cached file via attr(x, "file_modified")

Messages are printed to the console about file path and file last modified time which you can suppress with suppressMessages()

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

Run this code
# NOT RUN {
# Get data
ghcnd(stationid = "AGE00147704")

stations <- ghcnd_stations()
ghcnd(stations$id[40])

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))

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

# refresh the cached file
ghcnd(stationid = "AGE00147704", refresh = TRUE)

# Read in a .dly file you've already downloaded
path <- system.file("examples/AGE00147704.dly", package = "rnoaa")
ghcnd_read(path)
# }

Run the code above in your browser using DataLab