forked from TheAlgorithms/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rainfall_intensity.py
143 lines (116 loc) · 3.95 KB
/
rainfall_intensity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"""
Rainfall Intensity
==================
This module contains functions to calculate the intensity of
a rainfall event for a given duration and return period.
This function uses the Sherman intensity-duration-frequency curve.
References
----------
- Aparicio, F. (1997): Fundamentos de Hidrología de Superficie.
Balderas, México, Limusa. 303 p.
- https://en.wikipedia.org/wiki/Intensity-duration-frequency_curve
"""
def rainfall_intensity(
coefficient_k: float,
coefficient_a: float,
coefficient_b: float,
coefficient_c: float,
return_period: float,
duration: float,
) -> float:
"""
Calculate the intensity of a rainfall event for a given duration and return period.
It's based on the Sherman intensity-duration-frequency curve:
I = k * T^a / (D + b)^c
where:
I = Intensity of the rainfall event [mm/h]
k, a, b, c = Coefficients obtained through statistical distribution adjust
T = Return period in years
D = Rainfall event duration in minutes
Parameters
----------
coefficient_k : float
Coefficient obtained through statistical distribution adjust.
coefficient_a : float
Coefficient obtained through statistical distribution adjust.
coefficient_b : float
Coefficient obtained through statistical distribution adjust.
coefficient_c : float
Coefficient obtained through statistical distribution adjust.
return_period : float
Return period in years.
duration : float
Rainfall event duration in minutes.
Returns
-------
intensity : float
Intensity of the rainfall event in mm/h.
Raises
------
ValueError
If any of the parameters are not positive.
Examples
--------
>>> rainfall_intensity(1000, 0.2, 11.6, 0.81, 10, 60)
49.83339231138578
>>> rainfall_intensity(1000, 0.2, 11.6, 0.81, 10, 30)
77.36319588106228
>>> rainfall_intensity(1000, 0.2, 11.6, 0.81, 5, 60)
43.382487747633625
>>> rainfall_intensity(0, 0.2, 11.6, 0.81, 10, 60)
Traceback (most recent call last):
...
ValueError: All parameters must be positive.
>>> rainfall_intensity(1000, -0.2, 11.6, 0.81, 10, 60)
Traceback (most recent call last):
...
ValueError: All parameters must be positive.
>>> rainfall_intensity(1000, 0.2, -11.6, 0.81, 10, 60)
Traceback (most recent call last):
...
ValueError: All parameters must be positive.
>>> rainfall_intensity(1000, 0.2, 11.6, -0.81, 10, 60)
Traceback (most recent call last):
...
ValueError: All parameters must be positive.
>>> rainfall_intensity(1000, 0, 11.6, 0.81, 10, 60)
Traceback (most recent call last):
...
ValueError: All parameters must be positive.
>>> rainfall_intensity(1000, 0.2, 0, 0.81, 10, 60)
Traceback (most recent call last):
...
ValueError: All parameters must be positive.
>>> rainfall_intensity(1000, 0.2, 11.6, 0, 10, 60)
Traceback (most recent call last):
...
ValueError: All parameters must be positive.
>>> rainfall_intensity(0, 0.2, 11.6, 0.81, 10, 60)
Traceback (most recent call last):
...
ValueError: All parameters must be positive.
>>> rainfall_intensity(1000, 0.2, 11.6, 0.81, 0, 60)
Traceback (most recent call last):
...
ValueError: All parameters must be positive.
>>> rainfall_intensity(1000, 0.2, 11.6, 0.81, 10, 0)
Traceback (most recent call last):
...
ValueError: All parameters must be positive.
"""
if (
coefficient_k <= 0
or coefficient_a <= 0
or coefficient_b <= 0
or coefficient_c <= 0
or return_period <= 0
or duration <= 0
):
raise ValueError("All parameters must be positive.")
intensity = (coefficient_k * (return_period**coefficient_a)) / (
(duration + coefficient_b) ** coefficient_c
)
return intensity
if __name__ == "__main__":
import doctest
doctest.testmod()