Skip to contents

Get Zarr Variable

Usage

get_var(z, var, start = NA, count = NA, collapse = TRUE, unpack = FALSE, ...)

# S3 method for class 'character'
get_var(z, var, start = NA, count = NA, collapse = TRUE, unpack = FALSE, ...)

# S3 method for class 'NetCDF'
get_var(z, var, start = NA, count = NA, collapse = TRUE, unpack = FALSE, ...)

# S3 method for class 'ZarrGroup'
get_var(z, var, start = NA, count = NA, collapse = TRUE, unpack = FALSE, ...)

# S3 method for class '`NULL`'
get_var(z, var, start = NA, count = NA, collapse = TRUE, unpack = FALSE, ...)

Arguments

z

an open ZarrGroup as returned by open_nz

var

integer or character zero-based index id of variable of interest or name of variable of interest.

start

integer vector with length equal to the number of dimensions of var. Uses R-style 1 indexing. If NA the entire array is returned.

count

integer vector with length equal to the number of dimensions of var. Specifies the size of the returned array along the dimension in question. Can not be NA if start is not NA. NA count in one or more dimensions can be used to indicate all of a given dimension.

collapse

logical if TRUE degenerated dimensions (length=1) will be omitted.

...

passed to RNetCDF var.get.nc

Value

array of data

Examples


if(requireNamespace("pizzarr", quietly = TRUE)) {
z <- open_nz(z_demo())

latitude <- get_var(z, 0)

class(latitude)
dim(latitude)

pr <- get_var(z, "pr") |>
  aperm(c(3,2,1))

pr[pr > 1000] <- NA

image(pr[,,1], col = hcl.colors(12, "PuBuGn", rev = TRUE),
      useRaster = TRUE, axes = FALSE)

dim(pr)

# subsetting

pr <- get_var(z, "pr", start = c(1, 1, 1), count = c(5, 5, -1))

dim(pr)

}

#> [1]  5  5 81

# equivalent data in NetCDF
if(requireNamespace("RNetCDF", quietly = TRUE)) {
  nc <- z_demo(format = "netcdf")

  (get_var(nc, 0))

  pr <- get_var(nc, "pr")

  image(pr[,,1], col = hcl.colors(12, "PuBuGn", rev = TRUE),
        useRaster = TRUE, axes = FALSE)

}