mesmer.core.weighted.equal_scenario_weights_from_datatree#
- mesmer.core.weighted.equal_scenario_weights_from_datatree(dt, ens_dim='member', time_dim='time')#
Create a DataTree isomorphic to
dt
, holding the weights for each scenario to weight the ensemble members of each scenario such that each scenario contributes equally to some fitting procedure. The weight of each member = 1 / number of members in the scenario, so weights = 1 / ds[ens_dim].size.Thus, if all scenarios have the same number of members, all weights will be equal. If one scenario has more members than the others, its weights will be smaller. Weights are always along the time and ens dim, if there are more dimensions in a dataset, they will be dropped.
Parameters:#
- dtDataTree
DataTree holding the
xr.Datasets
for which the weights should be created. Each dataset must have at least ens_dim and time_dim as dimensions, but can have more dimensions.- ens_dimstr
Name of the dimension along which the weights should be created. Default is “member”.
- time_dimstr
Name of the time dimension, will be filled with equal values for each ensemble member. Default is “time”.
Returns:#
- DataTree
DataTree holding the weights for each scenario isomorphic to dt, where each dataset has dimensions (time_dim, ens_dim).
Example:#
>>> dt = DataTree() >>> dt["ssp119"] = DataTree(xr.Dataset({"tas": xr.DataArray(np.ones((20, 3)), dims=("time", "member"))})) >>> dt["ssp585"] = DataTree(xr.Dataset({"tas": xr.DataArray(np.ones((20, 2)), dims=("time", "member"))})) >>> weights = equal_scenario_weights_from_datatree(dt) >>> weights DataTree('None', parent=None) ├── DataTree('ssp119') │ Dimensions: (time: 20, member: 3) │ Coordinates: │ * time (time) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 │ * member (member) int64 0 1 2 │ Data variables: │ weights (time, member) float64 0.3333 0.3333 0.3333 ... 0.3333 0.3333 └── DataTree('ssp585') Dimensions: (time: 20, member: 2) Coordinates: * time (time) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 * member (member) int64 0 1 Data variables: weights (time, member) float64 0.5 0.5 0.5 0.5 0.5 ... 0.5 0.5 0.5 0.5 0.5