MCPcopy Index your code
hub / github.com/pydata/xarray / DatasetCoarsen

Class DatasetCoarsen

xarray/computation/rolling.py:1308–1389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1306
1307
1308class DatasetCoarsen(Coarsen["Dataset"]):
1309 __slots__ = ()
1310
1311 _reduce_extra_args_docstring = """"""
1312
1313 @classmethod
1314 def _reduce_method(
1315 cls, func: Callable, include_skipna: bool = False, numeric_only: bool = False
1316 ) -> Callable[..., Dataset]:
1317 """
1318 Return a wrapped function for injecting reduction methods.
1319 see ops.inject_reduce_methods
1320 """
1321 kwargs: dict[str, Any] = {}
1322 if include_skipna:
1323 kwargs["skipna"] = None
1324
1325 def wrapped_func(
1326 self: DatasetCoarsen, keep_attrs: bool | None = None, **kwargs
1327 ) -> Dataset:
1328 from xarray.core.dataset import Dataset
1329
1330 keep_attrs = self._get_keep_attrs(keep_attrs)
1331
1332 if keep_attrs:
1333 attrs = self.obj.attrs
1334 else:
1335 attrs = {}
1336
1337 reduced = {}
1338 for key, da in self.obj.data_vars.items():
1339 reduced[key] = da.variable.coarsen(
1340 self.windows,
1341 func,
1342 self.boundary,
1343 self.side,
1344 keep_attrs=keep_attrs,
1345 **kwargs,
1346 )
1347
1348 coords = {}
1349 for c, v in self.obj.coords.items():
1350 # variable.coarsen returns variables not containing the window dims
1351 # unchanged (maybe removes attrs)
1352 coords[c] = v.variable.coarsen(
1353 self.windows,
1354 self.coord_func[c],
1355 self.boundary,
1356 self.side,
1357 keep_attrs=keep_attrs,
1358 **kwargs,
1359 )
1360
1361 return Dataset(reduced, coords=coords, attrs=attrs)
1362
1363 return wrapped_func
1364
1365 def reduce(self, func: Callable, keep_attrs=None, **kwargs) -> Dataset:

Callers 1

coarsenMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…