Subsetting data

The main method for selecting parts of a dataset is subset. Its arguments allow partial matches — year works the same as years.

Variables

python
ds.subset(variables=["var1", "var2"])
ds.subset(variables="var1")

Years

python
ds.subset(years=[2000, 2001])
ds.subset(years=2000)               # a single year works too
ds.subset(years=range(2000, 2010))

subset allows partial matches for its arguments, so the following is equivalent to selecting years=2000:

python
ds.subset(year=2000)

Months

Months can be selected the same way as years. The following all do the same thing:

python
ds.subset(months=[1,2,3,4])
ds.subset(months=range(1,5))
ds.subset(mon=[1,2,3,4])   # partial match on "months"

Seasons

To select winter:

python
ds.subset(season="DJF")

Timesteps

To select the first two timesteps in a dataset, either of the following work:

python
ds.subset(time=[0,1])
ds.subset(time=range(0,2))

Geographic subsetting

Crop to a longitude/latitude box by giving the minimum and maximum of each:

python
ds.subset(lon=[-80, 90], lat=[50, 80])