Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docstrings #240

Merged
merged 13 commits into from
Aug 22, 2023
2 changes: 1 addition & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ New features and enhancements
* Add more comments in the template. (:pull:`233`, :issue:`232`).
* ``generate_weights`` now allows to split weights between experiments, and make them vary along the time/horizon axis. (:issue:`108`, :pull:`231`).
* New independence_level, `institution`, added to ``generate_weights``. (:pull:`231`).
* Updated ``produce_horizon`` so it can accept multiple periods or warming levels. (:pull:`231`).
* Updated ``produce_horizon`` so it can accept multiple periods or warming levels. (:pull:`231`, :pull:`240`).
* Add more comments in the template. (:pull:`233`,:pull:`235`, :issue:`232`).
* New function ``diagnostics.health_checks`` that can perform multiple checkups on a dataset. (:pull:`238`).

Expand Down
9 changes: 9 additions & 0 deletions tests/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,15 @@ def test_combine(self):
out.horizon, ["1982-1988", "+0.8Cvs1850-1900", "+0.85Cvs1850-1900"]
)

def test_single(self):
out = xs.produce_horizon(
self.ds,
indicators=self.yaml_file,
periods=[1982, 1988],
)
assert len(out.horizon) == 1
np.testing.assert_array_equal(out.horizon, ["1982-1988"])

def test_warminglevel_in_ds(self):
ds = self.ds.copy().expand_dims({"warminglevel": ["+1Cvs1850-1900"]})
out = xs.produce_horizon(
Expand Down
15 changes: 10 additions & 5 deletions xscen/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ def produce_horizon(

all_periods = []
if periods is not None:
all_periods.extend(periods)
all_periods.extend(standardize_periods(periods))
if warminglevels is not None:
if isinstance(warminglevels["wl"], (int, float)):
all_periods.append(warminglevels)
Expand Down Expand Up @@ -761,7 +761,12 @@ def produce_horizon(

if ds_sub is not None:
# compute indicators
ind_dict = compute_indicators(ds=ds_sub, indicators=indicators)
ind_dict = compute_indicators(
ds=ds_sub.squeeze(dim="warminglevel")
juliettelavoie marked this conversation as resolved.
Show resolved Hide resolved
if "warminglevel" in ds_sub.dims
else ds_sub,
indicators=indicators,
)

# Compute the window-year mean
ds_merge = xr.Dataset()
Expand Down Expand Up @@ -807,10 +812,10 @@ def produce_horizon(
)
ds_mean["horizon"] = ds_mean["horizon"].astype(str)

if "warminglevel" in ds_mean.dims:
wl = ds_mean["warminglevel"].values
if "warminglevel" in ds_mean.coords:
wl = np.array([ds_mean["warminglevel"].item()])
wl_attrs = ds_mean["warminglevel"].attrs
ds_mean = ds_mean.squeeze(dim="warminglevel", drop=True)
ds_mean = ds_mean.drop_vars("warminglevel")
ds_mean["horizon"] = wl
ds_mean["horizon"].attrs.update(wl_attrs)

Expand Down