daily_climate: Retrieve average daily weather data per US county.

Description Usage Arguments Value Note Examples

View source: R/prep_climate.R

Description

Retrieve average daily weather data per US county.

Usage

1
2
3
4
5
6
7
daily_climate(
  fips,
  var = c("prcp", "snow", "snwd", "tmax", "tmin"),
  date_min = "2015-01-01",
  date_max = "2015-12-31",
  coverage = 0.9
)

Arguments

fips

A string with the five-digit U.S. FIPS code of a county in numeric, character, or factor format.

var

A character vector specifying desired weather variables. For example, var = c("tmin", "tmax", "prcp") for maximum temperature, minimum temperature, and precipitation. The default is "all", which includes all available weather variables at any weather station in the county. For a full list of all possible variable names, see NOAA's README file for the Daily Global Historical Climatology Network (GHCN-Daily) at https://www1.ncdc.noaa.gov/pub/data/ghcn/daily/readme.txt. Many of the weather variables are available for some, but not all, monitors, so your output from this function may not include all the variables specified using this argument. If you specify a variable here but it is not included in the output dataset, it means that it was not available in the time range for any monitor in the county.

date_min

A string with the desired starting date in character, ISO format ("yyyy-mm-dd"). The dataframe returned will include only stations that have data for dates including and after the specified date.

date_max

A string with the desired ending date in character, ISO format ("yyyy-mm-dd"). The dataframe returned will include only stations that have data for dates up to and including the specified date.

coverage

A numeric value in the range of 0 to 1 that specifies the desired percentage coverage for the weather variable (i.e., what percent of each weather variable must be non-missing to include data from a monitor when calculating daily values averaged across monitors. The default is to include all monitors with any available data (i.e., coverage = 0).)

Value

A dataframe of daily weather data averaged across multiple stations.

Note

The function uses the NOAA API to identify the weather monitors within a U.S. county, you will need to get an access token from NOAA to use this function. Visit NOAA's token request page (https://www.ncdc.noaa.gov/cdo-web/token) to request a token by email. You then need to set that API code in your R session (e.g., using options(noaakey = "your key"), replacing "your key" with the API key you've requested from NOAA).

Examples

1
2
3
4
5
6
7
8
## Not run: s
climate <- daily_climate(fips = '06001',
                         var = c('prcp', 'snow', 'snwd', 'tmax', 'tmin'),
                         date_min = '2015-01-01',
                         date_max = '2015-12-31',
                         coverage = 0.90)

## End(Not run)

wildviz documentation built on Aug. 23, 2021, 9:06 a.m.