nctoolkit.DataSet.select

DataSet.select(self, \*\*kwargs)

A method for subsetting datasets to specific variables, years, longitudes etc. Operations are applied in the order supplied.

Parameters

*kwargs

Possible arguments: variables, years, months, seasons, timesteps, lon, lat

Note: this uses partial matches. So year, month, var etc. will also work

Each kwarg works as follows:

variablesstr or list

A variable or list of variables to select. This method will accept wild cards. So using ‘var*’ would select all variables beginning with ‘var’.

seasonsstr

Seasons to select. One of “DJF”, “MAM”, “JJA”, “SON”.

monthslist, range or int

Month(s) to select.

yearslist,range or int

Years(s) to select. These should be integers

rangelist

List of the form [date_min, date_max], where dates must be datetime objects or strings of the form “DD/MM/YYYY” or “DD-MM-YYYY”. Times selected will be on or after date_min and before date_max.

timestepslist or int

time step(s) to select. For example, if you wanted the first time step set times=0.

Examples

If you want to select a single variable do the following:

>>> ds.select(variable = "var")

If you want to select a list of variables, do this:

>>> ds.select(variable = ["var1", "var2"])

If you want to select data for January, do the following:

>>> ds.select(month = 1)

If you want to select a range of months, do the following:

>>> ds.select(months = range(1, 7))

If you want to select a range of years, for example the 2010s, do the following:

>>> ds.select(years = range(2010, 2020))

If you want to select the first two timesteps in a dataset, do the following:

>>> ds.select(timesteps = [0,1])