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
import opendata_vg_conf as vg_conf

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.1.0.tar.gz (444.4 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.1.0-cp313-cp313-win_amd64.whl (607.7 kB view details)

Uploaded CPython 3.13Windows x86-64

weathercop-0.1.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.1.0-cp313-cp313-macosx_11_0_arm64.whl (608.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

weathercop-0.1.0-cp313-cp313-macosx_10_13_x86_64.whl (621.8 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

File details

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

File metadata

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

File hashes

Hashes for weathercop-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5ce534fe277092daf138d03eab3e7802612c22001fd907f6ebe06ff285139f54
MD5 f137b966748ad236e8ceb56801464ac6
BLAKE2b-256 bac781ef66cb006ec8cdcb179429b13d9d46a625a2ce09af25947da40eaef567

See more details on using hashes here.

Provenance

The following attestation bundles were made for weathercop-0.1.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.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: weathercop-0.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 607.7 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.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5974141b5e7f774164fc69aff765e23c0ec1b33d425cd7c536cb18076d4e4400
MD5 14677c9221fa9203026d5c251b9bbc19
BLAKE2b-256 84b4372a1902752e8fcf4a3d93baab684f3a3b7aaf76b9cae577daa27f0b8f6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for weathercop-0.1.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.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for weathercop-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 09d12346e7fe10ec58f874ad939ac130b259000acdeedbaec6566199ebb7cac8
MD5 b1cb11ba00e11843942ca1c73240013c
BLAKE2b-256 fd5dd0825191ec7c1cb4f9f82ef6f9ed4d65c642a1cb5ab8ea44b7a17ae94ac6

See more details on using hashes here.

Provenance

The following attestation bundles were made for weathercop-0.1.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.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for weathercop-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 79d04b08519abf32b93c5b058c1552231710c8c643868d118b0758cb5f3388ba
MD5 b5f0b8640aad098e12bb23f93285ffe0
BLAKE2b-256 992e9542e70152e99e2fa044f61949d4b47efce68cd5a620cc1001d0dfb1209c

See more details on using hashes here.

Provenance

The following attestation bundles were made for weathercop-0.1.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.1.0-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for weathercop-0.1.0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 fb4ef8ca31703a645b71b2da669111d41a8377d30dc6fa9899305ab6e8591ce1
MD5 b9e0a01fdd3c63f9c67daaad00a09e48
BLAKE2b-256 89e8df790ef3778716ca4722d5775627449b454b861a226f009ae8c4092817e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for weathercop-0.1.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