Skip to main content

Python library used to calculate reservoir water balance.

Project description

tjwb

tjwb is a Python library designed for water balance management in reservoirs. The library provides methods to calculate inflow and outflow speeds of various components, such as pumps, box culverts, and valve overflows, based on water level and configuration.

Installation

To install the library, use pip:

pip install tjwb

Usage

Basic Example

import pandas as pd
from tjwb import (calculate, RequiredColumnsName, WaterLevelCapacityMappingColumnsName, PumpConfig, ValveOverflowConfig,
                  BoxCulvertConfig)

# Prepare your data
df = pd.DataFrame({
    'Datetime': ['2024-08-28 10:00:00', '2024-08-28 10:05:00'],
    'Water Level': [5.0, 5.5],
    'Pump.Pump-1': [1.0, 1.5],
    'BoxCulvert.BoxCulvert-1': [0.5, 0.7],
    'ValveOverflow.ValveOverflow-1': [0.3, 0.4],
    'ValveOverflow.ValveOverflow-2': [0.3, 0.4],
    'ValveOverflow.ValveOverflow-3': [0.3, 0.4],
})

water_level_capacity_mapping_df = pd.DataFrame({
    'Water Level': [5.0, 5.5],
    'Capacity': [1000, 1500]
})

# Define component configurations
pump_configs = [PumpConfig(column_name_prefix='Pump')]
box_culvert_configs = [BoxCulvertConfig(column_name_prefix='BoxCulvert', elevation=2.0, height=1.0)]
valve_overflow_configs = [ValveOverflowConfig(column_name_prefix='ValveOverflow', elevation=1.5, height=0.5)]

# Calculate results
result = calculate(
    _df=df,
    _water_level_capacity_mapping_df=water_level_capacity_mapping_df,
    water_level_capacity_mapping_columns_name=WaterLevelCapacityMappingColumnsName(),
    required_columns_name=RequiredColumnsName(),
    pump_configs=pump_configs,
    box_culvert_configs=box_culvert_configs,
    valve_overflow_configs=valve_overflow_configs
)

# Convert results to DataFrame
result_df = result.to_dataframe()
print(result_df)

Main Classes and Functions

  • calculate: The main function for calculating the inflow and outflow speeds based on the given configurations.
  • TJWBResult: Holds the calculated results, including inflow speed, outflow speed, and outflow speeds for each component.
  • RequiredColumnsName: Configuration for the required column names in the input DataFrame.
  • WaterLevelCapacityMappingColumnsName: Configuration for the column names in the water level-capacity mapping DataFrame.
  • Component Configurations:
    • PumpConfig
    • BoxCulvertConfig
    • ValveOverflowConfig

Error Handling

The tjwb library includes various validation steps to ensure that the inputs are correct. Below are the common scenarios where errors might be raised:

  • Invalid DataFrame Structure:

    • If the main DataFrame (_df) or the Water Level Capacity Mapping DataFrame (_water_level_capacity_mapping_df) contains missing required columns, a ValueError will be raised.
    • If the Water Level Capacity Mapping DataFrame contains non-numeric data in the water_level or capacity columns, a TypeError will be raised.
    • If any required column in the main DataFrame contains null values, a ValueError will be raised.
    • If the Datetime column cannot be converted to a valid datetime format, a ValueError will be raised.
  • Component Configuration Errors:

    • If the column_name_prefix of any component contains the character '.', a ValueError will be raised, as this character is not allowed in column name prefixes.
    • If there are duplicate column_name_prefix values among the configured components, a ValueError will be raised.
    • If a column referenced in the component configuration does not exist or is not of numeric type, a TypeError will be raised.
  • Invalid Water Level to Capacity Mapping:

    • If there is a mismatch between the water levels in the main DataFrame and the Water Level Capacity Mapping DataFrame, such that no valid capacity can be mapped, a ValueError will be raised.
  • Calculation Errors:

    • If the calculated inflow or outflow speeds result in negative or NaN values, the library automatically converts these to zero using internal validation functions.

License

This library is released under the MIT License.

Contact

If you have any questions or issues, please open an issue on GitHub or email us at duynguyen02.dev@gmail.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

tjwb-2.0.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

tjwb-2.0.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file tjwb-2.0.0.tar.gz.

File metadata

  • Download URL: tjwb-2.0.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-41-generic

File hashes

Hashes for tjwb-2.0.0.tar.gz
Algorithm Hash digest
SHA256 8d751ac16bb9589476fa7091fd3cc1e2961f467d755cbba6edbb9460308aa3ea
MD5 c100d4ae675972e0f61c118fde0c233a
BLAKE2b-256 3c04405449b4ffbabfe9903653599c4c0c18459b16dc95f54252447a95bfdc9b

See more details on using hashes here.

File details

Details for the file tjwb-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: tjwb-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-41-generic

File hashes

Hashes for tjwb-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 016e3a291820095f42877c528559526f3b0120da819fe7bd57468d935a3dd8e8
MD5 e3f5f42a073d1893070e99e752d2e50f
BLAKE2b-256 416d5d1df46d0f84c95e4f9acef3fc6c0aaf936e9e5a0a93a328e0f7c33cc52d

See more details on using hashes here.

Supported by

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