Skip to content

Commit 973efad

Browse files
committed
Improve docstrings
1 parent 3aeea78 commit 973efad

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed

src/earthkit/meteo/stats/array/distributions.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
class ContinuousDistribution(abc.ABC):
16-
"""Continuous probabiliy distribution function.
16+
"""Continuous probability distribution function.
1717
1818
Partially implements the interface of scipy.stats.rv_continuous, but all
1919
methods should be applicable along an axis so fields can be processed in
@@ -96,9 +96,9 @@ class MaxGumbel(ContinuousDistribution):
9696
9797
Parameters
9898
----------
99-
mu: array_like
99+
mu: Number | array_like
100100
Offset parameter.
101-
sigma: array_like
101+
sigma: Number | array_like
102102
Scale parameter.
103103
"""
104104

@@ -141,13 +141,14 @@ def cdf(self, x):
141141
142142
Parameters
143143
----------
144-
x: array_like
145-
Input value(s).
144+
x: Number | array_like
145+
Input value.
146146
147147
Returns
148148
-------
149-
The probability that a random variable X from the distribution is less
150-
than or equal to the input x.
149+
Number | array_like
150+
The probability that a random variable X from the distribution is
151+
less than or equal to the input x.
151152
"""
152153
x = _expand_dims_after(x, self.ndim)
153154
return 1.0 - np.exp(-np.exp((self.mu - x) / self.sigma))
@@ -157,13 +158,14 @@ def ppf(self, p):
157158
158159
Parameters
159160
----------
160-
p: array_like
161+
p: Number | array_like
161162
Probability in interval [0, 1].
162163
163164
Returns
164165
-------
165-
x such that the probability of a random variable from the distribution
166-
taking a value less than or equal to x is p.
166+
Number | array_like
167+
x such that the probability of a random variable from the
168+
distribution taking a value less than or equal to x is p.
167169
"""
168170
p = _expand_dims_after(p, self.ndim)
169171
return self.mu - self.sigma * np.log(-np.log(1.0 - p))

src/earthkit/meteo/stats/array/extreme_values.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
class MaximumStatistics:
1414
"""Recurrence statistics for a sample of maximum values.
1515
16+
All statistics are computed based on a fitted continuous probability
17+
distribution. Results will only be meaningful if this fitted distribution
18+
is representative of the sample statistics.
19+
20+
Use, e.g., to compute expected return periods of extreme precipitation or
21+
flooding events based on past observations.
22+
1623
Parameters
1724
----------
1825
sample: array_like
@@ -22,18 +29,10 @@ class MaximumStatistics:
2229
The axis along which to compute the statistics.
2330
freq: number | timedelta
2431
Temporal frequency of the input data. Used to scale return periods.
25-
Defaults to 1, i.e., no scaling applied. When supplying a numpy
26-
timedelta64, unit carries over to return periods, so make sure the
27-
resolution is sufficient.
32+
Defaults to 1, i.e., no scaling applied. Note: when supplying a numpy
33+
timedelta64, the unit carries over to return periods.
2834
dist:
2935
Continuous probability distribution fitted to the input data.
30-
31-
All statistics are computed based on a fitted continuous probability
32-
distribution. Results will only be meaningful if this fitted distribution
33-
is representative of the sample statistics.
34-
35-
Use, e.g., to compute expected return periods of extreme precipitation or
36-
flooding events based on past observations.
3736
"""
3837

3938
def __init__(self, sample, axis=0, freq=1.0, dist=MaxGumbel):
@@ -43,7 +42,7 @@ def __init__(self, sample, axis=0, freq=1.0, dist=MaxGumbel):
4342

4443
@property
4544
def dist(self):
46-
"""Estimated ontinuous probability distribution for the data."""
45+
"""Estimated continuous probability distribution for the data."""
4746
return self._dist
4847

4948
@property
@@ -56,13 +55,14 @@ def probability_of_threshold(self, threshold):
5655
5756
Parameters
5857
----------
59-
threshold: array_like
58+
threshold: Number | array_like
6059
Input threshold.
6160
6261
Returns
6362
-------
64-
The probability ([0, 1]) of a value to exceed the input threshold in a
65-
time interval.
63+
array_like
64+
The probability ([0, 1]) of a value to exceed the input threshold
65+
in a time interval.
6666
"""
6767
return self.dist.cdf(threshold)
6868

@@ -71,12 +71,13 @@ def return_period_of_threshold(self, threshold):
7171
7272
Parameters
7373
----------
74-
threshold: array_like
74+
threshold: Number | array_like
7575
Input threshold.
7676
7777
Returns
7878
-------
79-
The return period of the input threshold.
79+
array_like
80+
The return period of the input threshold.
8081
"""
8182
return self.freq / self.probability_of_threshold(threshold)
8283

@@ -85,12 +86,14 @@ def threshold_of_probability(self, probability):
8586
8687
Parameters
8788
----------
88-
probability: array_like
89+
probability: Number | array_like
8990
Input probability.
9091
9192
Returns
9293
-------
93-
Threshold with exceedance probability equal to the input probability.
94+
array_like
95+
Threshold with exceedance probability equal to the input
96+
probability.
9497
"""
9598
return self.dist.ppf(probability)
9699

@@ -99,11 +102,12 @@ def threshold_of_return_period(self, return_period):
99102
100103
Parameters
101104
----------
102-
return_period: array_like
105+
return_period: Number | array_like
103106
Input return period.
104107
105108
Returns
106109
-------
107-
Threshold with return period equal to the input return period.
110+
array_like
111+
Threshold with return period equal to the input return period.
108112
"""
109113
return self.threshold_of_probability(self.freq / return_period)

0 commit comments

Comments
 (0)