write_hourly_timeseries: Write hourly weather time series files for U.S. counties.

Description Usage Arguments Value Note Examples

Description

Given a vector of U.S. county FIPS codes, this function saves each element of the lists created from the function daily_fips to a separate folder within a given directory. The dataframe daily_data is saved to a subdirectory of the given directory called "data." This time series dataframe gives the values for specified weather variables and the number of weather stations contributing to the average for each day within the specified year(s). Metadata about the weather stations and county are saved in a list with four elements in a subdirectory called "metadata." These elements include station_metadata (station metadata for stations contributing to the time series dataframe), radius (the radius, in km, within which weather stations were pulled from each county's center), lat_center, and lon_center (the latitude and longitude of the county's geographic center). If the user specifies "csv" output for the metadata_type argument, radius, lat_center, and lon_center are added to the station_metadata dataframe as three additional columns.

Usage

1
2
3
4
write_hourly_timeseries(fips, year, coverage = NULL, var = "all",
  out_directory, data_type = "rds", metadata_type = "rds",
  average_data = TRUE, station_label = FALSE, keep_map = TRUE,
  verbose = TRUE)

Arguments

fips

A character string of the five-digit U.S. FIPS code of a U.S. county.

year

A four-digit number or vector of numbers indicating the year or years for which you want to pull hourly data. Values for year can be in the range from 1901 to the current year.

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

var

A character vector specifying desired weather variables. For example, var = c("wind_speed", "temperature") pulls data on hourly wind speed and temperature. The core weather variables available include "wind_direction", "wind_speed", "ceiling_height", "visibility_distance", "temperature", "temperature_dewpoint", "air_pressure". Alternatively, you can specify var = "all" to include additional flag and quality codes.

out_directory

The absolute or relative pathname for the directory where you would like the time series files to be saved.

data_type

A character string indicating that you would like either .rds files (data_type = "rds") or .csv files (data_type = "csv") for the time series output. This option defaults to .rds files.

metadata_type

A character string indicating that you would like either .rds files (metadata_type = "rds") or .csv files (metadata_type = "csv") for the station and county metadata output. This option defaults to .rds files, in which case a list of four elements is saved (station_metadata, radius, lat_center, and lon_center). If the user specifies "csv" output, radius, lat_center, and lon_center are added to the station_metadata dataframe as additional columns.

average_data

TRUE / FALSE to indicate if you want the function to average daily weather data across multiple monitors.

station_label

TRUE / FALSE to indicate whether to include station labels in the station map.

keep_map

TRUE / FALSE indicating if a map of the stations should be included. The map can substantially increase the size of the files. If FALSE, the "maps" subdirectory will not be created.

verbose

TRUE / FALSE to indicate if you want the function to print out the county or vector of counties it's saving files for.

Value

Writes out three subdirectories of a given directory, with hourly weather files saved in "data", station and county metadata saved in "metadata", and a map of weather station locations saved in "maps" for each FIPS code specified. The user can specify either .rds or .csv files for the data and metadatafiles, using the arguments data_type and metadata_type, respectively. Maps are saved as .png files.

Note

If the function is unable to pull weather data for a particular county given the specified percent coverage, date range, and/or weather variables, write_hourly_timeseries will not produce a file for that county.

Examples

1
2
3
4
5
6
## Not run: 
write_hourly_timeseries(fips = c("08031", "12086"), year = c(1994, 1995),
                        coverage = 0.90, var = c("wind_speed", "temperature"),
                        out_directory = "~/timeseries_hourly")

## End(Not run)

Example output

Saving daily weather files for FIPS codes 08031 and 12086 in the directory ~/timeseries_hourly. This may take a while.
Unable to pull weather data for FIPS code 08031 for the specified percent coverage, year(s), and/or weather variables.
Unable to pull weather data for FIPS code 12086 for the specified percent coverage, year(s), and/or weather variables.
Warning messages:
1: In dir.create(out_directory) :
  cannot create dir '/home/anon/timeseries_hourly', reason 'No such file or directory'
2: In dir.create(paste0(out_directory, "/data")) :
  cannot create dir '/home/anon/timeseries_hourly/data', reason 'No such file or directory'
3: In dir.create(paste0(out_directory, "/metadata")) :
  cannot create dir '/home/anon/timeseries_hourly/metadata', reason 'No such file or directory'

countyweather documentation built on May 1, 2019, 6:35 p.m.