Ouranosinc / xscen

A climate change scenario-building analysis framework.
https://xscen.readthedocs.io/
Apache License 2.0
15 stars 2 forks source link

Generate Weights should give a dataset compatible with xr.DatasetWeighted #305

Closed SarahG-579462 closed 9 months ago

SarahG-579462 commented 9 months ago

Generic Issue

Description

As an example:

Trying to get the weighted mean using dsim.weighted(generate_weights(dsim_array,weights)).mean() currently results in NaN values, since the coordinate for weights does not correspond to the realization coordinate for dsim.

Generating weights currently gives me a dataset with the coordinate "realization" = [0,1,2,3,4,5,6], for example. In my case, it should give the coordinates "realization"=['ScenarioMIP_BCC_BCC-CSM2-MR_r1i1p1f1_ssp245', 'ScenarioMIP_BCC_BCC-CSM2-MR_r1i1p1f1_ssp370', 'ScenarioMIP_BCC_BCC-CSM2-MR_r1i1p1f1_ssp585', 'ScenarioMIP_CAS_FGOALS-g3_r1i1p1f1_ssp245', 'ScenarioMIP_CAS_FGOALS-g3_r1i1p1f1_ssp370', 'ScenarioMIP_CAS_FGOALS-g3_r1i1p1f1_ssp585']

What I Did

Solution

weights = weights.assign_coords(realization=dsim.realization)

SarahG-579462 commented 9 months ago

woops just saw my typo