Learn R Programming

gimms (version 0.2.0)

monthlyComposite: Calculate monthly composite images

Description

Based on a user-defined function, e.g. sum for maximum value composites (MVC), aggregate bi-monthly GIMMS datasets to monthly composites.

Usage

## S3 method for class 'RasterStack':
monthlyComposite(x, indices, fun = max, ...)

## S3 method for class 'character': monthlyComposite(x, pos1 = 4L, pos2 = 8L, fun = max, ...)

Arguments

x
RasterStack (requires 'indices') or character vector of filenames. If the latter applies and 'pos1', 'pos2' are not specified, the function will try to retrieve monthly indices from monthlyIndices. N
indices
Numeric. Indices indicating RasterLayers or files from identical months; see stackApply.
fun
Function. Used to calculate monthly composite layers, defaults to sum, i.e. MVC; see stackApply.
...
Further arguments passed on to writeRaster.
pos1,pos2
Numeric. If 'x' is a vector of filenames, the first and last element of the date string to build monthly indices from. Defaults to the GIMMS naming convention; see monthlyIndices and

Value

  • A 'RasterStack' object with monthly composite layers.

See Also

stackApply, monthlyIndices.

Examples

Run this code
## Destination folder for data download
gimms_dir <- paste0(getwd(), "/data")

## Download GIMMS NDVI3g binary data from 2000-2005
gimms_files <- downloadGimms(x = 2000, y = 2005, dsn = gimms_dir)

## Rasterize downloaded GIMMS files from 2000
gimms_raster <- rasterizeGimms(x = gimms_files[1:24], remove_header = TRUE)

## Calculate monthly maximum value composites
indices <- monthlyIndices(gimms_files[1:24])
gimms_raster_mvc <- monthlyComposite(gimms_raster, indices = indices)

plot(gimms_raster_mvc[[1:4]])

Run the code above in your browser using DataLab