Discharge Tools¶
FDC from random data¶
Workflow¶
The workflow in this example will generate some random data and applies two processing steps to illustrate the general idea. All tools are designed to fit seamlessly into automated processing environments like WPS servers or other workflow engines.
The workflow in this example:
- generates a ten year random discharge time series from a gamma distribution
- aggregates the data to daily maximum values
- creates a flow duration curve
- uses python to visualize the flow duration curve
Generate the data¶
# use the ggplot plotting style
In [1]: import matplotlib as mpl
In [2]: mpl.style.use('ggplot')
In [3]: from hydrobox import toolbox
# Step 1:
In [4]: series = toolbox.io.timeseries_from_distribution(
...: distribution='gamma',
...: distribution_args=[2, 0.5], # [location, scale]
...: start='200001010000', # start date
...: end='201001010000', # end date
...: freq='15min', # temporal resolution
...: size=None, # set to None, for inferring
...: seed=42 # set a random seed
...: )
...:
In [5]: print(series.head())
2000-01-01 00:00:00 1.196840
2000-01-01 00:15:00 0.747232
2000-01-01 00:30:00 0.691142
2000-01-01 00:45:00 0.691151
2000-01-01 01:00:00 2.324857
Freq: 15T, dtype: float64
Apply the aggregation¶
In [6]: import numpy as np
In [7]: series_daily = toolbox.aggregate(series, by='1D', func=np.max)
In [8]: print(series_daily.head())
2000-01-01 3.648999
2000-01-02 3.398266
2000-01-03 3.196676
2000-01-04 3.842573
2000-01-05 2.578654
Freq: D, dtype: float64
Calculate the flow duration curve (FDC)¶
# the FDC is calculated on the values only
In [9]: fdc = toolbox.flow_duration_curve(x=series_daily.values, # an FDC does not need a DatetimeIndex
...: plot=False # return values, not a plot
...: )
...:
In [10]: print(fdc[:5])
[0.0002736 0.0005472 0.00082079 0.00109439 0.00136799]
In [11]: print(fdc[-5:])