Skip to main content

Library and command to calculate detention times, disinfectant residuals, and CT ratios for drinking water systems

Project description

py_disinfection: Drinking Water Disinfection Parameter Calculations

Overview

This library and CLI tool provide calculations for disinfection values, including contact time, CT, log inactivation, and log inactivation ratios. These values are used in drinking water treatment to assess the effectiveness of various disinfectants (e.g., free chlorine, chlorine dioxide, chloramines) against microbial targets like Giardia, as well as viruses.

This library implements most of the methods described in the US EPA Disinfection Profiling and Benchmarking Technical Guidance Manual. Its internal tables for CT values are also taken from this document. A PDF copy is included in this repository to guard against removal of the EPA link, or dissolution of the EPA.

Features

  • Python Library for programmatic access to CT calculations.
  • Command-Line Interface (CLI) for quick calculations from the terminal.
  • Supports Multiple Estimation Methods: for free chlorine disinfection:
    • Conservative: Uses worst-case values.
    • Interpolation: Performs multi-step interpolation.
    • Regression: Uses EPA regression equations.
  • Temperature Handling in Celsius or Fahrenheit.
  • Multiple Disinfectant Agents supported, including free chlorine, chloramines, and chlorine dioxide.
  • Giardia and Virus Targets for CT calculations.
  • JSON Output Support for easy integration with other systems.
  • Tested on Python 3.6 - 3.13-0a2, may work on other versions.

Installation

To install the package, run:

pip install py-disinfection

To install from source:

git clone git@github.com:SylvieWaterServices/py_disinfection.git
cd py-disinfection
make

Usage

🔹 Library Usage (Python API)

You can use the library to calculate required CT values programmatically:

from py_disinfection.core import DisinfectionSegment, DisinfectionSegmentOptions, DisinfectionTarget, DisinfectantAgent, CTReqEstimator

options = DisinfectionSegmentOptions(
    volume_gallons=1000,
    temperature_celsius=10,
    ph=7.0,
    concentration_mg_per_liter=0.5,
    baffling_factor=0.3,
    peak_hourly_flow_gallons_per_minute=20,
    agent=DisinfectantAgent.FREE_CHLORINE,
    ctreq_estimator=CTReqEstimator.INTERPOLATION
)

segment = DisinfectionSegment(options)
results = segment.analyze(DisinfectionTarget.GIARDIA)

print(results)  

🔹 CLI Usage

You can also run calculations using the command-line tool Run disinfect --help to see all options:

Basic Usage

disinfect -v 1000 -t 10 -u C -p 7.0 -c 0.5 -m interpolation -a free_chlorine -b 0.3 -f 20

Output:

Segment Parameters:
volume_gallons: 1000.0
temperature_celsius: 10.0
ph: 7.0
concentration_mg_per_liter: 0.5
baffling_factor: 0.3
peak_hourly_flow_gallons_per_minute: 20.0
agent: DisinfectantAgent.FREE_CHLORINE
ctreq_estimator: CTReqEstimator.INTERPOLATION

Disinfection Analysis Results:
tdt: 50.0
contact_time: 15.0
viruses_required_ct: 6
viruses_calculated_ct: 7.5
viruses_ct_ratio: 1.25
viruses_log_inactivation: 5.0
giardia_required_ct: 105.5
giardia_calculated_ct: 7.5
giardia_ct_ratio: 0.07109004739336493
giardia_log_inactivation: 0.21327014218009477

Output in JSON Format

disinfect -v 1000 -t 10 -u C -p 7.0 -c 0.5 -m interpolation -a free_chlorine -b 0.3 -f 20 --json

Output:

{
    "parameters": {
        "agent": "FREE_CHLORINE",
        "volume_gallons": 1000.0,
        "temperature_celsius": 10.0,
        "ph": 7.0,
        "concentration_mg_per_liter": 0.5,
        "peak_hourly_flow_gallons_per_minute": 20.0,
        "ctreq_estimator": "INTERPOLATION",
        "baffling_factor": 0.3,
        "temp_fahrenheit": 50.0
    },
    "results": {
        "tdt": 50.0,
        "contact_time": 15.0,
        "viruses_required_ct": 6,
        "viruses_calculated_ct": 7.5,
        "viruses_ct_ratio": 1.25,
        "viruses_log_inactivation": 5.0,
        "giardia_required_ct": 105.5,
        "giardia_calculated_ct": 7.5,
        "giardia_ct_ratio": 0.07109004739336493,
        "giardia_log_inactivation": 0.21327014218009477
    }
}

Features Coming Soon

  • Support for inactivation credits from filtration and other treatment steps
  • Ozone disinfection support
  • Ability to create multiple treatment segments, and calculate the sum parameters of all segments in a treatment chain
  • Expanded test suite

Development & Contribution

To contribute:

  1. Fork the repository.
  2. Clone your fork.
  3. Install dependencies: pip install .
  4. Run tests: make test

License

This project is licensed under the BSD License. See LICENSE for details.


Author

Developed by Sylvie Water Services. Contributions and suggestions welcome! Reach us at hello@sylviewater.com.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_disinfection-0.1.11.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_disinfection-0.1.11-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file py_disinfection-0.1.11.tar.gz.

File metadata

  • Download URL: py_disinfection-0.1.11.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for py_disinfection-0.1.11.tar.gz
Algorithm Hash digest
SHA256 82ebf2efec115ecb9b14050444ea3bd2295ce9e11d47dde82bc98197581d82ea
MD5 b790f20a8295bb6eba38c586cace1ae4
BLAKE2b-256 f8cac8273b2c48e54a8d2816ed2e77f53f637341762357e6f8a4e7041f4e4394

See more details on using hashes here.

File details

Details for the file py_disinfection-0.1.11-py3-none-any.whl.

File metadata

File hashes

Hashes for py_disinfection-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 653e296df6459b4de37eaa67eecade0ae459d4463fb6b7d3fd6acf6c22b6e5d0
MD5 04293c60669ed91fdd2571482f81356d
BLAKE2b-256 f3beb9eb808cc921cae66550af307d0a68f86e8b632913659780dbaad1f98437

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page