Code
import sys
sys.path.append('.')
from rainDrought.config import get_config
config = get_config()10-Year Interactive Drought and Precipitation Analysis
Antigravity Coding Assistant
July 19, 2026
In this document, we visualize the weekly drought records for Oglala Lakota County and Todd County alongside daily precipitation records for South Dakota using Python’s Plotly library, providing interactive and responsive dashboards.
We will display: 1. County drought datasets (Pine Ridge and Rosebud) and the statewide rolling precipitation plotted over time (10-year timeline). 2. Time within the year (standardized month, X-axis) vs. annual cumulative values (Y-axis) for cumulative precipitation and county cumulative drought indices. 3. Annual trajectories comparing cumulative precipitation (X-axis) vs. cumulative drought index (Y-axis) faceted side-by-side by county.
[!NOTE] Active Region Configuration: Currently configured for South Dakota (precipitation) and counties: Oglala Lakota County (Pine Ridge), Todd County (Rosebud). To customize these locations, copy the layout from
config.csv.default(or the example fromconfig.csv.example) into a newconfig.csvfile and re-run.
First, we load the collected datasets, calculate the Drought Severity and Coverage Index (DSCI), compute cumulative precipitation, and merge the tables on matching dates.
DSCI = D0 + D1 + D2 + D3 + D4 (range: 0 to 500).ValidStart date of each USDM report.| date | year | dsci | cumulative_dsci_year | precipitation_inches | cumulative_rain_year | rolling_365d_rain | year_str | day_in_year | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 2016-08-30 | 2016 | 189.31 | 387.84 | 0.011997 | 0.203763 | 0.203763 | 2016 | 2020-08-30 |
| 1 | 2016-09-06 | 2016 | 132.12 | 519.96 | 0.181070 | 1.112576 | 1.112576 | 2016 | 2020-09-06 |
| 2 | 2016-09-13 | 2016 | 127.53 | 647.49 | 0.017975 | 1.379606 | 1.379606 | 2016 | 2020-09-13 |
| 3 | 2016-09-20 | 2016 | 127.53 | 775.02 | 0.009988 | 1.878066 | 1.878066 | 2016 | 2020-09-20 |
| 4 | 2016-09-27 | 2016 | 98.78 | 873.80 | 0.000023 | 2.258240 | 2.258240 | 2016 | 2020-09-27 |
This faceted timeline displays the 10-year history of the weekly drought index (DSCI) for both counties alongside the daily South Dakota precipitation rolling average.
Here we plot time within the year (standardized month, X-axis) against cumulative values (Y-axis).
Each year is shown as a separate colored curve in a rainbow series, with open circles indicating the end of each month. Click on a year in the legend to toggle its visibility across all subplots.
Finally, we plot annual cumulative precipitation (X-axis) against the annual cumulative drought index (DSCI) (Y-axis).
Individual years are colored in a rainbow series with open circles marking the end of each month.
---
title: "Visualizing Climate Records using Plotly"
subtitle: "10-Year Interactive Drought and Precipitation Analysis"
author: "Antigravity Coding Assistant"
date: "2026-07-19"
format:
html:
theme: cosmo
toc: true
code-fold: true
code-tools: true
embed-resources: true
---
```{python}
#| label: config-init
#| warning: false
#| message: false
import sys
sys.path.append('.')
from rainDrought.config import get_config
config = get_config()
```
```{python}
#| label: introduction
#| warning: false
#| message: false
#| output: asis
from rainDrought.visualizations import show_plot_records_intro
show_plot_records_intro(config)
```
***
# Data Processing & Alignment
First, we load the collected datasets, calculate the **Drought Severity and Coverage Index (DSCI)**, compute **cumulative precipitation**, and merge the tables on matching dates.
- **DSCI Formula**: For cumulative USDM statistics, the index is calculated as `DSCI = D0 + D1 + D2 + D3 + D4` (range: 0 to 500).
- **Date Matching**: We align the daily precipitation and weekly drought records on the weekly `ValidStart` date of each USDM report.
```{python}
#| label: data-preparation
#| warning: false
#| message: false
from rainDrought.visualizations import load_and_preprocess
merged_dfs, df_precip = load_and_preprocess(config)
# Print preview of the first county's merged data
first_fips = config["counties"][0]["fips"]
merged_dfs[first_fips].head()
```
***
# Interactive Visualizations with Plotly
## 1. Visualizing Data Over Time (10-Year Timelines)
This faceted timeline displays the 10-year history of the weekly drought index (DSCI) for both counties alongside the daily South Dakota precipitation rolling average.
```{python}
#| label: plot-time-series
#| warning: false
#| message: false
from rainDrought.visualizations import plot_time_series
fig = plot_time_series(config, merged_dfs)
fig.show()
```
***
## 2. Visualizing Annual Cumulative Progression Over the Year (Time vs. Cumulative Values)
Here we plot time within the year (standardized month, X-axis) against cumulative values (Y-axis).
Each year is shown as a separate colored curve in a rainbow series, with open circles indicating the end of each month. Click on a year in the legend to toggle its visibility across all subplots.
```{python}
#| label: plot-time-vs-cumulative
#| warning: false
#| message: false
from rainDrought.visualizations import plot_time_vs_cumulative
fig = plot_time_vs_cumulative(config, merged_dfs)
fig.show()
```
***
## 3. Visualizing Trajectories of Cumulative Rain vs. Cumulative Drought Index (Faceted by County)
Finally, we plot **annual cumulative precipitation** (X-axis) against the **annual cumulative drought index (DSCI)** (Y-axis).
Individual years are colored in a rainbow series with open circles marking the end of each month.
### How to Interpret this Plot:
- **X-Axis (Precipitation)**: Represents the total cumulative rain since January 1 of that year.
- **Y-Axis (Drought DSCI)**: Represents the total cumulative weekly USDM DSCI since January 1 of that year.
- **Watermarks (DRY / WET)**:
- **Upper-Left Corner ("DRY")**: High cumulative drought index but low rainfall. Curves that bend steeply upwards and stay to the left represent persistent, severe drought years.
- **Lower-Right Corner ("WET")**: High cumulative rainfall but low/no drought index. Curves that stretch far to the right and remain low represent wet, drought-free years.
- **Month Circles**: Progress from left to right chronologically (January to December), allowing you to trace the exact weeks when drought conditions escalated (steep slopes) or recovered (slopes flattening out as rainfall accumulated).
```{python}
#| label: plot-combined-annual-trajectories
#| warning: false
#| message: false
from rainDrought.visualizations import plot_combined_annual_trajectories
fig = plot_combined_annual_trajectories(config, merged_dfs)
fig.show()
```