Skip to content

Commit 49f89d1

Browse files
committed
Add unit tests for MaximumStatistics
1 parent 973efad commit 49f89d1

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/stats/test_stats.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,44 @@ def test_quantiles_nans():
7272
sort = [quantile for quantile in stats.iter_quantiles(arr.copy(), qs, method="sort")]
7373
numpy = [quantile for quantile in stats.iter_quantiles(arr.copy(), qs, method="numpy")]
7474
assert np.all(np.isclose(sort, numpy, equal_nan=True))
75+
76+
77+
def test_MaximumStatistics():
78+
ms = stats.MaximumStatistics([6.0, 5.0, 6.0, 7.0, 9.0, 5.0, 6.0, 7.0])
79+
# Extreme ends of distribution
80+
np.testing.assert_allclose(ms.probability_of_threshold(0.0), 1.0)
81+
np.testing.assert_allclose(ms.probability_of_threshold(100.0), 0.0)
82+
# Test identity when calling method followed by inverse method
83+
thresholds = np.linspace(4.0, 10.0, 21)
84+
np.testing.assert_allclose(
85+
ms.threshold_of_probability(ms.probability_of_threshold(thresholds)), thresholds
86+
)
87+
np.testing.assert_allclose(
88+
ms.threshold_of_return_period(ms.return_period_of_threshold(thresholds)), thresholds
89+
)
90+
91+
92+
def test_MaximumStatistics_with_frequency():
93+
freq = np.timedelta64(24 * 60 * 60, "s")
94+
sample = [4.0, 3.0, 5.5, 6.0, 7.0, 5.3, 2.1]
95+
ms = stats.MaximumStatistics(sample, freq=freq)
96+
# Return periods should be scaled by the given frequency
97+
assert ms.return_period_of_threshold(6.0).dtype == freq.dtype
98+
99+
100+
def test_MaximumStatistics_along_axis():
101+
sample = [
102+
[0.3, 3.0, 30.0],
103+
[0.5, 5.0, 50.0],
104+
[0.7, 7.0, 70.0],
105+
[0.3, 3.0, 30.0],
106+
[0.4, 4.0, 40.0],
107+
[0.6, 6.0, 60.0],
108+
[0.7, 7.0, 70.0],
109+
]
110+
ms = stats.MaximumStatistics(sample, axis=0)
111+
rp = ms.threshold_of_probability([0.0, 0.3, 0.6, 1.0])
112+
assert rp.shape == (4, 3)
113+
# Results should scale with values
114+
np.testing.assert_allclose(rp[:, 0] * 10.0, rp[:, 1])
115+
np.testing.assert_allclose(rp[:, 1] * 10.0, rp[:, 2])

0 commit comments

Comments
 (0)