MCPcopy
hub / github.com/pydata/xarray / _reduce

Method _reduce

xarray/computation/weighted.py:211–232  ·  view source on GitHub ↗

reduce using dot; equivalent to (da * weights).sum(dim, skipna) for internal use only

(
        da: T_DataArray,
        weights: T_DataArray,
        dim: Dims = None,
        skipna: bool | None = None,
    )

Source from the content-addressed store, hash-verified

209
210 @staticmethod
211 def _reduce(
212 da: T_DataArray,
213 weights: T_DataArray,
214 dim: Dims = None,
215 skipna: bool | None = None,
216 ) -> T_DataArray:
217 """reduce using dot; equivalent to (da * weights).sum(dim, skipna)
218
219 for internal use only
220 """
221
222 # need to infer dims as we use `dot`
223 if dim is None:
224 dim = ...
225
226 # need to mask invalid values in da, as `dot` does not implement skipna
227 if skipna or (skipna is None and da.dtype.kind in "cfO"):
228 da = da.fillna(0.0)
229
230 # `dot` does not broadcast arrays, so this avoids creating a large
231 # DataArray (if `weights` has additional dimensions)
232 return dot(da, weights, dim=dim)
233
234 def _sum_of_weights(self, da: T_DataArray, dim: Dims = None) -> T_DataArray:
235 """Calculate the sum of weights, accounting for missing values"""

Callers 3

_sum_of_weightsMethod · 0.95
_sum_of_squaresMethod · 0.95
_weighted_sumMethod · 0.95

Calls 2

dotFunction · 0.90
fillnaMethod · 0.45

Tested by

no test coverage detected