ncToData: Match Data From a Netcdf File

Description Usage Arguments Value Author(s) Examples

View source: R/ncToData.R

Description

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

Usage

1
2
3
4
5
6
7
8
9
ncToData(
  data,
  nc,
  buffer = c(0, 0, 0),
  FUN = c(mean, median, sd),
  raw = FALSE,
  progress = TRUE,
  verbose = TRUE
)

Arguments

data

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

nc

name of a netcdf file

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

progress

logical flag to show progress bar for matching data

verbose

logical flag to show warning messages for possible coordinate mismatch

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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')
# calculate mean median and stdev
ncToData(data, nc = nc)
# calculate only median
ncToData(data, nc=nc, FUN=median, 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 Oct. 8, 2021, 9:08 a.m.