Lesson 21: Spatial Contaminant Contours, Ecotoxicity Maps & Low-Carbon Concrete Visualization

The “Boring Stuff” Problem: Reading 500 Numbers Instead of Seeing Hotspots at a Glance

A regulatory agency never wants a 50-row spreadsheet printout of groundwater plumes or aquatic chemical assays—they need 2D hazard contours and decision-ready multi-variable scatter plots where color encodes a third physical dimension (c=variable, cmap=...).

from pathlib import Path
def data_file(name):
    """Locate a dataset file whether running from SRC_DIR, module folder, HOMEWORK, or EXAMS."""
    for p in [
        Path("datasets") / name,
        Path("../datasets") / name,
        Path("../../datasets") / name,
    ]:
        if p.exists():
            return p
    raise FileNotFoundError(f"Missing dataset {name} in datasets/")
import numpy as np
import matplotlib.pyplot as plt

# Example 1 (Real UCI QSAR Aquatic Toxicity Dataset + LCA Track 2 USEtox Ecotoxicity Link)
# Columns: 0=TPSA, 1=SAacc, 2=H050, 3=MLOGP, 4=RDCHI, 5=GATS1p, 6=nN, 7=C040, 8=LC50_neglog_molL
qsar = np.loadtxt(data_file("UCI_QSAR_Aquatic_Toxicity.csv"), delimiter=",", skiprows=1)
tpsa, mlogp, lc50_neg = qsar[:, 0], qsar[:, 3], qsar[:, 8]

fig, ax = plt.subplots(figsize=(7.6, 4.3))
sc = ax.scatter(mlogp, lc50_neg, c=np.clip(tpsa, 0, 120), cmap="viridis", s=34, alpha=0.82, edgecolors="#0f172a", linewidths=0.3)
plt.colorbar(sc, ax=ax, label="Polar Surface Area TPSA [A^2]")
ax.axhline(5.0, color="#dc2626", ls="--", lw=1.6, label="High Acute Toxicity (-log LC50 > 5 -> LC50 < 10 uM)")
ax.set_title("Acute Aquatic Toxicity (-log LC50) vs Lipophilicity (546 UCI Industrial Chemicals)")
ax.set_xlabel("Octanol-Water Partition Proxy MLOGP (Log Kow)")
ax.set_ylabel("Fathead Minnow Toxicity -log10(LC50 [mol/L])")
ax.grid(True, alpha=0.3)
ax.legend(fontsize=8.5, loc="lower right")
fig.tight_layout()
print(f"Correlation(MLOGP, -log LC50) = {np.corrcoef(mlogp, lc50_neg)[0,1]:.3f} | High-Toxicity (>5): {(lc50_neg>5).sum()} chemicals")
Spatial Contaminant Contours, Ecotoxicity Maps & Low-Carbon Concrete Visualization Output Plot 1
Correlation(MLOGP, -log LC50) = 0.536 | High-Toxicity (>5): 205 chemicals
# Example 2 (Real UCI Low-Carbon Concrete Dataset + LCA Track 1 Allocation): Slag+FlyAsh SCM Fraction vs Strength
conc = np.loadtxt(data_file("UCI_Concrete_LowCarbon_SCMs.csv"), delimiter=",", skiprows=1)
cement, slag, ash, age_d, mpa = conc[:, 0], conc[:, 1], conc[:, 2], conc[:, 7], conc[:, 8]
m28 = (age_d == 28)
scm_pct = (slag[m28] + ash[m28]) / (cement[m28] + slag[m28] + ash[m28]) * 100.0
mpa28 = mpa[m28]

fig, ax = plt.subplots(figsize=(7.5, 4.1))
sc2 = ax.scatter(scm_pct, mpa28, c=cement[m28], cmap="RdYlGn_r", s=36, alpha=0.82, edgecolors="#1e293b", linewidths=0.35)
plt.colorbar(sc2, ax=ax, label="Portland Cement Clinker [kg/m^3] (CO2 driver)")
ax.axhline(40.0, color="#0284c7", ls="--", lw=1.5, label="Structural Grade Target (40 MPa @ 28 d)")
ax.axvline(40.0, color="#059669", ls=":", lw=1.6, label="40% Industrial Byproduct Replacement")
ax.set_title("28-Day Compressive Strength vs Low-Carbon SCM Replacement (UCI Concrete, n=425 @ 28d)")
ax.set_xlabel("Supplementary Cementitious Materials (Slag + Fly Ash) [%]")
ax.set_ylabel("28-Day Compressive Strength [MPa]")
ax.grid(True, alpha=0.3)
ax.legend(fontsize=8.5, loc="upper right")
fig.tight_layout()
Spatial Contaminant Contours, Ecotoxicity Maps & Low-Carbon Concrete Visualization Output Plot 2

Concept Check Questions

  1. Why is c=np.clip(tpsa, 0, 120) helpful before mapping a skewed variable onto a continuous colormap?
  2. Look at the concrete visualization: how does substituting blast-furnace slag and fly ash achieve structural concrete above 40 MPa while cutting Portland cement clinker mass nearly in half?
  3. Notice corr(MLOGP, -log LC50) > 0.5: explain why hydrophobic chemicals (high \(\log K_{ow}\)) bioaccumulate across fish gill membranes!

Guided Practice Problem 1: Highlight Multi-Source Plume Compliance Isopleths (contour)

Create a 2D meshgrid X, Y (0..3000 m, -400..400 m) combining two factory stacks at (0, -100) (Q1=30 g/s) and (0, +120) (Q2=40 g/s, Stability D, H_eff=55 m, u=4.0 m/s), and draw filled contours PLUS a bold red contour line at 150 ug/m^3.

# Guided Practice 1 Starter
x = np.linspace(100, 3000, 150)
y = np.linspace(-400, 400, 120)
X, Y = np.meshgrid(x, y)
sy = 0.08 * X / np.sqrt(1 + 0.0001 * X)
sz = 0.06 * X / (1 + 0.0002 * X)
C1 = (30e6 / (np.pi * 4 * sy * sz)) * np.exp(-0.5 * ((Y + 100) / sy) ** 2 - 0.5 * (55 / sz) ** 2)
C2 = (40e6 / (np.pi * 4 * sy * sz)) * np.exp(-0.5 * ((Y - 120) / sy) ** 2 - 0.5 * (55 / sz) ** 2)
C_tot = C1 + C2
fig, ax = plt.subplots(figsize=(7.4, 3.6))
cf = ax.contourf(X, Y, C_tot, levels=16, cmap="YlOrRd")
plt.colorbar(cf, ax=ax, label="Combined SO2 [ug/m^3]")
ax.contour(X, Y, C_tot, levels=[150.0], colors=["#0f172a"], linewidths=2.0)
ax.set_title("Twin-Stack Plume Superposition + 150 ug/m^3 Compliance Contour")
ax.set_xlabel("Downwind Distance [m]"); ax.set_ylabel("Crosswind Y [m]")
fig.tight_layout()
print(f"Combined Peak = {C_tot.max():.1f} ug/m^3")
Spatial Contaminant Contours, Ecotoxicity Maps & Low-Carbon Concrete Visualization Output Plot 3
Combined Peak = 524.3 ug/m^3