climate.utils.percentile¶
Module Contents¶
- climate.utils.percentile.get_percentile(baseline_dataset, varname, percentile, freq='YS')¶
Compute a regular percentile (e.g. 90th) of a variable over time, grouped by a temporal component (month, season, or year), and expand the result to have one value per day of the input period. The final dataset uses ‘dayofyear’ as the main temporal dimension.
- Parameters:
baseline_dataset (
xr.Dataset) – Dataset containing the variable to analyze.varname (
str) – Name of the variable within the dataset.percentile (
float) – Percentile value (e.g., 90 for 90th percentile).freq (
str, optional) – Frequency for grouping (e.g. ‘YS’, ‘MS’, ‘QS’). Default is yearly.
- Returns:
Dataset with the computed percentile values expanded to daily resolution, using ‘dayofyear’ (1–365) as the main coordinate.
- Return type:
xr.Dataset
- climate.utils.percentile.pandas_offset2time_component(aggregation)¶
Map a pandas-style frequency string to a corresponding time component.
- Parameters:
aggregation (
str) – Frequency alias following pandas conventions (e.g., ‘YS’, ‘QS-DEC’, ‘MS’).- Returns:
Time component corresponding to the given frequency: - ‘YS’ → ‘year’ - ‘QS-DEC’ → ‘season’ - ‘MS’ → ‘month’
- Return type:
str- Raises:
NotImplementedError – If the provided frequency alias is not supported.
- climate.utils.percentile.calculate_percentile_doy(reference_dataset, variable, percentile, window=5)¶
Calculate the daily percentile (doy) for a given variable in a reference dataset. Wraps xclim.core.calendar.percentile_doy.
- Parameters:
reference_dataset (
xr.Dataset) – The reference dataset containing the variable.variable (
str) – The name of the variable to calculate the percentile for.percentile (
float) – The percentile value (e.g., 90 for 90th percentile).window (
int, optional) – The window size for the rolling percentile calculation, by default 5.
- Returns:
A dataset containing the calculated percentile, renamed to ‘{variable}_per’.
- Return type:
xr.Dataset