Skip to main content

CAVA Python package. Retrive climate data.

Project description

cavapy logo

PyPI version Total downloads Python 3.11+

Retrieve, subset, and process CORDEX-CORE and ERA5 climate data directly from THREDDS/OPeNDAP.

Star this project on GitHub


What is cavapy?

cavapy is a Python package built for climate-impact workflows where you need reliable data access without handling massive raw NetCDF archives manually.

It is part of the CAVA (Climate and Agriculture Risk Visualization and Assessment) ecosystem and focuses on:

  • Fast access to CORDEX-CORE simulations
  • Access to ERA5 observations
  • Optional bias correction and calendar harmonization
  • Clean integration with downstream hydrology, agronomy, and risk-analysis pipelines

Project context: CAVA overview


Data Coverage

Sources

  • CORDEX-CORE regional climate simulations (25 km)
  • ERA5 reanalysis (used directly and for optional correction workflows)

Data is hosted on the University of Cantabria THREDDS infrastructure within the CAVA initiative (FAO, University of Cantabria, University of Cape Town, Predictia).

Available datasets

  • CORDEX-CORE: original model outputs
  • CORDEX-CORE-BC: pre-bias-corrected outputs using ISIMIP methodology

Available variables

  • tasmax: daily maximum temperature (degC)
  • tasmin: daily minimum temperature (degC)
  • pr: daily precipitation (mm)
  • hurs: daily relative humidity (%)
  • sfcWind: daily wind speed at 2 m (m/s)
  • rsds: daily solar radiation (W/m2)

Supported domains and scenario/model options

  • Domains: NAM-22, EUR-22, AFR-22, EAS-22, SEA-22, WAS-22, AUS-22, SAM-22, CAM-22
  • RCPs: rcp26, rcp85
  • GCMs: MOHC, MPI, NCC
  • RCMs: REMO, Reg

Installation

conda create -n cavapy "python>=3.11"
conda activate cavapy
pip install cavapy

Quick Start

1) Pre-bias-corrected projections (recommended)

import cavapy

togo = cavapy.get_climate_data(
    country="Togo",
    variables=["tasmax", "pr"],
    cordex_domain="AFR-22",
    rcp="rcp26",
    gcm="MPI",
    rcm="REMO",
    years_up_to=2030,
    dataset="CORDEX-CORE-BC",
)

2) Original CORDEX-CORE with on-the-fly bias correction

import cavapy

togo = cavapy.get_climate_data(
    country="Togo",
    variables=["tasmax", "pr"],
    cordex_domain="AFR-22",
    rcp="rcp26",
    gcm="MPI",
    rcm="REMO",
    years_up_to=2030,
    bias_correction=True,
    dataset="CORDEX-CORE",
)

3) ERA5 observations only

import cavapy

era5 = cavapy.get_climate_data(
    country="Togo",
    variables=["tasmax", "pr"],
    obs=True,
    years_obs=range(1980, 2019),
)

Core Workflows

Projections + historical baseline

import cavapy

data = cavapy.get_climate_data(
    country="Afghanistan",
    variables=["tasmax", "pr"],
    cordex_domain="WAS-22",
    rcp="rcp85",
    gcm="NCC",
    rcm="REMO",
    years_up_to=2030,
    historical=True,
    dataset="CORDEX-CORE-BC",
)

Multiple models and/or RCPs

Pass lists (or None) to rcp, gcm, and rcm.

import cavapy

multi = cavapy.get_climate_data(
    country="Togo",
    cordex_domain="AFR-22",
    rcp=["rcp26", "rcp85"],
    gcm=["MPI", "MOHC"],
    rcm=["Reg", "REMO"],
    years_up_to=2030,
    historical=True,
)

Return shape for multi-combination requests:

multi[rcp][f"{gcm}-{rcm}"][variable]  # -> xarray.DataArray

Processing Pipeline

get_climate_data() orchestrates:

  • Server-side access and subsetting via OPeNDAP
  • Parallel data retrieval
  • Unit conversions
  • Calendar conversion to Gregorian calendar
  • Optional empirical quantile mapping bias correction

Parallelization behavior

  • Single model/scenario combo: parallel across variables
  • Multiple combos: parallel across combo-variable tasks, capped globally
  • Sequential mode is used when num_processes <= 1 or only one variable is requested
  • Default global cap for multi-combo execution: up to 6 processes
  • Inside each process, threaded downloads are used for fetch operations

Plotting

cavapy includes built-in plotting helpers:

  • plot_spatial_map()
  • plot_time_series()

Spatial map example

import cavapy

data = cavapy.get_climate_data(country="Togo", obs=True, years_obs=range(1990, 2011))

fig = cavapy.plot_spatial_map(
    data["tasmax"],
    time_period=(2000, 2010),
    title="Mean Max Temperature 2000-2010",
    cmap="Reds",
)

Spatial temperature map

Time series example

fig = cavapy.plot_time_series(
    data["pr"],
    title="Precipitation Time Series - Togo (1990-2011)",
    trend_line=True,
    ylabel="Annual Precipitation (mm)",
    aggregation="sum",
    figsize=(12, 6),
)

Precipitation time series

If your primary goal is advanced visualization/reporting, see CAVAanalytics.


Operational Notes

  • Check GitHub issues for data server outages or announcement posts.
  • Set CAVAPY_NO_ANNOUNCEMENTS=1 to disable startup announcements in scripts/production runs.

Citation and License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cavapy-2.0.2.tar.gz (32.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cavapy-2.0.2-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

Details for the file cavapy-2.0.2.tar.gz.

File metadata

  • Download URL: cavapy-2.0.2.tar.gz
  • Upload date:
  • Size: 32.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.12 Darwin/25.3.0

File hashes

Hashes for cavapy-2.0.2.tar.gz
Algorithm Hash digest
SHA256 f5913a331f2220c155905a24dcdc5596ebba26bd986551a57f5e8802bd8da150
MD5 33c74d70c36297dd07658ea6e8e9194d
BLAKE2b-256 d2d0019975add1a1839028130be8da018a9ae6fc390f779e0c96bb74f73027d5

See more details on using hashes here.

File details

Details for the file cavapy-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: cavapy-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 34.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.12 Darwin/25.3.0

File hashes

Hashes for cavapy-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ebea971c3935b5bfe0c0ee9d504ee9c54fecd9d0578a3ccd0a72b978b1408749
MD5 1a5852b3cffcd7290dd21df85f8d6fc0
BLAKE2b-256 b1f41751de46a4c30b10e3963ffe9c1ed0821254a366a5a35ea03076fa903490

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page