get_var: Retrieve a variable as array or stars object.

View source: R/nc.R

get_varR Documentation

Retrieve a variable as array or stars object.

Description

Data are stored as [lon, lat, time] or [lon, lat, lev, time] Degenerate indices (dimension = 1) are discarded, so if a single time is requested for a [lon, lat, time] variable then a single band object is returned.

Usage

get_var(
  x,
  var = "tmpsfc",
  bb = get_bounds(x),
  time = get_loc(x, "time")[1:3],
  lev = get_loc(x, "lev")[1:5],
  nav = NULL,
  shift = 2,
  form = c("array", "stars")[2]
)

Arguments

x

ncdf4 object

var

character, one or more names of the variables to retrieve

bb

a 4 element bounding box for subsetting ordered as [xmin, xmax, ymin, ymax]

time

POSIXct vector of one or more times to retrieve. These are matched the closest known times in the object. See get_time Default is the first recorded time in the object. See shift argument

lev

numeric vector of one or more levels. These are matched the closest known levels in the object. See get_lev Default is the first level time in the object. Ignored if lev is not a dimension of the variable.

nav

list, see get_navigation If not provided then computed from bb, time and lev. If provided then bb, time and lev are ignored (since you have already computed the navigation.)

shift

2 number of days to shift the input time - see get_time. Set to 0 to add no shift

form

character either 'array' of 'stars' (default)

  • arrayan array or list of arrays, possibly degenerate to a matrix

  • starsa stars object, possibly with band (time) and z (level)

Details

The requested bounding box coordinates are matched to the closest grid cell centers, thus the output grids may differ in extent form the requested bounding box.

Requested times and levels are considered contiguous - we are extracting slabs of data after all. Currently the first and last times or levels requested mark the inclusive bounds of the slab in those dimensions. Requesting a single time or level works pefectly well. If you need disjoint bands (not contiguous bands) then you will need to make a separate request for each.


BigelowLab/nam218grads documentation built on Oct. 4, 2022, 2:01 a.m.