bk_make: bk.R Dean Koch, 2022 S3 class and methods for bk objects...

View source: R/bk.R

bk_makeR Documentation

bk.R Dean Koch, 2022 S3 class and methods for bk objects (grid lists) A "bk" object is just a list of 3-6 objects representing a grid and its data, similar to the "raster" and "SpatRaster" classes in terra and raster. The S3 class doesn't accomplish anything performance-wise. We use it to link blitzKrig grid methods to R's many generic functions (print, plot, etc) in a sensible way, and to point R's internal generic functions (like [, [<-, and length) to look at the contents of bk$gval

Description

At minimum, a "bk" object contains three items:

Usage

bk_make(g)

Arguments

g

list with any of the six named arguments mentioned above (gdim, etc)

Details

  • gdim: vector of two positive integers, the number of grid lines (n = their product)

  • gres: vector of two positive scalars, the resolution (in distance between grid lines)

  • gyx: list of two numeric vectors (lengths matching gdim), the grid line intercepts

This defines the grid dimensions, their spacing (resolution), and the grid extent. All are in the order y, x, so that gdim is consistent with base::dim if we interpret the data grid as a matrix.

  • gval: numeric vector or matrix, the grid data

In the single layer case, data are stored as a vector (the column-vectorization), with NAs representing missing data. In the multi-layer case, the data are stored in a matrix, with layers in columns. For the matrix case only, we use a sparse representation and omit the NAs. This requires an additional indexing vector:

  • idx_grid: length-n numeric vector mapping rows of multi-layer to grid points

Lastly, for geo-referenced data we store the projection info as a WKT CRS

  • crs: character, the CRS for the grid

CONSTRUCTOR

Make a bk grid object

This constructs a "bk" object from a named list containing at least the element gdim. Users can optionally provide other list elements gyx, gres, gval, crs, and idx_grid (which must have one non-NA index for each row in gval. See description).

Typical usage is to pass the results of bk_make to bk_validate. This fills in any missing and checks that all entries are valid and compatible with one another.

Input classes and lengths are checked before returning. gdim and gres are length-2 vectors (with y and x elements) but they can each be specified by a single number, as shorthand to use the same value for y and x. gval should be a matrix or vector of grid data, and crs should be a character string (the WKT representation).

Value

a "bk" object

Examples


# auto-print reminds users to validate
bk_make(list(gdim=10, gres=0.5))


deankoch/pkern documentation built on Oct. 26, 2023, 8:54 p.m.