Build a groundwater salinity intrusion watch: wells, conductivity, and drivers.
- User
Build a groundwater salinity intrusion watch: wells, conductivity, and drivers.
Assistant
Build a groundwater salinity intrusion watch: wells, conductivity, and drivers.
The user wants a "groundwater salinity intrusion watch" dashboard or information system. The key components requested are:
The user is asking to build this. Since I am a text-based AI, I cannot physically build a web application or a physical monitoring network. I have two main ways to interpret "build":
Given the complexity, a mix of both is usually best. I will provide a comprehensive guide on how to build a monitoring "watch" system, including the conceptual framework and a code example (likely Python with a library like Streamlit or Plotly, or just a structure for a dashboard).
Structure of the Response:
System Architecture (The "How-To"):
The Dashboard/Interface (The "Look"):
Code Example (The "Build"):
streamlit (popular for data apps) and plotly (for charts) and folium (for maps).Key Indicators/Thresholds:
Drafting the Content:
Introduction: Define what salinity intrusion is (saltwater encroachment).
Component 1: The Wells (Assets): Need spatial data.
Component 2: Conductivity (Signal): The proxy for salt. Relationship: (roughly), Chloride is the toxic component.
Component 3: The Drivers (Forces):
The Code: I will write a Python script that simulates a dashboard.
pandas, numpy, streamlit, plotly.express, folium (via streamlit-folium).Refining the "Watch" concept: It's not just data; it's status. I should add a status logic (Green/Yellow/Red).
Self-Correction/Refinement during thought process:
Final Plan:
Let's write the Python code mentally first to ensure it works.
df = pd.DataFrame(...)
Map: folium.Map(...) add markers based on df['status'].
Chart: px.line(df, x='date', y='conductivity', color='well_id').
Drivers: Maybe a second y-axis for precipitation vs conductivity.
This looks solid. I will proceed with this structure. Building a Groundwater Salinity Intrusion Watch system requires integrating real-time sensor data, geological mapping, and hydrological drivers into a single dashboard. This system allows water managers to identify when freshwater aquifers are being compromised by saltwater.
Below is a comprehensive guide to building this system, covering the Architecture, Data Logic, and a Python Prototype.
To build an effective "Watch" system, you need three distinct layers:
You need a network of observation wells strategically placed between the coastline and the freshwater supply wells.
Raw conductivity is not enough; you need to calculate Specific Conductance (normalized to 25°C) and correlate it with external stressors.
A dashboard that displays status indicators (Green/Yellow/Red) based on threshold exceedances.
You must define the logic that triggers a "Watch" vs. a "Warning."
| Parameter | Unit | Freshwater Baseline | Watch Level (Caution) | Warning Level (Action) |
|---|---|---|---|---|
| Specific Conductance | < 1,000 | 1,000 – 2,000 | > 2,000 (Approaching Brackish) | |
| Chloride (Est.) | mg/L | < 250 (EPA Secondary Std) | 250 – 500 | > 500 |
| Hydraulic Gradient | Ratio | Inland flow | Neutral (Stagnant) | Seaward flow (Reversal) |
Note: Conductivity is easily converted to Salinity/Chloride using empirical relationships specific to your local geology (e.g., ).
Here is a complete, runnable Python script using streamlit, pandas, and plotly. This prototype simulates a real-time watch system for a coastal aquifer.
Prerequisites:
pip install streamlit pandas plotly numpy
The Code (salinity_watch.py):
import streamlit as st
import pandas as pd
import numpy as np
import plotly.graph_objects as go
from datetime import datetime, timedelta
# -----------------------------------------
# 1. CONFIGURATION & SYNTHETIC DATA GENERATION
# -----------------------------------------
st.set_page_config(page_title="Groundwater Salinity Watch", layout="wide")
@st.cache_data
def generate_data():
"""
Simulates data for 3 monitoring wells over 30 days.
Well 1: Inland (Safe)
Well 2: Mid-zone (Fluctuating)
Well 3: Coastal (Intruding)
"""
dates = pd.date_range(end=datetime.now(), periods=720, freq='1H') # 30 days hourly
# Base noise
noise = np.random.normal(0, 50, len(dates))
data = []
# Well 1: Deep Inland (Stable Freshwater ~500 uS/cm)
w1_cond = 500 + noise + (np.sin(np.linspace(0, 6, len(dates))) * 20) # minor seasonal drift
data.append(pd.DataFrame({'Time': dates, 'Well': 'W-01 (Inland)', 'Conductivity': w1_cond, 'Temp': 15 + np.random.normal(0, 0.5, len(dates))}))
# Well 2: Transition Zone (Reacts to Tides/Pumping ~1500 uS/cm)
# Simulating a slow trend upward + tidal oscillation
w2_tidal = np.sin(np.linspace(0, 60, len(dates))) * 200 # Tidal influence
w2_trend = np.linspace(0, 400, len(dates)) # Intrusion trend
w2_cond = 1200 + w2_tidal + w2_trend + noise
data.append(pd.DataFrame({'Time': dates, 'Well': 'W-02 (Mid-Range)', 'Conductivity': w2_cond, 'Temp': 16 + np.random.normal(0, 0.5, len(dates))}))
# Well 3: Coastal Sentinel (High Salinity ~5000 uS/cm)
# Spikes during high tide/drought
w3_tidal = np.sin(np.linspace(0, 60, len(dates))) * 800
w3_cond = 4500 + w3_tidal + noise
data.append(pd.DataFrame({'Time': dates, 'Well': 'W-03 (Coastal)', 'Conductivity': w3_cond, 'Temp': 17 + np.random.normal(0, 0.8, len(dates))}))
df = pd.concat(data)
# Calculate Specific Conductance (normalized to 25 deg C) - simplified formula
# Sc = Conductivity / (1 + 0.02 * (Temp - 25))
df['Specific_Conductance'] = df['Conductivity'] / (1 + 0.02 * (df['Temp'] - 25))
# Estimate Chloride (rough conversion for demo)
# Relationship varies by region, using linear approx here
df['Chloride_mg_L'] = df['Specific_Conductance'] * 0.25
return df
df = generate_data()
# -----------------------------------------
# 2. DASHBOARD LAYOUT
# -----------------------------------------
st.title("💧 Groundwater Salinity Intrusion Watch")
st.markdown(f"**Last Updated:** {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
# --- SIDEBAR: DRIVER INPUTS ---
st.sidebar.header("Driver Inputs")
# In a real app, these would come from API feeds (NOAA, USGS)
tide_status = st.sidebar.selectbox("Tide Status", ["Low Tide", "Normal", "High Tide"])
pumping_rate = st.sidebar.slider("Avg Pumping Rate (m³/day)", 0, 5000, 2500)
rainfall_7d = st.sidebar.slider("7-Day Rainfall Accumulation (mm)", 0, 100, 5)
# Logic: High Tide + High Pumping + Low Rain = High Risk
driver_risk_score = 0
if tide_status == "High Tide": driver_risk_score += 1
if pumping_rate > 4000: driver_risk_score += 2
if rainfall_7d < 10: driver_risk_score += 1
st.sidebar.metric("Composite Driver Risk", f"{driver_risk_score} / 4")
# --- MAIN PANEL: STATUS CARDS ---
st.subheader("Network Status Overview")
# Get latest readings for each well
latest = df[df['Time'] == df['Time'].max()]
cols = st.columns(3)
threshold_watch = 1500 # uS/cm
threshold_alert = 3000 # uS/cm
def get_status(cond):
if cond < threshold_watch: return "NORMAL", "green", "✅"
if cond < threshold_alert: return "WATCH", "orange", "⚠️"
return "ALERT", "red", "🚨"
for idx, row in latest.iterrows():
well_name = row['Well']
cond = row['Specific_Conductance']
chloride = row['Chloride_mg_L']
status_text, color, icon = get_status(cond)
with cols[idx % 3]:
st.markdown(f"### {icon} {well_name}")
st.metric("Spec. Conductivity", f"{cond:.0f} µS/cm")
st.metric("Est. Chloride", f"{chloride:.0f} mg/L")
# Dynamic color formatting
st.markdown(f"<h4 style='color:{color};'>Status: {status_text}</h4>", unsafe_allow_html=True)
st.progress(min(cond / threshold_alert, 1.0))
st.markdown("---")
# --- CHARTS ---
st.subheader("Temporal Conductivity Trends")
# Filter for specific well if desired
selected_wells = st.multiselect("Select Wells", df['Well'].unique(), default=df['Well'].unique())
if selected_wells:
filtered_df = df[df['Well'].isin(selected_wells)]
fig = go.Figure()
for well in selected_wells:
well_data = filtered_df[filtered_df['Well'] == well]
fig.add_trace(go.Scatter(
x=well_data['Time'],
y=well_data['Specific_Conductance'],
mode='lines',
name=well,
line=dict(width=2)
))
# Add Threshold Lines
fig.add_hline(y=threshold_watch, line_dash="dash", line_color="orange", annotation_text="Watch Level")
fig.add_hline(y=threshold_alert, line_dash="dash", line_color="red", annotation_text="Alert Level")
fig.update_layout(
title="Specific Conductance (µS/cm) vs Time",
xaxis_title="Date",
yaxis_title="µS/cm",
hovermode="x unified",
template="plotly_white"
)
st.plotly_chart(fig, use_container_width=True)
# --- MAP VIEW (SIMULATED) ---
st.subheader("Geospatial View")
st.info("In a production environment, this map displays well locations and contour lines of the saltwater interface.")
import plotly.express as px
# Mock coordinates
map_data = pd.DataFrame({
'Well': ['W-01 (Inland)', 'W-02 (Mid-Range)', 'W-03 (Coastal)'],
'Lat': [34.05, 34.04, 34.03],
'Lon': [-118.50, -118.51, -118.52],
'Status': [get_status(latest[latest['Well']=='W-01 (Inland)']['Specific_Conductance'].values[0])[0],
get_status(latest[latest['Well']=='W-02 (Mid-Range)']['Specific_Conductance'].values[0])[0],
get_status(latest[latest['Well']=='W-03 (Coastal)']['Specific_Conductance'].values[0])[0])]
})
color_map = {'NORMAL': 'green', 'WATCH': 'orange', 'ALERT': 'red'}
fig_map = px.scatter_mapbox(map_data, lat="Lat", lon="Lon", hover_name="Well", hover_data=["Status"],
color="Status", color_discrete_map=color_map, zoom=10, height=300)
fig_map.update_layout(mapbox_style="open-street-map")
st.plotly_chart(fig_map, use_container_width=True)
To make the "Watch" predictive rather than just reactive, integrate these specific drivers into your data model:
Hydraulic Gradient ():
Pumping Recession:
Temperature Viscosity Correction:
salinity_watch.py.streamlit run salinity_watch.py.