7. Analyses fréquentielles régionales¶
[1]:
import matplotlib.pyplot as plt
import xdatasets
from lmoments3.distr import KappaGen
from sklearn.cluster import HDBSCAN, OPTICS, AgglomerativeClustering
import xhydro as xh
import xhydro.frequency_analysis as xhfa
import xhydro.gis as xhgis
ERROR 1: PROJ: proj_create_from_database: Open of /home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/share/proj failed
Redefining 'percent' (<class 'pint.delegates.txt_defparser.plain.UnitDefinition'>)
Redefining '%' (<class 'pint.delegates.txt_defparser.plain.UnitDefinition'>)
Redefining 'year' (<class 'pint.delegates.txt_defparser.plain.UnitDefinition'>)
Redefining 'yr' (<class 'pint.delegates.txt_defparser.plain.UnitDefinition'>)
Redefining 'C' (<class 'pint.delegates.txt_defparser.plain.UnitDefinition'>)
Redefining 'd' (<class 'pint.delegates.txt_defparser.plain.UnitDefinition'>)
Redefining 'h' (<class 'pint.delegates.txt_defparser.plain.UnitDefinition'>)
Redefining 'degrees_north' (<class 'pint.delegates.txt_defparser.plain.UnitDefinition'>)
Redefining 'degrees_east' (<class 'pint.delegates.txt_defparser.plain.UnitDefinition'>)
Redefining 'degrees' (<class 'pint.delegates.txt_defparser.plain.UnitDefinition'>)
Redefining '[speed]' (<class 'pint.delegates.txt_defparser.plain.DerivedDimensionDefinition'>)
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/xhydro/__init__.py:21: UserWarning: The `exactextract` library is not present in the environment and will not be used.
Ce Notebook montrera comment utiliser la librairie xHydro pour réaliser des analyses fréquentielles régionales sur un jeu de données de débit. Comme les étapes initiales pour l’analyse fréquentielle régionale sont les mêmes que pour l’analyse fréquentielle locale, les utilisateurs sont invités à consulter le Notebook Analyses fréquentielles locales pour un aperçu.
Dans cet exemple, nous utiliserons le même jeu de données de stations hydrométriques couvrant une partie du sud du Québec, assurant la continuité avec l’analyse précédente tout en s’étendant à une échelle régionale. Cependant, comme les analyses régionales nécessitent l’accès à plusieurs sources de données, nous allons extraire les débits pour 15 stations.
[2]:
ds = (
xdatasets.Query(
**{
"datasets": {
"deh": {
"id": ["02*"],
"regulated": ["Natural"],
"variables": ["streamflow"],
}
},
"time": {"start": "1970-01-01", "minimum_duration": (30 * 365, "d")},
}
)
.data.squeeze()
.load()
)
# This dataset lacks some attributes, so let's add them.
ds = ds.rename({"streamflow": "q"})
ds["id"].attrs["cf_role"] = "timeseries_id"
ds["q"].attrs = {
"long_name": "Streamflow",
"units": "m3 s-1",
"standard_name": "water_volume_transport_in_river_channel",
"cell_methods": "time: mean",
}
# Clean some of the coordinates that are not needed for this example
ds = ds.drop_vars([c for c in ds.coords if c not in ["id", "time", "name"]])
timeargs = {
"annual": {},
}
ds_4fa = xh.indicators.get_yearly_op(
ds, op="max", timeargs=timeargs, missing="pct", missing_options={"tolerance": 0.15}
)
ds_4fa
[2]:
<xarray.Dataset> Size: 4kB
Dimensions: (id: 15, time: 56)
Coordinates:
* id (id) object 120B '020404' '020602' ... '024007' '024013'
* time (time) datetime64[ns] 448B 1970-01-01 ... 2025-01-01
name (id) object 120B 'York' 'Dartmouth' ... 'Bécancour'
Data variables:
q_max_annual (id, time) float32 3kB nan nan nan nan nan ... nan nan nan nan
Attributes:
cat:xrfreq: YS-JAN
cat:frequency: yr
cat:processing_level: indicators
cat:variable: ('q_max_annual',)
cat:id: 7.1. Variables explicatives¶
Dans les analyses fréquentielles régionales, les variables explicatives sont utilisées pour aider à expliquer la variation spatiale des extrêmes hydrologiques à travers différents lieux. Ces variables peuvent inclure des facteurs tels que la superficie du bassin versant, l’altitude, les précipitations, l’utilisation des terres et le type de sol, entre autres. En intégrant ces variables explicatives, nous pouvons prendre en compte l’influence des caractéristiques géographiques et environnementales sur les événements extrêmes, ce qui permet d’obtenir des prédictions régionales plus précises.
7.1.1. a) Extraction des caractéristiques des bassins versants à l’aide de xhydro.gis¶
Dans cet exemple, nous utiliserons les propriétés des bassins versants comme variables explicatives principales. Cependant, d’autres variables, telles que les moyennes climatiques ou les données d’utilisation des terres, peuvent également être intégrées en fonction des exigences de l’analyse. Pour les étapes détaillées sur comment extraire et travailler avec ces données, consultez le Notebook Opérations SIG.
[3]:
gdf = xdatasets.Query(
**{
"datasets": {
"deh_polygons": {
"id": ["02*"],
"regulated": ["Natural"],
"variables": ["streamflow"],
}
},
"time": {"start": "1970-01-01", "minimum_duration": (30 * 365, "d")},
}
).data.reset_index()
dswp = xhgis.watershed_properties(
gdf[["Station", "geometry"]], unique_id="Station", output_format="xarray"
)
dswp
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/xhydro/gis.py:201: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/xhydro/gis.py:202: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.
[3]:
<xarray.Dataset> Size: 720B
Dimensions: (Station: 15)
Coordinates:
* Station (Station) object 120B '020404' '020602' ... '024007' '024013'
Data variables:
area (Station) float64 120B 6.712e+08 6.341e+08 ... 2.319e+08
perimeter (Station) float64 120B 2.509e+05 2.079e+05 ... 1.151e+05
gravelius (Station) float64 120B 2.732 2.329 2.51 ... 2.429 2.906 2.132
centroid_lon (Station) float64 120B -65.24 -64.91 -66.19 ... -71.6 -71.33
centroid_lat (Station) float64 120B 48.9 49.04 48.96 ... 46.1 46.19 46.087.1.2. b) Analyse en composantes principales¶
Après avoir acquis les variables explicatives, l’étape suivante consiste à les traiter en utilisant l’Analyse en Composantes Principales (ACP) pour réduire la dimensionnalité du jeu de données. L’ACP permet de simplifier le jeu de données en transformant les variables originales en un ensemble réduit de composantes non corrélées, tout en conservant la plupart des variations dans les données. Cela est réalisé en utilisant la fonction xhydro.frequency_analysis.regional.fit_pca.
[4]:
help(xhfa.regional.fit_pca)
Help on function fit_pca in module xhydro.frequency_analysis.regional:
fit_pca(ds: xr.Dataset, **kwargs) -> tuple
Perform Principal Component Analysis (PCA) on the input dataset.
This function scales the input data, applies PCA transformation, and returns
the transformed data along with the PCA object.
Parameters
----------
ds : xr.Dataset
Input dataset to perform PCA on.
\*\*kwargs : dict
Additional keyword arguments to pass to the PCA constructor.
Returns
-------
tuple: A tuple containing:
- data_pca (xr.DataArray): PCA-transformed data with 'Station' and 'components' as coordinates.
- obj_pca (sklearn.decomposition.PCA): Fitted PCA object.
Notes
-----
- The input data is scaled before PCA is applied.
- The number of components in the output depends on the n_components parameter passed to PCA.
[5]:
data_pca, pca = xhfa.regional.fit_pca(dswp, n_components=3)
data_pca
[5]:
<xarray.DataArray (Station: 15, components: 3)> Size: 360B
array([[-2.48506812e+03, 8.68222390e-01, 6.18492284e-01],
[-2.28706847e+03, -3.82682765e-01, -7.46540544e-01],
[-1.48206850e+03, 3.89329737e-01, -2.41928874e-01],
[-3.82066870e+02, -4.09517146e-01, 2.10528949e-01],
[-1.85066639e+02, 2.97231987e-01, 3.20226530e-03],
[ 1.12933711e+02, -2.73945787e+00, -2.80370822e-01],
[ 4.13933839e+02, 1.43184979e+00, 4.50497174e-02],
[ 5.11933876e+02, 9.70448285e-01, 1.23118865e+00],
[ 5.32933768e+02, -5.49290384e-01, -5.67606131e-01],
[ 5.38934065e+02, -3.95607723e-01, -8.15645783e-01],
[ 5.42933642e+02, -1.23796579e+00, 1.14791838e+00],
[ 8.11933845e+02, -6.70129061e-01, 8.80067651e-01],
[ 1.11393391e+03, 2.05320024e-01, -4.18140383e-01],
[ 1.11793429e+03, 4.39850876e+00, -5.36706342e-01],
[ 1.12393366e+03, -2.17626024e+00, -5.29509020e-01]])
Coordinates:
* Station (Station) object 120B '020404' '020602' ... '024007' '024013'
* components (components) int64 24B 0 1 2
Attributes:
long_name: Fitted Scaled Data
description: Fitted scaled data with StandardScaler and PCA from sk...
fitted_variables: ['area', 'perimeter', 'gravelius', 'centroid_lon', 'ce...Les résultats montrent que la corrélation entre les composantes est proche de 0, ce qui suggère que les trois premières composantes sont suffisamment indépendantes. Cela indique que ces composantes peuvent être utilisées efficacement pour le reste de notre analyse, car elles capturent la majorité de la variation des variables explicatives, sans chevauchement ou multicolinéarité significative.
[6]:
data_pca.to_dataframe(name="value").reset_index().pivot(
index="Station", columns="components"
).corr()
[6]:
| value | ||||
|---|---|---|---|---|
| components | 0 | 1 | 2 | |
| components | ||||
| value | 0 | 1.000000e+00 | 9.942103e-14 | 1.350617e-14 |
| 1 | 9.942103e-14 | 1.000000e+00 | -4.653426e-16 | |
| 2 | 1.350617e-14 | -4.653426e-16 | 1.000000e+00 | |
7.1.3. c) Clustering (regroupement)¶
Les résultats de l’ACP peuvent être utilisés pour regrouper les stations en clusters en fonction de leurs similarités dans les composantes principales. Le clustering aide à identifier des régions avec des caractéristiques similaires, permettant des analyses fréquentielles régionales plus ciblées et précises. Cette étape est réalisée en utilisant xhydro.frequency_analysis.regional.get_clusters, qui prend en charge les méthodes de clustering de sklearn.cluster. Dans cet exemple, nous utiliserons AgglomerativeClustering pour former 3 clusters en fonction des résultats de l’ACP.
[7]:
Help on function get_clusters in module xhydro.frequency_analysis.regional:
get_clusters(model: Callable, param: dict, sample: xr.Dataset | xr.DataArray) -> list
Get indices of groups from a fit using the specified model and parameters.
Parameters
----------
model : callable
Model class or instance with a fit method.
param : dict
Parameters for the model.
sample : xr.Dataset or xr.DataArray
Data sample to fit the model.
Returns
-------
list :
List of indices for each non-excluded group.
[8]:
groups = xhfa.regional.get_clusters(
AgglomerativeClustering, {"n_clusters": 3}, data_pca
)
groups
[8]:
[array(['023303', '023401', '023422', '023428', '023432', '023701',
'024003', '024007', '024013'], dtype=object),
array(['020404', '020602', '021407'], dtype=object),
array(['022507', '022704', '023002'], dtype=object)]
[9]:
ax = plt.subplot(1, 1, 1)
gdf[gdf["Station"].isin(groups[0])].plot(ax=ax, color="red")
gdf[gdf["Station"].isin(groups[1])].plot(ax=ax, color="green")
gdf[gdf["Station"].isin(groups[2])].plot(ax=ax, color="blue")
[9]:
<Axes: >
7.2. Analyse fréquentielle régionale¶
Hosking et Wallis ont introduit une méthode pour l’analyse fréquentielle régionale basée sur les L-moments, qui sont particulièrement utiles pour l’analyse des événements extrêmes à travers différentes régions. Voici un aperçu des principaux concepts :
L-Moments : Les L-moments sont des mesures statistiques dérivées des combinaisons linéaires des statistiques d’ordre. Ils offrent une alternative plus robuste aux moments traditionnels (comme la moyenne et la variance), en particulier en présence de valeurs aberrantes ou lorsque l’on traite de petits échantillons. Les L-moments sont largement utilisés dans les études hydrologiques pour estimer les caractéristiques des valeurs extrêmes, car ils fournissent des estimations plus stables et fiables.
Analyse fréquentielle régionale : Cette technique consiste à regrouper les données de plusieurs sites ou régions pour estimer la distribution de fréquence des événements extrêmes, tels que les inondations ou les sécheresses. L’approche permet de déterminer les paramètres statistiques communs à différents endroits, offrant ainsi une perspective plus généralisée et régionale sur le comportement des événements extrêmes. La méthode de Hosking et Wallis se concentre sur l’ajustement d’une distribution fréquentielle régionale et l’évaluation de sa capacité à capturer les caractéristiques des données.
L-Moments régionaux : Il s’agit des L-moments calculés à partir des données regroupées de plusieurs sites au sein d’une région. En appliquant les L-moments régionaux, nous pouvons estimer les paramètres des distributions fréquentielles régionales et mieux comprendre l’occurrence des événements extrêmes dans différentes parties de la région. Cette méthode améliore la précision et la robustesse des prédictions des événements extrêmes, en particulier lorsque des données de plusieurs sites sont disponibles.
Commençons par calculer les L-moments pour chaque station en utilisant xhydro.frequency_analysis.regional.calc_moments.
[10]:
Help on function calc_moments in module xhydro.frequency_analysis.regional:
calc_moments(ds: xr.Dataset) -> xr.Dataset
Calculate L-moments for multiple stations.
Parameters
----------
ds : xr.Dataset
A vector of stations, where each element is an array-like object containing the data for which to calculate L-moments.
Returns
-------
xr.Dataset
L-moment dataset with a new lmom dimension.
Notes
-----
NaN values in each station are removed before calculating L-moments.
The function uses the `moment_l` function to calculate L-moments for each individual stations.
Equations are based on Hosking, J. R. M., & Wallis, J. R. (1997). Regional frequency analysis (p. 240).
[11]:
ds_moments = xhfa.regional.calc_moments(ds_4fa)
ds_moments
[11]:
<xarray.Dataset> Size: 1kB
Dimensions: (id: 15, lmom: 6)
Coordinates:
* id (id) object 120B '020404' '020602' ... '024007' '024013'
* lmom (lmom) <U4 96B 'l1' 'l2' 'l3' 'tau' 'tau3' 'tau4'
name (id) object 120B 'York' 'Dartmouth' ... 'Bécancour'
Data variables:
q_max_annual (id, lmom) float64 720B 145.1 31.03 5.494 ... 0.0697 0.1307
Attributes:
cat:xrfreq: YS-JAN
cat:frequency: yr
cat:processing_level: indicators
cat:variable: ('q_max_annual',)
cat:id: Pour effectuer une analyse fréquentielle régionale, nous devons remodeler nos jeux de données de maximums annuels et de L-moments en fonction des regroupements identifiés par l’algorithme de clustering. Étant donné qu’il n’existe pas de convention de nommage standardisée pour cette nouvelle dimension, xHydro utilise le nom region_id pour les regroupements de clusters. Ce processus de remodelage est géré par la fonction xhydro.frequency_analysis.regional.group_ds_by_regions, qui organise les données en fonction des affectations de clusters et les prépare pour l’analyse ultérieure.
[12]:
Help on function group_ds_by_regions in module xhydro.frequency_analysis.regional:
group_ds_by_regions(ds: xr.Dataset, *, regions: list) -> xr.Dataset
Group a dataset by a list of regions.
Parameters
----------
ds : xr.Dataset
The input dataset to be grouped.
The associated dimension must have a 'cf_role: timeseries_id' attribute.
regions : list
A list of regions to be used for grouping the dataset.
Returns
-------
xr.Dataset
A new dataset with the grouped data.
[13]:
ds_groups = xhfa.regional.group_ds_by_regions(ds_4fa, regions=groups)
ds_moments_groups = xhfa.regional.group_ds_by_regions(ds_moments, regions=groups)
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/xhydro/frequency_analysis/regional.py:672: FutureWarning: In a future version of xarray the default value for join will change from join='outer' to join='exact'. This change will result in the following ValueError: cannot be aligned with join='exact' because index/labels/sizes are not equal along these coordinates (dimensions): 'id' ('id',) The recommendation is to set join explicitly for this case.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/xhydro/frequency_analysis/regional.py:672: FutureWarning: In a future version of xarray the default value for coords will change from coords='different' to coords='minimal'. This is likely to lead to different results when multiple datasets have matching variables with overlapping values. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set coords explicitly.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/xhydro/frequency_analysis/regional.py:672: FutureWarning: In a future version of xarray the default value for join will change from join='outer' to join='exact'. This change will result in the following ValueError: cannot be aligned with join='exact' because index/labels/sizes are not equal along these coordinates (dimensions): 'id' ('id',) The recommendation is to set join explicitly for this case.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/xhydro/frequency_analysis/regional.py:672: FutureWarning: In a future version of xarray the default value for coords will change from coords='different' to coords='minimal'. This is likely to lead to different results when multiple datasets have matching variables with overlapping values. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set coords explicitly.
Nous devons maintenant calculer deux scores importants pour évaluer l’analyse fréquentielle régionale : le H-Score et le Z-Score. Le H-Score mesure l’homogénéité des données à travers différents sites ou régions par rapport au modèle régional. Il permet de déterminer dans quelle mesure les données de plusieurs sites s’alignent avec la distribution régionale. Le Z-Score quantifie l’écart entre les valeurs observées et attendues, standardisé par leur variabilité. Il aide à déterminer dans quelle mesure la distribution théorique (basée sur le modèle régional) correspond aux données observées.
H-Score (Score d’homogénéité)
- H < 1 : HomogèneCela indique que les données des différents sites sont assez similaires et s’alignent bien avec le modèle régional, ce qui suggère que le modèle régional est adapté pour l’ensemble de la région.
- 1 ≤ H < 2 : Peut-être homogèneCette plage suggère une certaine hétérogénéité, ce qui signifie que les données peuvent encore s’adapter généralement au modèle régional, mais qu’il existe des variations que le modèle ne capture pas entièrement.
- H ≥ 2 : HétérogèneUn score aussi élevé indique des différences significatives entre les sites ou les régions, suggérant que le modèle régional pourrait ne pas être adapté à toutes les données. La région peut être trop diverse ou nécessiter des ajustements du modèle.
Z-Score (Qualité de l’ajustement)
Z-Score faible : Un Z-Score faible suggère un bon ajustement entre le modèle et les données observées. En général, un Z-Score absolu inférieur à 1,64 indique que le modèle est approprié et que l’ajustement est statistiquement acceptable.
Z-Score élevé : Un Z-Score élevé suggère des écarts significatifs entre les valeurs observées et attendues. Un Z-Score absolu supérieur à 1,64 implique que le modèle ne correspond peut-être pas bien aux données et que des ajustements supplémentaires ou un modèle différent pourraient être nécessaires.
La fonction xhydro.frequency_analysis.regional.calc_h_z est utilisée pour calculer le H-Score et le Z-Score pour l’analyse fréquentielle régionale.
AVERTISSEMENT
L’argument kap dans la fonction xhydro.frequency_analysis.regional.calc_h_z attend un objet de distribution Kappa3 généré à l’aide de lmoments3.distr.KappaGen(). En raison de problèmes de licence, la librairie lmoments3 ne peut pas être incluse dans les exigences de xHydro et doit être installée indépendamment.
[14]:
help(xhfa.regional.calc_h_z)
Help on function calc_h_z in module xhydro.frequency_analysis.regional:
calc_h_z(
ds_regions: xr.Dataset,
ds_moments_regions: xr.Dataset,
*,
kap: object,
seed: int | None = None
) -> xr.Dataset
Calculate heterogeneity measure H and Z-score for regional frequency analysis.
Parameters
----------
ds_regions : xr.Dataset
Dataset containing regions.
ds_moments_regions : xr.Dataset
Dataset containing L-moments for ds_regions.
kap : scipy.stats.kappa3
Kappa3 distribution object.
seed : int, optional
Random seed for reproducibility. Default is None.
Returns
-------
xr.Dataset
Dataset containing calculated H values and Z-scores for each region.
Notes
-----
This function applies the heterogeneity measure and Z-score calculations
for the regional frequency analysis. It uses L-moments and
the Kappa3 distribution in the process.
This function does not support lazy evaluation.
Equations are based on Hosking, J. R. M., & Wallis, J. R. (1997). Regional frequency analysis (p. 240).
[15]:
ds_hz = xhfa.regional.calc_h_z(ds_groups, ds_moments_groups, kap=KappaGen())
ds_hz
[15]:
<xarray.Dataset> Size: 96B
Dimensions: (region_id: 3, crit: 2)
Coordinates:
* region_id (region_id) int64 24B 0 1 2
* crit (crit) <U1 8B 'H' 'Z'
lmom <U4 16B 'l1'
Data variables:
q_max_annual (crit, region_id) float64 48B 0.6422 0.5977 ... 0.1358 0.3439Nous pouvons filtrer les résultats pour inclure uniquement les données ayant des scores H et Z inférieurs aux seuils donnés en utilisant la fonction xhydro.frequency_analysis.regional.mask_h_z. Par défaut, les seuils sont définis à 1 pour H et 1,64 pour Z. Cependant, ces seuils peuvent être personnalisés en fonction des exigences spécifiques de l’analyse fréquentielle.
[16]:
help(xhfa.regional.mask_h_z)
Help on function mask_h_z in module xhydro.frequency_analysis.regional:
mask_h_z(
ds: xr.Dataset,
*,
thresh_h: float | None = 1,
thresh_z: float | None = 1.64
) -> xr.DataArray
Create a boolean mask based on heterogeneity measure H and Z-score thresholds.
Parameters
----------
ds : xr.Dataset
Dataset containing H and Z values for each region.
thresh_h : float, optional
Threshold for the heterogeneity measure H. Default is 1.
thresh_z : float, optional
Threshold for the absolute Z-score. Default is 1.64.
Returns
-------
xr.DataArray
Boolean mask where True indicates regions that meet both threshold criteria.
[17]:
mask = xhfa.regional.mask_h_z(ds_hz)
ds_groups_h1 = ds_groups.where(mask).load()
ds_moments_groups_h1 = ds_moments_groups.where(mask).load()
La dernière étape de l’analyse fréquentielle régionale est similaire à l’analyse fréquentielle locale, mais au lieu d’utiliser xhydro.frequency_analysis.local.parametric_quantiles, nous utilisons xhydro.frequency_analysis.regional.calculate_return_period pour calculer les périodes de retour. De plus, pour éviter de réaliser l’analyse sur des régions très petites, l’argument remove_small_regions peut être utilisé pour exclure toute région comportant moins d’un nombre spécifié de stations. Par défaut, ce seuil est fixé à 5.
[18]:
Help on function calculate_return_period in module xhydro.frequency_analysis.regional:
calculate_return_period(
ds_regions: xr.Dataset,
ds_moments_regions: xr.Dataset,
*,
return_period: np.array,
l1: xr.DataArray | None = None
) -> xr.DataArray
Calculate return periods from the regional frequency analysis.
Parameters
----------
ds_regions : xr.Dataset
Dataset containing region flow data.
ds_moments_regions : xr.Dataset
Dataset containing L-moments for region data.
return_period : array-like
Return periods to calculate.
l1 : xr.DataArray, optional
First L-moment (location) values. L-moment can be specified for ungauged catchments.
If None, values are taken from ds_moments_regions.
Returns
-------
xr.DataArray
Calculated return periods for each region and specified return period.
Notes
-----
This function calculates return periods using the Annual Flow Regime method.
If l1 is not provided, it uses the first L-moment from ds_moments_regions.
The function internally calls calculate_ic_from_AFR to compute the flood index.
Equations are based on Hosking, J. R. M., & Wallis, J. R. (1997). Regional frequency analysis (p. 240).
[19]:
Help on function remove_small_regions in module xhydro.frequency_analysis.regional:
remove_small_regions(ds: xr.Dataset, *, thresh: int = 5) -> xr.Dataset
Remove regions from the dataset that have fewer than the threshold number of stations.
Parameters
----------
ds : xr.Dataset
The input dataset containing regions and stations.
thresh : int, optional
The minimum number of stations required for a region to be kept. Default is 5.
Returns
-------
xr.Dataset
The dataset with small regions removed.
[20]:
q_t = xhfa.regional.calculate_return_period(
ds_groups_h1, ds_moments_groups_h1, return_period=[2, 20, 100]
)
q_t
[20]:
<xarray.Dataset> Size: 2kB
Dimensions: (region_id: 3, return_period: 3, id: 15)
Coordinates:
* region_id (region_id) int64 24B 0 1 2
* return_period (return_period) int64 24B 2 20 100
* id (id) object 120B '020404' '020602' ... '024007' '024013'
lmom <U4 16B 'l1'
name (region_id, id) object 360B nan nan nan nan ... nan nan nan
Data variables:
q_max_annual (region_id, return_period, id) float64 1kB nan nan ... nan[21]:
q_t = xhfa.regional.remove_small_regions(q_t)
q_t
[21]:
<xarray.Dataset> Size: 648B
Dimensions: (region_id: 1, return_period: 3, id: 15)
Coordinates:
* region_id (region_id) int64 8B 0
* return_period (return_period) int64 24B 2 20 100
* id (id) object 120B '020404' '020602' ... '024007' '024013'
lmom <U4 16B 'l1'
name (region_id, id) object 120B nan nan ... 'Bécancour'
Data variables:
q_max_annual (region_id, return_period, id) float64 360B nan nan ... 131.7Affichons les résultats pour une station, en comparant les analyses locales et régionales.
[22]:
q_reg = q_t.sel(id="023401").dropna(dim="region_id", how="all")
reg = q_reg.q_max_annual.squeeze()
[23]:
params_loc = xhfa.local.fit(ds_4fa.sel(id="023401"))
q_loc = xhfa.local.parametric_quantiles(params_loc, return_period=[2, 20, 100])
loc = q_loc.sel(scipy_dist="genextreme").q_max_annual
[24]:
fig = plt.figure(figsize=(15, 4))
plt.plot(reg.return_period.values, reg.values, "red", label="Regional analysis")
plt.plot(loc.return_period.values, loc.values, "black", label="Local analysis")
plt.xscale("log")
plt.grid(visible=True)
plt.xlabel("Return period (years)")
plt.ylabel("Streamflow (m$^3$/s)")
plt.legend()
[24]:
<matplotlib.legend.Legend at 0x7b88250c2660>
7.3. Incertitudes¶
Les incertitudes sont un aspect important de l’analyse fréquentielle et doivent être prises en compte lors de l’interprétation des résultats. Ces incertitudes proviennent souvent de la qualité des données, du choix de la distribution et de l’estimation des paramètres. Bien que les visualisations puissent fournir des informations sur l’ajustement du modèle, il est essentiel de quantifier et de prendre en compte les incertitudes, telles que les intervalles de confiance pour les estimations des paramètres, afin d’assurer des conclusions robustes.
7.3.1. a) Bootstrap des observations¶
Une méthode pour quantifier les incertitudes consiste à effectuer un bootstrap des observations. Dans cet exemple, nous effectuerons le bootstrap un petit nombre de fois pour illustrer le processus, bien qu’en pratique, un nombre plus élevé d’itérations (par exemple, 5000) soit recommandé pour obtenir des estimations plus fiables. Le bootstrap consiste à rééchantillonner les données observées avec remplacement pour générer plusieurs ensembles de données, qui peuvent ensuite être utilisés pour évaluer la variabilité des paramètres et des résultats du modèle.
Cela peut être réalisé en appelant xhydro.frequency_analysis.uncertainties.bootstrap_obs. Une différence importante avec les analyses locales est qu’aucune étape d’ajustement n’est nécessaire pour les analyses fréquentielles régionales, ce qui rend cette fonction beaucoup plus rapide. Les résultats sont obtenus en utilisant d’abord xhydro.frequency_analysis.uncertainties.calc_moments_iter pour calculer les L-moments pour tous les échantillons de bootstrap. Ensuite, xhydro.frequency_analysis.uncertainties.calculate_quantiles_over_boostraped_groups est utilisé pour calculer les périodes de retour à partir de ces L-moments.
[25]:
help(xhfa.uncertainties.calculate_quantiles_over_boostraped_groups)
Help on function calculate_quantiles_over_boostraped_groups in module xhydro.frequency_analysis.uncertainties:
calculate_quantiles_over_boostraped_groups(
bv: str,
groups: xr.DataArray | xr.Dataset,
moments_iter: xr.DataArray | xr.Dataset,
return_period: np.array,
small_regions_threshold: int | None = 5,
l1: xr.DataArray | None = None
) -> xr.DataArray
Calculate quantiles for each bootstrap sample and group.
Parameters
----------
bv : str
The basin identifier or 'all' to proceed on all basins (needed for ungauged).
The associated dimension must have a 'cf_role: timeseries_id' attribute.
groups : xr.DataArray or xr.Dataset
The grouped data.
moments_iter : xr.DataArray or xr.Dataset
The L-moments for each bootstrap sample.
return_period : array-like
The return periods to calculate quantiles for.
small_regions_threshold : int, optional
The threshold for removing small regions. Default is 5.
l1 : xr.DataArray, optional
First L-moment (location) values. L-moment can be specified for ungauged catchments.
If `None`, values are taken from ds_moments_iter.
Returns
-------
xr.DataArray or xr.Dataset
Quantiles for each bootstrap sample and group. Returns a Dataset if input groups
and moments_iter are Datasets, otherwise returns a DataArray.
[26]:
help(xhfa.uncertainties.calculate_quantiles_over_boostraped_groups)
Help on function calculate_quantiles_over_boostraped_groups in module xhydro.frequency_analysis.uncertainties:
calculate_quantiles_over_boostraped_groups(
bv: str,
groups: xr.DataArray | xr.Dataset,
moments_iter: xr.DataArray | xr.Dataset,
return_period: np.array,
small_regions_threshold: int | None = 5,
l1: xr.DataArray | None = None
) -> xr.DataArray
Calculate quantiles for each bootstrap sample and group.
Parameters
----------
bv : str
The basin identifier or 'all' to proceed on all basins (needed for ungauged).
The associated dimension must have a 'cf_role: timeseries_id' attribute.
groups : xr.DataArray or xr.Dataset
The grouped data.
moments_iter : xr.DataArray or xr.Dataset
The L-moments for each bootstrap sample.
return_period : array-like
The return periods to calculate quantiles for.
small_regions_threshold : int, optional
The threshold for removing small regions. Default is 5.
l1 : xr.DataArray, optional
First L-moment (location) values. L-moment can be specified for ungauged catchments.
If `None`, values are taken from ds_moments_iter.
Returns
-------
xr.DataArray or xr.Dataset
Quantiles for each bootstrap sample and group. Returns a Dataset if input groups
and moments_iter are Datasets, otherwise returns a DataArray.
[27]:
ds_reg_boot = xhfa.uncertainties.bootstrap_obs(ds_4fa, n_samples=35)
ds_moments_iter = xhfa.uncertainties.calc_moments_iter(ds_reg_boot).load()
ds_moments_iter
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/xhydro/frequency_analysis/regional.py:222: RuntimeWarning: invalid value encountered in scalar divide
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/xhydro/frequency_analysis/regional.py:223: RuntimeWarning: invalid value encountered in scalar divide
[27]:
<xarray.Dataset> Size: 26kB
Dimensions: (samples: 35, id: 15, lmom: 6)
Coordinates:
* samples (samples) int64 280B 0 1 2 3 4 5 6 7 ... 28 29 30 31 32 33 34
* id (id) object 120B '020404' '020602' ... '024007' '024013'
* lmom (lmom) <U4 96B 'l1' 'l2' 'l3' 'tau' 'tau3' 'tau4'
name (id) object 120B 'York' 'Dartmouth' ... 'Bécancour'
Data variables:
q_max_annual (samples, id, lmom) float64 25kB 153.4 35.29 ... 0.07174[28]:
q_reg_boot = xhfa.uncertainties.calculate_quantiles_over_boostraped_groups(
"023401",
ds_groups_h1,
ds_moments_iter,
return_period=[2, 20, 100],
)
q_reg_boot
[28]:
<xarray.Dataset> Size: 2kB
Dimensions: (return_period: 3, id: 1, samples: 35)
Coordinates:
* return_period (return_period) int64 24B 2 20 100
* id (id) <U6 24B '023401'
* samples (samples) object 280B MultiIndex
lmom <U4 16B 'l1'
name object 8B 'Beaurivage'
* region_id (samples) int64 280B 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0
* obs_samples (samples) int64 280B 0 1 2 3 4 5 6 7 ... 28 29 30 31 32 33 34
variable <U12 48B 'q_max_annual'
Data variables:
q_max_annual (id, return_period, samples) float64 840B 192.1 ... 386.47.3.2. b) Utilisation de plusieurs régions¶
Une autre approche pour estimer l’incertitude consiste à considérer plusieurs régions pour un bassin versant d’intérêt. Cela peut être réalisé en appliquant différentes méthodes de clustering ou en effectuant une procédure de jackknife sur la liste des stations. Comme ce processus peut être intensif en termes de calcul, nous présentons ici un exemple simplifié pour illustrer le potentiel de cette méthode. L’objectif principal est de démontrer comment la prise en compte de plusieurs régions peut aider à évaluer l’incertitude dans l’analyse fréquentielle régionale.
Tout d’abord, nous utiliserons xhydro.frequency_analysis.uncertainties.generate_combinations sur les résultats de notre ACP pour générer des listes de stations. Cette fonction crée des combinaisons qui excluent un certain nombre de stations à chaque fois, nous permettant ainsi d’évaluer comment l’exclusion de différentes stations affecte les regroupements.
[29]:
Help on function generate_combinations in module xhydro.frequency_analysis.uncertainties:
generate_combinations(da: xr.DataArray, *, n: int) -> list
Generate combinations of indices omitting up to N indices.
Parameters
----------
da : xarray.DataArray
Input DataArray.
n : int
Number of indices to omit in each combination.
Returns
-------
list
List of all combinations.
[30]:
combinations_list = xhfa.uncertainties.generate_combinations(data_pca, n=2)
print(
f"This generated {len(combinations_list)} lists of stations, varying from {len(combinations_list[0])} to {len(combinations_list[-1])} stations."
)
This generated 121 lists of stations, varying from 15 to 13 stations.
Ensuite, nous combinerons ces listes avec trois méthodes de clustering et, pour chaque méthode, nous essaierons de modifier certains des paramètres.
[31]:
clust_options = {
AgglomerativeClustering: {"arg_name": "n_clusters", "range": range(2, 12)},
HDBSCAN: {"arg_name": "min_cluster_size", "range": range(6, 7)},
OPTICS: {"arg_name": "min_samples", "range": range(4, 5)},
}
[32]:
groups = []
for model in [AgglomerativeClustering, HDBSCAN, OPTICS]:
for p in clust_options[model]["range"]:
d_param = {}
d_param[clust_options[model]["arg_name"]] = p
for combination in combinations_list:
# Extract data for the current combination
data_com = data_pca.sel(Station=list(combination))
# Get groups from the fit and add to the list
groups = groups + xhfa.regional.get_clusters(model, d_param, data_com)
unique_groups = [list(x) for x in {tuple(x) for x in groups}]
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/sklearn/cluster/_hdbscan/hdbscan.py:722: FutureWarning: The default value of `copy` will change from False to True in 1.10. Explicitly set a value for `copy` to silence this warning.
Les étapes suivantes suivent une approche similaire à celles précédentes, mais maintenant avec plusieurs régions.
[33]:
ds_groups_multiregion = xhfa.regional.group_ds_by_regions(ds_4fa, regions=unique_groups)
ds_moments_groups_multiregion = xhfa.regional.group_ds_by_regions(
ds_moments, regions=unique_groups
)
ds_h_z_multiregion = xhfa.regional.calc_h_z(
ds_groups_multiregion, ds_moments_groups_multiregion, kap=KappaGen()
)
mask_multiregion = xhfa.regional.mask_h_z(ds_h_z_multiregion)
ds_groups_h1_multiregion = ds_groups_multiregion.where(mask_multiregion).load()
ds_moments_groups_h1_multiregion = ds_moments_groups_multiregion.where(
mask_multiregion
).load()
q_t_multiregion = xhfa.regional.calculate_return_period(
ds_groups_h1_multiregion,
ds_moments_groups_h1_multiregion,
return_period=[2, 20, 100],
)
q_t_multiregion = xhfa.regional.remove_small_regions(q_t_multiregion)
q = q_t_multiregion.sel(id="023401").dropna(dim="region_id", how="all")
q
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/xhydro/frequency_analysis/regional.py:672: FutureWarning: In a future version of xarray the default value for join will change from join='outer' to join='exact'. This change will result in the following ValueError: cannot be aligned with join='exact' because index/labels/sizes are not equal along these coordinates (dimensions): 'id' ('id',) The recommendation is to set join explicitly for this case.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/xhydro/frequency_analysis/regional.py:672: FutureWarning: In a future version of xarray the default value for coords will change from coords='different' to coords='minimal'. This is likely to lead to different results when multiple datasets have matching variables with overlapping values. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set coords explicitly.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/xhydro/frequency_analysis/regional.py:672: FutureWarning: In a future version of xarray the default value for join will change from join='outer' to join='exact'. This change will result in the following ValueError: cannot be aligned with join='exact' because index/labels/sizes are not equal along these coordinates (dimensions): 'id' ('id',) The recommendation is to set join explicitly for this case.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/xhydro/frequency_analysis/regional.py:672: FutureWarning: In a future version of xarray the default value for coords will change from coords='different' to coords='minimal'. This is likely to lead to different results when multiple datasets have matching variables with overlapping values. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set coords explicitly.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/lmoments3/distr.py:579: RuntimeWarning: invalid value encountered in power
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/numpy/lib/_function_base_impl.py:2630: UserWarning: Kappa distribution fit blablabla (quelle serait la cause d'un ValueError?), returning all NaNs. Error: L-Moments invalid.
[33]:
<xarray.Dataset> Size: 7kB
Dimensions: (region_id: 172, return_period: 3)
Coordinates:
* region_id (region_id) int64 1kB 2 3 5 6 9 11 ... 315 316 318 322 323
* return_period (return_period) int64 24B 2 20 100
lmom <U4 16B 'l1'
id <U6 24B '023401'
name (region_id) object 1kB 'Beaurivage' ... 'Beaurivage'
Data variables:
q_max_annual (region_id, return_period) float64 4kB 188.9 321.8 ... 418.37.3.3. c) Combinaison du bootstrap avec plusieurs régions¶
Il est possible de combiner les deux méthodes—bootstrap et plusieurs régions—en intégrant les éléments suivants :
Les L-moments bootstrapés de
xhydro.frequency_analysis.uncertainties.calc_moments_iter.Les résultats masqués de
xhydro.frequency_analysis.regional.group_ds_by_regionsqui ont été filtrés en fonction des scores H et Z.
Lors de la combinaison de ces méthodes, xhydro.frequency_analysis.uncertainties.calculate_quantiles_over_boostraped_groups vérifiera dans combien de valeurs distinctes de region_id la station est présente et empilera les données en conséquence avec les échantillons de bootstrap. Par exemple, si nous avons 35 bootstraps et environ 220 régions, cela générera un total d’environ 7 700 échantillons pour l’analyse ultérieure.
[34]:
q_reg_multiregion_boot = xhfa.uncertainties.calculate_quantiles_over_boostraped_groups(
"023401",
ds_groups_h1_multiregion,
ds_moments_iter,
return_period=[2, 20, 100],
)
q_reg_multiregion_boot
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/xhydro/frequency_analysis/uncertainties.py:223: FutureWarning: In a future version of xarray the default value for join will change from join='outer' to join='exact'. This change will result in the following ValueError: cannot be aligned with join='exact' because index/labels/sizes are not equal along these coordinates (dimensions): 'id' ('id',) The recommendation is to set join explicitly for this case.
/home/docs/checkouts/readthedocs.org/user_builds/xhydro-fr/conda/latest/lib/python3.14/site-packages/xhydro/frequency_analysis/uncertainties.py:223: FutureWarning: In a future version of xarray the default value for coords will change from coords='different' to coords='minimal'. This is likely to lead to different results when multiple datasets have matching variables with overlapping values. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set coords explicitly.
[34]:
<xarray.Dataset> Size: 337kB
Dimensions: (return_period: 3, id: 1, samples: 6020)
Coordinates:
* return_period (return_period) int64 24B 2 20 100
* id (id) <U6 24B '023401'
* samples (samples) object 48kB MultiIndex
lmom <U4 16B 'l1'
name (samples) object 48kB 'Beaurivage' ... 'Beaurivage'
* region_id (samples) int64 48kB 2 2 2 2 2 2 ... 323 323 323 323 323 323
* obs_samples (samples) int64 48kB 0 1 2 3 4 5 6 7 ... 28 29 30 31 32 33 34
variable <U12 48B 'q_max_annual'
Data variables:
q_max_annual (id, return_period, samples) float64 144kB 194.8 ... 413.97.3.4. d) Comparaison¶
Illustrons la différence entre les approches.
[35]:
fig, ax = plt.subplots(1, 3)
fig.set_figheight(4)
fig.set_figwidth(15)
# Subset the data
q_reg_boots = q_reg_boot.q_max_annual.sel(id="023401")
q_t_multiregions = q_t_multiregion.q_max_annual.sel(id="023401")
q_t_multiregion_boots = q_reg_multiregion_boot.q_max_annual.sel(id="023401")
def _make_plot(data, dim, label):
# Original fit
ax.plot(
loc.return_period.values,
loc,
"black",
label="Local frequency analysis",
)
ax.plot(
reg.return_period.values,
reg,
"red",
label="Original regional frequency analysis",
)
ax.plot(
data.return_period.values,
data.quantile(0.5, dim),
"green",
label=label,
)
data_05 = data.quantile(0.05, dim)
data_95 = data.quantile(0.95, dim)
ax.fill_between(
data.return_period.values, data_05, data_95, alpha=0.2, color="green"
)
plt.xscale("log")
plt.grid(visible=True)
plt.xlabel("Return period (years)")
plt.ylabel("Streamflow (m$^3$/s)")
plt.ylim([150, 500])
ax.legend()
ax = plt.subplot(1, 3, 1)
_make_plot(q_reg_boots, "samples", "Bootstrapped observations")
ax = plt.subplot(1, 3, 2)
_make_plot(q_t_multiregions, "region_id", "Multiple regions")
ax = plt.subplot(1, 3, 3)
_make_plot(q_t_multiregion_boots, "samples", "Combined")