|
36 | 36 | | |-- DataNode("elevation")
|
37 | 37 | | | Variable("height_above_sea_level")
|
38 | 38 | |-- DataNode("population")
|
| 39 | +
|
| 40 | +
|
| 41 | +DEVELOPERS' NOTE |
| 42 | +---------------- |
| 43 | +The idea of this module is to create a `DataTree` class which inherits the tree structure from TreeNode, and also copies |
| 44 | +the entire API of `xarray.Dataset`, but with certain methods decorated to instead map the dataset function over every |
| 45 | +node in the tree. As this API is copied without directly subclassing `xarray.Dataset` we instead create various Mixin |
| 46 | +classes which each define part of `xarray.Dataset`'s extensive API. |
| 47 | +
|
39 | 48 | """
|
40 | 49 |
|
41 | 50 |
|
@@ -227,8 +236,7 @@ def imag(self):
|
227 | 236 | 'isin', 'astype']
|
228 | 237 |
|
229 | 238 | # TODO NUM_BINARY_OPS apparently aren't defined on DatasetArithmetic, and don't appear to be injected anywhere...
|
230 |
| -#['__array_ufunc__'] \ |
231 |
| -_ARITHMETIC_METHODS_TO_WRAP = REDUCE_METHODS + NAN_REDUCE_METHODS + NAN_CUM_METHODS |
| 239 | +_ARITHMETIC_METHODS_TO_MAP = REDUCE_METHODS + NAN_REDUCE_METHODS + NAN_CUM_METHODS + ['__array_ufunc__'] |
232 | 240 |
|
233 | 241 |
|
234 | 242 | def _wrap_then_attach_to_cls(target_cls_dict, source_cls, methods_to_set, wrap_func=None):
|
@@ -296,7 +304,7 @@ class DataTreeArithmetic(DatasetArithmetic):
|
296 | 304 | because they (a) only call dataset properties and (b) don't return a dataset that should be nested into a new
|
297 | 305 | tree) and some will get overridden by the class definition of DataTree.
|
298 | 306 | """
|
299 |
| - _wrap_then_attach_to_cls(vars(), DatasetArithmetic, _ARITHMETIC_METHODS_TO_WRAP, wrap_func=map_over_subtree) |
| 307 | + _wrap_then_attach_to_cls(vars(), DatasetArithmetic, _ARITHMETIC_METHODS_TO_MAP, wrap_func=map_over_subtree) |
300 | 308 |
|
301 | 309 |
|
302 | 310 | class DataTree(TreeNode, DatasetPropertiesMixin, MappedDatasetMethodsMixin, MappedDataWithCoords, DataTreeArithmetic):
|
@@ -343,6 +351,8 @@ class DataTree(TreeNode, DatasetPropertiesMixin, MappedDatasetMethodsMixin, Mapp
|
343 | 351 |
|
344 | 352 | # TODO dataset methods which should not or cannot act over the whole tree, such as .to_array
|
345 | 353 |
|
| 354 | + # TODO del and delitem methods |
| 355 | + |
346 | 356 | def __init__(
|
347 | 357 | self,
|
348 | 358 | data_objects: Dict[PathType, Union[Dataset, DataArray]] = None,
|
|
0 commit comments