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.

## Illustration

## Usage

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

For statistic types Maximum, Minimum, Mean, Median, Majority, Minority and Sum, 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, and for Variety, all 1.

When a multiband raster is specified as one of the Input rasters or constant values (in_rasters_or_constants in Python), all the bands will be used.

To process a selection of bands from a multiband raster, you can first create a new raster dataset composed of those particular bands with the Composite Bands tool, and use the result in the list of the Input rasters or constant values (in_rasters_or_constants in Python).

To process a selection of bands from a multiband raster, first create a new raster dataset composed of those particular bands with the Composite Bands tool. You can then use the resulting multiband rasters as inputs to this tool.

To treat all bands from multiband inputs equally, uncheck the Process as multiband parameter (process_as_multiband is set to SINGLE_BAND in Python). This means any multiband rasters will be converted into multiple single-band rasters. The tool will then operate across all of the input bands, and return the result of the statistic being calculated on them as a single-band output raster.

Cell Statistics creates a single-band output when processed as SINGLE_BAND. To process a selection of bands from a multiband raster, first create a new raster dataset composed of those particular bands with the Composite Bands tool. You can then use the resulting multiband rasters as inputs to the tool.

To calculate multiband output statistics from multiband input rasters, check the Process as multiband parameter (process_as_multiband is set to MULTI_BAND in Python). In this case, each multiband input will be used to calculate band-wise statistics. This means the statistic will be calculated for the first band across all the inputs, then the second band across all the inputs, and so on. The results from each band will be used to create a multiband output. In this case, all inputs must have an equal number of bands.

Cell Statistics creates a multiband output when processed as MULTI_BAND. All of the multiband inputs must have an equal number of bands. If some of your intended inputs have fewer than others, you will need to create new NoData bands to get equal number of bands for all inputs. You can do this by using the Composite Bands tool to create new multiband datasets, combining the existing bands with NoData for the missing bands. You can then use the resulting multiband rasters as inputs to the tool.

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})

Parameter | Explanation | Data Type |

in_rasters_or_constants [in_raster_or_constant,...] | A list of input rasters for which a statistic will be calculated for each cell within 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) | Statistic type to be calculated. - MEAN —Calculates the mean (average) of the inputs.
- MAJORITY —Determines the majority (value that occurs most often) of the inputs.
- MAXIMUM —Determines the maximum (largest value) of the inputs.
- MEDIAN —Calculates the median of the inputs.
- MINIMUM —Determines the minimum (smallest value) of the inputs.
- MINORITY —Determines the minority (value that occurs least often) of the inputs.
- RANGE —Calculates the range (difference between largest and smallest value) of the inputs.
- STD —Calculates the standard deviation of the inputs.
- SUM —Calculates the sum (total of all values) of the inputs.
- VARIETY —Calculates the variety (number of unique values) of the inputs.
The default statistic type is Mean. | String |

ignore_nodata (Optional) | Denotes whether NoData values are ignored by the statistic calculation. - DATA —At the processing cell location, if any of the input rasters has NoData, then that NoData value will be ignored. The statistics will be computed by only considering the cells with valid data. This is the default.
- NODATA —If the processing cell location for any of the input rasters is NoData, then the output for that cell will be NoData.
| Boolean |

process_as_multiband (Optional) | Determines how multiband input rasters bands are processed. - SINGLE_BAND —All multibands will be processed as single bands. This is the default.
- MULTI_BAND — All multiband inputs will be processed as multiband.
| Boolean |

#### Return Value

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

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")
```

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")
```

## Environments

## Licensing information

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