|
1 | 1 | # Precipitation Index - SPI & SPEI for Climate Extremes Monitoring |
2 | 2 |
|
3 | | -> **⚠️ Active Development:** This package is under active development. Some features may not work as expected and bugs may be present. Please report issues on GitHub. |
| 3 | +**precip-index** is a lightweight set of Python scripts for calculating precipitation-based climate indices (SPI and SPEI) and analyzing **dry and wet extremes** using **run theory**, designed for gridded `xarray` workflows. |
4 | 4 |
|
5 | | -A minimal, efficient Python implementation of **Standardized Precipitation Index (SPI)** and **Standardized Precipitation Evapotranspiration Index (SPEI)** for monitoring **both drought and wet conditions** using run theory. |
| 5 | +📚 Documentation: https://bennyistanto.github.io/precip-index/ |
6 | 6 |
|
7 | | -[](https://www.python.org/downloads/) |
8 | | -[](https://opensource.org/licenses/BSD-3-Clause) |
| 7 | +## Key features |
9 | 8 |
|
10 | | -## Features |
| 9 | +- **SPI / SPEI** at 1, 3, 6, 12, 24-month scales (xarray + CF-style NetCDF outputs) |
| 10 | +- **Bidirectional extremes**: drought (dry) and flood-prone (wet) conditions in one framework |
| 11 | +- **Multi-distribution fitting**: Gamma, Pearson Type III, Log-Logistic |
| 12 | +- **Run theory events**: duration, magnitude, intensity, peak, interarrival + gridded summaries |
| 13 | +- **Scalable processing**: chunked tiling, memory estimation, streaming I/O for global datasets |
| 14 | +- **Visualization**: event-highlighted time series, 11-category classification, maps, comparisons |
11 | 15 |
|
12 | | -**Climate Indices:** |
| 16 | +## What makes precip-index different? |
13 | 17 |
|
14 | | -- SPI (Standardized Precipitation Index) - precipitation-based |
15 | | -- SPEI (Standardized Precipitation Evapotranspiration Index) - temperature-inclusive |
16 | | -- Multiple time scales (1, 3, 6, 12, 24 months) |
17 | | -- CF-compliant NetCDF output |
18 | | -- **Monitor both dry (drought) and wet (flood/excess) conditions** |
19 | | - |
20 | | -**Climate Extremes Analysis (Run Theory):** |
21 | | - |
22 | | -- Event identification for **both drought and wet conditions** |
23 | | -- Duration, magnitude, intensity, peak for any extreme |
24 | | -- Time-series monitoring with varying characteristics |
25 | | -- Period aggregation (gridded statistics for decision-making) |
26 | | -- Comprehensive visualization suite |
27 | | -- Works with negative thresholds (dry) or positive thresholds (wet) |
28 | | - |
29 | | -**Optimized for:** |
30 | | - |
31 | | -- Global-scale gridded data |
32 | | -- CF Convention (time, lat, lon) |
33 | | -- Operational climate monitoring (drought, flooding, extremes) |
34 | | - |
35 | | -## Getting Started |
36 | | - |
37 | | -**📖 See [QUICK_START.md](QUICK_START.md) for detailed installation and usage examples.** |
38 | | - |
39 | | -The Quick Start guide covers: |
40 | | - |
41 | | -- Installation and setup |
42 | | -- Calculating SPI and SPEI |
43 | | -- Analyzing climate extremes (both dry and wet) |
44 | | -- Visualization examples |
45 | | -- Working with your own data |
46 | | - |
47 | | -## Installation |
48 | | - |
49 | | -```bash |
50 | | -# Install dependencies |
51 | | -pip install numpy scipy xarray netCDF4 numba matplotlib |
52 | | - |
53 | | -# Clone repository |
54 | | -git clone https://github.com/bennyistanto/precip-index.git |
55 | | -cd precip-index |
56 | | -``` |
57 | | - |
58 | | -## Documentation |
59 | | - |
60 | | -**User Guides:** |
61 | | - |
62 | | -- [SPI Guide](docs/user-guide/spi.md) - Calculation, parameters, examples |
63 | | -- [SPEI Guide](docs/user-guide/spei.md) - Temperature-inclusive index |
64 | | -- [Climate Extremes Analysis](docs/user-guide/runtheory.md) - Event analysis (dry & wet) |
65 | | -- [Magnitude Explained](docs/user-guide/magnitude.md) - Cumulative vs instantaneous |
66 | | -- [Visualization Guide](docs/user-guide/visualization.md) - Plotting functions |
67 | | - |
68 | | -**Tutorials (Jupyter Notebooks):** |
69 | | - |
70 | | -- `notebooks/01_calculate_spi.ipynb` - SPI calculation |
71 | | -- `notebooks/02_calculate_spei.ipynb` - SPEI with PET |
72 | | -- `notebooks/03_event_characteristics.ipynb` - Climate extremes event analysis |
73 | | -- `notebooks/04_visualization_gallery.ipynb` - All plot types |
74 | | - |
75 | | -**Technical Documentation:** |
76 | | - |
77 | | -- [Implementation Details](docs/technical/implementation.md) - Architecture and design |
78 | | -- [CHANGELOG.md](CHANGELOG.md) - Version history |
79 | | - |
80 | | -## Key Capabilities |
81 | | - |
82 | | -### Neutral Climate Extremes Analysis |
83 | | - |
84 | | -All event analysis functions work for **both dry and wet conditions**: |
85 | | - |
86 | | -| Function | Dry Events (Drought) | Wet Events (Flooding) | |
87 | | -| ---------- | ---------------------- | ---------------------- | |
88 | | -| `identify_events()` | `threshold=-1.2` | `threshold=+1.2` | |
89 | | -| `calculate_timeseries()` | Monitors dry periods | Monitors wet periods | |
90 | | -| `calculate_period_statistics()` | SPI/SPEI < 0 | SPI/SPEI > 0 | |
91 | | -| `plot_index()` | Full range with WMO colors | Both extremes | |
92 | | - |
93 | | -**The threshold direction determines which extreme to analyze** - the same tools work for both ends of the precipitation spectrum! |
94 | | - |
95 | | - |
96 | | - |
97 | | -**Run Theory Framework:** Events are identified when an index crosses a threshold. This example shows **dry events** (below threshold), but the identical analysis applies to **wet events** (above threshold). Key metrics—Duration (D), Magnitude (M), Intensity (I), and Inter-arrival Time (T)—are calculated the same way for both extremes. |
98 | | - |
99 | | -*See [Climate Extremes Analysis Guide](docs/user-guide/runtheory.md) for detailed explanation.* |
100 | | - |
101 | | -### Three Analysis Modes |
102 | | - |
103 | | -**1. Event-Based** - Identify complete extreme events |
104 | | - |
105 | | -```python |
106 | | -events = identify_events(spi_ts, threshold=-1.2) |
107 | | -# Returns: DataFrame with event_id, duration, magnitude, intensity, peak |
108 | | -``` |
109 | | - |
110 | | -**2. Time-Series** - Month-by-month monitoring |
111 | | - |
112 | | -```python |
113 | | -ts = calculate_timeseries(spi_ts, threshold=-1.2) |
114 | | -# Returns: DataFrame with varying characteristics over time |
115 | | -``` |
116 | | - |
117 | | -**3. Period Statistics** - Gridded decision support |
118 | | - |
119 | | -```python |
120 | | -stats = calculate_period_statistics(spi, threshold=-1.2, |
121 | | - start_year=2020, end_year=2024) |
122 | | -# Returns: xarray Dataset (lat, lon) with 9 variables |
123 | | -``` |
124 | | - |
125 | | -### Dual Magnitude Approach |
126 | | - |
127 | | -Provides **both** magnitude types for comprehensive analysis: |
128 | | - |
129 | | -- **Cumulative** - Total water deficit (standard run theory) |
130 | | -- **Instantaneous** - Current severity (NDVI-like pattern) |
131 | | - |
132 | | -See [Magnitude Explained](docs/user-guide/magnitude.md) for details. |
| 18 | +- **Dry + wet symmetry**: same API and methodology for negative (drought) and positive (wet) thresholds |
| 19 | +- **Distribution-aware SPI/SPEI**: choose the best-fit distribution per workflow (Gamma / P-III / Log-Logistic) |
| 20 | +- **Event analytics included**: run theory metrics beyond simple threshold exceedance |
| 21 | +- **Designed for large grids**: practical for CHIRPS / ERA5-Land / TerraClimate via chunked processing |
133 | 22 |
|
134 | 23 | ## Credits |
135 | 24 |
|
136 | | -**Modified/adapted from:** [climate-indices](https://github.com/monocongo/climate_indices) by James Adams (monocongo) |
137 | | - |
138 | | -**Author:** Benny Istanto |
139 | | -**Organization:** GOST/DEC Data Group, The World Bank |
140 | | -**Email:** bistanto@worldbank.org |
141 | | - |
142 | | -## References |
143 | | - |
144 | | -- McKee, T.B., Doesken, N.J., Kleist, J. (1993). The relationship of drought frequency and duration to time scales. 8th Conference on Applied Climatology. |
145 | | - |
146 | | -- Vicente-Serrano, S.M., Beguería, S., López-Moreno, J.I. (2010). A Multiscalar Drought Index Sensitive to Global Warming: The Standardized Precipitation Evapotranspiration Index. Journal of Climate, 23(7), 1696-1718. |
147 | | - |
148 | | -- Yevjevich, V. (1967). An objective approach to definitions and investigations of continental hydrologic droughts. Hydrology Papers 23, Colorado State University. |
149 | | - |
150 | | -## License |
151 | | - |
152 | | -BSD 3-Clause License - See [LICENSE](LICENSE) for details. |
153 | | - |
154 | | -## Contributing |
155 | | - |
156 | | -Contributions welcome! Please: |
157 | | - |
158 | | -1. Fork the repository |
159 | | -2. Create a feature branch |
160 | | -3. Submit a pull request |
161 | | - |
162 | | -For bugs or feature requests, open an issue on GitHub. |
163 | | - |
164 | | ---- |
165 | | - |
166 | | -**Version:** 2026.1 |
167 | | -**Last Updated:** 2026-01-21 |
| 25 | +SPI/SPEI components are modified/adapted from `climate-indices` by James Adams ([monocongo](https://github.com/monocongo/climate_indices)). |
0 commit comments