Skip to content

Commit

Permalink
Merge pull request #240 from Ouranosinc/typo_fix
Browse files Browse the repository at this point in the history
Fix docstrings
  • Loading branch information
RondeauG committed Aug 22, 2023
2 parents f2262c3 + e0b6e5b commit 9904ff1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
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")
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

0 comments on commit 9904ff1

Please sign in to comment.