Get Zarr Variable
Usage
get_var(z, var, start = NA, count = NA)
# S3 method for character
get_var(z, var, start = NA, count = NA)
# S3 method for NetCDF
get_var(z, var, start = NA, count = NA)
# S3 method for ZarrGroup
get_var(z, var, start = NA, count = NA)
# S3 method for `NULL`
get_var(z, var, start = NA, count = NA)
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. -1 can be used to indicate all of a given dimension.
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)
}