# xarray.group_subtrees

### xarray.group_subtrees(\*trees)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/treenode.py#L810-L873)

Iterate over subtrees grouped by relative paths in breadth-first order.

group_subtrees allows for applying operations over all nodes of a
collection of DataTree objects with nodes matched by their relative paths.

Example usage:

```default
outputs = {}
for path, (node_a, node_b) in group_subtrees(tree_a, tree_b):
    outputs[path] = f(node_a, node_b)
tree_out = DataTree.from_dict(outputs)
```

* **Parameters:**
  **\*trees** (`Tree`) – Trees to iterate over.
* **Yields:**
  * `A tuple` of `the relative path` and `corresponding nodes for each subtree in the`
  * `inputs.`
* **Raises:**
  [**TreeIsomorphismError**](xarray.TreeIsomorphismError.html.md#xarray.TreeIsomorphismError) – If trees are not isomorphic, i.e., they have different structures.

#### SEE ALSO
[`DataTree.subtree`](xarray.DataTree.subtree.html.md#xarray.DataTree.subtree), [`DataTree.subtree_with_keys`](xarray.DataTree.subtree_with_keys.html.md#xarray.DataTree.subtree_with_keys)
