xarray.Dataset.pr.count

xarray.Dataset.pr.count#

Dataset.pr.count(dim: DimOrDimsT | None = None, *, reduce_to_dim: DimOrDimsT | None = None, keep_attrs: bool = True, **kwargs) Dataset | DataArray#

Reduce this Dataset by counting along some dimension(s).

By default, works like xarray.Dataset.count(), but with some 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, count will be applied along all other dimensions (including entity).

  3. If you specify entity in “dim”, the Dataset is converted to a DataArray and counted along the data variables.

Parameters:
dim: str or list of str, optional

Dimension(s) over which to apply count. Only one of dim and reduce_to_dim arguments can be supplied. If neither is supplied, then the count 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.

keep_attrs: bool, optional

Keep the attr metadata (default True).

**kwargs: dict

Additional keyword arguments are passed directly to xarray.Dataset.count().

Returns:
countedxr.Dataset or xr.DataArray if “entity” in dims.