Repository navigation
Climate Analysis
The pyhydra.climate package contains time-series analysis, bias correction,
spatial statistics and stochastic generation tools.
Package: pyhydra.climate.time_series.events
Main APIs:
extract_eventsextract_discharge_eventsextract_precipitation_eventsextract_precipitation_events_potextract_precipitation_events_ndayextract_concurrent_events
Typical uses include separating rainfall spells, extracting independent POT events and pairing event windows across multiple hydroclimatic series.
Package: pyhydra.climate.time_series.extremes
Main APIs:
extract_block_maximaextract_potthreshold_stability_plotfit_gevfit_gpdreturn_level_gevreturn_level_gpdreturn_levelsreturn_level_ciplot_return_levelsplot_diagnostic
Example:
from pyhydra.climate.time_series import extract_block_maxima, fit_gev, return_levels
annual_maxima = extract_block_maxima(series, freq="YE")
params = fit_gev(annual_maxima, method="mle")
levels = return_levels(params, [10, 50, 100], dist="gev")Bayesian and Fisher-information variants are available through:
fit_gev_mapfit_gev_fisherfit_gev_mcmc
Use them only when their assumptions and dependencies are appropriate for the study.
Package: pyhydra.climate.time_series.stats
compute_nsecompute_kgecompute_pbias
These functions compare observed and simulated series.
Package: pyhydra.climate.bias_correction
Main APIs:
delta_methodBiasCorrection
BiasCorrection provides empirical quantile mapping, quantile delta mapping and
scaled distribution mapping workflows. Typical usage:
from pyhydra.climate.bias_correction import BiasCorrection
corrected = BiasCorrection.fit_transform(
obs=obs_series,
hist=historical_model_series,
future=future_model_series,
var="pr",
method="qdm",
)Package: pyhydra.climate.spatial_analysis
fit_gev_mlefit_gev_lmomfit_gev_bayesreturn_levelreturn_level_bayesregional_index_floodfit_regional_gevregional_return_levelsregional_discordancydiscordancy_critical_valueregional_heterogeneity
Example:
from pyhydra.climate.spatial_analysis import regional_return_levels
levels = regional_return_levels(
annual_maxima_by_station,
T_values=[10, 50, 100, 500],
)fit_regional_gev/regional_return_levels also accept method="bayes": the
pooled, normalised data are fit with fit_gev_bayes (PyMC), and
regional_return_levels then returns a (median, lower, upper) tuple of
DataFrames — each station's regional posterior scaled by its own index
flood — instead of a single point-estimate DataFrame.
Before pooling stations into a region, check that the pooling is
statistically justified. Formulas are cross-checked against Hosking &
Wallis's own reference implementation (lmomRFA::regtst.s(), R package
lmomRFA):
-
regional_discordancy(data_dict)— per-station discordancy statisticDi(a Mahalanobis-type distance between a station's L-CV/L-skew/ L-kurtosis and the regional average) plus the Hosking & Wallis (1997, Table 3.1) critical value and adiscordantflag. -
discordancy_critical_value(n_sites)— the critical value alone. -
regional_heterogeneity(data_dict, n_sim=1000)— theHstatistic, from Monte Carlo simulation of homogeneous regions drawn from a kappa distribution fitted to the record-length-weighted regional-average L-moments.H < 1: acceptably homogeneous;1 <= H < 2: possibly heterogeneous;H >= 2: definitely heterogeneous — do not pool as a single region.
Both require lmoments3 (see Installation).
IDWInterpolatorKrigingInterpolatorGaussianProcessInterpolatorNeopreneGPReconstructorCopulaCDFEmulator
Kriging and Gaussian-process workflows require optional dependencies and careful validation against station density and spatial covariance assumptions.
FloodEventCopulafit_marginalfit_discrete_marginalBivariateCopulaTrivariateCopulaVineCopulaGaussianCopulaSampler
Copula workflows are intended for dependence modelling in multivariate event analysis and synthetic event generation.
HierarchicalGEV
This module supports hierarchical modelling workflows and should be interpreted with the same care as any Bayesian extreme-value model.