PINN-Based Spatio-Temporal Workflow for Groundwater Risk Prediction and Decision Support
Description
Model Introduction and Process: Groundwater systems that sustain more than 2.5 billion people are increasingly stressed by the compound pressures of climate variability and rapid urbanisation. Traditional numerical models struggle to assimilate sparse observations and physical constraints simultaneously. We therefore develop a physics-informed neural network (PINN) that embeds the transient groundwater-flow equation directly into the loss function, achieving physically consistent hind-casts and forecasts while capturing fine-scale heterogeneity. This code implements a Physics-Informed Neural Network (PINN) for groundwater modeling. In this case, the PINN is designed to solve a groundwater flow problem by minimizing not only the error between its predictions and the observed data but also the error in satisfying the governing partial differential equation (PDE) for groundwater flow. This helps the model learn physically consistent solutions, even with limited data. This full script is ready for Colab (T4 GPU or similar) and delivers state-of-the-art accuracy for physics-informed modeling of groundwater heads. Remember to change the path "/content/groundwater_pinn_dataset.csv" in Colab if directly uploaded.
Files
Steps to reproduce
1. Prepare the Data Collect Data: Obtain groundwater data, including spatial coordinates (x, y), time (t), observed head values (h), DEM, rainfall, pumping, and water quality indices. Organize Structure: Compile data into a 3D or 4D array (data cube) representing h(x,y,t,k), where k denotes additional features if needed. Clean & Normalize: Remove missing values. Normalize spatial-temporal coordinates (to [-1, 1]). Standardize groundwater head values for model stability. 2. Set Up the Computational Environment Use a cloud-based Jupyter or Colab platform, ideally with GPU support (e.g., T4 GPU). Install required packages: TensorFlow (>=2.15) tf-keras scikit-learn tensorflow-probability rasterio, imageio for visualization Example installation block: python !pip install tensorflow==2.18 tf-keras scikit-learn tensorflow-probability rasterio imageio 3. Load and Prepare Data in the Notebook Upload your CSV file (e.g., groundwater_pinn_dataset.csv) to the notebook environment. Read and process the data: python import pandas as pd df = pd.read_csv('/content/groundwater_pinn_dataset.csv').dropna() Extract input (x, y, t) and output (h), then apply normalization and scaling. 4. Construct the PINN Model Build Input Featurization: Use Fourier feature mapping to enrich inputs. Define Neural Network: Employ 6 SIREN (sinusoidal activation) layers with 256 units each. Include learnable weighting of data and physics losses. Embed Physics: Encode the transient groundwater PDE as a loss component within the model. Provide functionality to compute the differential residual over random collocation points in the (x, y, t) space. 5. Train the Model Batch Preparation: Set aside collocation (physics) and observation (data) points for each training batch. Training Protocol: First, use the Adam optimizer for initial training (e.g., 3,000 epochs). Every 500 epochs, apply Residual-based Adaptive Refinement (RAR-D) to add collocation points where PDE residuals are highest. Monitor interim metrics Fine-tuning: Run the L-BFGS optimizer for further convergence (e.g., 700 iterations) after Adam. 6. Evaluate the Model Prediction: Generate head predictions for the validation and test datasets. Metrics: R2, RMSE, MAE between observed and predicted values. Visualization: Create scatter plots of predicted vs. observed values. Plot loss curves for data, physics, and total loss over epochs. Generate heat maps for predicted risk and uncertainty.
Institutions
- Loyola College
- University of Madras