R/getVariable.R

Defines functions getVariable

Documented in getVariable

#' Extract Variable
#'
#' Extract specified variable from netCDF.  Suggested use for filling template rasters
#' @param nc_path Path to netCDF file.
#' @param name Name of variable to extract.
#' @export
#' @return \code{raster} object
#' @examples
#' getVariable(nc_path = '.../smos.nc', name = 'Soil_Moisture')

getVariable <- function(nc_path,
                        name){
  # open connection to netcdf
  nc <- ncdf4::nc_open(nc_path)

  # get lat, lon, and values and place into list
  z = ncdf4::ncvar_get(nc, name)

  # close connection to netcdf
  ncdf4::nc_close(nc)

  # return
  return(z)
}
ssaxe-usgs/EASEgridR documentation built on May 27, 2019, 3:32 p.m.