Skip to content

Commit c5bbfaf

Browse files
committed
Update docs
1 parent b7ef1d8 commit c5bbfaf

File tree

11 files changed

+288
-233
lines changed

11 files changed

+288
-233
lines changed

README.md

Lines changed: 15 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,25 @@
11
# Precipitation Index - SPI & SPEI for Climate Extremes Monitoring
22

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.
44

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/
66

7-
[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
8-
[![License: BSD-3](https://img.shields.io/badge/License-BSD%203--Clause-green.svg)](https://opensource.org/licenses/BSD-3-Clause)
7+
## Key features
98

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
1115

12-
**Climate Indices:**
16+
## What makes precip-index different?
1317

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-
![Run Theory Concept](./docs/images/runtheory.svg)
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
13322

13423
## Credits
13524

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)).

docs/get-started/quick-start.qmd

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,19 +290,22 @@ The same functions work for both drought (negative threshold) and wet events (po
290290

291291
### SPI/SPEI Classification
292292

293-
| Value Range | Category | Probability | Interpretation |
294-
|-------------|----------|-------------|----------------|
295-
| ≤ -2.00 | Exceptionally Dry | Bottom 2.3% | Exceptional drought |
296-
| -2.00 to -1.50 | Extremely Dry | Bottom 6.7% | Severe drought |
297-
| -1.50 to -1.20 | Severely Dry | Bottom 9.7% | Severe drought |
298-
| -1.20 to -0.70 | Moderately Dry | Bottom 24.2% | Moderate drought |
299-
| -0.70 to -0.50 | Abnormally Dry | Bottom 30.9% | Below normal |
300-
| -0.50 to +0.50 | Near Normal | Middle 38.2% | Normal conditions |
301-
| +0.50 to +0.70 | Abnormally Moist | Top 30.9% | Above normal |
302-
| +0.70 to +1.20 | Moderately Moist | Top 24.2% | Moderately wet |
303-
| +1.20 to +1.50 | Very Moist | Top 9.7% | Very wet conditions |
304-
| +1.50 to +2.00 | Extremely Moist | Top 6.7% | Extremely wet conditions |
305-
| ≥ +2.00 | Exceptionally Moist | Top 2.3% | Extreme flooding risk |
293+
| Value Range | Category | Percentile band (approx.) | Interpretation |
294+
|-------------|----------|---------------------------|----------------|
295+
| ≤ -2.00 | Exceptionally Dry | 0–2.3% | Exceptional drought |
296+
| -2.00 to -1.50 | Extremely Dry | 2.3–6.7% | Severe drought |
297+
| -1.50 to -1.20 | Severely Dry | 6.7–11.5% | Severe drought |
298+
| -1.20 to -0.70 | Moderately Dry | 11.5–24.2% | Moderate drought |
299+
| -0.70 to -0.50 | Abnormally Dry | 24.2–30.9% | Below normal |
300+
| -0.50 to +0.50 | Near Normal | 30.9–69.1% | Normal conditions |
301+
| +0.50 to +0.70 | Abnormally Moist | 69.1–75.8% | Above normal |
302+
| +0.70 to +1.20 | Moderately Moist | 75.8–88.5% | Moderately wet |
303+
| +1.20 to +1.50 | Very Moist | 88.5–93.3% | Very wet conditions |
304+
| +1.50 to +2.00 | Extremely Moist | 93.3–97.7% | Extremely wet conditions |
305+
| ≥ +2.00 | Exceptionally Moist | 97.7–100% | Extreme flooding risk |
306+
307+
> Percentile bands are approximate (standard normal) and provided for intuitive frequency interpretation.
308+
306309

307310
### Time Scales
308311

docs/index.qmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ Learn through interactive tutorials with real TerraClimate data.
239239

240240
**Modified/adapted from:** [climate-indices](https://github.com/monocongo/climate_indices) by James Adams ([monocongo](https://github.com/monocongo/))
241241

242-
**Author:** Benny Istanto
243-
**Organization:** GOST/DEC Data Group, The World Bank
244-
**Email:** bistanto@worldbank.org
242+
**Author:** Benny Istanto</br>
243+
**Organization:** GOST/DEC Data Group, The World Bank</br>
244+
**Email:** bistanto@worldbank.org</br>
245245

246246
## Citation
247247

docs/technical/implementation.qmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ precip-index/
1212
│ ├── chunked.py # Memory-efficient chunked processing
1313
│ ├── config.py # Configuration and constants
1414
│ ├── utils.py # PET, data validation, memory utilities
15-
│ ├── runtheory.py # Drought event analysis
15+
│ ├── runtheory.py # Event analysis (dry & wet)
1616
│ ├── visualization.py # Plotting functions
1717
│ └── __init__.py # Package exports
1818
├── input/ # User data (not in repo)
1919
├── output/ # Generated results
2020
│ ├── netcdf/
2121
│ ├── csv/
2222
│ └── plots/
23-
└── notebooks/ # Tutorials
23+
└── notebook/ # Tutorials
2424
```
2525

2626
## Core Modules
2727

2828
### 1. indices.py
2929

30-
**Purpose:** Calculate SPI and SPEI drought indices
30+
**Purpose:** Calculate SPI and SPEI indices
3131

3232
**Key Functions:**
3333

docs/tutorials/01-calculate-spi.qmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ print(f" Zero values: {int((precip == 0).sum())} ({100 * float((precip == 0).su
126126
```
127127

128128
::: {.callout-note}
129-
## Data Format
129+
### Data Format
130130

131131
The precipitation data is in NetCDF format with dimensions `(time, lat, lon)`. TerraClimate provides monthly precipitation in mm/month at ~4km resolution.
132132
:::
@@ -184,7 +184,7 @@ print(f" NaN values: {int(np.isnan(spi_12).sum())} ({100 * float(np.isnan(spi_1
184184
```
185185

186186
::: {.callout-tip}
187-
## Calibration Period
187+
### Calibration Period
188188

189189
We use 1991-2020 as the calibration period (30 years) following WMO recommendations. This period is used to fit the probability distribution. NaN values come from two sources: (1) the first 11 months where SPI-12 cannot be calculated, and (2) ocean grid cells with no data.
190190
:::
@@ -289,7 +289,7 @@ print(" Results are identical!" if max_diff < 1e-6 else " Warning: Results dif
289289
```
290290

291291
::: {.callout-tip}
292-
## Performance Benefits
292+
### Performance Benefits
293293

294294
Using saved parameters is **5-10x faster** than refitting, ideal for operational monitoring where you update with new data regularly.
295295
:::
@@ -364,7 +364,7 @@ print(" - Extreme events persist longer at longer time scales")
364364
```
365365

366366
::: {.callout-important}
367-
## Time Scale Interpretation
367+
### Time Scale Interpretation
368368

369369
- **SPI-1:** Month-to-month meteorological anomalies
370370
- **SPI-3:** Seasonal agricultural drought

docs/tutorials/02-calculate-spei.qmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ print(f" Output directory: {output_netcdf}")
138138
```
139139

140140
::: {.callout-note}
141-
## PET Calculation Methods
141+
### PET Calculation Methods
142142

143143
The `spei()` function accepts either:
144144

@@ -284,7 +284,7 @@ else:
284284
When using temperature, the trend line shows how temperatures have changed over the record. Warming trends increase PET, which affects the water balance and makes SPEI more negative relative to SPI.
285285

286286
::: {.callout-tip}
287-
## Distribution Selection for SPEI
287+
### Distribution Selection for SPEI
288288

289289
By default, SPEI uses the **Gamma** distribution. For SPEI, the **Pearson III** or **Log-Logistic** distributions are also available and may better handle the water balance data (P - PET), which can be negative:
290290

@@ -464,7 +464,7 @@ print(f" Difference: {spei_drought - spi_drought} months ({100*(spei_drought -
464464
```
465465

466466
::: {.callout-important}
467-
## SPI vs SPEI: Key Differences
467+
### SPI vs SPEI: Key Differences
468468

469469
**SPI (Precipitation only):**
470470

@@ -571,7 +571,7 @@ print(" - Extreme events persist longer at longer time scales")
571571
```
572572

573573
::: {.callout-note}
574-
## Time Scale Interpretation
574+
### Time Scale Interpretation
575575

576576
- **SPEI-1:** Month-to-month meteorological anomalies
577577
- **SPEI-3:** Seasonal agricultural drought --- crop water stress

docs/tutorials/03-event-analysis.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ print(events_dry[['start_date', 'end_date', 'duration', 'magnitude', 'intensity'
191191
```
192192

193193
::: {.callout-note}
194-
## Threshold Selection
194+
### Threshold Selection
195195

196196
Common thresholds for SPI/SPEI event analysis:
197197

@@ -312,7 +312,7 @@ plt.show()
312312
```
313313

314314
::: {.callout-important}
315-
## Bidirectional Analysis
315+
### Bidirectional Analysis
316316

317317
The same functions work for both extremes:
318318

docs/tutorials/04-visualization.qmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ plt.show()
207207
Each annotation shows the duration (D) of the event in months, positioned at the event peak. Longer durations indicate more persistent drought conditions.
208208

209209
::: {.callout-tip}
210-
## Event Highlighting
210+
### Event Highlighting
211211

212212
Events are highlighted with:
213213

@@ -374,7 +374,7 @@ else:
374374
```
375375

376376
::: {.callout-note}
377-
## Magnitude Types
377+
### Magnitude Types
378378

379379
- **Cumulative**: Total deficit, monotonically increases during event --- like debt accumulation. Use for event comparison and total impact assessment.
380380
- **Instantaneous**: Current severity, varies within event --- like NDVI crop phenology. Use for monitoring evolution and trend detection.
@@ -614,7 +614,7 @@ print("Reset to default settings")
614614
```
615615

616616
::: {.callout-tip}
617-
## Export Best Practices
617+
### Export Best Practices
618618

619619
- **DPI**: 300 for publications, 150 for presentations, 72 for web
620620
- **Format**: PNG for raster, PDF/SVG for vector graphics

0 commit comments

Comments
 (0)