xarray.DataArray.pr.count

xarray.DataArray.pr.count#

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

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

By default, works like xarray.DataArray.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.

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.

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) - {"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’s da.count().

Returns:
counted: xr.DataArray