datatree.DataTree.map_over_subtree#

DataTree.map_over_subtree(func: Callable, *args: Iterable[Any], **kwargs: Any) Union[datatree.datatree.DataTree, Tuple[datatree.datatree.DataTree]][source][source]#

Apply a function to every dataset in this subtree, returning a new tree which stores the results.

The function will be applied to any dataset stored in this node, as well as any dataset stored in any of the descendant nodes. The returned tree will have the same structure as the original subtree.

func needs to return a Dataset in order to rebuild the subtree.

Parameters
  • func (callable()) – Function to apply to datasets with signature: func(node.ds, *args, **kwargs) -> Dataset.

    Function will not be applied to any nodes without datasets.

  • *args (tuple, optional) – Positional arguments passed on to func.

  • **kwargs (Any) – Keyword arguments passed on to func.

Returns

subtrees (DataTree, Tuple of DataTrees) – One or more subtrees containing results from applying func to the data at each node.