10-Year Historical Records for South Dakota and Oglala Lakota County
Author
Antigravity Coding Assistant
Published
July 19, 2026
Introduction
This document contains Python code to programmatically retrieve, process, and store 10 years of historical data for: 1. Weekly Drought Monitor records for Oglala Lakota County (FIPS 46102) and Todd County (FIPS 46121), South Dakota. 2. Daily Precipitation records for the State of South Dakota (state-wide mean).
The collected datasets are saved to the data/ directory as: - data/oglala_lakota_drought_weekly.csv - data/todd_drought_weekly.csv - data/south_dakota_precipitation_daily.csv
Data Sources & Citations
U.S. Drought Monitor (USDM)
Source: National Drought Mitigation Center (NDMC), University of Nebraska-Lincoln, USDA, and NOAA.
Description: Weekly reports of drought severity classifications (None, D0-D4) indicating the percentage of area affected.
Data Access: Retrieved via the USDM REST Data Services API: https://usdmdataservices.unl.edu/api/.
Citation: > U.S. Drought Monitor. (2026). U.S. Drought Monitor data archives. National Drought Mitigation Center. Retrieved from https://droughtmonitor.unl.edu/
Applied Climate Information System (ACIS)
Source: NOAA Regional Climate Centers (RCCs).
Description: Daily precipitation observations aggregated and interpolated across the state of South Dakota, computed as a statewide mean.
Data Access: Retrieved via the ACIS GridData API: https://data.rcc-acis.org/GridData.
Citation: > Applied Climate Information System (ACIS). (2026). Gridded Daily Precipitation (NRCC Interpolated Grid). NOAA Regional Climate Centers. Retrieved from https://www.rcc-acis.org/
Data Collection Pipeline
The following Python block dynamically computes the date range for the past 10 years and calls the respective APIs to fetch and store the records.
Code
import osimport ioimport datetimeimport requestsimport pandas as pd# Create target data directoryos.makedirs("data", exist_ok=True)# Calculate dynamic dates for the past 10 yearstoday = datetime.date.today()try: start_date = today.replace(year=today.year -10)exceptValueError:# Handle leap year edge case (Feb 29) start_date = today.replace(year=today.year -10, day=28)start_date_str = start_date.strftime("%Y-%m-%d")end_date_str = today.strftime("%Y-%m-%d")print(f"Collection timeframe: {start_date_str} to {end_date_str}")# --- Task 1: Fetch U.S. Drought Monitor Data for Counties ---counties = {"46102": ("Oglala Lakota County", "oglala_lakota_drought_weekly.csv"),"46121": ("Todd County", "todd_drought_weekly.csv")}for fips_code, (county_name, filename) in counties.items(): usdm_url = (f"https://usdmdataservices.unl.edu/api/CountyStatistics/GetDroughtSeverityStatisticsByAreaPercent"f"?aoi={fips_code}&startdate={start_date_str}&enddate={end_date_str}&statisticsType=1" )print(f"Querying USDM API for {county_name}...") usdm_response = requests.get(usdm_url)if usdm_response.status_code ==200: usdm_csv = usdm_response.text usdm_path = os.path.join("data", filename)withopen(usdm_path, "w", encoding="utf-8") as f: f.write(usdm_csv)print(f"-> Successfully saved weekly drought data to {usdm_path}")else:print(f"-> Error fetching USDM data for {county_name}: {usdm_response.status_code}")print(usdm_response.text[:500])# --- Task 2: Fetch Daily Precipitation Records for South Dakota (State Mean) ---acis_url ="https://data.rcc-acis.org/GridData"acis_payload = {"state": "sd","sdate": start_date_str,"edate": end_date_str,"grid": "1","elems": [{"name": "pcpn", "area_reduce": "state_mean"}]}print(f"Querying ACIS GridData API...")acis_response = requests.post(acis_url, json=acis_payload)if acis_response.status_code ==200: acis_json = acis_response.json() raw_records = acis_json.get("data", [])# Process the nested list format into a standard DataFrame processed = []for date_val, val_dict in raw_records: val = val_dict.get("SD") ifisinstance(val_dict, dict) elseNone# Handle potential trace ('T') or missing ('M') string codesif val isNoneor val in ["M", "M ", " M", ""]: val_float =Noneelif val =="T"or val =="T ": val_float =0.0001else:try: val_float =float(val)exceptValueError: val_float =None processed.append({"date": date_val, "precipitation_inches": val_float}) df_precip = pd.DataFrame(processed) precip_path = os.path.join("data", "south_dakota_precipitation_daily.csv") df_precip.to_csv(precip_path, index=False)print(f"-> Successfully saved daily precipitation data to {precip_path}")else:print(f"-> Error fetching ACIS data: {acis_response.status_code}")print(acis_response.text[:500])
Collection timeframe: 2016-07-22 to 2026-07-22
Querying USDM API for Oglala Lakota County...
-> Successfully saved weekly drought data to data/oglala_lakota_drought_weekly.csv
Querying USDM API for Todd County...
-> Successfully saved weekly drought data to data/todd_drought_weekly.csv
Querying ACIS GridData API...
-> Successfully saved daily precipitation data to data/south_dakota_precipitation_daily.csv
Data Previews & Summaries
Let’s load the saved datasets to verify their content and print summary statistics.
U.S. Drought Monitor Data Summary (Oglala Lakota County)