Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
huard committed Oct 8, 2024
1 parent 8663652 commit bab0819
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ def pr_series():
return _pr_series


@pytest.fixture
def evspsbl_series():
"""Return precipitation time series."""
return partial(test_timeseries, variable="evspsbl")


@pytest.fixture
def prc_series():
"""Return convective precipitation time series."""
Expand Down
8 changes: 8 additions & 0 deletions tests/test_atmos.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,3 +656,11 @@ def test_chill_portions(atmosds):
# due to implementation details
exp = [np.nan, 99.91534493, 92.5473925, 99.03177047, np.nan]
np.testing.assert_allclose(cp.isel(location=0), exp, rtol=1e-03)


def test_water_cycle_intensity(pr_series, evspsbl_series):
pr = pr_series(np.ones(31))
evspsbl = evspsbl_series(np.ones(31))

wci = atmos.water_cycle_intensity(pr=pr, evspsbl=evspsbl, freq="MS")
np.testing.assert_allclose(wci, 2 * 60 * 60 * 24 * 31)
9 changes: 9 additions & 0 deletions tests/test_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3983,3 +3983,12 @@ def test_simple(self, sfcWind_series):
pb = xci.wind_power_potential(b)

np.testing.assert_array_almost_equal(pa, pb, decimal=6)


class TestWaterCycleIntensity:
def test_simple(self, pr_series, evspsbl_series):
pr = pr_series(np.ones(31))
evspsbl = evspsbl_series(np.ones(31))

wci = xci.water_cycle_intensity(pr=pr, evspsbl=evspsbl, freq="MS")
np.testing.assert_allclose(wci, 2 * 60 * 60 * 24 * 31)
2 changes: 1 addition & 1 deletion xclim/indices/_multivariate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@ def water_cycle_intensity(
pr = convert_units_to(pr, evspsbl)

# Water cycle intensity
wci = pr + evspsbl
wci = (pr + evspsbl).assign_attrs(units=pr.units)
wci = rate2amount(wci)
wci = wci.resample(time=freq).sum(dim="time").assign_attrs(units=wci.units)
return wci

0 comments on commit bab0819

Please sign in to comment.