geozarr_array: GeoZarr Array

geozarr_arrayR Documentation

GeoZarr Array

Description

This class implements a GeoZarr array. A GeoZarr array is like a regular Zarr array but it has attributes and/or associated Zarr arrays that provide a coordinate system for the array.

Super classes

zarr::zarr_object -> zarr::zarr_node -> zarr::zarr_array -> geozarr_array

Active bindings

coordinate_system

(read-only) Retrieve the coordinate system of this array.

Methods

Public methods

Inherited methods

geozarr_array$new()

Initialize a new GeoZarr array.

Usage
geozarr_array$new(name, metadata, parent, store, coord_sys)
Arguments
name

The name of the GeoZarr array.

metadata

List with the metadata of the array.

parent

The parent zarr_group instance of this new array, can be missing or NULL if the Zarr object should have just this array.

store

The zarr_store instance to persist data in.

coord_sys

Optional, an instance of CoordinateSystem providing the coordinate system of the array. If not provided, the coordinate system is constructed from the metadata of the array persisted in the store.

Returns

An instance of geozarr_array.


geozarr_array$post_open()

Perform any processing after the Zarr hierarchy is in place and out-of-group references can be resolved.

Usage
geozarr_array$post_open()
Returns

Self, invisibly.


geozarr_array$build_coordsys()

Build the coordinate system of the GeoZarr array if it has not been set yet. This should only be called when the Zarr hierarchy is in place and out-of-group references can be resolved, particularly for the cs convention.

Usage
geozarr_array$build_coordsys()
Returns

Self, invisibly.


geozarr_array$subset()

This method extracts a subset of values from the GeoZarr array, with the range along each axis to extract expressed in coordinate values of the domain of each axis.

Usage
geozarr_array$subset(
  ...,
  .name = NULL,
  .location = NULL,
  .rightmost.closed = FALSE
)
Arguments
...

One or more arguments of the form axis = range. The "axis" part should be the name of an axis or its abbreviation X, Y, Z or T. The "range" part is a vector of values representing coordinates along the axis where to extract data. Axis abbreviations and names are case-sensitive and can be specified in any order. If values for the range per axis fall outside of the extent of the axis, the range is clipped to the extent of the axis.

.name

The name of the GeoZarr array to be created. If omitted, an array will be created at the root of a new in-memory Zarr store.

.location

Optional. If supplied, either an existing zarr_group in a zarr object, or a character string giving the location on a local file system where to persist the data. If the argument is a zarr_group, argument .name must be provided. If the argument gives the location for a new Zarr store then the location must be writable by the calling code. As per the Zarr specification, it is recommended to use a location that ends in ".zarr" when providing a location for a new store. If argument .name is given then the geozarr_array will be created in the root of the zarr store with that name. If the .name argument is not given, a single-array Zarr store will be created. If the location argument is not given, a zarr object is created in memory.

.rightmost.closed

Optional. Single logical value to indicate if the upper boundary of range in each axis should be included.

Details

The range of values along each axis to be subset is expressed in coordinates of the domain of the axis. Any axes for which no selection is made in the ... argument are extracted in whole. Coordinates can be specified in a variety of ways that are specific to the nature of the axis. For numeric axes it should (resolve to) be a vector of real values from which the range is computed. For time axes a vector of character timestamps, POSIXct or Date values must be specified. As with numeric values, only the two extreme values in the vector will be used. For character axes the order in the axis will be used, with the first and last value in the supplied range.

If the range of coordinate values for an axis in argument ... extends the valid range of the axis, the extracted data will start at the beginning for smaller values and extend to the end for larger values. If the values envelope the valid range the entire axis will be extracted in the result. If the range of coordinate values for any axis are all either smaller or larger than the valid range of the axis then nothing is extracted and NULL is returned.

The extracted data has the same dimensional structure as the data in the array, with degenerate dimensions preserved. The order of the axes in argument ... does not reorder the axes in the result.

Arguments following ... must be explicitly named, like .rightmost.closed = TRUE, to avoid the argument being treated as an axis name.

As an example, to extract values of a variable for Australia for the year 2020, where the first axis in GeoZarr array x is the longitude, the second axis is the latitude, both in degrees, and the third (and final) axis is time, the values are extracted by x$subset(X = c(112, 154), Y = c(-9, -44), T = c("2020-01-01", "2021-01-01")). Note that this works equally well for projected coordinate reference systems - the key is that the specification in argument ... uses the same domain of values as the respective axes in x use.

Returns

If the .location argument is a zarr_group, the new Zarr geozarr_array is returned, with a subset of data from this GeoZarr array, having the axes and attributes of this GeoZarr array. Otherwise, the zarr object that is newly created and which contains the geozarr_array instance, or an error if the zarr object could not be created. If one or more of the selectors in the ... argument fall entirely outside of the range of the axis NULL is returned.


geozarr_array$write_external_coordinates()

Write any external coordinates of this array to the underlying Zarr store. The metadata of this array is scanned for ref objects in the cs convention attributes. The values of the external coordinates are taken from the CoordinateSystem instance of this array.

Usage
geozarr_array$write_external_coordinates()
Returns

Self, invisibly.


geozarr documentation built on Sept. 16, 2026, 1:07 a.m.