Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
235 views
in Technique[技术] by (71.8m points)

matplotlib - Plotting a flow duration curve for a range of several timeseries in Python

Flow duration curves are a common way in hydrology (and other fields) to visualize timeseries. They allow an easy assessment of the high and low values in a timeseries and how often certain values are reached. Is there an easy way in Python to plot it? I could not find any matplotlib tools, which would allow it. Also no other package seems to include it, at least not with the possibility to plot a range of flow duration curves easily.

An example for a flow duration curve would be: enter image description here

An explantion on how to create it in general can be found here: http://www.renewablesfirst.co.uk/hydropower/hydropower-learning-centre/what-is-a-flow-duration-curve/

So the basic calculation and plotting of the flow duration curve are pretty straightforward. Simply calculate the exceedence and plot it against the sorted timeseries (see the answer of ImportanceOfBeingErnest). It gets more difficult though if you have several timeseries and want to plot the range of the values for all exceedence probabilities. I present one solution in my answer to this thread, but would be glad to hear more elegant solutions. My solution also incorporates an easy use as a subplot, as it is common to have several timeseries for different locations, that have to be plotted seperately.

An example for what I mean with range of flow duration curves would be this: enter image description here

Here you can see three distinct curves. The black line is the measured value from a river, while the two shaded areas are the range for all model runs of those two models. So what would be the most easy way to calculate and plot a range of flow duration curves for several timeseries?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If I understand the concept of a flow duration curve correctly, you just plot the flow as a function of the exceedence.

import numpy as np
import matplotlib.pyplot as plt

data = np.random.rayleigh(10,144)

sort = np.sort(data)[::-1]
exceedence = np.arange(1.,len(sort)+1) / len(sort)

plt.plot(exceedence*100, sort)
plt.xlabel("Exceedence [%]")
plt.ylabel("Flow rate")
plt.show()

enter image description here

From this you easily read that a flow rate of 11 or larger is expected 60% of the time.


In case there are several datasets one may use fill_between to plot them as a range.
import numpy as np; np.random.seed(42)
import matplotlib.pyplot as plt

data0 = np.random.rayleigh(10,144)
data1 = np.random.rayleigh(9,144)
data2 = np.random.normal(10,5,144)

data = np.c_[data0, data1, data2]

exceedence = np.arange(1.,len(data)+1) /len(data)
sort = np.sort(data, axis=0)[::-1]

plt.fill_between(exceedence*100, np.min(sort, axis=1),np.max(sort, axis=1))

plt.xlabel("Exceedence [%]")
plt.ylabel("Flow rate")
plt.grid()
plt.show()

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...