aggregateSpatial: Spatially aggregate a Field

aggregateSpatialR Documentation

Spatially aggregate a Field

Description

Spatially aggregate all gridcells of a Field (or a data.table assuming it has columns "Lon" and "Lat"). Can use a variety of aggregation methods, see argument 'method'

Usage

aggregateSpatial(x, method = "mean", verbose = FALSE, ...)

Arguments

x

Field (or data.table) to be averaged

method

The method with which to spatially aggregate. Can be "weighted.mean", "w.mean", "mean", "weighted.sum", "w.sum", "sum", "mode", "median", "max", "min", "sd", "var" and "cv" (= coefficient of variation: sd/mean).

verbose

If TRUE give some progress update about the averaging.

...

Extra arguments passed to addArea function if a weighted method is being used. Note in particular the lon_centres and lat_centres arguments if you are using a regular but sparsely populated grid.

Details

For summing variables which are defined on a per m^2 use the method = "w.sum" (or "weighted.sum) to scale from m^-2 to gridcell totals before adding (gridcell area calculated by addArea() function). For averaging, use method = "w.mean" (or "weighted.mean") to weight by the gridcell area.

Value

A Field or data.table depending on the input object

Author(s)

Matthew Forrest matthew.forrest@senckenberg.de

Examples


 
# Get an example Field
africa.dir <- system.file("extdata", "LPJ-GUESS_Runs", "CentralAfrica", package = "DGVMTools")
africa.Source <- defineSource(name = "LPJ-GUESS", dir = africa.dir,  format = GUESS)
field <- getField(source = africa.Source, quant = "cmass")

# calculate mean over gridcells and look at the resulting data table
spatial.mean <- aggregateSpatial(x = field, method = "mean", verbose = TRUE)
print(spatial.mean@data)

# do weighted.sum and look at the resulting data table
spatial.wsum <- aggregateSpatial(x = field, method = "w.sum", verbose = TRUE)
print(spatial.wsum@data) 

# plot the weight and unweighted sums as a time series
# (also modify ylab to be more meaningful)
p <- plotTemporal(list(spatial.wsum))
p <- p + ylab("Vegetation Carbon Mass (kgC)")
print(p)



MagicForrest/DGVMTools documentation built on Aug. 23, 2024, 8:05 a.m.