as_raster: Coerce an LPJmLData object to a Raster* object

View source: R/LPJmLData_as.R

as_rasterR Documentation

Coerce an LPJmLData object to a Raster* object

Description

Function to coerce (convert) an LPJmLData object into a raster or brick object that allows for any GIS-based raster operations. Read more about the raster package at https://rspatial.github.io/raster/reference/raster-package.html. The successor package of raster is called terra: https://rspatial.org/.

Usage

as_raster(x, subset = NULL, aggregate = NULL, ...)

Arguments

x

LPJmLData object

subset

List of array dimension(s) as name/key and corresponding subset vector as value, e.g.list(cell = c(27411:27415)). More information at subset.LPJmLData().

aggregate

List of array dimension(s) as name/key and corresponding aggregation function as value, e.g. list(band = sum).

...

Arguments passed to the aggregate function(s), e.g. na.rm = TRUE.

Details

The ⁠$grid⁠ attribute is required for spatial transformation. When using file_type = "meta", grid data are usually read automatically via add_grid() if the grid file is present in the same directory. Otherwise, add_grid() has to be called explicitly with the path to a matching grid file. Supports either multiple bands or multiple time steps. Use subset or aggregate to reduce data with multiple bands and time steps.

Value

A raster or brick object with spatial extent and coordinates based on internal ⁠$grid⁠ attribute and containing a lon/lat representation of x$data. If multiple bands or time steps exist, a brick is created. Further meta information such as the lon/lat resolution are extracted from ⁠$meta⁠.

Examples

## Not run: 

vegc <- read_io(filename = "./vegc.bin.json")

# Returns a RasterBrick for all data
as_raster(vegc)
# class      : RasterBrick
# dimensions : 280, 720, 201600, 200  (nrow, ncol, ncell, nlayers)
# resolution : 0.5, 0.5  (x, y)
# extent     : -180, 180, -56, 84  (xmin, xmax, ymin, ymax)
# crs        : +proj=longlat +datum=WGS84 +no_defs
# source     : memory
# names      : X1901.12.31, X1902.12.31, X1903.12.31, X1904.12.31, ...
# min values :           0,           0,           0,           0, ...
# max values :    28680.72,    28662.49,    28640.29,    28634.03, ...


## End(Not run)


lpjmlkit documentation built on March 31, 2023, 9:35 p.m.