Skip to main content

Lean probabilistic climate risk calculation engine

Project description

climate-lama-engine

Lean probabilistic climate risk calculation engine. Clean-room reimplementation of CLIMADA's core math — no geospatial dependencies, no I/O, just numpy and scipy.

Runtime deps: numpy>=1.24, scipy>=1.11 Python: >=3.10


Install

uv sync --group dev

Or with pip:

pip install -e ".[dev]"

Run tests

uv run pytest

Use on another machine

Clone the repo and sync the environment — the lockfile guarantees identical versions:

git clone <repo-url>
cd climate-lama-core
uv sync --group notebooks

Then open VS Code, create or open any notebook, and select the .venv inside climate-lama-core/ as the kernel. import climate_lama_engine as cc will work from any notebook on the machine, not just the ones in this repo.

To update later:

git pull
uv sync --group notebooks

Notebooks

Documentation and manual testing notebooks live in notebooks/.

Setup

uv sync --group notebooks
uv run jupyter notebook

Or with pip:

pip install -e .
pip install -r notebooks/requirements.txt
jupyter notebook

Then open any notebook from the notebooks/ folder in your browser.

Notebook overview

Notebook Description
00_quickstart.ipynb 10-minute end-to-end walkthrough: hazard to EAD to measure
01_hazard.ipynb Hazard deep dive: marginal frequencies, sparse matrix internals
02_exposures.ipynb Exposures: centroid assignment, insurance parameters
03_impact_functions.ipynb MDR, MDD, PAA -- why they are separate, JRC flood function
04_impact_calculation.ipynb Core engine: all output attributes, identity checks, spatial risk map
05_measures.ipynb Adaptation measures: intensity reduction, retrofits, early warning
06_cost_benefit.ipynb Cost-benefit analysis: BCR, discount rates, risk metric sensitivity
07_flood_greece_pattern.ipynb Realistic JRC flood scenario on a 50x50 Greece grid
08_climada_comparison.ipynb Side-by-side verification against upstream CLIMADA

Quick example

import numpy as np
from scipy import sparse
import climate_lama_engine as cc

rps = np.array([10, 100, 500])
intensity = sparse.csr_matrix(np.array([
    [0.0, 0.5, 1.0, 0.0, 0.2],
    [0.0, 1.2, 2.5, 0.5, 0.8],
    [0.0, 2.0, 4.0, 1.0, 1.5],
]))
hazard = cc.Hazard.from_rp_maps(
    haz_type="RF", intensity_unit="m",
    return_periods=rps, intensity=intensity,
    centroid_lat=np.array([37.9, 38.0, 38.1, 38.2, 38.3]),
    centroid_lon=np.array([23.7, 23.8, 23.9, 24.0, 24.1]),
)

impf = cc.ImpactFunc(
    id=1, haz_type="RF",
    intensity=np.array([0.0, 0.5, 1.0, 2.0, 3.0, 5.0]),
    mdd=np.array([0.0, 0.02, 0.07, 0.25, 0.50, 0.80]),
    paa=np.array([0.0, 0.20, 0.40, 0.70, 0.90, 1.00]),
)
impfset = cc.ImpactFuncSet([impf])

exposures = cc.Exposures(
    value=np.array([500_000, 1_200_000, 800_000, 300_000]),
    centroid_idx=np.array([1, 2, 3, 4]),
    impf_id=np.array([1, 1, 1, 1]),
    value_unit="EUR",
)

result = cc.ImpactCalc(hazard, exposures, impfset).impact()
print(f"EAD: EUR {result.aai_agg:,.0f}")

levee = cc.Measure(name="Flood Levee", haz_type="RF", haz_inten_a=0.8, cost=2_000_000)
mod_haz, mod_impf = levee.apply(hazard, impfset)
result_with_levee = cc.ImpactCalc(mod_haz, exposures, mod_impf).impact()
print(f"EAD with levee: EUR {result_with_levee.aai_agg:,.0f}")

Changelog

See CHANGELOG.md for a full history of releases.


License & Legal

Apache 2.0 — see LICENSE.

climate-lama-engine is a clean-room reimplementation of well-known probabilistic climate risk mathematics. No GPL-licensed source code was used during implementation. See CLEAN_ROOM.md for the full implementation statement.

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

climate_lama_engine-0.2.0.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

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

climate_lama_engine-0.2.0-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for climate_lama_engine-0.2.0.tar.gz
Algorithm Hash digest
SHA256 51c78a4deb5db49733033aab99bc165e66e450739a718fd1a29a8388bbe10677
MD5 7d233d8150742731b012205ae4b6e0d7
BLAKE2b-256 bd244178a74c670aff80e404af61953564d2881a5b2ae9d373027328e01129b0

See more details on using hashes here.

Provenance

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

Publisher: release.yml on CortoMaltese3/climate-lama-engine

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

File details

Details for the file climate_lama_engine-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for climate_lama_engine-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 87813fd6bf5864d265a8b8014efbe64189d3688271abe07b75c92dcc04db7208
MD5 c785b26ba1574a1b10e3bbbf2f738910
BLAKE2b-256 8b705de1158073f53ddf8868231d1b0234817e8b9f3c2b311622141910676fe2

See more details on using hashes here.

Provenance

The following attestation bundles were made for climate_lama_engine-0.2.0-py3-none-any.whl:

Publisher: release.yml on CortoMaltese3/climate-lama-engine

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