Learn R Programming

bfastSpatial (version 0.6.2)

summaryBrick: Summarize a RasterBrick

Description

Computes pixel-based summary statistics for a multi-layered raster object

Usage

summaryBrick(x, fun, dates = NULL, na.rm = NULL, minDate = NULL,
  maxDate = NULL, sensor = NULL, ...)

Arguments

x

RasterBrick or RasterStack to be summarized

fun

Function to apply to vectors extracted from each pixel

dates

Date. Optional: vector of dates corresponding exactly to layers of x

minDate

Date, Character or Numeric. Optional: minimum date to include in the calculation. Should either be supplied as a date or numeric of length 2 (see Details)

maxDate

Date, Character or Numeric. Optional: maximum date to include in the calculation (see subsetRasterTS). Should either be supplied as a date or numeric of length 2 (see Details)

sensor

Character. Optional: limit calculation to selected (Landsat) sensors. Defaults to NULL for all data.

...

Additional arguments to be passed to mc.calc

Value

A Raster layer representing the summary statistic of each pixel in the input RasterBrick or RasterStack

Details

This function is identical to calc, except for the fact that a number of sensor or date parameters are added to constrain the calculation.

If fun takes a na.rm argument and none is supplied, it will be ignored and the default value for na.rm for that function will be used.

If fun returns a vector of length greater than one, a RasterBrick object will be returned (see fun=range example in examples).

minDate and maxDate are optional arguments to limit the calculation to a specific date range. These arguments can be supplied as Date or Character objects in the form "

See Also

calc annualSummary

Examples

Run this code
# NOT RUN {
# load tura dataset
data(tura)

# median value per pixel
medVI <- summaryBrick(tura, fun=median)
plot(medVI) # use na.rm=TRUE!!
medVI <- summaryBrick(tura, fun=median, na.rm=TRUE)
plot(medVI)

# custom pixel-wise function to count values > 7500
countVal <- function(x){
 return(length(which(x > 7500)))
}
vals <- summaryBrick(tura, fun=countVal)
plot(vals)

# the above could just as easily be done in calc() or mc.calc()
# but summaryBrick allows for additional parameters
# such as minDate and maxDate

# same function, but only for 2005
vals <- summaryBrick(tura, fun=countVal, minDate=c(2005, 1), maxDate=c(2006, 1))
# equivalent to:
vals <- summaryBrick(tura, fun=countVal, minDate="2005-01-01", maxDate="2006-01-01")

# range of values for each pixel
valRange <- summaryBrick(tura, fun=range, na.rm=TRUE)
plot(valRange)
# returns a brick with min and max values
# see ?range
# }

Run the code above in your browser using DataLab