# Focal Statistics (Image Analyst)

## Summary

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

## Usage

• There are several neighborhood shapes and statistics types to choose from. The available statistics depend on the type of the input raster.

• 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 How Focal Statistics works for information about creating and using kernel files.

• For integer input rasters, the valid choices for Statistics type are: majority, maximum, mean, median, minimum, minority, percentile, range, standard deviation, sum, and variety. For float input rasters, the valid statistics are: maximum, mean, median, minimum, percentile, range, standard deviation, and sum. Majority, minority, and variety are not available.

• If the input raster is integer, the output raster will be integer for the following statistics: majority, maximum, minimum, minority, range, sum, and variety. The output will be float for: mean, median, percentile, and standard deviation.

If the input raster is of float type, the output will be float for all of the available statistic types.

• For the Median setting of the Statistics type parameter, if the neighborhood has an odd number of cells, the values will be ranked and the middle value will be reported as the median. If the neighborhood has an even number of cells, the values will be ranked and the middle two values will be averaged.

• For the Majority setting of the Statistics type parameter, if one cell value occurs most frequently in the neighborhood (a single value with the highest frequency of occurrence), that value will be returned for the processing cell. If two or more cell values have the highest frequency of occurrence (a tie among cell values), no single majority value is identified, and the output for that processing cell will be NoData. For the Minority setting, ties among the least frequently occurring values in a neighborhood will also be assigned NoData.

• The Neighborhood parameter can be set to Weight only for the Mean, Standard deviation, and Sum statistic types.

• 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.

## Parameters

### Return Value

 Label Explanation Data Type Output raster The output focal statistics raster. Raster

`FocalStatistics(in_raster, {neighborhood}, {statistics_type}, {ignore_nodata}, {percentile_value})`

### Return Value

 Name Explanation Data 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