Skip to content

Commit 9faab40

Browse files
committed
chore: improve fuction and coefficient documentation
1 parent 1509a29 commit 9faab40

File tree

1 file changed

+59
-31
lines changed

1 file changed

+59
-31
lines changed

physics/rainfall_intensity.py

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,61 @@
33
==================
44
This module contains functions to calculate the intensity of
55
a rainfall event for a given duration and return period.
6+
7+
This function uses the Sherman intensity-duration-frequency curve.
8+
9+
References
10+
----------
11+
- Aparicio, F. (1997): Fundamentos de Hidrología de Superficie.
12+
Balderas, México, Limusa. 303 p.
13+
- https://en.wikipedia.org/wiki/Intensity-duration-frequency_curve
614
"""
715

816

917
def rainfall_intensity(
10-
k: float, a: float, b: float, c: float, tr: float, t: float
18+
coefficient_k: float,
19+
coefficient_a: float,
20+
coefficient_b: float,
21+
coefficient_c: float,
22+
return_period: float,
23+
duration: float,
1124
) -> float:
1225
"""
1326
Calculate the intensity of a rainfall event for a given duration and return period.
14-
The coefficients K, a, b, and c are obtained from the Sherman
15-
intensity-duration-frequency curve for a specific location.
27+
It's based on the Sherman intensity-duration-frequency curve:
28+
29+
I = K * T^a / (D + b)^c
30+
31+
where:
32+
I = Intensity of the rainfall event [mm/h]
33+
k, a, b, c = Coefficients obtained through statistical distribution adjust
34+
T = Return period in years
35+
D = Rainfall event duration in minutes
1636
1737
Parameters
1838
----------
19-
k : float
20-
Coefficient [adm].
21-
a : float
22-
Coefficient [adm].
23-
b : float
24-
Coefficient [adm].
25-
c : float
26-
Coefficient [adm].
27-
tr : float
39+
coefficient_k : float
40+
Coefficient obtained through statistical distribution adjust.
41+
coefficient_a : float
42+
Coefficient obtained through statistical distribution adjust.
43+
coefficient_b : float
44+
Coefficient obtained through statistical distribution adjust.
45+
coefficient_c : float
46+
Coefficient obtained through statistical distribution adjust.
47+
return_period : float
2848
Return period in years.
29-
t : float
49+
duration : float
3050
Rainfall event duration in minutes.
3151
3252
Returns
3353
-------
3454
intensity : float
3555
Intensity of the rainfall event in mm/h.
3656
37-
References
38-
----------
39-
- Aparicio, F. (1997): Fundamentos de Hidrología de Superficie.
40-
Balderas, México, Limusa. 303 p.
41-
- https://en.wikipedia.org/wiki/Intensity-duration-frequency_curve
57+
Raises
58+
------
59+
ValueError
60+
If any of the parameters are not positive.
4261
4362
Examples
4463
--------
@@ -55,57 +74,66 @@ def rainfall_intensity(
5574
>>> rainfall_intensity(0, 0.2, 11.6, 0.81, 10, 60)
5675
Traceback (most recent call last):
5776
...
58-
ValueError: Please ensure that all parameters are positive.
77+
ValueError: All parameters must be positive.
5978
6079
>>> rainfall_intensity(1000, -0.2, 11.6, 0.81, 10, 60)
6180
Traceback (most recent call last):
6281
...
63-
ValueError: Please ensure that all parameters are positive.
82+
ValueError: All parameters must be positive.
6483
6584
>>> rainfall_intensity(1000, 0.2, -11.6, 0.81, 10, 60)
6685
Traceback (most recent call last):
6786
...
68-
ValueError: Please ensure that all parameters are positive.
87+
ValueError: All parameters must be positive.
6988
7089
>>> rainfall_intensity(1000, 0.2, 11.6, -0.81, 10, 60)
7190
Traceback (most recent call last):
7291
...
73-
ValueError: Please ensure that all parameters are positive.
92+
ValueError: All parameters must be positive.
7493
7594
>>> rainfall_intensity(1000, 0, 11.6, 0.81, 10, 60)
7695
Traceback (most recent call last):
7796
...
78-
ValueError: Please ensure that all parameters are positive.
97+
ValueError: All parameters must be positive.
7998
8099
>>> rainfall_intensity(1000, 0.2, 0, 0.81, 10, 60)
81100
Traceback (most recent call last):
82101
...
83-
ValueError: Please ensure that all parameters are positive.
102+
ValueError: All parameters must be positive.
84103
85104
>>> rainfall_intensity(1000, 0.2, 11.6, 0, 10, 60)
86105
Traceback (most recent call last):
87106
...
88-
ValueError: Please ensure that all parameters are positive.
107+
ValueError: All parameters must be positive.
89108
90109
>>> rainfall_intensity(0, 0.2, 11.6, 0.81, 10, 60)
91110
Traceback (most recent call last):
92111
...
93-
ValueError: Please ensure that all parameters are positive.
112+
ValueError: All parameters must be positive.
94113
95114
>>> rainfall_intensity(1000, 0.2, 11.6, 0.81, 0, 60)
96115
Traceback (most recent call last):
97116
...
98-
ValueError: Please ensure that all parameters are positive.
117+
ValueError: All parameters must be positive.
99118
100119
>>> rainfall_intensity(1000, 0.2, 11.6, 0.81, 10, 0)
101120
Traceback (most recent call last):
102121
...
103-
ValueError: Please ensure that all parameters are positive.
122+
ValueError: All parameters must be positive.
104123
105124
"""
106-
if k <= 0 or a <= 0 or b <= 0 or c <= 0 or tr <= 0 or t <= 0:
107-
raise ValueError("Please ensure that all parameters are positive.")
108-
intensity = (k * (tr**a)) / ((t + b) ** c)
125+
if (
126+
coefficient_k <= 0
127+
or coefficient_a <= 0
128+
or coefficient_b <= 0
129+
or coefficient_c <= 0
130+
or return_period <= 0
131+
or duration <= 0
132+
):
133+
raise ValueError("All parameters must be positive.")
134+
intensity = (coefficient_k * (return_period**coefficient_a)) / (
135+
(duration + coefficient_b) ** coefficient_c
136+
)
109137
return intensity
110138

111139

0 commit comments

Comments
 (0)