Skip to contents

The surface layer is defined as the first available depth layer in the netCDF file. This is usually the shallowest layer.

Usage

extract3d_surface(data, nc, var = NULL, ...)

Arguments

data

Object containing observation points. Can be a data frame, tibble, sf object with POINT geometries, matrix with column names, or named list.

nc

netCDF source. Can be a file path, vector of file paths, list of file paths, opened ncdf4 object, list of opened objects, or a data frame with a file column.

var

Name of the variable to extract from the netCDF file. If NULL, the function tries to detect the variable automatically from each file. This only works when each netCDF file contains one single variable.

...

Additional arguments passed to extract_to_point().

Value

The input observations with extracted values appended. Data frames, tibbles and sf objects retain their structure; matrices and named lists are returned as data frames.

Examples

nc_file <- system.file(
  "extdata", "example_3d.nc",
  package = "ocean3d"
)

observations <- data.frame(
  lon = c(0, 1),
  lat = c(40, 41),
  date = as.Date(c("2020-01-01", "2020-01-03"))
)

extract3d_surface(
  data = observations,
  nc = nc_file,
  var = "temp"
)
#>   lon lat       date temp
#> 1   0  40 2020-01-01 20.0
#> 2   1  41 2020-01-03 23.5