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

Check for discharge unit compliance in streamflow statistical indicators #1225

Merged
merged 22 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ec95da5
fix: check for discharge unit compliance in streamflow statistical in…
huard Nov 8, 2022
4de562c
update history with pr #
huard Nov 8, 2022
3b33971
Merge branch 'master' into fix-1130
Zeitsperre Nov 8, 2022
7693d99
Update xclim/indicators/land/_streamflow.py
huard Nov 14, 2022
035d1d4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 14, 2022
d53a269
Created generic indicator realm. Moved generic indicators from land r…
huard Nov 14, 2022
109271d
merge
huard Nov 14, 2022
f61cd65
Merge branch 'master' into fix-1130
huard Nov 14, 2022
639fe20
reinstated streamflow indicators to avoid breaking code without a dep…
huard Nov 14, 2022
5ddf6f0
Merge branch 'fix-1130' of github.com:Ouranosinc/xclim into fix-1130
huard Nov 14, 2022
9c97ae4
Merge branch 'master' into fix-1130
huard Nov 16, 2022
e304690
Merge branch 'master' into fix-1130
aulemahal Dec 5, 2022
666e648
Merge branch 'master' into fix-1130
Zeitsperre Dec 5, 2022
1c31a75
Merge branch 'master' into fix-1130
Zeitsperre Dec 9, 2022
3a55e96
Merge branch 'master' into fix-1130
Zeitsperre Dec 9, 2022
542708f
Merge branch 'master' into fix-1130
Zeitsperre Dec 9, 2022
1e2d896
Merge branch 'master' into fix-1130
aulemahal Dec 14, 2022
8052d15
Update HISTORY.rst
aulemahal Dec 14, 2022
a2de036
Update xclim/indicators/land/_streamflow.py
huard Dec 15, 2022
b89440e
Merge branch 'master' into fix-1130
huard Dec 16, 2022
ef14fa9
french translation for discharge_distribution_fit
huard Dec 16, 2022
5f61995
Merge branch 'master' into fix-1130
aulemahal Dec 19, 2022
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: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ History

0.40.0 (unreleased)
-------------------
Contributors to this version: Trevor James Smith (:user:`Zeitsperre`)

Bug fixes
^^^^^^^^^
* Streamflow indicators relying on indices defined in `xclim.indices.stats` were not checking input variable units. These indicators will now raise an error if input data units are not m^3/s. (:issue:`1130`, :pull:`1225`).

Internal changes
^^^^^^^^^^^^^^^^
Expand Down
5 changes: 5 additions & 0 deletions xclim/data/variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ variables:
cell_methods: "area: sum"
description: Cell area (over the ocean).
standard_name: cell_area
discharge:
canonical_units: m3 s-1
cell_methods: "time: mean"
description: The amount of water, in all phases, flowing in the river channel and flood plain.
standard_name: water_volume_transport_in_river_channel
evspsblpot:
canonical_units: kg m-2 s-1
cell_methods: "time: mean"
Expand Down
10 changes: 5 additions & 5 deletions xclim/indicators/land/_streamflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def cfcheck(self, **das):
"distribution.",
abstract="Streamflow frequency analysis on the basis of a given mode and distribution.",
units="m^3 s-1",
compute=declare_units(da=None)(frequency_analysis),
compute=declare_units(da="[discharge]")(frequency_analysis),
huard marked this conversation as resolved.
Show resolved Hide resolved
)

rb_flashiness_index = Streamflow(
Expand All @@ -101,7 +101,7 @@ def cfcheck(self, **das):
long_name="Daily flow statistics",
description="{freq} {op} of daily flow ({indexer}).",
units="m^3 s-1",
compute=declare_units(da=None)(generic.select_resample_op),
compute=declare_units(da="[discharge]")(generic.select_resample_op),
)

fit = Fit(
Expand All @@ -113,7 +113,7 @@ def cfcheck(self, **das):
long_name="{dist} distribution parameters",
description="Parameters of the {dist} distribution.",
cell_methods="time: fit",
compute=declare_units(da=None)(_fit),
compute=declare_units(da="[discharge]")(_fit),
)


Expand All @@ -124,7 +124,7 @@ def cfcheck(self, **das):
long_name="Day of the year of the maximum streamflow over {indexer}",
description="Day of the year of the maximum streamflow over {indexer}.",
units="",
compute=declare_units(da=None)(generic.select_resample_op),
compute=declare_units(da="[discharge]")(generic.select_resample_op),
parameters=dict(op=generic.doymax),
)

Expand All @@ -136,6 +136,6 @@ def cfcheck(self, **das):
long_name="Day of the year of the minimum streamflow over {indexer}",
description="Day of the year of the minimum streamflow over {indexer}.",
units="",
compute=declare_units(da=None)(generic.select_resample_op),
compute=declare_units(da="[discharge]")(generic.select_resample_op),
parameters=dict(op=generic.doymin),
)
8 changes: 8 additions & 0 deletions xclim/testing/tests/test_land.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import annotations

import numpy as np
import pytest
import xarray as xr

import xclim.core.utils
from xclim import land, set_options


Expand Down Expand Up @@ -55,6 +57,12 @@ def test_empty(self, ndq_series):
)
assert np.isnan(out.values[:, 0, 0]).all()

def test_wrong_variable(self, pr_series):
with pytest.raises(xclim.core.utils.ValidationError):
land.freq_analysis(
pr_series(np.random.rand(100)), mode="max", t=2, dist="gamma"
)


class TestStats:
def test_simple(self, ndq_series):
Expand Down