Skip to content

Commit f266a57

Browse files
committed
Update docs
1 parent cf49bc0 commit f266a57

18 files changed

+869
-7
lines changed
615 KB
Loading
133 KB
Loading
241 KB
Loading

docs/index.qmd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Regional subsets (country-level) complete in seconds to minutes.
154154

155155
## Validation Results
156156

157-
All distributions tested against TerraClimate Bali data (1958–2024). Cross-distribution correlation exceeds 0.98. The test suite generates **25 visualizations** including advanced analytics.
157+
All distributions tested against TerraClimate Bali data (1958–2024). Cross-distribution correlation exceeds 0.98. The test suite generates **28 visualizations** including advanced analytics and operational mode validation.
158158

159159
::: {.panel-tabset}
160160
### Multi-Scale SPI
@@ -204,6 +204,12 @@ Climate stripes visualization showing annual drought conditions from 1959-2024.
204204
![](images/exceedance_probability.png)
205205

206206
Risk assessment plot showing probability of exceeding drought thresholds with return period annotations.
207+
208+
### Operational Mode
209+
210+
![](images/operational_mode_workflow.png)
211+
212+
Parameter persistence for real-time monitoring: calibrate once on historical data, apply consistently to new observations. Results are identical to fresh calculations.
207213
:::
208214

209215
See [Validation & Test Results](technical/validation.qmd) for detailed analysis.

docs/technical/validation.qmd

Lines changed: 98 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,100 @@ Climate stripes provide an intuitive visual summary of drought conditions over t
272272
- This visualization style (inspired by "warming stripes") provides immediate visual impact.
273273

274274

275-
## 6. Validation Summary {#sec-summary}
275+
## 6. Operational Mode: Parameter Persistence {#sec-operational}
276+
277+
In real-world drought monitoring, you don't recalibrate every time new data arrives. Instead, you establish a stable baseline period, save those distribution parameters, and apply them consistently to new observations. This ensures temporal consistency and makes drought assessments comparable over time.
278+
279+
### The Workflow
280+
281+
1. **Calibration Phase**: Calculate SPI/SPEI on historical data (1958-2021) and save fitted distribution parameters
282+
2. **Operational Phase**: Load saved parameters and apply to new data (2022-2024) without refitting
283+
3. **Validation**: Confirm operational results are identical to fresh calculations
284+
285+
### Workflow Visualization
286+
287+
![Operational mode workflow: The top panel shows the full time series with calibration (blue) and operational (green) periods. The middle panel zooms on the transition to verify seamless continuation. The bottom panel validates that operational and fresh calculations produce identical results.](../images/operational_mode_workflow.png){#fig-operational-workflow}
288+
289+
**What to look for**:
290+
291+
- The transition from calibration to operational period should be seamless.
292+
- Results using loaded parameters match fresh calculations exactly (r = 1.0, max diff < 10⁻⁶).
293+
- New drought/wet events in 2022-2024 are properly detected using historical parameters.
294+
295+
### Distribution Parameters
296+
297+
The fitted parameters are stored as spatial grids for each calendar month, allowing consistent application to new data:
298+
299+
![Distribution parameter maps showing the Gamma shape (alpha) and scale (beta) parameters for January and July. These parameters, fitted on 1958-2021 data, are applied to all future calculations.](../images/operational_mode_parameters.png){#fig-operational-params}
300+
301+
### Multi-Scale, Multi-Distribution Validation
302+
303+
The operational mode was validated across multiple configurations:
304+
305+
![Multi-scale and multi-distribution validation showing that operational mode produces identical results across SPI-3, SPI-12 with both Gamma and Pearson III distributions.](../images/operational_mode_multiscale.png){#fig-operational-multiscale}
306+
307+
**Validation Results**:
308+
309+
| Configuration | Correlation | Max Difference | Status |
310+
|:-------------|:------------|:---------------|:-------|
311+
| SPI-3 (Gamma) | 1.000000 | 0.00e+00 | IDENTICAL |
312+
| SPI-3 (Pearson III) | 1.000000 | 0.00e+00 | IDENTICAL |
313+
| SPI-12 (Gamma) | 1.000000 | 0.00e+00 | IDENTICAL |
314+
| SPI-12 (Pearson III) | 1.000000 | 0.00e+00 | IDENTICAL |
315+
| SPEI-3 (Gamma) | 1.000000 | 0.00e+00 | IDENTICAL |
316+
| SPEI-3 (Pearson III) | 1.000000 | 0.00e+00 | IDENTICAL |
317+
| SPEI-12 (Gamma) | 1.000000 | 0.00e+00 | IDENTICAL |
318+
| SPEI-12 (Pearson III) | 1.000000 | 0.00e+00 | IDENTICAL |
319+
320+
: Operational mode validation results. All 8 configurations produce results identical to fresh calculations. {#tbl-operational}
321+
322+
### Usage Example
323+
324+
```python
325+
from indices import spi, save_fitting_params, load_fitting_params
326+
327+
# === CALIBRATION PHASE (run once) ===
328+
# Calculate SPI and get fitted parameters
329+
spi_12, params = spi(
330+
historical_precip, # 1958-2021
331+
scale=12,
332+
calibration_start_year=1991,
333+
calibration_end_year=2020,
334+
return_params=True
335+
)
336+
337+
# Save parameters for future use
338+
save_fitting_params(
339+
params, 'spi_12_params.nc',
340+
scale=12, periodicity='monthly',
341+
calibration_start_year=1991,
342+
calibration_end_year=2020
343+
)
344+
345+
# === OPERATIONAL PHASE (run monthly/as new data arrives) ===
346+
# Load saved parameters
347+
params = load_fitting_params('spi_12_params.nc', scale=12, periodicity='monthly')
348+
349+
# Apply to new data without refitting
350+
spi_12_new = spi(
351+
new_precip, # 2022-2024 (or any period)
352+
scale=12,
353+
fitting_params=params # Uses pre-computed parameters
354+
)
355+
```
356+
357+
This workflow is essential for:
358+
359+
- **Operational drought bulletins**: Maintain consistency across monthly updates
360+
- **Climate services**: Ensure comparability of drought assessments over time
361+
- **Near-real-time monitoring**: Avoid expensive recalibration with each new observation
362+
363+
364+
## 7. Validation Summary {#sec-summary}
276365

277366
### Test Suite Results
278367

279-
The test suite consists of 6 structured test modules that comprehensively validate the package:
368+
The test suite consists of 7 structured test modules that comprehensively validate the package:
280369

281370
| Test Script | Status | Time | Description |
282371
|:-----------|:-------|:-----|:-----------|
@@ -286,16 +375,17 @@ The test suite consists of 6 structured test modules that comprehensively valida
286375
| `04_spei_calculation.py` | PASS | 823.6s | SPEI with pre-computed PET, Thornthwaite, Hargreaves |
287376
| `05_spi_spei_comparison.py` | PASS | 17.7s | SPI vs SPEI correlation, drought detection comparison |
288377
| `06_visualization.py` | PASS | 147.7s | 25 visualization outputs including advanced analytics |
378+
| `07_operational_mode.py` | PASS | ~120s | Parameter save/load, operational consistency validation |
289379

290-
: Test suite results. All 6 tests pass with the TerraClimate Bali dataset (total runtime: ~21 minutes). {#tbl-test-results}
380+
: Test suite results. All 7 tests pass with the TerraClimate Bali dataset (total runtime: ~23 minutes). {#tbl-test-results}
291381

292382
### Output Summary
293383

294384
The test suite generates comprehensive outputs:
295385

296-
- **NetCDF files**: 26 files (SPI/SPEI at multiple scales and distributions)
297-
- **Plot files**: 25 visualizations (time series, spatial maps, advanced analytics)
298-
- **Report files**: 5 text reports with detailed statistics
386+
- **NetCDF files**: 34 files (SPI/SPEI indices + saved parameters)
387+
- **Plot files**: 28 visualizations (time series, spatial maps, advanced analytics, operational mode)
388+
- **Report files**: 6 text reports with detailed statistics
299389

300390
### Distribution Fitting Quality
301391

@@ -323,6 +413,8 @@ The test suite generates comprehensive outputs:
323413

324414
7. **Advanced visualizations** (seasonal heatmaps, climate stripes, exceedance probability) provide intuitive tools for communication and risk assessment.
325415

416+
8. **Operational mode works perfectly** — parameter save/load produces results identical to fresh calculations across all configurations (SPI/SPEI × scales × distributions).
417+
326418
---
327419

328420
## See Also

0 commit comments

Comments
 (0)