Skip to main content

hydrostab

CI Release PyPI version

A Python package for analyzing the numerical stability of hydrograph time series data. Intended to be used with hydrographs from hydrodynamic models, such as HEC-RAS.

Installation

To install from PyPI:

pip install hydrostab

To install with dependencies for analyzing HEC-RAS model data (rashdf):

pip install "hydrostab[ras]"

To install with dependencies for experimental methods:

pip install "hydrostab[exp]"

Methods

Slope Change

The default and recommended method for stability analysis. This method can be used with flow, depth, or water surface elevation. It is also indifferent to time, though it assumes that the hydrograph has a constant timestep. This methods works by measuring the magitude of slope reversals (+/-) in the hydrograph shape.

Steps:

  1. Normalizes hydrograph values to a 0-1 range
  2. Computes differences between consecutive values (assuming a constant timestep)
  3. Detects sign changes in the differences (i.e., slope reversals)
  4. Sums the magnitude of these sign changes
  5. Normalizes by the length of the hydrograph (i.e., the number of values)

This produces a score between 0 and 1, where:

  • 0.0 indicates perfect stability (no oscillations)
  • Higher values indicate more instability
  • Default threshold of 0.002 classifies hydrographs as stable/unstable

stable unstable

More examples: notebooks/stability-examples.ipynb

Experimental Methods

The following methods are experimental and not recommended for typical production use:

  • Abrupt Change Detection: Identifies sudden changes in flow values
  • Normalized First Derivative: Analyzes rate of change patterns
  • FFT Analysis: Uses Fast Fourier Transforms to identify high-frequency oscillations

Developer Setup

Create a virtual environment in the project directory:

$ python -m venv venv-hydrostab

Activate the virtual environment:

$ source ./venv-hydrostab/bin/activate
(venv-hydrostab) $

Install the package in editable mode:

(venv-hydrostab) $ pip install -e .

Install dev dependencies:

(venv-hydrostab) $ pip install ".[dev]"

Install dependencies for notebooks:

(venv-hydrostab) $ pip install ".[nb]"

Install git hook scripts (used for automatic liniting/formatting)

(venv-hydrostab) $ pre-commit install

With the virtual environment activated, run the tests:

(venv-hydrostab) $ pytest

Usage

Single Hydrograph

import hydrostab
import pandas as pd

# Load your hydrograph data
df = pd.read_csv("hydrograph.csv")
flow = df["flow"]

# Basic stability check
is_stable = hydrostab.is_stable(flow)

# Get both stability classification and score
is_stable, score = hydrostab.stability(flow)

# Adjust thresholds if needed
is_stable = hydrostab.is_stable(flow, unstable_threshold=0.003, range_threshold=0.2)

HEC-RAS Model Analysis

A couple methods leveraging rashdf are included to assist with analyzing stability of HEC-RAS model outputs. This requires installation of the rashdf library -- either run pip install rashdf after installing hydrostab, or:

pip install hydrostab[ras]

Reference Lines Hydrograph Stability

>>> from hydrostab.ras import reflines_stability, mesh_cells_stability
>>> from rashdf import RasPlanHdf
>>> plan = RasPlanHdf("ElkMiddle.p04.hdf")
>>> print(plan)
<HDF5 file "ElkMiddle.p04.hdf" (mode r)>
>>> plan.reference_lines_timeseries_output()
<xarray.Dataset> Size: 28kB
Dimensions:        (time: 577, refln_id: 5)
Coordinates:
  * time           (time) datetime64[ns] 5kB 1996-01-14T12:00:00 ... 1996-02-...
  * refln_id       (refln_id) int64 40B 0 1 2 3 4
    refln_name     (refln_id) <U17 340B 'Herold Gage' ... 'DS Sutton Gage'
    mesh_name      (refln_id) <U9 180B 'ElkMiddle' 'ElkMiddle' ... 'ElkMiddle'
Data variables:
    Flow           (time, refln_id) float32 12kB 3.314 758.6 ... 148.9 137.2
    Water Surface  (time, refln_id) float32 12kB 931.0 608.5 ... 776.2 812.0
>>> reflines_stability(plan) # reflines stability as xarray Dataset
<xarray.Dataset> Size: 28kB
Dimensions:                        (time: 577, refln_id: 5)
Coordinates:
  * time                           (time) datetime64[ns] 5kB 1996-01-14T12:00...
  * refln_id                       (refln_id) int64 40B 0 1 2 3 4
    refln_name                     (refln_id) <U17 340B 'Herold Gage' ... 'DS...
    mesh_name                      (refln_id) <U9 180B 'ElkMiddle' ... 'ElkMi...
Data variables:
    Flow                           (time, refln_id) float32 12kB 3.314 ... 137.2
    Water Surface                  (time, refln_id) float32 12kB 931.0 ... 812.0
    Flow Stability Score           (refln_id) float64 40B 0.0007717 ... 0.0104
    Flow is Stable                 (refln_id) bool 5B True True True True False
    Water Surface Stability Score  (refln_id) float64 40B 0.0003811 ... 0.007469
    Water Surface is Stable        (refln_id) bool 5B True True True True False
>>> reflines_stability(plan, gdf=True) # reflines stability as GeoDataFrame
   refln_id         refln_name  mesh_name      type                                           geometry  ... water_surface_stability_score  water_surface_is_stable
0         0        Herold Gage  ElkMiddle  Internal  LINESTRING (4284949.51 6009708.559, 4284382.80...  ...                      0.000381                     True
1         1  Queen Shoals Gage  ElkMiddle  Internal  LINESTRING (4156474.299 5951074.402, 4155756.7...  ...                      0.000124                     True
2         2          Clay Gage  ElkMiddle  Internal  LINESTRING (4211649.866 5955409.88, 4211315.60...  ...                      0.000146                     True
3         3     Frametown Gage  ElkMiddle  Internal  LINESTRING (4261185.452 6013057.623, 4260451.4...  ...                      0.000064                     True
4         4     DS Sutton Gage  ElkMiddle  Internal  LINESTRING (4305558.092 6045936.846, 4305629.2...  ...                      0.007469                    False

[5 rows x 17 columns]

2D Mesh Cells Hydrograph Stability

>>> plan.mesh_cells_timeseries_output("ElkMiddle")
<xarray.Dataset> Size: 66MB
Dimensions:                              (time: 577, cell_id: 14188)
Coordinates:
  * time                                 (time) datetime64[ns] 5kB 1996-01-14...
  * cell_id                              (cell_id) int64 114kB 0 1 ... 14187
Data variables:
    Water Surface                        (time, cell_id) float32 33MB 1.092e+...
    Cell Cumulative Precipitation Depth  (time, cell_id) float32 33MB 0.0 ......
Attributes:
    mesh_name:  ElkMiddle
>>> mesh_cells_stability(plan, "ElkMiddle")  # mesh cells stability as xarray Dataset
<xarray.Dataset> Size: 66MB
Dimensions:                              (time: 577, cell_id: 14188)
Coordinates:
  * time                                 (time) datetime64[ns] 5kB 1996-01-14...
  * cell_id                              (cell_id) int64 114kB 0 1 ... 14187
Data variables:
    Water Surface                        (time, cell_id) float32 33MB 1.092e+...
    Cell Cumulative Precipitation Depth  (time, cell_id) float32 33MB 0.0 ......
    Water Surface Stability Score        (cell_id) float64 114kB 0.0 ... 5.65...
    Water Surface is Stable              (cell_id) bool 14kB True True ... True
Attributes:
    mesh_name:  ElkMiddle
>>> mesh_cells_stability(plan, "ElkMiddle", gdf=True) # mesh cells stability as GeoDataFrame
       mesh_name  cell_id                                           geometry  ... water_surface_stability_score  water_surface_is_stable
0      ElkMiddle        0  POLYGON ((4313815.212 6066402.721, 4313815.212...  ...                      0.000000                     True
1      ElkMiddle        1  POLYGON ((4313815.212 6064483.392, 4313815.212...  ...                      0.000000                     True
2      ElkMiddle        2  POLYGON ((4286315.212 6061983.392, 4286149.808...  ...                      0.000000                     True
3      ElkMiddle        3  POLYGON ((4288815.212 6061983.392, 4288815.212...  ...                      0.000000                     True
4      ElkMiddle        4  POLYGON ((4291315.212 6061983.392, 4291315.212...  ...                      0.000175                     True
...          ...      ...                                                ...  ...                           ...                      ...
14183  ElkMiddle    14183  POLYGON ((4154877.704 5951410.744, 4154809.092...  ...                      0.000106                     True
14184  ElkMiddle    14184  POLYGON ((4154877.704 5951410.744, 4154735.661...  ...                      0.000219                     True
14185  ElkMiddle    14185  POLYGON ((4153903.574 5951208.58, 4153939.554 ...  ...                      0.000133                     True
14186  ElkMiddle    14186  POLYGON ((4153903.574 5951208.58, 4153511.347 ...  ...                      0.000074                     True
14187  ElkMiddle    14187  POLYGON ((4153847.847 5950208.646, 4154061.979...  ...                      0.000057                     True

[14188 rows x 13 columns]

Metadata

Release files for hydrostab 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hydrostab 0.2.0
File Size Uploaded Provenance
hydrostab-0.2.0.tar.gz 13.9 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for hydrostab 0.2.0
File Interpreter ABI Platform
hydrostab-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.8 kB

Release files / hydrostab-0.2.0.tar.gz

Download URL hydrostab-0.2.0.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9285e12f431068c7c4e8d4c8df75e9d916e3e83e17b9707998195494ea95824a
BLAKE2b-256 checksum
How to use checksums
47baf675b2a7c6c98d1c3bb3cb3a6e30972a64b4459ab06c7dcd13a4c4e2b6dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 17, 2025.

Transparency log

Release files / hydrostab-0.2.0-py3-none-any.whl

Download URL hydrostab-0.2.0-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e139159d7e0e4b4ead70879c4e79cf48f39dbe0a22a26cf26f3d37f04a32eeba
BLAKE2b-256 checksum
How to use checksums
4154de7d2d78b6fbb66020042f762570688f1ca0f078d76c7ca0097638a74137
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 17, 2025.

Transparency log

Security for hydrostab 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hydrostab-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 17, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page