Skip to main content

A Copula-based Weather Generator

Project description

What is WeatherCop?

Python License: MIT Managed with uv

WeatherCop is a multisite weather generator based on vine copulas. It was developed to generate synthetic weather scenarios that preserve both spatial dependencies across weather stations and temporal structure within each station. The package combines statistical copula theory with time series analysis from the VarWG library to create realistic weather ensembles for hydrodynamic and ecological modeling.

Architecture Overview

How It Works

WeatherCop operates through a carefully choreographed workflow combining two complementary systems:

  1. VarWG Component (marginal distributions):
    • Fits KDE/parametric distributions to each weather variable at each site, accounting for seasonal variations (Fdoy)
    • Transforms measurement data to standard-normal space via inverse CDF of day-of-year distributions: Φ⁻¹(Fdoy(X))
    • Handles dryness probability estimation for precipitation
    • Applies the inverse transformation to convert simulated data back to the measurement domain: X = Fdoy⁻¹(Φ(Y))
  2. WeatherCop Component (dependence structure):
    • Fits vine copulas to deseasonalized observations to capture inter-variate dependencies (relationships between different weather variables)
    • Decorrelates observations for phase randomization
    • Re-correlates synthetic data using the fitted copula structure
    • Preserves both temporal autocorrelation within each station and spatial cross-correlations between stations through phase randomization

This separation of concerns enables realistic what-if scenarios: by conditioning on a guiding variable (e.g., temperature), changes propagate to other variables through the vine copula's inter-variate dependence structure, while VarWG ensures each variable maintains realistic distributions and seasonal patterns.

Installation

Using uv (recommended)

WeatherCop uses uv for dependency management. To install:

  1. Install uv if you haven't already:

    curl -LsSf https://astral.sh/uv/install.sh | sh
    
  2. Clone the repository and install:

    git clone <repository-url>
    cd weathercop
    uv sync
    
  3. Build Cython extensions:

    python setup.py build_ext --inplace
    

Development installation

For development with additional tools:

uv sync --group dev
python setup.py build_ext --inplace

Note: The first import may take 5-10 minutes as Cython extensions compile. Pre-build them to avoid this delay.

Important: WeatherCop depends on the VarWG library, currently installed from GitHub. For general availability, VarWG will be published to PyPI first.

Quick Start

Generate a weather ensemble in 10 lines of code:

import xarray as xr
from weathercop.multisite import Multisite, set_conf
from weathercop.configs import get_dwd_vg_config

# Load bundled DWD configuration
vg_conf = get_dwd_vg_config()
set_conf(vg_conf)
xds = xr.open_dataset("~/data/opendata_dwd/multisite_testdata.nc")
multisite = Multisite(xds, verbose=True)
ensemble = multisite.simulate_ensemble(n_realizations=5, name="example")
figs = multisite.plot_ensemble_meteogram_daily()
multisite.close()

See examples/quickstart.py for a complete working example.

For detailed tutorial with customization examples, see examples/notebook_tutorial.ipynb. To download real DWD weather data in the format WeatherCop expects, use the dwd_opendata package.

Troubleshooting

First Import Takes 5-10 Minutes

The first time you import weathercop, Cython extensions compile automatically. This is normal. To avoid the wait:

python setup.py build_ext --inplace

Environment Variables

WeatherCop respects these environment variables:

  • WEATHERCOP_DIR: Base directory for cache and data (default: ~/.weathercop)
  • WEATHERCOP_ENSEMBLE_ROOT: Directory for ensemble outputs (default: $WEATHERCOP_DIR/ensembles)

Example:

export WEATHERCOP_DIR=/path/to/your/weathercop/data
python your_script.py

Running Tests

To run the test suite:

uv run pytest

Or install test dependencies and run:

uv sync --group test
uv run pytest

Memory-Efficient Testing

For running the full test suite on systems with limited memory, automated memory optimizations are enabled during pytest:

  • Intermediate results are skipped by default during ensemble tests
  • Fixtures prevent duplicate dataset loading
  • Explicit garbage collection runs between tests

See docs/TESTING_MEMORY.md for detailed information and manual memory profiling.

Key Features

  • Vine Copula Models: Canonical (C-vine) and Regular (R-vine) implementations
  • Seasonal Variations: Time-varying copula parameters with Fourier series smoothing
  • Multisite Generation: Simultaneous weather generation across multiple stations
  • Comprehensive Copula Library: Clayton, Gumbel, Joe, Plackett, and many more families
  • High Performance: Cython-optimized computations with automatic SymPy code generation
  • Parallel Processing: Built-in multiprocessing support for large ensembles

Release Notes

0.1.0

  • Initial release with vine copula implementations (CVine, RVine)
  • Seasonal copula wrapper for time-varying parameters
  • Integration with VarWG library for temporal structure preservation
  • Automatic Cython code generation for copula functions
  • Multisite weather generation workflows
  • Migration to modern build system with pyproject.toml
  • Dependency management with uv

Requirements: Python ≥ 3.13

Web Sites

Code is hosted at: <repository-url>

Related project: VarWG Weather Generator

License Information

MIT License

Copyright (c) iskur <32363199+iskur@users.noreply.github.com>

See the file "LICENSE" for information on the history of this software, terms & conditions for usage, and a DISCLAIMER OF ALL WARRANTIES.

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

weathercop-0.2.0.tar.gz (467.6 kB view details)

Uploaded Source

Built Distributions

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

weathercop-0.2.0-cp313-cp313-win_amd64.whl (630.1 kB view details)

Uploaded CPython 3.13Windows x86-64

weathercop-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

weathercop-0.2.0-cp313-cp313-macosx_11_0_arm64.whl (643.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

weathercop-0.2.0-cp313-cp313-macosx_10_13_x86_64.whl (649.6 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

File details

Details for the file weathercop-0.2.0.tar.gz.

File metadata

  • Download URL: weathercop-0.2.0.tar.gz
  • Upload date:
  • Size: 467.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for weathercop-0.2.0.tar.gz
Algorithm Hash digest
SHA256 28d8c138f5180d7192e9d0ff199c344dbd78e79352ed624f38bf2796034eeabf
MD5 c0014e85560221460d15d7ff00fc71ef
BLAKE2b-256 b0d0363bf91f810ca7eae4f49a2752c0bbfd610f9d3ad07f5fdb8ae4383623d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for weathercop-0.2.0.tar.gz:

Publisher: build-wheels.yml on iskur/weathercop

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file weathercop-0.2.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: weathercop-0.2.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 630.1 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for weathercop-0.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 78253fcef93a567ce7b17adf6c74d98152b4acbfe995d6a8a0852767549a183b
MD5 8ec240b0e30803d81e1cc0bcd1b61750
BLAKE2b-256 40ece39ab303e3c99bb34f7ae0647417e859de5fa865b5b6f8b7731a9c9c0b34

See more details on using hashes here.

Provenance

The following attestation bundles were made for weathercop-0.2.0-cp313-cp313-win_amd64.whl:

Publisher: build-wheels.yml on iskur/weathercop

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file weathercop-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for weathercop-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9c974d4170aa87acef340b1dd654d226f7dbd254003e9a231c0d660ca59e8a0f
MD5 dfb968fe356fa0171c736fafa967ae96
BLAKE2b-256 e0ab51d6324f4fcf6fa72169d5a7cad51d964a79462ca1b5c1b33d2efbdb41a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for weathercop-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on iskur/weathercop

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file weathercop-0.2.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for weathercop-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d21b9259ba70ba4d833d61410b7a8a5c3251c362e46a6d41d8e525f4a16def07
MD5 84e34d42496f7c2d8aabd92b5fd05d17
BLAKE2b-256 56b97b46b22879971cd20e814a36601dd67d751c7a269fe69ef567ff0f9e8091

See more details on using hashes here.

Provenance

The following attestation bundles were made for weathercop-0.2.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on iskur/weathercop

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file weathercop-0.2.0-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for weathercop-0.2.0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 00b94e7d3f9b4d355989c495c05af47d532280a09f14893dcdfdf6765cf3a633
MD5 ce9dcc0ddf0d9075b1f5e08efe387fc1
BLAKE2b-256 7c1d1601c49db3cf229c3ca67ca3b0c98511db257ac67c516b8cccf96a554ba6

See more details on using hashes here.

Provenance

The following attestation bundles were made for weathercop-0.2.0-cp313-cp313-macosx_10_13_x86_64.whl:

Publisher: build-wheels.yml on iskur/weathercop

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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