Overview

Preamble: how this project got here, and what AI had to do with it

This project started in May of 2018, about three months before I, Matt R. (as opposed to Matt C.), started as an Assistant Professor at Colorado State University, and 16 months before the birth of my son. It was a time when I probably peaked in my own ability to produce and write code, and I had grand visions of continuing to build detailed bookdown documentation, paired with compelling visuals, reproducible code, and grand architectures that would make my papers something beyond the PDF. It was an absolute pleasure to work in this flow state of peak technical ability, and I was proud that I could be an engine for many of the ideas Jim, Matt C., and I were bouncing off each other. Over the years, that pride turned sour as I entered my overpromise-and-underdeliver phase of life, where I constantly underestimated how much deep-work time I would have and therefore kept underdelivering on the work I had promised to do myself. Progress on this project languished, as it was unfunded and a collaboration between three very busy profs. This slow, slow, and not at all steady progress was punctuated by Jim flying to France to visit me on sabbatical, where we hammered out all the remaining details that ultimately led to submitting. It was a heroic effort by Jim, and I finally understood my limits better and was ready to let the project get published and move on.

Then our esteemed Limnology and Oceanography Associate Editor (name reveal pending approval) correctly chastised us for not using our own data products to update our analysis. We had started this in 2018, and my own lab had published massive updates to the underlying data in 2024–2026, yet we weren’t using them because of the relatively high burden for me to go back into my code and fix everything around the new data. In the background, I was increasingly using AI to offload my own coding and to better understand how to teach Environmental Analysis, so instead of pushing back against the new data, I unleashed Claude and Gemini to rewrite the codebase around the new data, build out the documentation, explore model decisions further, and so on. This site is the result of that handoff, and it is the first project that actually accomplishes my vision of a more reproducible, clearer, and better version of my own science, all because AI can take care of the details far better than I ever can.

So why the long preamble? I think many in my academic circles view AI as a net evil, a dehumanizing force that rips away from us our most cherished artifacts: writing, code, discovery. While this may be true in parts, my experience in this particular case is essentially the opposite. AI allowed me to accomplish a vision I didn’t have time to realize on my own, and at a higher quality than I ever could have marshaled. So yes, all of the code and documentation here was edited, reworked, or redone with AI, but the core ideas are ours and the entire codebase is so much better for it.

— Matt R.

AI use, plainly. The R pipeline in R/, the figures, and this bookdown documentation were written or rewritten with Claude (Anthropic) and Gemini (Google) under Matt R.’s direction, starting from the analysis code and manuscript we developed by hand between 2018 and 2025. The questions, hypotheses, model structure, and interpretation predate that handoff and are ours. The rewritten pipeline was checked against the original analysis, and an automated audit (Section 10) ties the numbers quoted in the manuscript to pipeline output. Claude was also allowed to make edits in the manuscript and in the response to reviewers, solely pertaining to model updates and to changes that came with switching data sources. All of this was reviewed and double-checked by the authors, who are responsible for what is submitted.


The science in brief

Water clarity is one of our oldest and most intuitive lenses into aquatic ecosystems. For more than a century, hydrologists and limnologists have lowered Secchi disks into rivers, lakes, and estuaries to measure how deeply light penetrates the water column. Yet Secchi disk depth (\(z_{SD}\), in meters) alone tells us only how much light is lost—not what is blocking it.

Across inland and coastal waters, diffuse light attenuation (\(k_d = 1 / z_{SD}\); Lee et al. 2015) is governed by pure water (\(k_w\)) and three primary light-attenuating constituents (LACs): non-algal particles (NAP), dissolved organic carbon (DOC), and phytoplankton chlorophyll a (\(\text{Chl }a\)). Under the additive Beer–Lambert model, Secchi depth can be written directly in terms of constituent concentrations:

\[z_{SD} = \frac{1}{k_w + \alpha_{\text{NAP}}\,\text{NAP} + \alpha_{\text{DOC}}\,\text{DOC} + \alpha_{\text{Chl }a}\,\text{Chl }a}\]

To understand how these three constituents partition water clarity across the contiguous United States, we built an open-source pipeline on top of the AquaMatch data suite (Brousil et al. 2024a, 2024b, 2025; De La Torre et al. 2025)—the successor to AquaSat (Ross et al. 2019). Combining 276,321 simultaneous four-variable matchups (Secchi + Chl a + DOC + TSS/SSC) for model calibration with 484,723 three-constituent matchups across 39,595 monitoring stations (1970–2025), we estimate regional specific attenuation coefficients (\(\alpha_i\)) across U.S. EPA Level III ecoregions and project nearly half a million water quality observations into ternary attenuation space.


Why Optical Partitioning & Total Visibility Both Matter ({sonicray} 3D Simulation)

Ternary diagrams are a powerful way to visualize which constituent dominates light attenuation (\(f_{\text{NAP}} + f_{\text{DOC}} + f_{\text{Chl }a} = 1\)), but proportions alone miss a critical physical dimension: total visibility (\(z_{SD}\)). Two lakes sitting at the exact same coordinate in ternary space can represent either a crystal-clear oligotrophic basin (\(z_{SD} > 5\text{ m}\)) or a murky waterbody (\(z_{SD} < 0.4\text{ m}\)) when total constituent concentrations scale up. Moreover, each constituent alters the underwater light field in a distinct way:

  • Chlorophyll a (Algae): Absorbs blue and red light while cells scatter green wavelengths, shifting water from deep blue to emerald green.
  • DOC (Brownification): Absorbs short wavelengths exponentially with negligible particulate scattering, turning water into dark tea-stained blackwater.
  • NAP / TSS (Sediment): Strongly backscatters broadband light, turning water chalky tan/ochre and driving the steepest collapse in Secchi visibility.

To visualize both ternary composition and total visibility simultaneously, we path-traced a naturalistic 3-hill lake basin on an Apple Silicon Metal GPU using {sonicray}’s native dielectric and Beer–Lambert water engine (sr_upload_mesh(water = ...) + sr_water_preset()). Four submerged 3D trout and white Secchi spheres sit at 0.4 m, 0.9 m, 1.5 m, and 2.1 m depth. In Act I (Clear Water Regime), low constituent loads shift the ternary position while all four depth tiers remain visible; in Act II (Dark/Turbid Regime), high loads of Chl a, DOC, and TSS shift the ternary diagram into its dark regime and progressively extinguish visibility from 2.1 m up to 0.4 m:

3D Bio-Optical Titration Film (path-traced in {sonicray}). Left: 3D lake basin with submerged fish and Secchi spheres at 0.4 m, 0.9 m, 1.5 m, and 2.1 m. Right: Live constituent titration and a dynamic ternary diagram transitioning from the Clear Water Regime (Act I) into the Dark/Turbid Regime (Act II).

Six keyframe stages from the {sonicray} 3D water titration: (1–3) Act I Clear Water Regime across oligotrophic and low-load ternary sweeps (fish and Secchi spheres remain visible across 0.4–2.1 m), followed by (4–6) Act II Dark/Turbid Regime during an algal bloom (high Chl a), brownification (high DOC), and a sediment plume (high TSS).

Figure 0.1: Six keyframe stages from the {sonicray} 3D water titration: (1–3) Act I Clear Water Regime across oligotrophic and low-load ternary sweeps (fish and Secchi spheres remain visible across 0.4–2.1 m), followed by (4–6) Act II Dark/Turbid Regime during an algal bloom (high Chl a), brownification (high DOC), and a sediment plume (high TSS).


Continental Ternary Partitioning at a Glance

Across 484,723 co-located U.S. water quality samples, dissolved organic matter (DOC, 59.5%) and non-algal suspended sediment (NAP, 32.9%) dominate average non-water light attenuation in streams and estuaries, whereas lakes span the full ternary simplex with more than double the phytoplankton attenuation share (Chl a, 15.4% vs. 6.0% in streams and 5.3% in estuaries):

Continental ternary partitioning of non-water light attenuation across (a) all U.S. waters (n = 484,723), (b) streams, (c) lakes, and (d) estuaries (see Section 8 and Section 9 for full diagnostics).

Figure 0.2: Continental ternary partitioning of non-water light attenuation across (a) all U.S. waters (n = 484,723), (b) streams, (c) lakes, and (d) estuaries (see Section 8 and Section 9 for full diagnostics).


Pipeline Funnel & Dataset Summary

Stage Description Observations (n) Unique Sites Pipeline Section
  1. Raw AquaMatch Inputs
Harmonized WQP records (sdd, chla, doc, tss; 1970–2025) 12,580,000+ 150,000+ Downloaded via AquaMatchr (Section 1)
  1. 3-Constituent Matchups
Same-site, same-day Chl a + DOC + TSS/SSC 486,689 40,021 Ambient Stream, Lake, and Estuary stations (Section 2)
  1. 4-Variable Matchups
Same-site, same-day Secchi + Chl a + DOC + TSS/SSC 281,439 22,888 Excludes turbidity tubes & <=0.01 m floor flags (Section 2)
  1. Values Below Reporting Limits
Chl a, DOC and TSS below reporting limits drawn below the limit 281,439 22,888 Chl a 0.10 µg/L, DOC 0.25 mg/L, TSS 0.50 mg/L (Section 4)
  1. Beer–Lambert QC Screen
Screen against a published reference attenuation, &#124;z_r&#124; <= 2.5 SD (5.4-fold) 276,321 22,481 Final Training Set: removes 1.82% discordant outliers (Section 4)
  1. Continental Application
All 3-constituent matchups inside training bounds (Model 7) 484,723 39,595 276,321 Measured + 208,402 Modeled Secchi (Section 8)
  1. Temporal Stability Set
Long-term stations with > 7 matchups (Fig. 4) 425,535 9,258 5,391 streams, 2,399 lakes, 1,468 estuaries (Section 9)

Reproducing the Workflow & Code Architecture

source('R/00_setup.R')
fetch_all()                  # Downloads harmonized AquaMatch EDI products + spatial layers
bookdown::render_book()      # Runs pipeline, saves figs/*.png & *.pdf, builds docs/index.html
Script / Folder Role
R/00_setup.R, R/00_download.R Package setup, parameter registry (P), and programmatic {AquaMatchr} / spatial data retrieval
R/prep.R Same-day matchup assembly, Gohin et al. (2005) NAP derivation, draws below reporting limits, and Beer–Lambert plausibility screening
R/ecoregions.R, R/models.R EPA Level I–IV ecoregion joins, Models 1–10 OLS fitting, stability cones, and Model 7 ternary projection
R/ternary.R, R/figures.R Ternary geometry, Sutherland–Hodgman \(\pm k\text{ SD}\) polygon clipping, and Figures 1–4 / S1
R/sonicray_lake.R Apple Silicon Metal GPU 3D lake optical titration renderer ({sonicray})
R/claims.R, R/verify.R Dominance-regime hypothesis tests and automated verification audit (Section 10)