s2spy.rgdr.utils ================ .. py:module:: s2spy.rgdr.utils .. autoapi-nested-parse:: Commonly used utility functions for s2spy. Attributes ---------- .. autoapisummary:: s2spy.rgdr.utils.XrType Functions --------- .. autoapisummary:: s2spy.rgdr.utils.weighted_groupby s2spy.rgdr.utils.geographical_cluster_center s2spy.rgdr.utils.intervals_subtract Module Contents --------------- .. py:data:: XrType .. py:function:: weighted_groupby(ds: XrType, groupby: str, weight: str, method: str = 'mean') -> XrType Apply a weighted reduction after a groupby call. xarray does not currently support combining `weighted` and `groupby`. An open PR adds supports for this functionality (https://github.com/pydata/xarray/pull/5480), but this branch was never merged. :param ds: Data containing the coordinates or variables specified in the `groupby` and `weight` kwargs. :param groupby: Coordinate which should be used to make the groups. :param weight: Variable in the Dataset containing the weights that should be used. :param method: Method that should be used to reduce the dataset, by default 'mean'. Supports any of xarray's builtin methods, e.g. 'median', 'min', 'max'. :returns: Dataset reduced using the `groupby` coordinate, using weights = based on `ds[weight]`. :rtype: Same as input .. py:function:: geographical_cluster_center(masked_data: xarray.DataArray, reduced_data: xarray.DataArray) -> xarray.DataArray Add the geographical centers to the clusters. :param masked_data: Precursor data before being reduced to clusters, with the dimensions latitude and longitude, and cluster labels added. :type masked_data: xr.DataArray :param reduced_data: Data reduced to the clusters, to which the geographical centers will be added :type reduced_data: xr.DataArray :returns: Reduced data with the latitude and longitude of the geographical centers added as coordinates of the cluster labels. :rtype: xr.DataArray .. py:function:: intervals_subtract(intervals: list[int], n: int) -> list[int] Subtracts n from the interval indices, skipping 0.