The main method for selecting parts of a dataset is subset. Its arguments allow partial matches — year works the same as years.
ds.subset(variables=["var1", "var2"]) ds.subset(variables="var1")
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:
ds.subset(year=2000)
Months can be selected the same way as years. The following all do the same thing:
ds.subset(months=[1,2,3,4]) ds.subset(months=range(1,5)) ds.subset(mon=[1,2,3,4]) # partial match on "months"
To select winter:
ds.subset(season="DJF")
To select the first two timesteps in a dataset, either of the following work:
ds.subset(time=[0,1]) ds.subset(time=range(0,2))
Crop to a longitude/latitude box by giving the minimum and maximum of each:
ds.subset(lon=[-80, 90], lat=[50, 80])