Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 16, 2024
1 parent 9b4a5ac commit 948fa30
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions xclim/indices/_streamflow_flow_indices.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

import xarray as xr
import numpy as np

from xclim.core.units import declare_units
from xclim.indices.generic import compare, threshold_count
from xclim.indices.generic import compare


@declare_units(q="[discharge]")
Expand Down Expand Up @@ -64,11 +65,12 @@ def high_flow_frequency(
1. Addor, Nans & Nearing, Grey & Prieto, Cristina & Newman, A. & Le Vine, Nataliya & Clark, Martyn. (2018). A Ranking of Hydrological Signatures Based on Their Predictability in Space. Water Resources Research. 10.1029/2018WR022606.
2. Clausen, B., & Biggs, B. J. F. (2000). Flow variables for ecological studies in temperate streams: Groupings based on covariance. Journal of Hydrology, 237(3–4), 184–197. https://doi.org/10.1016/S0022-1694(00)00306-1
"""

median_flow = q.median(dim="time")
with xr.set_options(keep_attrs=True):
threshold = threshold_factor * median_flow
high_flow_days = compare(q, op=">", right=threshold).resample(time=freq).sum(dim="time")
high_flow_days = (
compare(q, op=">", right=threshold).resample(time=freq).sum(dim="time")
)
out = high_flow_days.mean(dim="time")
out.attrs["units"] = "days/year"
return out
Expand Down Expand Up @@ -104,11 +106,12 @@ def low_flow_frequency(
Olden, J. D., & Poff, N. L. (2003). Redundancy and the choice of hydrologic indices for characterizing streamflow regimes. River Research and
Applications, 19(2), 101–121. https://doi.org/10.1002/rra.700
"""

mean_flow = q.mean(dim="time")
with xr.set_options(keep_attrs=True):
threshold = threshold_factor * mean_flow
low_flow_days = compare(q, op="<", right=threshold).resample(time=freq).sum(dim="time")
low_flow_days = (
compare(q, op="<", right=threshold).resample(time=freq).sum(dim="time")
)
out = low_flow_days.mean(dim="time")
out.attrs["units"] = "days"
return out

0 comments on commit 948fa30

Please sign in to comment.