- Dataset.temporal.average(data_var, weighted=True, keep_weights=False)#
Returns a Dataset with the average of a data variable and the time dimension removed.
This method infers the time grouping frequency by checking the distance between a set of upper and lower time bounds. This method is particularly useful for calculating the weighted averages of monthly or yearly time series data because the number of days per month/year can vary based on the calendar type, which can affect weighting. For other frequencies, the distribution of weights will be equal so
weighted=Trueis the same as
Time bounds are used for inferring the time series frequency and for generating weights (refer to the
weightedparameter documentation below).
str) – The key of the data variable for calculating averages
bool, optional) – Calculate averages using weights, by default True.
Weights are calculated by first determining the length of time for each coordinate point using the difference of its upper and lower bounds. The time lengths are grouped, then each time length is divided by the total sum of the time lengths to get the weight of each coordinate point.
The weight of masked (missing) data is excluded when averages are taken. This is the same as giving them a weight of 0.
bool, optional) – If calculating averages using weights, keep the weights in the final dataset output, by default False.
xr.Dataset– Dataset with the average of the data variable and the time dimension removed.
Get weighted averages for a monthly time series data variable:
>>> ds_month = ds.temporal.average("ts") >>> ds_month.ts