ncToData: Match Data From a Netcdf File

View source: R/ncToData.R

ncToDataR Documentation

Match Data From a Netcdf File


Extracts all variables from a netcdf file matching Longitude, Latitude, and UTC coordinates in given dataframe


  buffer = c(0, 0, 0),
  FUN = c(mean),
  raw = FALSE,
  keepMatch = TRUE,
  progress = TRUE,
  depth = 0,
  verbose = TRUE



dataframe containing Longitude, Latitude, and UTC to extract matching variables from the netcdf file


name of a netcdf file


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


a vector or list of functions to apply to the data. Default is to apply mean, median, and standard deviation calculations


logical flag to return only the raw values of the variables. If TRUE the output will be changed to a list with length equal to the number of data points. Each item in the list will have separate named entries for each variable that will have all values within the given buffer and all values for any Z coordinates present.


logical flag to keep the matched coordinates, these are useful to make sure the closest point is actually close to your XYZT


logical flag to show progress bar for matching data


depth values (meters) to use for matching, overrides any Depth column in the data or can be used to specify desired depth range when not present in data. Variables will be summarised over the range of these depth values. NULL uses all available depth values


logical flag to show warning messages for possible coordinate mismatch


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


Taiki Sakai


data <- data.frame(Latitude = 32, Longitude = -117,
                   UTC = as.POSIXct('2005-01-01 00:00:00', tz='UTC'))
nc <- system.file('extdata', '', 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))

PAMmisc documentation built on Dec. 28, 2022, 1:30 a.m.