nctoolkit.DataSet.subset#
- DataSet.subset(**kwargs)#
subset: 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”.
- dayslist, range or int
Days(s) to select.
- monthslist, range or int
Month(s) to select.
- yearslist,range or int
Years(s) to select. These should be integers
- hourslist, range or int
Hours(s) to select.
- 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.
- lon: list
The longitude range to select. This must be two variables, between -180 and 180. The variables should be the minimum and maximum longitude.
- lat: list
The latitude range to select. This must be two variables, between -90 and 90. The variables should be the minimum and maximum latitude.
- levelslist
List of the form [min_level, max_level]. Levels/depths between the two will be selected
Examples
If you want to select a single variable do the following:
>>> ds.subset(variable = "var")
If you want to select a list of variables, do this:
>>> ds.subset(variable = ["var1", "var2"])
If you want to select data for January, do the following:
>>> ds.subset(month = 1)
If you want to select a range of months, do the following:
>>> ds.subset(months = range(1, 7))
If you want to select a range of years, for example the 2010s, do the following:
>>> ds.subset(years = range(2010, 2020))
If you want to select the first two timesteps in a dataset, do the following:
>>> ds.subset(timesteps = [0,1])