xarray.DataArray.pr.sum#
- DataArray.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) DataArray #
Reduce this DataArray’s data by applying
sum
along some dimension(s).By default, works like
xarray.DataArray.sum()
, but has additional features:Dimension aliases can be used instead of full dimension names everywhere.
Instead of specifying the dimension(s) to reduce via
dim
, you can specify the dimensions that the result should have viareduce_to_dim
. Then,sum
will be applied along all other dimensions.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 dimensionstime
andposition
, summing overtime
with the evaluation dimensionposition
will skip only those values where all values with the sameposition
are NA.
skipna
andmin_count
work like in thexarray.DataArray.sum()
function. The behaviour of primap1 is reproduced byskipna=True, min_count=1
.- Parameters:
- dim: str or list of str, optional
Dimension(s) over which to apply
sum
. Only one ofdim
andreduce_to_dim
arguments can be supplied. If neither is supplied, then the sum is calculated over all dimensions.- reduce_to_dim: str or list of str, optional
Dimension(s) of the result. Only one of
dim
andreduce_to_dim
arguments can be supplied. Supplyingreduce_to_dim="dim_1"
is therefore equivalent to givingdim=set(da.dims) - {"dim_1"}
, but more legible.- skipna: bool, optional
If
True
, 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) orskipna=True
has not been implemented (object
,datetime64
ortimedelta64
).- 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
andskipna_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. Ifskipna=False
, all countries in the region need to have non-NA data for that sector, gas, year combination. Ifskipna=True
andmin_count=1
then one country with non-NA data is enough for a non-NA result. All NA values will be treated as zero. Ifmin_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
See also