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
sumalong some dimension(s).By default, works like
xarray.Dataset.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 (includingentity).You can specify
skipna_evaluation_dimsto skip NA values only if all values along the given dimension(s) are NA. Example: If you have a data array with the dimensionstimeandposition, summing overtimewith the evaluation dimensionpositionwill skip only those values where all values with the samepositionare NA.If you specify
entityin “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).
skipnaandmin_countwork like in thexarray.Dataset.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 of
dimandreduce_to_dimarguments 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
dimandreduce_to_dimarguments can be supplied. Supplyingreduce_to_dim="dim_1"is therefore equivalent to givingdim=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) orskipna=Truehas not been implemented (object,datetime64ortimedelta64).- skipna_evaluation_dims: str or list of str, optional
Dimension(s) to evaluate along to determine if values should be skipped. Only one of
skipnaandskipna_evaluation_dimscan 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=Trueandmin_count=1then one country with non-NA data is enough for a non-NA result. All NA values will be treated as zero. Ifmin_count=0all 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
See also