Skip to main content

A python library for fitting stage-discharge rating curves.

Project description

ratingcurve

A Python library for fitting stage-discharge rating curves.

DOI

Use ratingcurve to fit streamflow ratings with a segmented power law, which is the the most common type rating model used by USGS.

The segmented power law is parameterized as:

$$ \log(Q) = a + \sum_{i=1}^{n} b_i \log(x - x_{o,i}) H_i(x - x_{o,i}) $$

where $Q$ is a vector discharge,
$n$ is the number of breakpoints in the rating,
$a$ and $b$ are model parameters,
$x$ is a vector of stage observations,
$x_o$ is a vector of breakpoints, and
$H$ is the Heaviside function.

In a standard linear model $b$ represents the slope of the function with respect the input. In the segmented power law $b_o$ is the slope and each subsequent $b_i$ are adjustment to the base slope for each segment.

This library is for experimental purposes only.

Installation

conda env create -f environment.yaml # use mamba if possible

# add environment to jupyter
conda activate ratingcurve
python -m ipykernel install --user --name=ratingcurve

Getting Started

The segmented-power-law-demo.ipynb notebook demonstrates basic use of the package. To run the notebook click the Google Colab badge
Open In Colab

or to run the notebook locally

conda activate base # or your jupyter lab environment
jupyter lab

then open the notebook and select the ratingcurve kernel that was installed earlier.

A simple example is given below.

from ratingcurve.ratingmodel import SegmentedRatingModel

# load tutorial data
df = tutorial.open_dataset('green_channel')


# setup model
segments = 2

powerrating = SegmentedRatingModel(q=df['q'],
                                   h=df['stage'], 
                                   q_sigma=df['q_sigma'],
                                   segments=segments)
                                   
# fit model, then simulate the rating
with powerrating:
    mean_field = pm.fit(n=150_000)
    trace = mean_field.sample(5000)
    
powerrating.plot(trace)

example plot

Disclaimer

This software is in the public domain because it contains materials that originally came from the U.S. Geological Survey, an agency of the United States Department of Interior. For more information, see the official USGS copyright policy.

Although this software program has been used by the U.S. Geological Survey (USGS), no warranty, expressed or implied, is made by the USGS or the U.S. Government as to the accuracy and functioning of the program and related program material nor shall the fact of distribution constitute any such warranty, and no responsibility is assumed by the USGS in connection therewith.

This software is provided “AS IS.”

CC0

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

ratingcurve-0.2.5.tar.gz (192.1 kB view details)

Uploaded Source

Built Distribution

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

ratingcurve-0.2.5-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file ratingcurve-0.2.5.tar.gz.

File metadata

  • Download URL: ratingcurve-0.2.5.tar.gz
  • Upload date:
  • Size: 192.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for ratingcurve-0.2.5.tar.gz
Algorithm Hash digest
SHA256 55fdbf569c52b1824c053487033e0c56fba7ec24fc938356a1f0a464b4165b02
MD5 3fd9536b20a020cc196aaf1e5ceab4fe
BLAKE2b-256 7bf5e8222f6bd71ef406af7a6915543973141b48f80c2ef33f096d85372781c5

See more details on using hashes here.

File details

Details for the file ratingcurve-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: ratingcurve-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for ratingcurve-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 859174443ba212f31b530fe3c1e546eaa47a4065e69e0b47c9b063202ab70317
MD5 0adb223b2d5a2e94d5a47b17efffce95
BLAKE2b-256 573834b824591b016782da8eec7f3b800cd8fa8ea06f09bbfca93d29a410c963

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