matchEnvData: Match Data From an Existing Netcdf File or Download and Match

Description Usage Arguments Value Author(s) Examples

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
10
11
12
13
14
15
16
17
18
19
20
21
22
matchEnvData(
  data,
  nc = NULL,
  var = NULL,
  buffer = c(0, 0, 0),
  FUN = c(mean, median, sd),
  fileName = NULL,
  progress = TRUE,
  ...
)

## S4 method for signature 'data.frame'
matchEnvData(
  data,
  nc = NULL,
  var = NULL,
  buffer = c(0, 0, 0),
  FUN = c(mean, median, sd),
  fileName = NULL,
  progress = TRUE,
  ...
)

Arguments

data

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

nc

name of a netcdf file, ERDDAP dataset id, or an edinfo object

var

(optional) vector of variable names

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

fileName

(optional) file name to save downloaded nc file to. If not provided, then no nc files will be stored, instead small temporary files will be downloaded and then deleted. This can be much faster, but means that the data will need to be downloaded again in the future. If fileName is provided, then the function will attempt to download a single nc file covering the entire range of your data. If your data spans a large amount of time and space this can be problematic.

progress

logical flag to show progress bar

...

other parameters to pass to ncToData

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
13
14
15
16
17
18
19
20
data <- data.frame(Latitude = 32, Longitude = -117,
                   UTC = as.POSIXct('2000-01-01 00:00:00', tz='UTC'))
## Not run: 
# Not run because downloads files
sstEdi <- getEdinfo()[['jplMURSST41']]
sstEdi <- varSelect(sstEdi, TRUE)
# default calculates mean, median, and standard deviation
matchEnvData(data, sstEdi)
# get just mean within a buffer around coordinates
matchEnvData(data, sstEdi, FUN = mean, buffer = c(.01, .01, 86400))
# Can also work from an existing nc file
nc <- downloadEnv(data, sstEdi, buffer = c(.01, .01, 86400))
matchEnvData(data, nc = nc)
# Using a custom function
meanPlusOne <- function(x) {
  mean(x, na.rm=TRUE) + 1
}
matchEnvData(data, nc=nc, FUN=c(mean, meanPlusOne))

## End(Not run)

PAMmisc documentation built on Oct. 8, 2021, 9:08 a.m.