arctichoke.analysis.sum_by_year

Functions

sum_by_year(dataset[, attr_long_name, attr_units, ...])

Sum a dataset by year along the time axis.

Module Contents

arctichoke.analysis.sum_by_year.sum_by_year(dataset: str, [str], xarray.DataArray, xarray.Dataset, attr_long_name: str = None, attr_units: str = None, save_as: str = None, verbose: bool = False, **kwargs)

Sum a dataset by year along the time axis.

Groups the dataset by year and sums each year. This results in one time step for each year in the given dataset.

Parameters:
  • dataset (str, list of str, xarray.DataArray, xarray.Dataset) – The dataset of which to sum by year.

  • attr_long_name (str, None, optional) – The name of the variable for which to put in the long_name attribute. Default is None, which uses the original long_name plus ‘Yearly Sum of ‘.

  • attr_units (str, None, optional) – The units of the variable for which to put in the units attribute. Default is None, which uses the original units plus ‘_per_year’.

  • save_as (str, None, optional) – The file name to which to save the modified dataset. Default is None, which doesn’t save the dataset to a file.

  • verbose (bool, optional) – Whether to verbosely output information as the function executes. Default is False.

  • **kwargs – Keyword arguments to pass to xr.sum().

Returns:

dataset – A dataset where the data has been summed by year.

Return type:

xarray.Dataset

Examples

>>> from arctichoke.dataset.example_dataset import make_example_dataset
>>> dataset = make_example_dataset(n=3, time_axis=True)
>>> dataset['test_var'].values
array([[[0., 1., 2.],
        [3., 4., 5.],
        [6., 7., 8.]],
[[0., 1., 2.],

[3., 4., 5.], [6., 7., 8.]]])

>>> from arctichoke.analysis.sum_by_year import sum_by_year
>>> dataset_year_sum = sum_by_year(dataset)
>>> dataset_year_sum['test_var_year_sum'].values
array([[[ 0.,  2.,  4.],
        [ 6.,  8., 10.],
        [12., 14., 16.]]])