A python library for fitting stage-discharge rating curves.
Project description
ratingcurve
A Python library for fitting stage-discharge rating curves.
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
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)
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.”
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ratingcurve-0.2.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de84a86e330a5902c13485cc12bf2428756d5fdbbd248221575bde8bfa30d1f5 |
|
MD5 | 8a7afe72b7bd594142aae34ea7749612 |
|
BLAKE2b-256 | 9ba382c7c75c99b0c89fb420a4b3accaf57a8f6e9d871c4c8e74cf27c4a21355 |