-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- Please ensure the PR fulfills the following requirements! --> <!-- If this is your first PR, make sure to add your details to the AUTHORS.rst! --> ### Pull Request Checklist: - [x] This PR addresses an already opened issue (for bug fixes / features) - This PR fixes #xyz - [x] (If applicable) Documentation has been added / updated (for bug fixes / features). - [x] (If applicable) Tests have been added. - [x] This PR does not seem to break the templates. - [x] CHANGES.rst has been updated (with summary of main changes). - [x] Link to issue (:issue:`number`) and pull request (:pull:`number`) has been added. ### What kind of change does this PR introduce? * Tests for `xclim_modules/conversions.py` * Added `context="hydro"` to the precipitation conversion. * Fixed a bug in `tasmin/max_from_dtr` when `dtr` was in different units than `tasmin/max`. ### Does this PR introduce a breaking change? * I changed `dtr` (the function) to `dtr_from_minmax` to avoid conflicts with `dtr` (the variable). This is only breaking if people directly used the Python file, which should be no one. ### Other information:
- Loading branch information
Showing
4 changed files
with
77 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import numpy as np | ||
from xclim.testing.helpers import test_timeseries as timeseries | ||
|
||
import xscen.xclim_modules.conversions as conv | ||
|
||
|
||
def test_precipitation(): | ||
prsn = timeseries(np.ones(3), variable="prsn", start="2001-01-01", freq="D") | ||
prlp = timeseries( | ||
np.ones(3) * 10, variable="pr", start="2001-01-01", freq="D", units="mm d-1" | ||
) | ||
prlp.attrs["standard_name"] = "liquid_precipitation_flux" | ||
|
||
pr = conv.precipitation(prsn, prlp) | ||
assert pr.attrs["units"] == prsn.attrs["units"] | ||
np.testing.assert_array_equal(pr, prsn + prlp / 86400) | ||
|
||
|
||
def test_tasmin_from_dtr(): | ||
dtr = timeseries( | ||
np.ones(3) * 10, variable="tas", start="2001-01-01", freq="D", units="C" | ||
) | ||
dtr.attrs["standard_name"] = "daily_temperature_range" | ||
tasmax = timeseries( | ||
np.ones(3) * 20, variable="tasmax", start="2001-01-01", freq="D" | ||
) | ||
|
||
tasmin = conv.tasmin_from_dtr(dtr, tasmax) | ||
assert tasmin.attrs["units"] == tasmax.attrs["units"] | ||
np.testing.assert_array_equal( | ||
tasmin, tasmax - dtr | ||
) # DTR in Celsius should not matter in the result, for a tasmax in Kelvin | ||
|
||
|
||
def test_tasmax_from_dtr(): | ||
dtr = timeseries( | ||
np.ones(3) * 10, variable="tas", start="2001-01-01", freq="D", units="C" | ||
) | ||
dtr.attrs["standard_name"] = "daily_temperature_range" | ||
tasmin = timeseries( | ||
np.ones(3) * 10, variable="tasmin", start="2001-01-01", freq="D" | ||
) | ||
|
||
tasmax = conv.tasmax_from_dtr(dtr, tasmin) | ||
assert tasmax.attrs["units"] == tasmin.attrs["units"] | ||
np.testing.assert_array_equal( | ||
tasmax, tasmin + dtr | ||
) # DTR in Celsius should not matter in the result, for a tasmin in Kelvin | ||
|
||
|
||
def test_dtr(): | ||
tasmax = timeseries( | ||
np.ones(3) * 20, variable="tasmax", start="2001-01-01", freq="D", units="C" | ||
) | ||
tasmin = timeseries( | ||
np.ones(3) * 10, variable="tasmin", start="2001-01-01", freq="D" | ||
) | ||
|
||
dtr = conv.dtr_from_minmax(tasmin, tasmax) | ||
assert dtr.attrs["units"] == "K" | ||
np.testing.assert_array_equal(dtr, (tasmax + 273.15) - tasmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters