Cell Statistics (Spatial Analyst)

Available with Spatial Analyst license.

Available with Image Analyst license.

Summary

Calculates a per-cell statistic from multiple rasters.

The available statistics are Majority, Maximum, Mean, Median, Minimum, Minority, Range, Standard deviation, Sum, and Variety.

Learn more about how Cell Statistics works

Illustration

Cell Statistics illustration
OutRas = CellStatistics([InRas1, InRas2, InRas3], "SUM", "NODATA", "SINGLE_BAND")

Usage

  • The order of the input rasters is irrelevant for this tool.

  • For the Maximum, Minimum, Mean, Median, Majority, Minority and Sum statistic types, if a single raster is used as the input, the output cell values will be the same as the input cell values. For Range and Standard deviation, the output cell values will all be 0. For Variety, it will be 1.

  • If the Process as multiband parameter is unchecked (process_as_multiband is set to SINGLE_BAND in Python), each band from a multiband raster input will be processed separately as a single band raster, and the output will be a single band raster.

    Single-band output when processed as SINGLE_BAND
    The Cell Statistics tool creates a single-band output when processed as SINGLE_BAND.
  • If the Process as multiband parameter is checked (process_as_multiband is set to MULTI_BAND in Python), each multiband raster input will be processed as a multiband raster, and the output will be a multiband raster. The output raster will also be multiband if the inputs are a combination of a multiband raster and constants. The number of bands in each multiband input must be the same.

    The tool will perform the operation on each band from one input using the corresponding band from the other input. If one of the inputs is a multiband raster and the other input is a constant, the tool will perform the operation using the constant value for each band in the multiband input.

    Multiband output when processed as MULTI_BAND.
    The Cell Statistics tool creates a multiband output when processed as MULTI_BAND.
  • See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool.

Syntax

CellStatistics(in_rasters_or_constants, {statistics_type}, {ignore_nodata}, {process_as_multiband})
ParameterExplanationData Type
in_rasters_or_constants
[in_raster_or_constant,...]

A list of input rasters for which a statistic will be calculated for each cell in the Analysis window.

A number can be used as an input; however, the cell size and extent must first be set in the environment.

If the processing_as_multiband parameter is set to MULTI_BAND, all multiband inputs should have an equal number of bands.

Raster Layer; Constant
statistics_type
(Optional)

Specifies the statistic type to be calculated.

  • MEANThe mean (average) of the inputs will be calculated.
  • MAJORITYThe majority (value that occurs most often) of the inputs will be calculated.
  • MAXIMUMThe maximum (largest value) of the inputs will be calculated.
  • MEDIANThe median of the inputs will be calculated.
  • MINIMUMThe minimum (smallest value) of the inputs will be calculated.
  • MINORITYThe minority (value that occurs least often) of the inputs will be calculated.
  • RANGEThe range (difference between largest and smallest value) of the inputs will be calculated.
  • STDThe standard deviation of the inputs will be calculated.
  • SUMThe sum (total of all values) of the inputs will be calculated.
  • VARIETYThe variety (number of unique values) of the inputs will be calculated.

The default statistic type is Mean.

String
ignore_nodata
(Optional)

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

  • DATAAt the processing cell location, if any of the input rasters has NoData, that NoData value will be ignored. The statistics will be computed by only considering the cells with valid data. This is the default.
  • NODATAIf the processing cell location for any of the input rasters is NoData, the output for that cell will be NoData.
Boolean
process_as_multiband
(Optional)

Specifies how the input multiband raster bands will be processed.

  • SINGLE_BANDEach band from a multiband raster input will be processed separately as a single band raster. This is the default.
  • MULTI_BANDEach multiband raster input will be processed as a multiband raster. The operation will be performed for each band from one input using the corresponding band number from the other inputs.
Boolean

Return Value

NameExplanationData Type
out_raster

The output raster.

For each cell, the value is determined by applying the specified statistic type to the input rasters at that location.

Raster

Code sample

CellStatistics example 1 (Python window)

This example calculates the standard deviation per cell on several input Grid rasters and outputs the result as an IMG raster.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outCellStats = CellStatistics(["degs", "negs", "cost"], "STD", "DATA")
outCellStats.save("C:/sapyexamples/output/outcellstats.img")
CellStatistics example 2 (stand-alone script)

This example calculates the range per cell per band on several input multiband rasters and creates a multiband output raster.

# Name: CellStatistics_Ex_standalone.py
# Description: Calculates a per-cell statistic from multiple multiband rasters
#               and process as multiband.
# Requirements: Spatial Analyst Extension

# Import system modules
import arcpy
from arcpy.sa import *

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

# Set the analysis environments
arcpy.env.workspace = "C:/sapyexamples/data"

# Set the local variables
inRaster01 = "degs_MB"
inRaster02 = "negs_MB"
inRaster03 = "cost_MB"

# Execute CellStatistics
outCellStatistics = CellStatistics([inRaster01, inRaster02, inRaster03], "RANGE", "NODATA", "MULTI_BAND")

# Save the output 
outCellStatistics.save("C:/sapyexamples/output/cellstats_MB.tif")

Licensing information

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

Related topics