Skip to main content

Python 3 implementation of HEC Java/Jython utility classes

Project description

hec-python-library

This package provides many of the capabilities of using Jython to access HEC's Java class libraries. The library is focused on working with time series objects and associated infrasturcture:

  • locations
  • parameters
  • parameter types
  • times
  • intervals
  • durations
  • ratings

The package interoperates with the following packages for storing and retrieving data:

Requirements.

Python 3.9+

Installation & Usage

pip install

pip install hec-python-library

The top-level package is hec

Getting Started

import os
from hec import CwmsDataStore, DssDataStore

with CwmsDataStore.open("https://cwms-data-test.cwbi.us/cwms-data", office="SWT") as db:
    db.time_window = "t-30h, t"
    # --------------------------------- #
    # retrieve an elevation time series #
    # --------------------------------- #
    raw_elev_ts = db.retrieve("Bluestem.Elev.Inst.1Hour.0.Raw")
    print(raw_elev_ts)
    # ----------------------- #
    # do some quality control #
    # ----------------------- #
    rev_elev_ts = raw_elev_ts\
        .estimate_missing_values(max_missing_count=4)\
        .iolympic_moving_average(window=7, only_valid=True, use_reduced=True)
    rev_elev_ts.version = "Rev"
    rev_elev_ts = rev_elev_ts[6:] # don't keep the start of smoothing
    print(rev_elev_ts)
    # ------------------------------------ #
    # transform the elevations to storages #
    # ------------------------------------ #
    rating = db.retrieve("Bluestem.Elev;Stor.Linear.Production")
    stor_ts = rating.rate(rev_elev_ts)
    print(stor_ts)
    # ---------------------------- #
    # print the time series values #
    # ---------------------------- #
    print("")
    for i in range(len(rev_elev_ts)):
        print(
            f"{rev_elev_ts.times[i]}"
            f"\t{round(rev_elev_ts.values[i], 2):.2f}"
            f"\t{round(stor_ts.values[i], -1)}"
        )
    # ----------------------------------- #
    # store the time series to a DSS file #
    # ----------------------------------- #
    print("")
    with DssDataStore.open("demo.dss", read_only=False) as dss:
        dss.store(raw_elev_ts)
        dss.store(rev_elev_ts)
        dss.store(stor_ts)
        print("")
        for pathname in dss.catalog():
            print(pathname)
        print("")
Bluestem.Elev.Inst.1Hour.0.Raw 30 values in ft
Bluestem.Elev.Inst.1Hour.0.Rev 24 values in ft
Bluestem.Stor.Inst.1Hour.0.Rev 24 values in ac-ft

2025-10-21 10:00:00-05:00       725.08  436090.0
2025-10-21 11:00:00-05:00       725.09  436170.0
2025-10-21 12:00:00-05:00       725.09  436170.0
2025-10-21 13:00:00-05:00       725.08  436060.0
2025-10-21 14:00:00-05:00       725.07  435760.0
2025-10-21 15:00:00-05:00       725.04  435250.0
2025-10-21 16:00:00-05:00       725.01  434700.0
2025-10-21 17:00:00-05:00       724.97  434040.0
2025-10-21 18:00:00-05:00       724.93  433390.0
2025-10-21 19:00:00-05:00       724.90  432910.0
2025-10-21 20:00:00-05:00       724.89  432600.0
2025-10-21 21:00:00-05:00       724.88  432470.0
2025-10-21 22:00:00-05:00       724.88  432470.0
2025-10-21 23:00:00-05:00       724.88  432500.0
2025-10-22 00:00:00-05:00       724.89  432710.0
2025-10-22 01:00:00-05:00       724.90  432880.0
2025-10-22 02:00:00-05:00       724.92  433120.0
2025-10-22 03:00:00-05:00       724.93  433290.0
2025-10-22 04:00:00-05:00       724.94  433490.0
2025-10-22 05:00:00-05:00       724.95  433670.0
2025-10-22 06:00:00-05:00       724.96  433910.0
2025-10-22 07:00:00-05:00       724.97  434000.0
2025-10-22 08:00:00-05:00       724.97  434100.0
2025-10-22 09:00:00-05:00       724.98  434220.0

09:35:42.041      -----DSS---zopen   New file opened,  File: U:\Devl\git\hec-python-library\demo.dss
09:35:42.042                         Handle 3;  Process: 23056;  DSS Version:  7-IW
09:35:42.042                         Single-user advisory access mode
09:35:49.240 -----DSS--- zwrite  Handle 3;  Version 1:  //Bluestem/Elev/01Oct2025/1Hour/Raw/
09:35:49.329 -----DSS--- zwrite  Handle 3;  Version 1:  //Bluestem/Elev/01Oct2025/1Hour/Rev/
09:35:49.427 -----DSS--- zwrite  Handle 3;  Version 1:  //Bluestem/Stor/01Oct2025/1Hour/Rev/

//Bluestem/Elev/01Oct2025/1Hour/Raw/
//Bluestem/Elev/01Oct2025/1Hour/Rev/
//Bluestem/Stor/01Oct2025/1Hour/Rev/

09:35:49.428      -----DSS---zclose  Handle 3;  Process: 23056;  File: U:\Devl\git\hec-python-library\demo.dss
09:35:49.428                         Number records:         3
09:35:49.428                         File size:              15990  64-bit words
09:35:49.428                         File size:              124 Kb;  0 Mb
09:35:49.428                         Dead space:             0
09:35:49.428                         Hash range:             8192
09:35:49.429                         Number hash used:       3
09:35:49.429                         Max paths for hash:     1
09:35:49.429                         Corresponding hash:     759
09:35:49.429                         Number non unique hash: 0
09:35:49.429                         Number bins used:       3
09:35:49.429                         Number overflow bins:   0
09:35:49.429                         Number physical reads:  25
09:35:49.429                         Number physical writes: 37
09:35:49.429                         Number denied locks:    0

Documentation

Scripting Guide at: https://hec-python-library.readthedocs.io/en/latest/

Examples at: https://github.com/HydrologicEngineeringCenter/hec-python-library/tree/main/examples

API Documentation at https://hydrologicengineeringcenter.github.io/hec-python-library/index.html

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

hec_python_library-1.0.tar.gz (278.5 kB view details)

Uploaded Source

Built Distribution

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

hec_python_library-1.0-py3-none-any.whl (235.6 kB view details)

Uploaded Python 3

File details

Details for the file hec_python_library-1.0.tar.gz.

File metadata

  • Download URL: hec_python_library-1.0.tar.gz
  • Upload date:
  • Size: 278.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.19

File hashes

Hashes for hec_python_library-1.0.tar.gz
Algorithm Hash digest
SHA256 607ea409e4fa528a8d0ef916e9fdaa886d1d9e9875b8906885c3f1cfc60f75c1
MD5 c9f573b20a55eb9010bed154a3c6f233
BLAKE2b-256 c42464bec91ca4a594323199d2b3eb2e816b75d20a3eb0f0da7a4399ec4fa08c

See more details on using hashes here.

File details

Details for the file hec_python_library-1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hec_python_library-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9bce7b1841670195bfe876b06731fb496b3e6dea8d0d597ee498f3884830de57
MD5 e3cdf7a31e8d2088302a7f25cade8682
BLAKE2b-256 1884368e101c4c9de36f84f4e3b90d5d4566940b7e6d2293f8ab97e3616a470b

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