predict_rasterEngine: Model predictions (including Raster* objects)

Description Usage Arguments Details Author(s) See Also Examples

View source: R/predict_rasterEngine.R

Description

Model predictions (including Raster* objects)

Usage

1
predict_rasterEngine(object, na.rm.mode = TRUE, debugmode = FALSE, ...)

Arguments

object

a model object for which prediction is desired.

na.rm.mode

Logical. Attempt to fix missing data, even if the model object doesn't support na.rm? Default is TRUE.

debugmode

Logical. Internal debugging for the code, will be removed eventually. Default is FALSE.

...

additional arguments affecting the predictions produced.

Details

predict will operate normally, unless a parameter named "newdata" is found and it is of class Raster*. If this occurs, predict will use rasterEngine to perform a prediction. Currently, this works for predict.* statements in which the data to predict on is called by the parameter "newdata", the input data is in the form of a data.frame, and the output is a vector or matrix of numbers or factors.

predict will run in parallel if a cluster is registered with foreach via a do* statement, or if the user uses sfQuickInit().

Author(s)

Jonathan A. Greenberg ([email protected])

See Also

predict

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# This example creates a linear model relating a vegetation
# index (NDVI) to vegetation height, and applies it to a raster
# of NDVI.

# Load up a 3-band image:
tahoe_highrez <- setMinMax(
		brick(system.file("external/tahoe_highrez.tif", package="spatial.tools")))

# Determine NDVI
ndvi_nodrop <- function(GRNIR_image)
{
	red_band <- GRNIR_image[,,2,drop=FALSE]
	nir_band <- GRNIR_image[,,3,drop=FALSE]
	ndvi <- (nir_band-red_band)/(nir_band + red_band)
	return(ndvi)
}

tahoe_ndvi <- rasterEngine(GRNIR_image=tahoe_highrez,fun=ndvi_nodrop)
names(tahoe_ndvi) <- "ndvi"

# Load up Lidar files
tahoe_lidar_highesthit <- setMinMax(
		raster(system.file("external/tahoe_lidar_highesthit.tif", package="spatial.tools")))

tahoe_lidar_bareearth <- setMinMax(
		raster(system.file("external/tahoe_lidar_bareearth.tif", package="spatial.tools")))

# Determine vegetation height:
LIDAR_height <- function(bareearth,firstreturn)
{
	height <- firstreturn-bareearth
	return(height)
}

tahoe_height <- rasterEngine(
		bareearth=tahoe_lidar_bareearth,
		firstreturn=tahoe_lidar_highesthit,
		fun=LIDAR_height)
names(tahoe_height) <- "vegetation_height"

# Stack them:
tahoe_analysis_stack <- stack(tahoe_ndvi,tahoe_height)

# Pick some random points from the stack
randomly_extracted_data <- as.data.frame(sampleRandom(tahoe_analysis_stack,size=100))

# Generate a linear model from these points:
height_from_ndvi_model <- lm(vegetation_height~ndvi,data=randomly_extracted_data)

# Apply model to NDVI image:
# Enable parallel engine to run larger images faster:
# sfQuickInit()
height_from_ndvi_raster <- predict_rasterEngine(object=height_from_ndvi_model,newdata=tahoe_ndvi)
# sfQuickStop()

azvoleff/spatial.tools documentation built on June 4, 2017, 12:08 a.m.