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 indicator outputting delta degC #1973

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
Changelog
=========

v0.54 (unpublished)
v0.54.0 (unreleased)
--------------------
Contributors to this version: Éric (:user:`coxipi`).
Contributors to this version: Éric Dupuis (:user:`coxipi`), Pascal Bourgault (:user:`aulemahal`).

Bug fixes
^^^^^^^^^
* Conversion of units of multivariate DataArray is now properly handled in `sdba.TrainAdjust` and `sdba.Adjust`. There was a bug where the units could be changed before a conversion of the magntitudes could occur. (:pull:`1972`).
* Fix for indicators that output "delta" Celsius degrees. (:pull:`1973`).

v0.53.1 (2024-10-21)
--------------------
Expand Down
14 changes: 14 additions & 0 deletions tests/test_indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@ def test_temp_unit_conversion(tas_series):
np.testing.assert_array_almost_equal(txk, txc + 273.15)


def test_temp_diff_unit_conversion(tasmax_series, tasmin_series):
tx = tasmax_series(np.arange(365) + 1, start="2001-01-01")
tn = tasmin_series(np.arange(365), start="2001-01-01")
txC = convert_units_to(tx, "degC")
tnC = convert_units_to(tn, "degC")

ind = xclim.atmos.daily_temperature_range.from_dict(
{"units": "degC"}, "dtr_degC", "test"
)
out = ind(tasmax=txC, tasmin=tnC)
assert out.attrs["units"] == "degC"
assert out.attrs["units_metadata"] == "temperature: difference"


def test_multiindicator(tas_series):
tas = tas_series(np.arange(366), start="2000-01-01")
tmin, tmax = multiTemp(tas, freq="YS")
Expand Down
2 changes: 1 addition & 1 deletion xclim/core/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ def __call__(self, *args, **kwds):

# Convert to output units
outs = [
convert_units_to(out, attrs["units"], self.context)
convert_units_to(out, attrs, self.context)
for out, attrs in zip(outs, out_attrs, strict=False)
]

Expand Down
Loading