xarray.Dataset.pr.sum

Contents

xarray.Dataset.pr.sum#

Dataset.pr.sum(dim: DimOrDimsT | None = None, *, reduce_to_dim: DimOrDimsT | None = None, skipna: bool | None = None, skipna_evaluation_dims: DimOrDimsT | None = None, keep_attrs: bool = True, min_count: int | None = None) DatasetOrDataArray#

Reduce this Dataset’s data by applying sum along some dimension(s).

By default, works like xarray.Dataset.sum(), but has additional features:

  1. Dimension aliases can be used instead of full dimension names everywhere.

  2. Instead of specifying the dimension(s) to reduce via dim, you can specify the dimensions that the result should have via reduce_to_dim. Then, sum will be applied along all other dimensions (including entity).

  3. You can specify skipna_evaluation_dims to skip NA values only if all values along the given dimension(s) are NA. Example: If you have a data array with the dimensions time and position, summing over time with the evaluation dimension position will skip only those values where all values with the same position are NA.

  4. If you specify entity in “dim”, the Dataset is converted to a DataArray and summed along the data variables (which will only work if the units of the DataArrays are compatible).

skipna and min_count work like in the xarray.Dataset.sum() function. The behaviour of primap1 is reproduced by skipna=True, min_count=1.

Parameters:
dim: str or list of str, optional

Dimension(s) over which to apply sum. Only one of dim and reduce_to_dim arguments can be supplied. If neither is supplied, then the sum is calculated over all dimensions. Use “entity” to convert to a DataArray and sum along the data variables.

reduce_to_dim: str or list of str, optional

Dimension(s) of the result. Only one of dim and reduce_to_dim arguments can be supplied. Supplying reduce_to_dim="dim_1" is therefore equivalent to giving dim=set(da.dims) + {"entity"} - {"dim_1"}, but more legible.

skipna: bool, optional

If True (default), skip missing values (as marked by NaN). By default, only skips missing values for float dtypes; other dtypes either do not have a sentinel missing value (int) or skipna=True has not been implemented (object, datetime64 or timedelta64).

skipna_evaluation_dims: str or list of str, optional

Dimension(s) to evaluate along to determine if values should be skipped. Only one of skipna and skipna_evaluation_dims can be supplied. If all values along the specified dimensions are NA, the values are skipped, other NA values are not skipped and will lead to NA in the corresponding result.

keep_attrs: bool, optional

Keep the attr metadata (default True).

min_count: int (default None, but set to 1 if skipna=True)

The minimal number of non-NA values in a sum that is necessary for a non-NA result. This only has an effect if skipna=True. As an example: you sum data for a region for a certain sector, gas and year. If skipna=False, all countries in the region need to have non-NA data for that sector, gas, year combination. If skipna=True and min_count=1 then one country with non-NA data is enough for a non-NA result. All NA values will be treated as zero. If min_count=0 all NA values will be treated as zero also if there is no single non-NA value in the data that is to be summed.

Returns:
summedxr.DataArray | xr.Dataset