KernelDensity

Estimates the density of the values of a raster: for each cell, it sums the values of the cells within a radius, each weighted by a kernel that decreases with the distance from the cell. Applied to a map of presences, with 1 where something is and 0 elsewhere, it gives how concentrated they are around each cell: the density of the channels, of the landslides, of the trees found by a lidar survey.

The kernels are the ones of the Jaitools project, and the Epanechnikov one is the default. The weights are not normalized: the result is a weighted count, whose scale depends on the kernel and on the radius, so the maps are good to compare areas with each other, computed with the same settings.

The cells that have no value in the input have no value in the output, as the ones closer to the border than the radius. For a density everywhere, the cells without presence must be 0, not novalue, as in the example.

Details

The kernel is a circle of the given radius in cells, from the Jaitools project, with weights that follow the chosen function of the distance from the center (all the same for the binary one). The weights are not normalized: the output is the weighted sum of the values, so with values of 1 it is a weighted count of the cells, and its scale depends on the kernel and the radius.

The novalues of the neighbours count as 0. The cells that are novalue in the input, and those closer to the border of the map than the radius, are novalue in the output: to get a density everywhere, give 0 to the cells without presence instead of novalue.

The kernel codes are: 0 binary, 1 cosine, 2 distance, 3 Epanechnikov, 4 Gaussian, 5 inverse distance, 6 quartic, 7 triangular, 8 triweight.

Parameters

Kernel density estimator: for each cell, the sum of the values of the cells within a radius, each weighted by a kernel that decreases with the distance. Applied to a map of presences, as 1 for the channels and 0 elsewhere, it gives their density.

Toolbox folder: Raster Processing
Status: Experimental
Keywords: Kernel Density, Raster
Authors: Andrea Antonello, Diego Bengocheapaz
Class: org.hortonmachine.modules.KernelDensity

Inputs

Parameter

Type

Unit

Default

Description

inMap

raster file

The map of the values, as presences or quantities.

pKernel

int

3

The code of the kernel: 0 binary, 1 cosine, 2 distance, 3 Epanechnikov, 4 Gaussian, 5 inverse distance, 6 quartic, 7 triangular, 8 triweight.

pRadius

int

10

The radius of the kernel, in cells.

doConstant

boolean

false

If true, every valid cell counts as 1 instead of its value.

Outputs

Parameter

Type

Unit

Description

outDensity

output file

The kernel weighted sum of the values around each cell.

Example

The example runs on the sample elevation model of the manual, dtm_flanginec.tif in docs/manual/modules/maps/data, each module on the outputs of the previous ones. Mapcalc turns the network of ExtractNetwork into presences, then the module sums them within 100 m:

import org.hortonmachine.modules.KernelDensity
import org.hortonmachine.modules.Mapcalc

// the folder with the elevation model: change it to yours
var folder = "/data/flanginec/"

// the channels of ExtractNetwork as presences: 1 on the network, 0 elsewhere
var mapcalc = new Mapcalc()
mapcalc.inRaster1 = folder + "net.tif"
mapcalc.pFunction = """
images {
    net = read;
    channels = write;
}
channels = con(isnull(net), 0, 1);
"""
mapcalc.outRaster = folder + "channels.tif"
mapcalc.process()

// the density of the channels within 10 cells, 100 m
var density = new KernelDensity()
density.inMap = folder + "channels.tif"
density.pRadius = 10
density.outDensity = folder + "channels_density.tif"
density.process()
The density of the channels within 100 m: highest where many channels converge, as on the fan in the north east. The cells with no channel within 100 m are zero and not colored; the band of 100 m along the border has no value.

The density of the channels within 100 m: highest where many channels converge, as on the fan in the north east. The cells with no channel within 100 m are zero and not colored; the band of 100 m along the border has no value.