pynumerics 2.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pynumerics/__init__.py +73 -0
- pynumerics/_bin/Microsoft.CodeAnalysis.CSharp.dll +0 -0
- pynumerics/_bin/Microsoft.CodeAnalysis.LICENSE.txt +27 -0
- pynumerics/_bin/Microsoft.CodeAnalysis.dll +0 -0
- pynumerics/_bin/Numerics.dll +0 -0
- pynumerics/_bin/pynumerics.runtimeconfig.json +15 -0
- pynumerics/_coverage.py +3825 -0
- pynumerics/_util.py +237 -0
- pynumerics/_version.py +40 -0
- pynumerics/bootstrap.py +593 -0
- pynumerics/callbacks.py +791 -0
- pynumerics/copulas.py +910 -0
- pynumerics/data.py +2233 -0
- pynumerics/differentiation.py +348 -0
- pynumerics/distributions.py +4043 -0
- pynumerics/download.py +623 -0
- pynumerics/enums.py +119 -0
- pynumerics/errors.py +245 -0
- pynumerics/functions.py +1142 -0
- pynumerics/goodness_of_fit.py +699 -0
- pynumerics/graphs.py +556 -0
- pynumerics/hypothesis_tests.py +445 -0
- pynumerics/identity.py +144 -0
- pynumerics/integration.py +677 -0
- pynumerics/linalg.py +1408 -0
- pynumerics/machine_learning.py +1335 -0
- pynumerics/marshal.py +733 -0
- pynumerics/mathematics.py +1053 -0
- pynumerics/mcmc.py +1406 -0
- pynumerics/multivariate.py +1539 -0
- pynumerics/ode.py +156 -0
- pynumerics/optimization.py +1736 -0
- pynumerics/probability.py +966 -0
- pynumerics/py.typed +0 -0
- pynumerics/regional.py +522 -0
- pynumerics/roots.py +274 -0
- pynumerics/runtime.py +384 -0
- pynumerics/sampling.py +1758 -0
- pynumerics/special.py +1079 -0
- pynumerics/statistics.py +1958 -0
- pynumerics/timeseries.py +1326 -0
- pynumerics-2.3.0.dist-info/METADATA +142 -0
- pynumerics-2.3.0.dist-info/RECORD +46 -0
- pynumerics-2.3.0.dist-info/WHEEL +5 -0
- pynumerics-2.3.0.dist-info/licenses/LICENSE +10 -0
- pynumerics-2.3.0.dist-info/top_level.txt +1 -0
pynumerics/py.typed
ADDED
|
File without changes
|
pynumerics/regional.py
ADDED
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
"""Hosking-Wallis regional frequency analysis by L-moments from ``Numerics.Distributions.Regional``.
|
|
2
|
+
|
|
3
|
+
:class:`RegionalData` holds a region's sites (name, record length, mean and L-moment ratios), built from raw samples
|
|
4
|
+
or from precomputed L-moments, with the record-length weighted regional average (Hosking and Wallis, 1997, equation
|
|
5
|
+
4.3) and the discordancy measure ``D_i`` (section 3.2.3). :class:`RegionalHomogeneityTest` runs the Monte Carlo
|
|
6
|
+
simulations of a homogeneous kappa region and gives the heterogeneity measures ``H1``, ``H2`` and ``H3`` (section
|
|
7
|
+
4.3.3) and the goodness-of-fit measures ``Z`` of GLO, GEV, GNO, PE3 and GPA (section 5.2.3), as Hosking's ``REGTST``
|
|
8
|
+
and R's ``lmomRFA::regtst`` do. :class:`RegionalGrowthCurve` fits a distribution to the regional L-moments with mean 1
|
|
9
|
+
and gives growth factors and site quantiles (index flood times growth factor).
|
|
10
|
+
|
|
11
|
+
The simulations are seeded per simulated region from the master seed, so a seed gives the same results whatever the
|
|
12
|
+
number of threads. The sites are simulated as independent.
|
|
13
|
+
|
|
14
|
+
Distributions are named by their ``UnivariateDistributionType`` member (``"GeneralizedExtremeValue"``) or by
|
|
15
|
+
Hosking's abbreviation (``"GEV"``), case-insensitively.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
import numpy as np
|
|
23
|
+
|
|
24
|
+
from pynumerics._util import _nd, namespace, net_enum
|
|
25
|
+
from pynumerics.distributions import UnivariateDistribution, wrap
|
|
26
|
+
from pynumerics.errors import translate_public
|
|
27
|
+
from pynumerics.marshal import to_net_doubles, to_net_ints, to_numpy_doubles, to_numpy_matrix
|
|
28
|
+
|
|
29
|
+
ABBREVIATIONS: dict[str, str] = {
|
|
30
|
+
"GLO": "GeneralizedLogistic",
|
|
31
|
+
"GEV": "GeneralizedExtremeValue",
|
|
32
|
+
"GNO": "GeneralizedNormal",
|
|
33
|
+
"PE3": "PearsonTypeIII",
|
|
34
|
+
"GPA": "GeneralizedPareto",
|
|
35
|
+
"KAP": "KappaFour",
|
|
36
|
+
}
|
|
37
|
+
"""Hosking's three-letter abbreviations, mapped to the ``UnivariateDistributionType`` member names."""
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _regional() -> Any:
|
|
41
|
+
"""Return the ``Numerics.Distributions.Regional`` namespace after starting the runtime."""
|
|
42
|
+
return namespace("Numerics.Distributions.Regional")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _type(distribution: Any) -> Any:
|
|
46
|
+
"""Return the .NET ``UnivariateDistributionType`` member for a name or abbreviation."""
|
|
47
|
+
if isinstance(distribution, str):
|
|
48
|
+
distribution = ABBREVIATIONS.get(distribution.upper(), distribution)
|
|
49
|
+
return net_enum(_nd().UnivariateDistributionType, distribution)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _strings(values: Any) -> Any:
|
|
53
|
+
"""Copy names into a new ``System.String[]``."""
|
|
54
|
+
import System # noqa: PLC0415 - the runtime is running
|
|
55
|
+
|
|
56
|
+
items = [str(v) for v in values]
|
|
57
|
+
array = System.Array.CreateInstance(System.String, len(items))
|
|
58
|
+
for index, item in enumerate(items):
|
|
59
|
+
array[index] = item
|
|
60
|
+
return array
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class RegionalData:
|
|
64
|
+
"""The sites of a region: names, record lengths, means and L-moment ratios (``RegionalData``).
|
|
65
|
+
|
|
66
|
+
Parameters
|
|
67
|
+
----------
|
|
68
|
+
names : sequence of str
|
|
69
|
+
The site names.
|
|
70
|
+
record_lengths : array_like of int
|
|
71
|
+
The record length of each site, at least 1.
|
|
72
|
+
mean : array_like
|
|
73
|
+
The sample mean ``l1`` of each site (its index flood).
|
|
74
|
+
l_cv : array_like
|
|
75
|
+
The sample L-CV ``t = l2 / l1`` of each site.
|
|
76
|
+
tau3 : array_like
|
|
77
|
+
The sample L-skewness of each site.
|
|
78
|
+
tau4 : array_like
|
|
79
|
+
The sample L-kurtosis of each site.
|
|
80
|
+
tau5 : array_like, optional
|
|
81
|
+
The sample ``t5`` of each site; None leaves every ``t5`` NaN.
|
|
82
|
+
|
|
83
|
+
Raises
|
|
84
|
+
------
|
|
85
|
+
ValueError
|
|
86
|
+
If the lists differ in length, there are no sites, a record length is below 1, a ratio is not finite, an
|
|
87
|
+
L-CV is not positive or a ``t5`` is infinite.
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
def __init__(self, names: Any, record_lengths: Any, mean: Any, l_cv: Any, tau3: Any, tau4: Any,
|
|
91
|
+
tau5: Any = None) -> None:
|
|
92
|
+
self._net = _regional().RegionalData(
|
|
93
|
+
_strings(names), to_net_ints(record_lengths), to_net_doubles(mean), to_net_doubles(l_cv),
|
|
94
|
+
to_net_doubles(tau3), to_net_doubles(tau4), None if tau5 is None else to_net_doubles(tau5))
|
|
95
|
+
|
|
96
|
+
@classmethod
|
|
97
|
+
def from_net(cls, net: Any) -> RegionalData:
|
|
98
|
+
"""Wrap an existing .NET ``RegionalData``.
|
|
99
|
+
|
|
100
|
+
Parameters
|
|
101
|
+
----------
|
|
102
|
+
net : Numerics.Distributions.Regional.RegionalData
|
|
103
|
+
The .NET object.
|
|
104
|
+
|
|
105
|
+
Returns
|
|
106
|
+
-------
|
|
107
|
+
RegionalData
|
|
108
|
+
The wrapper.
|
|
109
|
+
"""
|
|
110
|
+
instance = cls.__new__(cls)
|
|
111
|
+
instance._net = net
|
|
112
|
+
return instance
|
|
113
|
+
|
|
114
|
+
@classmethod
|
|
115
|
+
def from_samples(cls, samples: Any, names: Any = None) -> RegionalData:
|
|
116
|
+
"""Build regional data from each site's raw sample (``FromSamples``).
|
|
117
|
+
|
|
118
|
+
Parameters
|
|
119
|
+
----------
|
|
120
|
+
samples : sequence of array_like, or 2-D array_like
|
|
121
|
+
The sample of each site; a 2-D array has one site per row. NaN marks a missing year and is left out.
|
|
122
|
+
names : sequence of str, optional
|
|
123
|
+
The site names; None names the sites ``"1"``, ``"2"``, and so on.
|
|
124
|
+
|
|
125
|
+
Returns
|
|
126
|
+
-------
|
|
127
|
+
RegionalData
|
|
128
|
+
The sites, with the unbiased sample L-moments of ``Statistics.LinearMoments`` up to ``t5``.
|
|
129
|
+
|
|
130
|
+
Raises
|
|
131
|
+
------
|
|
132
|
+
ValueError
|
|
133
|
+
If there are no samples, or a sample holds an infinity, has fewer than four values, a nonpositive mean or
|
|
134
|
+
no spread.
|
|
135
|
+
"""
|
|
136
|
+
regional = _regional() # starts the runtime, which the System imports below need
|
|
137
|
+
from System import Double # noqa: PLC0415
|
|
138
|
+
from System.Collections.Generic import IList, List # noqa: PLC0415
|
|
139
|
+
|
|
140
|
+
rows = List[IList[Double]]()
|
|
141
|
+
for sample in samples:
|
|
142
|
+
rows.Add(to_net_doubles(np.asarray(sample, dtype=np.float64).ravel()))
|
|
143
|
+
return cls.from_net(regional.RegionalData.FromSamples(rows, None if names is None else _strings(names)))
|
|
144
|
+
|
|
145
|
+
@property
|
|
146
|
+
def net(self) -> Any:
|
|
147
|
+
"""The wrapped .NET ``RegionalData``."""
|
|
148
|
+
return self._net
|
|
149
|
+
|
|
150
|
+
@property
|
|
151
|
+
def site_count(self) -> int:
|
|
152
|
+
"""The number of sites (``SiteCount``)."""
|
|
153
|
+
return int(self._net.SiteCount)
|
|
154
|
+
|
|
155
|
+
@property
|
|
156
|
+
def names(self) -> list[str]:
|
|
157
|
+
"""The site names (``Names``)."""
|
|
158
|
+
return [str(name) for name in self._net.Names]
|
|
159
|
+
|
|
160
|
+
@property
|
|
161
|
+
def record_lengths(self) -> np.ndarray:
|
|
162
|
+
"""The record length of each site, int32 (``RecordLengths``)."""
|
|
163
|
+
return np.asarray([int(n) for n in self._net.RecordLengths], dtype=np.int32)
|
|
164
|
+
|
|
165
|
+
@property
|
|
166
|
+
def mean(self) -> np.ndarray:
|
|
167
|
+
"""The sample mean ``l1`` of each site (``Mean``)."""
|
|
168
|
+
return to_numpy_doubles(self._net.Mean)
|
|
169
|
+
|
|
170
|
+
@property
|
|
171
|
+
def l_cv(self) -> np.ndarray:
|
|
172
|
+
"""The sample L-CV of each site (``LCV``)."""
|
|
173
|
+
return to_numpy_doubles(self._net.LCV)
|
|
174
|
+
|
|
175
|
+
@property
|
|
176
|
+
def tau3(self) -> np.ndarray:
|
|
177
|
+
"""The sample L-skewness of each site (``Tau3``)."""
|
|
178
|
+
return to_numpy_doubles(self._net.Tau3)
|
|
179
|
+
|
|
180
|
+
@property
|
|
181
|
+
def tau4(self) -> np.ndarray:
|
|
182
|
+
"""The sample L-kurtosis of each site (``Tau4``)."""
|
|
183
|
+
return to_numpy_doubles(self._net.Tau4)
|
|
184
|
+
|
|
185
|
+
@property
|
|
186
|
+
def tau5(self) -> np.ndarray:
|
|
187
|
+
"""The sample ``t5`` of each site, NaN where unavailable (``Tau5``)."""
|
|
188
|
+
return to_numpy_doubles(self._net.Tau5)
|
|
189
|
+
|
|
190
|
+
def site_linear_moments(self, site: int) -> np.ndarray:
|
|
191
|
+
"""Return one site's L-moments (``SiteLinearMoments``).
|
|
192
|
+
|
|
193
|
+
Parameters
|
|
194
|
+
----------
|
|
195
|
+
site : int
|
|
196
|
+
The zero-based site index.
|
|
197
|
+
|
|
198
|
+
Returns
|
|
199
|
+
-------
|
|
200
|
+
numpy.ndarray
|
|
201
|
+
``(l1, l2, t3, t4, t5)``.
|
|
202
|
+
"""
|
|
203
|
+
return to_numpy_doubles(self._net.SiteLinearMoments(int(site)))
|
|
204
|
+
|
|
205
|
+
def regional_average(self, weights: Any = None) -> np.ndarray:
|
|
206
|
+
"""Return the regional average L-moments (``RegionalAverage``).
|
|
207
|
+
|
|
208
|
+
Parameters
|
|
209
|
+
----------
|
|
210
|
+
weights : array_like, optional
|
|
211
|
+
One nonnegative weight per site; None weights by record length (equation 4.3).
|
|
212
|
+
|
|
213
|
+
Returns
|
|
214
|
+
-------
|
|
215
|
+
numpy.ndarray
|
|
216
|
+
``(1, t^R, t3^R, t4^R, t5^R)``, the regional L-moments scaled to ``l1 = 1``.
|
|
217
|
+
"""
|
|
218
|
+
if weights is None:
|
|
219
|
+
return to_numpy_doubles(self._net.RegionalAverage())
|
|
220
|
+
return to_numpy_doubles(self._net.RegionalAverage(to_net_doubles(weights)))
|
|
221
|
+
|
|
222
|
+
def discordancy(self) -> np.ndarray:
|
|
223
|
+
"""Return the discordancy measure of each site (``Discordancy``).
|
|
224
|
+
|
|
225
|
+
Returns
|
|
226
|
+
-------
|
|
227
|
+
numpy.ndarray
|
|
228
|
+
``D_i`` by site; all 1 for three or fewer sites, all NaN when the cross-product matrix is singular.
|
|
229
|
+
"""
|
|
230
|
+
return to_numpy_doubles(self._net.Discordancy())
|
|
231
|
+
|
|
232
|
+
@staticmethod
|
|
233
|
+
def discordancy_critical_value(site_count: int, significance: float = 0.10) -> float:
|
|
234
|
+
"""Return the critical discordancy for a region (``DiscordancyCriticalValue``).
|
|
235
|
+
|
|
236
|
+
Parameters
|
|
237
|
+
----------
|
|
238
|
+
site_count : int
|
|
239
|
+
The number of sites, at least 1.
|
|
240
|
+
significance : float, optional
|
|
241
|
+
0.10 (Hosking and Wallis's Table 3.1, 3 from 15 sites) or 0.05 (4 from 19 sites).
|
|
242
|
+
|
|
243
|
+
Returns
|
|
244
|
+
-------
|
|
245
|
+
float
|
|
246
|
+
The critical value.
|
|
247
|
+
"""
|
|
248
|
+
return float(_regional().RegionalData.DiscordancyCriticalValue(int(site_count), float(significance)))
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
class RegionalHomogeneityTest:
|
|
252
|
+
"""Heterogeneity ``H`` and goodness-of-fit ``Z`` of a region by kappa simulation (``RegionalHomogeneityTest``).
|
|
253
|
+
|
|
254
|
+
Parameters
|
|
255
|
+
----------
|
|
256
|
+
data : RegionalData
|
|
257
|
+
The region, at least two sites with record lengths of at least 4.
|
|
258
|
+
simulations : int, optional
|
|
259
|
+
The number of simulated regions, at least 2 (Hosking and Wallis use 500).
|
|
260
|
+
seed : int, optional
|
|
261
|
+
The master seed; each simulated region takes its own seed drawn from it.
|
|
262
|
+
max_degree_of_parallelism : int, optional
|
|
263
|
+
The largest number of simulations run at once; -1 lets the scheduler choose. The results do not depend
|
|
264
|
+
on it.
|
|
265
|
+
|
|
266
|
+
Raises
|
|
267
|
+
------
|
|
268
|
+
ValueError
|
|
269
|
+
If the region has fewer than two sites or a record shorter than 4, or ``simulations`` is below 2.
|
|
270
|
+
"""
|
|
271
|
+
|
|
272
|
+
def __init__(self, data: RegionalData, simulations: int = 500, seed: int = 12345,
|
|
273
|
+
max_degree_of_parallelism: int = -1) -> None:
|
|
274
|
+
self._data = data
|
|
275
|
+
self._net = _regional().RegionalHomogeneityTest(data.net, int(simulations), int(seed),
|
|
276
|
+
int(max_degree_of_parallelism))
|
|
277
|
+
|
|
278
|
+
@property
|
|
279
|
+
def net(self) -> Any:
|
|
280
|
+
"""The wrapped .NET ``RegionalHomogeneityTest``."""
|
|
281
|
+
return self._net
|
|
282
|
+
|
|
283
|
+
@property
|
|
284
|
+
def data(self) -> RegionalData:
|
|
285
|
+
"""The regional data tested (``Data``)."""
|
|
286
|
+
return self._data
|
|
287
|
+
|
|
288
|
+
@property
|
|
289
|
+
def simulations(self) -> int:
|
|
290
|
+
"""The number of simulated regions (``Simulations``)."""
|
|
291
|
+
return int(self._net.Simulations)
|
|
292
|
+
|
|
293
|
+
@property
|
|
294
|
+
def seed(self) -> int:
|
|
295
|
+
"""The master seed (``Seed``)."""
|
|
296
|
+
return int(self._net.Seed)
|
|
297
|
+
|
|
298
|
+
@property
|
|
299
|
+
def regional_linear_moments(self) -> np.ndarray:
|
|
300
|
+
"""The regional average ``(1, t^R, t3^R, t4^R, t5^R)`` (``RegionalLinearMoments``)."""
|
|
301
|
+
return to_numpy_doubles(self._net.RegionalLinearMoments)
|
|
302
|
+
|
|
303
|
+
@property
|
|
304
|
+
def discordancy(self) -> np.ndarray:
|
|
305
|
+
"""The discordancy ``D_i`` of each site (``Discordancy``)."""
|
|
306
|
+
return to_numpy_doubles(self._net.Discordancy)
|
|
307
|
+
|
|
308
|
+
@property
|
|
309
|
+
def discordancy_critical_value(self) -> float:
|
|
310
|
+
"""The 10% critical discordancy for the number of sites (``DiscordancyCriticalValue``)."""
|
|
311
|
+
return float(self._net.DiscordancyCriticalValue)
|
|
312
|
+
|
|
313
|
+
@property
|
|
314
|
+
def kappa_parameters(self) -> np.ndarray:
|
|
315
|
+
"""The simulated kappa parent ``(xi, alpha, k, h)``; ``h = -1`` for the GLO stand-in (``KappaParameters``)."""
|
|
316
|
+
return to_numpy_doubles(self._net.KappaParameters)
|
|
317
|
+
|
|
318
|
+
@property
|
|
319
|
+
def is_generalized_logistic_parent(self) -> bool:
|
|
320
|
+
"""Whether the kappa fit failed and the GLO is the parent (``IsGeneralizedLogisticParent``)."""
|
|
321
|
+
return bool(self._net.IsGeneralizedLogisticParent)
|
|
322
|
+
|
|
323
|
+
@property
|
|
324
|
+
def observed_dispersion(self) -> np.ndarray:
|
|
325
|
+
"""The observed ``(V1, V2, V3)`` (``ObservedDispersion``)."""
|
|
326
|
+
return to_numpy_doubles(self._net.ObservedDispersion)
|
|
327
|
+
|
|
328
|
+
@property
|
|
329
|
+
def simulated_dispersion_mean(self) -> np.ndarray:
|
|
330
|
+
"""The mean of each V over the simulations (``SimulatedDispersionMean``)."""
|
|
331
|
+
return to_numpy_doubles(self._net.SimulatedDispersionMean)
|
|
332
|
+
|
|
333
|
+
@property
|
|
334
|
+
def simulated_dispersion_standard_deviation(self) -> np.ndarray:
|
|
335
|
+
"""The sample standard deviation of each V (``SimulatedDispersionStandardDeviation``)."""
|
|
336
|
+
return to_numpy_doubles(self._net.SimulatedDispersionStandardDeviation)
|
|
337
|
+
|
|
338
|
+
@property
|
|
339
|
+
def heterogeneity(self) -> np.ndarray:
|
|
340
|
+
"""The heterogeneity measures ``(H1, H2, H3)`` (``Heterogeneity``)."""
|
|
341
|
+
return to_numpy_doubles(self._net.Heterogeneity)
|
|
342
|
+
|
|
343
|
+
@property
|
|
344
|
+
def nonpositive_mean_simulations(self) -> int:
|
|
345
|
+
"""Simulated regions with a site of zero or negative mean, which corrupts H (``NonpositiveMeanSimulations``)."""
|
|
346
|
+
return int(self._net.NonpositiveMeanSimulations)
|
|
347
|
+
|
|
348
|
+
@property
|
|
349
|
+
def tau4_bias(self) -> float:
|
|
350
|
+
"""The bias ``B4`` of the regional L-kurtosis (``Tau4Bias``)."""
|
|
351
|
+
return float(self._net.Tau4Bias)
|
|
352
|
+
|
|
353
|
+
@property
|
|
354
|
+
def tau4_standard_deviation(self) -> float:
|
|
355
|
+
"""``sigma4``, the standard deviation of the simulated regional L-kurtosis (``Tau4StandardDeviation``)."""
|
|
356
|
+
return float(self._net.Tau4StandardDeviation)
|
|
357
|
+
|
|
358
|
+
@property
|
|
359
|
+
def distributions(self) -> list[str]:
|
|
360
|
+
"""The candidate distributions, GLO, GEV, GNO, PE3 and GPA, by type name (``Distributions``)."""
|
|
361
|
+
return [str(d) for d in self._net.Distributions]
|
|
362
|
+
|
|
363
|
+
@property
|
|
364
|
+
def distribution_tau4(self) -> np.ndarray:
|
|
365
|
+
"""The L-kurtosis of each fitted candidate (``DistributionTau4``)."""
|
|
366
|
+
return to_numpy_doubles(self._net.DistributionTau4)
|
|
367
|
+
|
|
368
|
+
@property
|
|
369
|
+
def z(self) -> dict[str, float]:
|
|
370
|
+
"""``Z^DIST`` of each candidate, keyed by Hosking's abbreviation (``Z``)."""
|
|
371
|
+
values = to_numpy_doubles(self._net.Z)
|
|
372
|
+
return dict(zip(("GLO", "GEV", "GNO", "PE3", "GPA"), (float(v) for v in values), strict=True))
|
|
373
|
+
|
|
374
|
+
def get_z(self, distribution: str) -> float:
|
|
375
|
+
"""Return ``Z^DIST`` of one candidate (``GetZ``).
|
|
376
|
+
|
|
377
|
+
Parameters
|
|
378
|
+
----------
|
|
379
|
+
distribution : str
|
|
380
|
+
A candidate, by abbreviation or type name.
|
|
381
|
+
|
|
382
|
+
Returns
|
|
383
|
+
-------
|
|
384
|
+
float
|
|
385
|
+
The goodness-of-fit measure.
|
|
386
|
+
"""
|
|
387
|
+
return float(self._net.GetZ(_type(distribution)))
|
|
388
|
+
|
|
389
|
+
def acceptable_distributions(self, critical_value: float = 1.64) -> list[str]:
|
|
390
|
+
"""Return the candidates with ``|Z|`` at most the critical value, best first (``AcceptableDistributions``).
|
|
391
|
+
|
|
392
|
+
Parameters
|
|
393
|
+
----------
|
|
394
|
+
critical_value : float, optional
|
|
395
|
+
The largest acceptable ``|Z|``; 1.64 is the 10% level.
|
|
396
|
+
|
|
397
|
+
Returns
|
|
398
|
+
-------
|
|
399
|
+
list of str
|
|
400
|
+
The accepted candidates' type names.
|
|
401
|
+
"""
|
|
402
|
+
return [str(d) for d in self._net.AcceptableDistributions(float(critical_value))]
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
class RegionalGrowthCurve:
|
|
406
|
+
"""The regional growth curve: a distribution with mean 1 fitted to regional L-moments (``RegionalGrowthCurve``).
|
|
407
|
+
|
|
408
|
+
Parameters
|
|
409
|
+
----------
|
|
410
|
+
distribution : str
|
|
411
|
+
``"GLO"``, ``"GEV"``, ``"GNO"``, ``"PE3"``, ``"GPA"`` or ``"KAP"``, or the type name.
|
|
412
|
+
data : RegionalData
|
|
413
|
+
The region; the curve is fitted to its record-length weighted regional average.
|
|
414
|
+
|
|
415
|
+
Raises
|
|
416
|
+
------
|
|
417
|
+
ValueError
|
|
418
|
+
If the distribution is not supported or the fit fails.
|
|
419
|
+
"""
|
|
420
|
+
|
|
421
|
+
def __init__(self, distribution: str, data: RegionalData) -> None:
|
|
422
|
+
self._data: RegionalData | None = data
|
|
423
|
+
self._net = _regional().RegionalGrowthCurve(_type(distribution), data.net)
|
|
424
|
+
|
|
425
|
+
@classmethod
|
|
426
|
+
def from_ratios(cls, distribution: str, l_cv: float, tau3: float,
|
|
427
|
+
tau4: float = float("nan")) -> RegionalGrowthCurve:
|
|
428
|
+
"""Fit the growth curve to regional L-moment ratios.
|
|
429
|
+
|
|
430
|
+
Parameters
|
|
431
|
+
----------
|
|
432
|
+
distribution : str
|
|
433
|
+
The family, as for the constructor.
|
|
434
|
+
l_cv : float
|
|
435
|
+
The regional L-CV, positive.
|
|
436
|
+
tau3 : float
|
|
437
|
+
The regional L-skewness.
|
|
438
|
+
tau4 : float, optional
|
|
439
|
+
The regional L-kurtosis; required only by the kappa.
|
|
440
|
+
|
|
441
|
+
Returns
|
|
442
|
+
-------
|
|
443
|
+
RegionalGrowthCurve
|
|
444
|
+
The fitted curve.
|
|
445
|
+
"""
|
|
446
|
+
instance = cls.__new__(cls)
|
|
447
|
+
instance._data = None
|
|
448
|
+
instance._net = _regional().RegionalGrowthCurve(_type(distribution), float(l_cv), float(tau3), float(tau4))
|
|
449
|
+
return instance
|
|
450
|
+
|
|
451
|
+
@property
|
|
452
|
+
def net(self) -> Any:
|
|
453
|
+
"""The wrapped .NET ``RegionalGrowthCurve``."""
|
|
454
|
+
return self._net
|
|
455
|
+
|
|
456
|
+
@property
|
|
457
|
+
def data(self) -> RegionalData | None:
|
|
458
|
+
"""The regional data the curve was fitted to, or None for ratios (``Data``)."""
|
|
459
|
+
return self._data
|
|
460
|
+
|
|
461
|
+
@property
|
|
462
|
+
def distribution_type(self) -> str:
|
|
463
|
+
"""The fitted family's type name (``DistributionType``)."""
|
|
464
|
+
return str(self._net.DistributionType)
|
|
465
|
+
|
|
466
|
+
@property
|
|
467
|
+
def parameters(self) -> np.ndarray:
|
|
468
|
+
"""The growth curve parameters in the family's order (``Parameters``)."""
|
|
469
|
+
return to_numpy_doubles(self._net.Parameters)
|
|
470
|
+
|
|
471
|
+
def get_distribution(self) -> UnivariateDistribution:
|
|
472
|
+
"""Return a copy of the growth curve distribution, whose mean is 1 (``GetDistribution``).
|
|
473
|
+
|
|
474
|
+
Returns
|
|
475
|
+
-------
|
|
476
|
+
UnivariateDistribution
|
|
477
|
+
The typed distribution wrapper.
|
|
478
|
+
"""
|
|
479
|
+
return wrap(self._net.GetDistribution())
|
|
480
|
+
|
|
481
|
+
def growth_factors(self, probabilities: Any) -> Any:
|
|
482
|
+
"""Return the growth factors at non-exceedance probabilities (``GrowthFactor``, ``GrowthFactors``).
|
|
483
|
+
|
|
484
|
+
Parameters
|
|
485
|
+
----------
|
|
486
|
+
probabilities : float or array_like
|
|
487
|
+
Non-exceedance probabilities in [0, 1].
|
|
488
|
+
|
|
489
|
+
Returns
|
|
490
|
+
-------
|
|
491
|
+
float or numpy.ndarray
|
|
492
|
+
A float for a scalar, otherwise an array shaped like ``probabilities``.
|
|
493
|
+
"""
|
|
494
|
+
p = np.asarray(probabilities, dtype=np.float64)
|
|
495
|
+
if p.ndim == 0:
|
|
496
|
+
return float(self._net.GrowthFactor(float(p)))
|
|
497
|
+
return to_numpy_doubles(self._net.GrowthFactors(to_net_doubles(p.ravel()))).reshape(p.shape)
|
|
498
|
+
|
|
499
|
+
def site_quantiles(self, index_flood: Any, probabilities: Any) -> np.ndarray:
|
|
500
|
+
"""Return site quantiles, index flood times growth factor (``SiteQuantiles``).
|
|
501
|
+
|
|
502
|
+
Parameters
|
|
503
|
+
----------
|
|
504
|
+
index_flood : float or RegionalData
|
|
505
|
+
One site's index flood, or a region whose site means are the index floods.
|
|
506
|
+
probabilities : array_like
|
|
507
|
+
Non-exceedance probabilities in [0, 1].
|
|
508
|
+
|
|
509
|
+
Returns
|
|
510
|
+
-------
|
|
511
|
+
numpy.ndarray
|
|
512
|
+
One quantile per probability, or a ``(sites, probabilities)`` array for a region.
|
|
513
|
+
"""
|
|
514
|
+
p = to_net_doubles(np.asarray(probabilities, dtype=np.float64).ravel())
|
|
515
|
+
if isinstance(index_flood, RegionalData):
|
|
516
|
+
return to_numpy_matrix(self._net.SiteQuantiles(index_flood.net, p))
|
|
517
|
+
return to_numpy_doubles(self._net.SiteQuantiles(float(index_flood), p))
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
__all__ = ["ABBREVIATIONS", "RegionalData", "RegionalGrowthCurve", "RegionalHomogeneityTest"]
|
|
521
|
+
|
|
522
|
+
translate_public(globals())
|