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

2024/9/20 17:23:47

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?

Answer

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 pltdata = 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 pltdata0 = 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

https://en.xdnf.cn/q/119304.html

Related Q&A

HTML variable value is not changing in Flask

I have written this code in Flaskans = 999 @app.route(/, methods=[POST, GET]) def home():flag = 0global anssession["ans"] = 0if (request.method == "POST"):jsdata = request.form[data…

How to add two lists with the same amount of indexs in python

I am still new to coding so i apologize for the basic question. How do I add to elements of two seperate lists? listOne = [0, 1 , 7, 8] listTwo = [3, 4, 5, 6] listThree = []for i in listOne:listAdd = …

How to crawl thousands of pages using scrapy?

Im looking at crawling thousands of pages and need a solution. Every site has its own html code - they are all unique sites. No clean datafeed or API is available. Im hoping to load the captured data i…

Object Transmission in Python using Pickle [duplicate]

This question already has answers here:Send and receive objects through sockets in Python(3 answers)Closed last year.I have the following class, a Point objectclass Point:def __init__(self):passdef __i…

Google App Engine: Modifying 1000 entities

I have about 1000 user account entities like this:class UserAccount(ndb.Model):email = ndb.StringProperty()Some of these email values contain uppercase letters like [email protected]. I want to select …

more efficient method of dealing with large numbers in Python? [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

MLM downline distribution count

I make my first MLM software and I think I managed to code how to get the points from the downline even though it is a recursive problem I didnt use recursion and I might refactor to a recursive versio…

Can someone please explain to me the purpose of the asterisk in Python? [duplicate]

This question already has answers here:What does asterisk * mean in Python? [duplicate](5 answers)How are pythons unpacking operators * and ** used?(1 answer)Closed 5 years ago.For instance, can some…

Linear Programming with cvxpy

I would like to ask you regarding on the Linear Program for optimization.I have an objective function, and constraint functions as below,variables(x1, x2, x3, x4, x5, x6) are quantities of the products…

Program runs forever without giving an error when plotting data only on continent [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…