Return the interpolation parameter.
(n: float, q: np.ndarray, method: QUANTILE_METHODS)
| 326 | """Apply a weighted ``quantile`` to a DataArray along some dimension(s).""" |
| 327 | |
| 328 | def _get_h(n: float, q: np.ndarray, method: QUANTILE_METHODS) -> np.ndarray: |
| 329 | """Return the interpolation parameter.""" |
| 330 | # Note that options are not yet exposed in the public API. |
| 331 | h: np.ndarray |
| 332 | if method == "linear": |
| 333 | h = (n - 1) * q + 1 |
| 334 | elif method == "interpolated_inverted_cdf": |
| 335 | h = n * q |
| 336 | elif method == "hazen": |
| 337 | h = n * q + 0.5 |
| 338 | elif method == "weibull": |
| 339 | h = (n + 1) * q |
| 340 | elif method == "median_unbiased": |
| 341 | h = (n + 1 / 3) * q + 1 / 3 |
| 342 | elif method == "normal_unbiased": |
| 343 | h = (n + 1 / 4) * q + 3 / 8 |
| 344 | else: |
| 345 | raise ValueError(f"Invalid method: {method}.") |
| 346 | return h.clip(1, n) |
| 347 | |
| 348 | def _weighted_quantile_1d( |
| 349 | data: np.ndarray, |