Skip to content

TGF — advisory water treatment for industrial cooling towers

Python 3.10+ License CI OpenSSF Best Practices DOI

TGF tells a cooling-tower operator what their water is about to do — scale up, turn corrosive, or drift out of spec — and what to dose about it. It reads the routine water-analysis data a plant already collects, flags anomalies, forecasts where the chemistry is heading, and recommends a dose. A human authorizes every dose. TGF is not wired to dosing hardware.

Underneath: water-chemistry risk indices (LSI/RSI, via cooling-tower-chem), foundation-model anomaly detection and forecasting, model-predictive dose optimization, and a layered safety system that clamps every recommendation to hard limits. "TGF" is the project's original working name; it has stuck.

In use

Advisory use since 2025 at eight cooling towers across two Indian plants — DCM Shriram Alkali and Atul Ltd, named with permission. The engagement began with a data-gathering phase; the maintainer then ran TGF remotely on incoming plant data and plant teams acted on its outputs. Since June 2026 it has been self-hosted on-site at DCM Shriram Alkali (four towers), running without maintainer involvement. The four Atul Ltd towers continue on the same advisory basis.

The closed-loop controller is a separate, stricter claim: it is validated in backtest only, over 5,614 historical water-analysis records. Autonomous actuation is roadmap, not shipped.

Deployment verification

A verification letter from DCM Shriram Limited — Unit: Shriram Alkali & Chemicals, Jhagadia (company letterhead, CIN shown, named signatory line: Head — Utilities) states: an adapted build of TGF in operational use at the unit since June 2026, across its four cooling towers, for monitoring and analysis; its daily dosing quantities, daily biocide dosing quantity, and blowdown recommendations in day-to-day use; every dosing action authorised by plant personnel; and no connection to plant hardware. It does not confirm an upstream version — the plant runs its own adapted build — and it is a statement of fact, not an endorsement.

Read the letter. The copy published here is unsigned; the signed original has been requested and will replace it when it arrives. The letter is dated 20 July 2026, prepared by the unit when confirmation was first requested, and was received on 30 July 2026. Verification of its statements may be sought care of the unit address on the letterhead; the maintainer will also connect evaluators with the plant's utility head and plant manager directly (choksimac167005@gmail.com).

Two earlier solicited confirmation letters were withdrawn on 29 July 2026. The letter does not cover the Atul Ltd towers or the 2025 advisory phase; those rest on the maintainer's attestation.

Check the claims yourself

Claim How to check it
It runs, and you can see it Live demo — every component on a simulated tower, no install, no login
The water chemistry is real and cited cooling-tower-chem on PyPI — every formula cited to its primary paper, 111 tests, published with build attestations
The code is tested CI runs on Python 3.10–3.12
It is archived and citable 10.5281/zenodo.21573444
Security practices OpenSSF Best Practices
Every load-bearing claim above EVIDENCE.md maps each one to a checkable artifact

The Problem

India's cooling towers lose 2--5% of operational capacity annually to scaling, corrosion, and biofouling. Manual operators test water 2--3 times per day and react to problems after they appear, wasting 15--25% of chemicals through over-dosing. A single unplanned shutdown from scaling or corrosion costs $50K--$200K. The industry charges $50K--$200K/year for automation -- TGF targets $20K/year total cost.

What TGF Does

By design, TGF ingests water parameters (pH and conductivity, plus temperature and ORP where instrumented) on a 5-minute loop, detects anomalies using a 385M-parameter foundation model, forecasts parameter trajectories 24 hours ahead, and optimizes chemical doses using Model Predictive Control -- all with a 5-tier safety layer that enforces hard limits by clamping. Validation to date uses historical lab water-analysis records (see the backtest results below), not live 5-minute telemetry; the released datasets carry pH and conductivity but not temperature or ORP.

graph TD
    A[Sensors: pH, Conductivity, Temp, ORP] --> B[Data Ingestion Pipeline]
    B --> C[5-Layer Anomaly Detection]
    C --> D{Anomaly?}
    D -->|Yes| E[Alert Manager]
    D -->|No| F[Dosing Controller]
    C --> F
    F --> G[Physics Engine: LSI / RSI / CoC]
    F --> H[Chronos-T5 Forecaster: 24h Ahead]
    F --> I[MPC Optimizer: L-BFGS-B]
    F --> J[Chemical Tracker: 7 Chemicals]
    G --> I
    H --> I
    I --> K[5-Tier Safety Layer]
    K --> L[Dosing Commands]
    L --> M[SQLite: 7 Tables]
    M --> N[FastAPI Dashboard: 18 Endpoints]
Loading

Backtest results (closed-loop controller, simulated on historical data)

The advisory outputs are in production use (see above). The closed-loop controller metrics below are a different, stricter claim, and come from replaying 5,614 historical water-analysis records through the controller in simulation -- not from autonomous operation. The records are periodic lab reports (labelled roughly 2012--2025, with gaps; per-row timestamps were not preserved in the released CSV) consolidated across multiple cooling towers at DCM Shriram Alkali plants, used with the operator's permission. The manual-dosing baseline is modeled, not measured, and TGF has not commanded dosing on physical equipment.

Metric (backtest) Value
Cycles in optimal LSI range 86.2%
Critical-risk cycles 0%
Preemptive dosing rate 78%
Modeled chemical savings vs manual baseline 16.7%
Constraint violations (dose clamps exceeded) 0 / 5,614

Technical Architecture

MPC Optimizer

L-BFGS-B with 24-step receding horizon (2 hours at 5-minute intervals). 10-component cost function balancing chemical cost, scaling/corrosion/biofouling risk, Chronos-T5 forecast penalties, CPCB discharge compliance, and rate smoothing. Differential evolution fallback for non-convex cases. Only the first step is executed, then re-optimized next cycle.

MOMENT Anomaly Detection

385M-parameter pre-trained time-series foundation model (ICML 2024). Reconstruction-based anomaly detection with RevIN normalization and adaptive POT (Peaks Over Threshold) thresholding. Validated against two alternatives:

Model Type Params Val Loss Status
MOMENT Foundation (pre-trained) 385M 0.0069 Selected
TransNAS-TSAD NAS + Transformer ~2M 0.0145 Evaluated
VTT Variable Temporal Transformer ~500K 0.0203 Evaluated

These are internal validation figures; the trained checkpoint and raw artifacts are not yet published, so treat them as indicative rather than independently reproducible.

Detection uses 5 layers: range check, z-score, rate-of-change, cross-parameter correlation, and MOMENT reconstruction error.

Chronos-T5 Forecaster

Amazon's zero-shot probabilistic forecasting model. Returns p10/p50/p90 quantiles for a 24-hour horizon. Enables preemptive dosing -- treating problems before they manifest. When Chronos-T5 predicts pH will exceed 8.5 in 6 hours, the MPC begins scale inhibitor dosing immediately at a lower rate, rather than reacting later at a higher rate.

Cascade Detector

Granger-causality state machine detecting failure chains: corrosion → particles → biofilm → scale. Tests causal links between iron→turbidity, turbidity→free chlorine, and free chlorine→hardness. Left-to-right state transitions only (no backtracking).

Physics Engine

Langelier Saturation Index (LSI) and Ryznar Stability Index (RSI) from classical water chemistry equations. Cycles of Concentration (CoC) estimated from conductivity. Virtual sensor provides physics-informed ML hybrid estimates of hardness and alkalinity when lab data is unavailable.

The water-chemistry index math has been extracted into a standalone, dependency-free library — cooling-tower-chem (LSI, RSI, Puckorius PSI, Larson-Skold, cooling-tower water balance) — which TGF uses as its single source of truth for these calculations when it is installed.

This library is an optional enhancement, not a hard requirement: the physics engine vendors a byte-for-byte-equivalent fallback (tgf_dosing/core/physics_engine.py), so a plain pip install . works standalone. It lives in the chem optional-dependencies extra, and now that cooling-tower-chem is published on PyPI, that extra resolves straight from the registry — enable it with:

pip install ".[chem]"

This pulls cooling-tower-chem (>=0.1.0) from PyPI automatically; the earlier git+https source install is no longer needed.

Safety Layer

5-tier defense-in-depth:

  1. Sensor fault detection -- impossible values trigger PID fallback
  2. Hard limits -- absolute max/min for every chemical dose
  3. Rate limiting -- max 20% change per 5-minute cycle
  4. PID backup -- classical controllers with anti-windup saturation
  5. Emergency stop -- halt all dosing on multiple sensor failures

Chemical Tracker

Mass balance for 7 Aquatech chemicals with Arrhenius temperature-dependent decay rates, Bayesian confidence scoring, and calibration from ORP sensor feedback and weekly lab tests.

Why MPC, Not Reinforcement Learning

  1. Works with ~5K samples -- RL needs millions of interactions
  2. Hard safety constraints -- enforced by clamping, not soft penalties
  3. Explainable -- "dosing because LSI forecast at +1.8 in 6 hours"
  4. Faster to a working prototype -- RL needs months of simulation-environment development
  5. No constraint violations in backtest during exploration

With ~5,600 historical water-analysis records and hard safety requirements for eventual industrial deployment, MPC was the principled engineering choice.

Quick Start

# Install dependencies
pip install -r requirements.txt

# Run simulation (headless, 100 cycles)
python -m tgf_dosing.main --data data/Parameters_5K.csv --cycles 100 --no-api --speed 0

# Run with dashboard (open http://localhost:8000)
python -m tgf_dosing.main --data data/Parameters_5K.csv --cycles 500 --speed 0

# Run with MOMENT anomaly detection
python -m tgf_dosing.main --data data/Parameters_5K.csv --moment-checkpoint checkpoints/moment_model.pkl

# Run tests
pytest tests/ -v

Project Structure

tgf_dosing/                      # Production package (~10K LOC)
    config/                      # Tower specs, 7 chemical definitions
    core/                        # Physics engine, MPC, safety layer, cascade detection
    infrastructure/              # Data pipeline, anomaly detection, API, persistence
    models/                      # MOMENT wrapper, online detection
    validation/                  # Walk-forward backtester
tests/                           # 10 test files (pytest)
data/                            # Curated datasets from real Indian cooling towers
research/                        # Model experiments (MOMENT, TransNAS, VTT, Tempura)
docs/                            # Architecture, API reference, hardware guide
scripts/                         # Model download utility

Roadmap

  • Edge deployment on Raspberry Pi 4 ($12K hardware per tower)
  • ONNX export for MOMENT inference at the edge
  • Multi-tower fleet management

Citations

  • MOMENT: Goswami et al., "MOMENT: A Family of Open Time-series Foundation Models", ICML 2024
  • Chronos: Ansari et al., "Chronos: Learning the Language of Time Series", Amazon, 2024
  • LSI: Langelier, W.F., "The Analytical Control of Anti-Corrosion Water Treatment", 1936
  • RSI: Ryznar, J.W., "A New Index for Determining Amount of Calcium Carbonate Scale Formed by a Water", 1944

License

Apache 2.0 -- see LICENSE.

About

Advisory water treatment for industrial cooling towers: risk indices, anomaly detection, forecasting and dose recommendations. A human authorizes every dose.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

10 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages