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.
1 2 3
(character) A character vector giving the identification of
the weather stations for which the user would like to pull data. To get a full
and current list of stations, the user can use the
In the case of
(character) a path to a file with a
This function saves the full set of weather data for the queried
site locally in the directory specified by the
You can access the path for the cached file via
You can access the last modified time for the cached file via
Messages are printed to the console about file path and file last modified time
which you can suppress with
For those station ids that are not found, we will delete the file locally so that a bad station id file is not cached. The returned data for a bad station id will be an empty data.frame and the attributes are empty strings.
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.
The base url for data requests can be changed. The allowed urls are: https://www1.ncdc.noaa.gov/pub/data/ghcn/daily/all (default), ftp://ftp.ncei.noaa.gov/pub/data/ghcn/daily/all, ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/daily/all
You can set the base url using the
variable; see example below.
The reason for this is that sometimes one base url source is temporarily down, but another base url may work. It doesn't make sense to allow an arbitrary base URL; open an issue if there is another valid base URL for GHNCD data that we should add to the allowed set of base urls.
See ghcnd_cache for managing cached files
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
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 29 30 31 32 33 34 35 36
## Not run: # Get data ghcnd(stationid = "AGE00147704") stations <- ghcnd_stations() ghcnd(stations$id) library("dplyr") ghcnd(stations$id) %>% 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") filter(dat, 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) # change the base url for data requests Sys.setenv(RNOAA_GHCND_BASE_URL = "ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/daily/all") ghcnd(stations$id, verbose = TRUE) ## must be in the allowed set of urls # Sys.setenv(RNOAA_GHCND_BASE_URL = "https://google.com") # ghcnd(stations$id, verbose = TRUE) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.