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}")

License

Apache 2.0

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.1.0.tar.gz (21.8 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.1.0-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: climate_lama_engine-0.1.0.tar.gz
  • Upload date:
  • Size: 21.8 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.1.0.tar.gz
Algorithm Hash digest
SHA256 3b9b9b964278b93475537dd36648daa81e04d9cf9b06497bfe9c5b735b86707f
MD5 f643ae7c0e861686e17cf4497d3f22a6
BLAKE2b-256 9b054977300becc6f6b09ae4ce101fcb26d835bec664cd13d52beea0c4e757a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for climate_lama_engine-0.1.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.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for climate_lama_engine-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f009e2e6dcd38a49ebd174092b17b5f9020bcbcd5c22235bcc3ef2f0f774d8be
MD5 3536954134c58fac01de005ff9c491c4
BLAKE2b-256 d497c6488feb20e8758587f8299a241698662911f845fec6789426902881029d

See more details on using hashes here.

Provenance

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