or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

atmospheric-indicators.mdconversion-indicators.mdcore-computation.mdensemble-analysis.mdfire-weather.mdindex.mdland-indicators.mdsea-ice-indicators.mdspatial-analogs.mdstatistical-downscaling.mdstatistical-indicators.mdutilities.md
tile.json

tessl/pypi-xclim

Climate indices computation package based on Xarray with extensive climate analysis capabilities

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/xclim@0.58.x

To install, run

npx @tessl/cli install tessl/pypi-xclim@0.58.0

index.mddocs/

XClim

A comprehensive Python library for climate indices computation based on Xarray. XClim provides extensive climate analysis capabilities including 200+ climate indicators, statistical downscaling, bias adjustment, ensemble analysis, and spatial analog methods for climate services applications.

Package Information

  • Package Name: xclim
  • Language: Python
  • Installation: pip install xclim
  • Documentation: https://xclim.readthedocs.io/

Core Imports

import xclim

Common for working with climate indicators:

from xclim import atmos, land, seaIce, generic, convert
import xclim.indices as xci

For utilities and configuration:

from xclim import set_options, units
from xclim.core import calendar, missing

Basic Usage

import xarray as xr
import xclim.atmos as xca
import xclim.indices as xci

# Load temperature data (example with sample dataset)
ds = xr.tutorial.open_dataset("air_temperature")
tasmax = ds.air.rename("tasmax")

# Compute growing degree days using high-level indicator
gdd = xca.growing_degree_days(tasmax, thresh="10 degC", freq="YS")

# Or use low-level computation function directly  
gdd_manual = xci.growing_degree_days(tasmax, thresh=10, freq="YS")

# Compute heat wave frequency
heat_waves = xca.heat_wave_frequency(
    tasmax=tasmax,
    thresh_tasmax="30 degC", 
    window=3,
    freq="YS"
)

# Work with precipitation data
pr = ds.precip.rename("pr") if "precip" in ds else None
if pr is not None:
    # Total precipitation
    precip_total = xca.prcptot(pr, freq="YS")
    
    # Consecutive dry days
    dry_days = xca.cdd(pr, thresh="1 mm/day", freq="YS")

Architecture

XClim follows a two-layer architecture:

  • Indicators Layer: High-level Indicator classes that provide automatic unit conversion, missing data validation, metadata handling, and CF-compliant output
  • Indices Layer: Low-level computation functions that perform the mathematical operations on xarray DataArrays
  • Core Utilities: Units handling, calendar operations, missing data detection, and configuration management
  • Analysis Tools: Ensemble processing, spatial analogs, and statistical downscaling capabilities

This design enables both simple usage through indicators and advanced customization through direct access to computation functions and utilities.

Capabilities

Atmospheric Indicators

Comprehensive atmospheric climate indicators including temperature, precipitation, wind, and humidity analysis with over 80 pre-defined indicators for climate services applications.

# Temperature indicators
def tg_mean(tas, freq="YS"): ...
def tx_max(tasmax, freq="YS"): ...  
def tn_min(tasmin, freq="YS"): ...
def growing_degree_days(tas, thresh="10 degC", freq="YS"): ...
def heating_degree_days(tas, thresh="17 degC", freq="YS"): ...

# Precipitation indicators  
def prcptot(pr, freq="YS"): ...
def sdii(pr, thresh="1 mm/day", freq="YS"): ...
def cdd(pr, thresh="1 mm/day", freq="YS"): ...
def r10mm(pr, thresh="10 mm/day", freq="YS"): ...

Atmospheric Indicators

Land-based Indicators

Land surface climate indicators focusing on snow, streamflow, and terrestrial processes for hydrological and agricultural applications.

# Snow indicators
def snow_depth(snd, freq="YS"): ...
def snd_max(snd, freq="YS"): ...
def continuous_snow_season_start(snd, thresh="2 cm", freq="YS"): ...

# Streamflow indicators
def base_flow_index(q, freq="YS"): ...
def rb_flashiness_index(q, freq="YS"): ...

Land Indicators

Sea Ice Indicators

Sea ice concentration and extent indicators for polar climate analysis and marine applications.

def sea_ice_area(sic, freq="YS"): ...
def sea_ice_extent(sic, freq="YS"): ...
def sic_days_above(sic, thresh="15%", freq="YS"): ...

Sea Ice Indicators

Statistical Indicators

Generic statistical analysis tools applicable to any climate variable, including distribution fitting, frequency analysis, and spell detection.

def stats(da, op="mean", freq="YS"): ...
def fit(da, dist="norm", freq="YS"): ...
def spell_length(da, threshold, op=operator.ge, freq="YS"): ...
def threshold_count(da, threshold, op=operator.ge, freq="YS"): ...

Statistical Indicators

Unit Conversion Indicators

Specialized indicators for converting between climate-related units and computing derived indices like heat index and wind chill.

def heat_index(tas, hurs, freq="YS"): ...
def humidex(tas, hurs, freq="YS"): ...
def wind_chill_index(tas, sfcwind, freq="YS"): ...

Conversion Indicators

Core Computation Functions

Low-level mathematical functions for climate indices calculation, providing the computational engine underlying all indicators.

# Temperature computations
def tg_mean(tas, freq="YS"): ...
def daily_temperature_range(tasmax, tasmin, freq="YS"): ...
def growing_degree_days(tas, thresh=10.0, freq="YS"): ...

# Precipitation computations  
def precip_accumulation(pr, freq="YS"): ...
def wetdays(pr, thresh=1.0, freq="YS"): ...
def maximum_consecutive_wet_days(pr, thresh=1.0, freq="YS"): ...

Core Computation Functions

Fire Weather Indices

Complete Canadian Forest Fire Weather Index System implementation for wildfire risk assessment and forest management applications.

def drought_code(pr, tas, lat, **kwargs): ...
def fine_fuel_moisture_code(pr, tas, hurs, sfcwind, **kwargs): ...
def fire_weather_index(pr, tas, hurs, sfcwind, lat, **kwargs): ...

Fire Weather Indices

Ensemble Analysis

Multi-model climate ensemble processing and analysis tools for climate projection assessment and uncertainty quantification.

def create_ensemble(datasets, **kwargs): ...
def ensemble_mean_std_max_min(ens, **kwargs): ...
def ensemble_percentiles(ens, values=[10, 50, 90], **kwargs): ...
def robustness_fractions(ens, test="threshold", **kwargs): ...

Ensemble Analysis

Spatial Analogs

Spatial analog analysis for identifying regions with similar climate characteristics, useful for climate adaptation and impact assessment.

def spatial_analogs(reference, candidates, method="kldiv", **kwargs): ...

Spatial Analogs

Statistical Downscaling and Bias Adjustment

Comprehensive statistical downscaling and bias correction methods for climate model post-processing.

# Adjustment methods
def EmpiricalQuantileMapping(**kwargs): ...
def DetrendedQuantileMapping(**kwargs): ...
def PrincipalComponents(**kwargs): ...

# Measures and utilities
def bias(obs, sim, **kwargs): ...
def correlation(obs, sim, **kwargs): ...

Statistical Downscaling

Utilities and Configuration

Core utilities for units handling, calendar operations, missing data management, and global configuration.

# Units operations
def convert_units_to(da, target, **kwargs): ...
def check_units(da, expected): ...

# Calendar operations  
def convert_calendar(da, target_calendar, **kwargs): ...
def get_calendar(da): ...

# Configuration
def set_options(**kwargs): ...

Utilities

Types

# Core types
from typing import Union, Optional, Sequence
import xarray as xr
import pandas as pd

DataArray = xr.DataArray
Dataset = xr.Dataset
Quantified = Union[str, int, float]  # Value with units
FreqStr = str  # Frequency string like "YS", "MS", "D"
ThresholdType = Union[str, int, float]  # Threshold with optional units

# Indicator classes
class Indicator:
    def __call__(self, *args, **kwargs) -> DataArray: ...
    
class Daily(Indicator): ...
class Monthly(Indicator): ...
class Percentile(Indicator): ...

# Missing data validators
class MissingBase: ...
class AtLeastNValid(MissingBase): ...
class SkipMissing(MissingBase): ...