ncToData {PAMmisc} | R Documentation |
Match Data From a Netcdf File
Description
Extracts all variables from a netcdf file matching Longitude, Latitude, and UTC coordinates in given dataframe
Usage
ncToData(
data,
nc,
var = NULL,
buffer = c(0, 0, 0),
FUN = c(mean),
raw = FALSE,
keepMatch = TRUE,
progress = TRUE,
depth = 0,
verbose = TRUE,
...
)
Arguments
data |
dataframe containing Longitude, Latitude, and UTC to extract matching variables from the netcdf file |
nc |
name of a netcdf file |
var |
(optional) character vector of variable names to match. If |
buffer |
vector of Longitude, Latitude, and Time (seconds) to buffer around each datapoint. All values within the buffer will be used to report the mean, median, and standard deviation |
FUN |
a vector or list of functions to apply to the data. Default is to apply mean, median, and standard deviation calculations |
raw |
logical flag to return only the raw values of the variables. If |
keepMatch |
logical flag to keep the matched coordinates, these are useful to make sure the closest point is actually close to your XYZT |
progress |
logical flag to show progress bar for matching data |
depth |
depth values (meters) to use for matching, overrides any |
verbose |
logical flag to show warning messages for possible coordinate mismatch |
... |
not used |
Value
original dataframe with three attached columns for each variable in the netcdf file, one for each of mean, median, and standard deviation of all values within the buffer
Author(s)
Taiki Sakai taiki.sakai@noaa.gov
Examples
data <- data.frame(Latitude = 32, Longitude = -117,
UTC = as.POSIXct('2005-01-01 00:00:00', tz='UTC'))
nc <- system.file('extdata', 'sst.nc', package='PAMmisc')
# default calculates mean
ncToData(data, nc = nc)
# calculate mean, median, and sd
ncToData(data, nc=nc, FUN=c(mean, median, sd), buffer = c(.01, .01, 86400))
# custom function
meanPlusOne <- function(x) {
mean(x, na.rm=TRUE) + 1
}
ncToData(data, nc=nc, FUN=c(mean, meanPlusOne))