Creates a raster object that is a subset of the input multidimensional raster based on selected variables and dimension intervals.


Use the Subset function to extract a subgroup of variable data from a multidimensional raster object. You can use the subgroup as an input to additional functions. For example, to calculate the average monthly precipitation values for a multidimensional raster that contains both temperature and precipitation data, you can first use Subset to extract the precipitation variable only as a raster object. Then you can use the Aggregate Multidimensional Raster tool to compute the monthly average.

The function creates a raster object that is a subgroup of the input, with dimension and variable information defined by the input parameters.

The referenced raster dataset for the raster object is temporary. To make it permanent, you can call the raster object's save method.


Subset (in_raster, {variables}, {dimension_definitions})
ParameterExplanationData Type

The input multidimensional raster dataset.


A variable name or a list of variable names to be included in the output raster. If not specified, all variables will be included.


The dimension interval used to subset the multidimensional raster. This parameter is passed as a dictionary in which the key:value pairs are described as dimension_name:dimension interval. The key is the name of the dimension along which you wish to subset, and the value is the dimension interval. The dimension interval must use one of the following formats:

  • A single dimension input.

    For example, to subset variables only at the depth of 0, use {"depth": 0 }.

  • A tuple containing the minimum and maximum dimension values.

    For example, to subset variables from a depth of 0 to 100, use {"depth": (-100,0)}.

  • A tuple containing minimum and maximum dimension values, an increment size and an increment unit.

    For example, to subset variables from the year 1980 until the end of the time series, extracting the first day of every year, use {"StdTime": ('1980-01-01T12:00:00', None, 1, 'year')}.

    To subset variables with the time dimension 1980 to 2000, extracting January of every year, use {"StdTime": ('1980-01-01T12:00:00', 1980-31-01T12:00:00', 1, 'year')}.

  • A list containing any of the above. You can include multiple single-dimension inputs and multiple minimum and maximum ranges.

    For example, to subset variables at depths of 0, 50, and 200, use {"depth": [0, -50, -200]}.

    For example, to subset variables from a depth of 0 to 100 and also at a depth of 500, use {"depth": [-500, (-100, 0)]}.

Return Value
Data TypeExplanation

The output subset multidimensional raster.

Code sample

Subset example

Extract four subsets from climate multidimensional data and save the final subset.

# Import system modules
import arcpy
from import *

in_raster = Raster('C:/sapyexamples/data/', True)

# Select two variables: precipitation and water temperature 
out_subset_raster1 = Subset(in_raster, variables = ['precip', 'water_temp'])

# Filter variables that have the Depth dimension and where depth=0.
# For variables that do not have dimension depth, all slices are selected.
out_subset_raster2 = Subset(in_raster, dimension_definitions = {'depth' : 0})   

# Select water temperature data on the 1st of every January
out_subset_raster3 = Subset(
	in_raster, variables = 'water_temp', 
	dimension_definitions = {'time': 
	('1980-01-01T12:00:00', None, 1, 'year')})   

# Select surface water temperature in January 1980
out_subset_raster4 = Subset(
	in_raster, variables = 'water_temp', 
	dimension_definitions  = {'StdTime': 
	('1980-01-01T12:00:00', '1980-01-31T12:00:00'), 'depth': 0})

# Save the water temperature in January 1980"C:/sapyexamples/output/Jan1980_watertemp.crf")