Focal Statistics (Image Analyst)

Available with Spatial Analyst license.

Available with Image Analyst license.

Summary

Calculates for each input cell location a statistic of the values within a specified neighborhood around it.

Learn more about how Focal Statistics works

Illustration

Focal Statistics illustration
OutRas = FocalStatistics(InRas1, NbrRectangle(3,3,MAP), "SUM", "")

Usage

  • If the input raster is integer, all the statistics types are available. If the input raster is floating point, only the Mean, Maximum, Median, Minimum, Percentile, Range, Standard deviation, and Sum statistics are available; the Majority, Minority, and Variety statistics are not permitted.

  • When a circular, an annulus-shaped, or a wedge-shaped neighborhood is specified, some of the outer diagonal cells may not be considered in the calculations because the center of the cell must be encompassed within the neighborhood.

  • The Irregular and Weight Neighborhood types require that a Kernel file be specified. Kernel files should have a .txt file extension.

    See the Irregular and Weight sections of Learn more about how Focal Statistics works for information on creating and using kernel files.

  • The Neighborhood type can be set to Weight for the Mean, Standard Deviation, and Sum statistics types only.

  • Input NoData cells may receive a value in the output if the Ignore NoData in calculations parameter is checked, provided at least one cell within the neighborhood has a valid value.

Syntax

FocalStatistics(in_raster, {neighborhood}, {statistics_type}, {ignore_nodata}, {percentile_value})
ParameterExplanationData Type
in_raster

The raster for which the focal statistics for each input cell will be calculated.

Raster Layer
neighborhood
(Optional)

The Neighborhood class dictates the shape of the area around each cell used to calculate the statistic.

The available neighborhood types are NbrAnnulus, NbrCircle, NbrRectangle, NbrWedge, NbrIrregular, and NbrWeight.

The following are the forms of the neighborhoods:

  • NbrAnnulus({innerRadius}, {outerRadius}, {units})
  • NbrCircle({radius}, {units}
  • NbrRectangle({width}, {height}, {units})
  • NbrWedge({radius}, {startAngle}, {endAngle}, {units})
  • NbrIrregular(inKernelFile)
  • NbrWeight(inKernelFile)

The default neighborhood is a square NbrRectangle with a width and height of three cells.

Neighborhood
statistics_type
(Optional)

Specifies the statistic type to be calculated.

  • MEANCalculates the mean (average value) of the cells in the neighborhood.
  • MAJORITYCalculates the majority (value that occurs most often) of the cells in the neighborhood.
  • MAXIMUMCalculates the maximum (largest value) of the cells in the neighborhood.
  • MEDIANCalculates the median of the cells in the neighborhood.
  • MINIMUMCalculates the minimum (smallest value) of the cells in the neighborhood.
  • MINORITYCalculates the minority (value that occurs least often) of the cells in the neighborhood.
  • PERCENTILECalculates a percentile of the cells in the neighborhood. The 90th percentile is calculated by default. You can specify other values (from 0 to 100) using the Percentile value parameter.
  • RANGECalculates the range (difference between largest and smallest value) of the cells in the neighborhood.
  • STDCalculates the standard deviation of the cells in the neighborhood.
  • SUMCalculates the sum (total of all values) of the cells in the neighborhood.
  • VARIETYCalculates the variety (the number of unique values) of the cells in the neighborhood.

The default statistic type is Mean.

If the input raster is integer, all the statistics types are available. If the input raster is floating point, only the Mean, Maximum, Median, Minimum, Percentile, Range, Standard deviation, and Sum statistic types are available.

String
ignore_nodata
(Optional)

Specifies whether NoData values will be ignored by the statistic calculation.

  • DATAIf a NoData value exists within a neighborhood, the NoData value will be ignored. Only cells within the neighborhood that have data values will be used in determining the output value. This means that if the processing cell value is NoData, the processing cell may receive a value in the output raster if this option is selected, provided at least one cell within the neighborhood has a valid value. This is the default.
  • NODATAIf any cell in a neighborhood has a value of NoData, the output for the processing cell will be NoData. With this option, the presence of a NoData value implies that there is insufficient information to determine the statistic value for the neighborhood.
Boolean
percentile_value
(Optional)

The percentile to calculate. The default is 90, for the 90th percentile.

The values can range from 0 to 100. The 0th percentile is essentially equivalent to the Minimum statistic, and the 100th percentile is equivalent to Maximum. A value of 50 will produce essentially the same result as the Median statistic.

This option is only supported if the statistics_type parameter is set to percentile. If any other statistics type has been specified, this parameter will be ignored.

Double

Return Value

NameExplanationData Type
out_raster

The output focal statistics raster.

Raster

Code sample

FocalStatistics example 1 (Python window)

This example calculates the least-frequently occurring value in a ring-shaped neighborhood around each cell in the input raster.

import arcpy
from arcpy import env
from arcpy.ia import *
env.workspace = "C:/data"
outFocalStat = FocalStatistics("elevation", NbrAnnulus(5, 10, "CELL"), 
                               "MINORITY", "NODATA")
outFocalStat.save("C:/output/focalstat01")
FocalStatistics example 2 (stand-alone script)

This example determines the least frequently occurring value in a 10-by-10 neighborhood around each cell in the input raster.

# Name: FocalStatistics_Ex_02.py
# Description: Calculates a statistic on a raster over a specified
#    neighborhood.
# Requirements: Image Analyst Extension

# Import system modules
import arcpy
from arcpy import env
from arcpy.ia import *

# Set environment settings
env.workspace = "C:/data"

# Set local variables
inRaster = "elevation"
neighborhood = NbrRectangle(10, 10, "CELL")

# Check out the ArcGIS Image Analyst extension license
arcpy.CheckOutExtension("ImageAnalyst")

# Execute FocalStatistics
outFocalStatistics = FocalStatistics(inRaster, neighborhood, "MINORITY",
                                     "")

# Save the output 
outFocalStatistics.save("C:/output/focalstatout")

Licensing information

  • Basic: Requires Image Analyst or Spatial Analyst
  • Standard: Requires Image Analyst or Spatial Analyst
  • Advanced: Requires Image Analyst or Spatial Analyst

Related topics