Skip to main content

Banner Image

climate_indices

Actions Status License PyPI - Python Version

Python library of indices useful for climate monitoring

This project contains Python implementations of various climate index algorithms which provide a geographical and temporal picture of the severity and duration of precipitation and temperature anomalies useful for climate monitoring and research.

The following indices are provided:

  • SPI, Standardized Precipitation Index, utilizing both gamma and Pearson Type III distributions
  • SPEI, Standardized Precipitation Evapotranspiration Index, utilizing both gamma and Pearson Type III distributions
  • PET, Potential Evapotranspiration, utilizing either Thornthwaite or Hargreaves equations
  • PNP, Percentage of Normal Precipitation
  • PCI, Precipitation Concentration Index

This Python implementation of the above climate index algorithms is being developed with the following goals in mind:

  • to provide an open source software package to compute a suite of climate indices commonly used for climate monitoring, with well documented code that is faithful to the relevant literature and which produces scientifically verifiable results
  • to provide a central, open location for participation and collaboration for researchers, developers, and users of climate indices
  • to facilitate standardization and consensus on best-of-breed climate index algorithms and corresponding compliant implementations in Python
  • to provide transparency into the operational code used for climate monitoring activities at NCEI/NOAA, and consequent reproducibility of published datasets computed from this package
  • to incorporate modern software engineering principles and scientific programming best practices

This is a developmental/forked version of code that was originally developed by NIDIS/NCEI/NOAA. See drought.gov.

Supported Python Versions

Python Version Status Notes
3.10 Supported Minimum supported version
3.11 Supported
3.12 Supported
3.13 Supported Latest supported version

All versions are tested on Linux (ubuntu-latest). Python 3.10 and 3.13 are additionally tested on macOS. Both latest and minimum declared dependency versions are tested in CI.

Version Support Policy

This project provides 12 months notice before dropping support for a Python version. When a version approaches end-of-life, removal will be announced via the CHANGELOG and a GitHub issue, and implemented no sooner than 12 months after announcement with a version bump.

Python 3.9 support was dropped in v2.2.0 (August 2025) due to scipy>=1.15.3 requiring 3.10+.

API Stability

API Surface Status Guarantee
NumPy array functions (indices.spi, indices.spei, indices.pet) Stable No breaking changes in minor versions
xarray DataArray functions (spi(), spei(), pet_thornthwaite(), pet_hargreaves()) Beta No breaking changes in patch versions

Stable API: The NumPy-based computation functions follow strict semantic versioning.

Beta API: The xarray adapter layer provides automatic parameter inference, coordinate preservation, CF metadata, and Dask support. While beta, computation results are identical to the stable NumPy API — only the interface surface (parameter names, metadata attributes, coordinate handling) may evolve. Beta features are tagged with BetaFeatureWarning and marked in docstrings.

Migration Guide for v2.2.0

Breaking Change: Exception-Based Error Handling

Version 2.2.0 introduces a significant architectural improvement in error handling. The library now uses exception-based error handling instead of returning None tuples for error conditions.

What Changed

Before (v2.1.x and earlier):

# Old behavior - functions returned None tuples on failure
result = some_internal_function(data)
if result == (None, None, None, None):
    # Handle error case
    pass

After (v2.2.0+):

# New behavior - functions raise specific exceptions
try:
    result = some_internal_function(data)
except climate_indices.compute.InsufficientDataError as e:
    # Handle insufficient data case
    print(f"Not enough data: {e.non_zero_count} values found, {e.required_count} required")
except climate_indices.compute.PearsonFittingError as e:
    # Handle fitting failure case
    print(f"Fitting failed: {e}")

New Exception Hierarchy

  • DistributionFittingError (base class)
    • InsufficientDataError - raised when there are too few non-zero values for statistical fitting
    • PearsonFittingError - raised when L-moments calculation fails for Pearson Type III distribution

Impact on Users

  • Direct API users: No changes needed - the public SPI/SPEI functions handle exceptions internally
  • Library integrators: If you were checking for None return values from internal functions, update to use try/catch blocks
  • Benefits: More informative error messages, better debugging, and automatic fallback from Pearson to Gamma distribution when appropriate

Code Quality Improvements

Version 2.2.0 also addresses floating point comparison issues (python:S1244) throughout the codebase:

Floating Point Comparisons:

# ❌ OLD: Direct equality checks (unreliable)
if values == 0.0:
    handle_zero_case()

# ✅ NEW: Safe comparison using numpy.isclose()
if np.isclose(values, 0.0, atol=1e-8):
    handle_zero_case()

Benefits:

  • Eliminates floating point precision issues in statistical parameter validation
  • Improves test reliability and numerical robustness
  • Follows scientific computing best practices for floating point arithmetic
  • See docs/floating_point_best_practices.md for comprehensive guidelines

Citation

You can cite climate_indices in your projects and research papers via the BibTeX entry below.

@misc {climate_indices,
    author = "James Adams",
    title  = "climate_indices, an open source Python library providing reference implementations of commonly used climate indices",
    url    = "https://github.com/monocongo/climate_indices",
    month  = "may",
    year   = "2017--"
}

Release files for climate-indices 2.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for climate-indices 2.4.0
File Size Uploaded
climate_indices-2.4.0.tar.gz 2.1 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for climate-indices 2.4.0
File Interpreter ABI Platform
climate_indices-2.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 2.2 MB

Release files / climate_indices-2.4.0.tar.gz

Download URL climate_indices-2.4.0.tar.gz
Size 2.1 MB
Tags Source
SHA-256 checksum
How to use checksums
834546bf1f39aa88c44e1ee974898126bd9f329d7579e547e8928d4252b652cb
BLAKE2b-256 checksum
How to use checksums
a6d9b7b61668a6b508fd7c2da5a76de6d9e40cc66a1e032f243c3c952f47fe2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 6, 2026.

Transparency log

Release files / climate_indices-2.4.0-py3-none-any.whl

Download URL climate_indices-2.4.0-py3-none-any.whl
Size 111.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
19b47d76b2b1024cf7ca41b8a9a6d894b95928a6ceaced7f4cfa57f75c78b893
BLAKE2b-256 checksum
How to use checksums
eb3e817bb74a4d039e6564368168a5cbda73e62e852dc8a5814ca7ebe796c17a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 6, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.4.0 This release

2 release files

2.2.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.13

1 release file

1.0.12

1 release file

1.0.11

1 release file

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page