interpolate_GSOD: Interpolate GSOD data to a daily gridded surface

View source: R/interpolate_gsod.R

interpolate_GSODR Documentation

Interpolate GSOD data to a daily gridded surface

Description

This function is designed to be wrapped in an base::lapply() function to process multiple years of GSOD data for interpolation, though a single year may be used. Output is written to a fst::fst file.

Usage

interpolate_GSOD(x, dem, dsn = NULL, fname, vars = NULL, dates = NULL)

Arguments

x

A base::list() of data frames or fst files of GSOD data created by make_GSOD_set().

dem

Digital elevation model that has been fetched and processed using glint::make_DEM().

dsn

Optional. A file path where resulting fst files are to be saved on local disk. If unspecified a tidy data frame is returned in the R session.

fname

Optional. A file name for the data to be saved as a fst::fst() compressed file object on local disk.

vars

Weather variables to interpolate. Possible values are TEMP, MAX, MIN and RH. Defaults to TEMP.

dates

Optional. A vector of dates to optionally filter and interpolate. If left NULL, the default, all days of the specified year(s) are interpolated and returned. Values should be entered as a complete date in ISO 8601 format, e.g. "2017-07-15 or a vector, e.g. c("2017-07-15", "2017-05-01", "2017-02-15").

Value

A terra::SpatRaster() of daily interpolated weather variables and optionally writes values to a fst::fst() compressed file.

Author(s)

adamhsparks@gmail.com

Examples


# Get and aggregate the raster digital elevation model
dem <- make_DEM()

# Create a list of GSOD files
files <- list.files("~/Data/GSOD", full.names = TRUE)

# Run the function for MAX and MIN temperature using parallel processing
future::plan("multisession")
GRID <- lapply(X = files, FUN = interpolate_GSOD, dem = dem,
dsn = "~/Cache/GTiff", vars = c("MAX", "MIN"))

# Run the function for MAX and MIN temperature using a single core
future::plan("sequential")
GRID <- lapply(X = files, FUN = interpolate_GSOD, dem = dem, vars = "MAX")


adamhsparks/GRID documentation built on Jan. 27, 2023, 5:48 a.m.