GSODR (version 2.1.1)

reformat_GSOD: Tidy and Return a data.table Object of GSOD Weather From Local Storage

Description

This function automates cleaning and reformatting of GSOD station files in “YEAR.tar.gz”, provided that they have been untarred or “STATION.csv” format that have been downloaded from the United States National Center for Environmental Information's (NCEI) download page. Three additional useful elements: saturation vapour pressure (es), actual vapour pressure (ea) and relative humidity (RH) are calculated and returned in the final data frame using the improved August-Roche-Magnus approximation (Alduchov and Eskridge 1996). All units are converted to International System of Units (SI), e.g., Fahrenheit to Celsius and inches to millimetres.

Usage

reformat_GSOD(dsn = NULL, file_list = NULL)

Arguments

dsn

User supplied file path to location of data files on local disk for tidying.

file_list

User supplied list of files of data on local disk for tidying.

Value

A data frame as a data.table object of GSOD data.

Details

Parallel processing can be enabled using plan to set up a parallel backend of your choice, e.g., future::plan("multisession"). See Examples for more.

If multiple stations are given, data are summarised for each year by station, which include vapour pressure and relative humidity elements calculated from existing data in GSOD. Else, a single station is tidied and a data frame is returned.

All missing values in resulting files are represented as NA regardless of which field they occur in.

Only station files in the original “csv” file format are supported by this function. If you have downloaded the full annual (“YYYY.tar.gz”) file you will need to extract the individual station files from the tar file first to use this function.

Note that reformat_GSOD() will attempt to reformat any “.csv” files found in the dsn that you provide. If there are non- GSOD files present this will lead to errors.

For a complete list of the fields and description of the contents and units, please refer to Appendix 1 in the GSODR vignette, vignette("GSODR", package = "GSODR").

References

Alduchov, O.A. and Eskridge, R.E., 1996. Improved Magnus form approximation of saturation vapor pressure. Journal of Applied Meteorology and Climatology, 35(4), pp.601-609. DOI: <10.1175

See Also

For automated downloading and tidying see the get_GSOD function which provides expanded functionality for automatically downloading and expanding annual GSOD files and cleaning station files.

Examples

Run this code
# NOT RUN {
# Download data to 'tempdir()'
download.file(
  url =
    "https://www.ncei.noaa.gov/data/global-summary-of-the-day/access/2010/95551099999.csv",
  destfile = file.path(tempdir(), "95551099999.csv"),
  mode = "wb"
)

# Reformat station data files in R's tempdir() directory
tbar <- reformat_GSOD(dsn = tempdir())

tbar
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab