Skip to content
This repository was archived by the owner on Oct 24, 2024. It is now read-only.
This repository was archived by the owner on Oct 24, 2024. It is now read-only.

Weighting a tree by a tree of dataarrays isn't possible #193

Closed
@TomNicholas

Description

@TomNicholas

ds.weighted(da).mean() can't be easily generalised to involve two trees, because there is no tree version of a dataarray. This is one reason why I haven't tried to write .weighted for datatree yet.

We should be able to generalise an operation involving multiple datasets such as ds.weighted(ds).mean(), i.e. dt.weighted(dt).mean() (as it's equivalent to dt + dt from map_over_subtree's perspective), but this particular weighted operation doesn't actually make sense.

We could also do dt.weighted(da).mean(), but I don't see how to make something like dt.weighted(dt).mean() work nicely.

The problem is that you can't weight by multiple variables, but at the moment you can't extract one variable from a node and retain the tree structure.

You could do this though, this is well-defined:

def weighted_mean_da(ds):
    return ds.data.weighted(ds.var).mean()

dt.map_over_subtree(weighted_mean_da)

cc @jbusecke

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions