Band Collection Statistics (Spatial Analyst)
Summary
Calculates the statistics for a set of raster bands.
Usage
-
The raster bands must have a common intersection. If there is none, an error occurs and no output is created.
-
If the extents of the raster bands are not the same, the statistics will be calculated on the common spatial extent of all the input raster bands. The cell size will be that of the maximum of the input rasters, by default; otherwise, it will depend on the Raster Analysis environment settings.
-
The default setting of the Compute matrices parameter (BRIEF in scripting, unchecked in the tool dialog box) is to only compute the minimum, maximum, mean, and standard deviation of the input raster bands. To calculate these statistics and also the covariance and correlation matrices, set the parameter to DETAILED in scripting, or checked in the tool dialog box. A covariance matrix presents the variances of all raster bands along the diagonal from the upper left to lower right and covariances between all raster bands in the remaining entries. The correlation matrix provides the correlation coefficients between each combination of two input bands.
-
In the calculation of the covariance matrix, the mean value of the band is used for any input cells that are NoData.
-
The statistics are written to the output file in ASCII text format. The extension for the output must be .txt.
-
If the input is a layer created from a multiband raster with more than three bands, the operation will consider all the bands associated with the source dataset, not just the three bands that were loaded (symbolized) by the layer.
There are several ways you can specify a subset of bands from a multiband raster to use as input into the tool.
- If using the tool dialog box, navigate to the multiband raster using the browse button next to Input raster bands, open the raster, and select the desired bands.
- If the multiband raster is a layer in the Table of Contents, you can use the Make Raster Layer tool create a new multiband layer containing only the desired bands.
- You can also create a new dataset that contains only the desired bands with Composite Bands and use the resulting dataset as input to the tool.
- In Python, the desired bands can be directly specified in the tool parameter as a list.
Syntax
Parameter | Explanation | Data Type |
in_raster_bands [in_raster_band,...] |
The input raster bands. | Raster Layer |
out_stat_file |
The output ASCII file containing the statistics. A .txt extension is required. | File |
compute_matrices (Optional) |
Specifies whether covariance and correlation matrices are calculated.
| Boolean |
Code Sample
This example calculates the statistics for a set of raster bands.
import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
BandCollectionStats("redlands", "c:/sapyexamples/output/redbandstats.txt", "BRIEF")
This example calculates the statistics for a set of raster bands.
# Name: BandCollectionStats_Ex_02.py
# Description: Calculates the statistics for a set of raster bands.
# Requirements: Spatial Analyst Extension
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
# Set environment settings
env.workspace = "C:/sapyexamples/data"
# Set local variables
inRasterBand1 = "sb/sbc1"
inRasterBand2 = "sb/sbc2"
outStatFile = "C:/sapyexamples/output/bandstatfile.txt"
# Check out the ArcGIS Spatial Analyst extension license
arcpy.checkOutExtension("Spatial")
# Execute BandCollectionStats
BandCollectionStats([inRasterBand1, inRasterBand2], outStatFile, "DETAILED")