Skip to main content

fitting hydrological stage discharge rating curves

Project description

hydrating

pypi_shield pypi_license tests_workflow

Overview

hydrating is a python package for fitting hydrological rating curves.

This initial preview only provides basic powerlaw fitting.

Development Status: Pre-Alpha. Due to personal obligations, development is mostly on pause until second half of 2023. Consider the API unstable, it may change at short/no notice.

Requirements and installation

Requirements:

numpy
pandas
lmfit

Install from pypi using pip

pip install hydrating

General description and example usage

Functionality is currently limited to fitting basic powerlaw rating curve

# imports for creating demo data
from numpy.random import SeedSequence, default_rng
import pandas as pd
from lmfit import Parameters

# imports for hydrating
from hydrating import RatingCurve
from hydrating.models import PowerLaw 

# Test data for power law rating
a = 0.1
b = 2.5
h0 = 0.65

rng = default_rng(SeedSequence(123))

stage = rng.uniform(1, 10, size=20) #+ rng.normal(0, 0.01, size=20) # uncomment for stage with some noise
discharge_c = PowerLaw().func(stage, a, h0, b)
discharge = discharge_c #+  discharge_c * rng.normal(0, 0.1, size=20) # uncomment for discharge with some noise

data_df = pd.DataFrame({'stage_key': stage,
                        'discharge_key': discharge})

# fit by passing numpy arrays of the data
rc_c = RatingCurve(PowerLaw)
rc_c.fit(x=stage, y=discharge)
rc_c.fit_summary() # for a fit summary
rc_c.fit_best_parameters
Out: {'a': 0.09999999999999991, 'h0': 0.6499999999999992, 'b': 2.5000000000000004}

# fit by adding a dataframe. In future versions this will allow for more options adding 
# other metadata to the rating curve
rc_c = RatingCurve(PowerLaw)
rc_c.add_data(data_df, stage='stage_key', discharge='discharge_key')
rc_c.fit() # will automatically use keys provided in add_data, but can also pass other keys here

# specify parameter bounds and fixed values, using lmfit.Parameters objects
input_parameters = Parameters()
input_parameters.add('a', value=1)
input_parameters.add('b', value=2.6, vary=False)
input_parameters.add('h0', value=0, max=0.4)
rc_c = RatingCurve(PowerLaw, initial_parameters=input_parameters)
rc_c.fit(x=stage, y=discharge)
Out: {'a': 0.07495641841621854, 'b': 2.6, 'h0': 0.3999999978452029}

# one can also let hydrating create the parameters simpy by ommiting
# initial_parameters keyword, and then modify them
# refer to lmfit documentation
rc_c = RatingCurve(PowerLaw)
rc_c.initial_parameters['b'].value = 2.55
rc_c.initial_parameters['b'].vary = False
rc_c.fit(x=stage, y=discharge)
rc_c.fit_best_parameters
Out: {'a': 0.08681743671415193, 'h0': 0.5320384707736181, 'b': 2.55}

Feedback and issues

Please report issues here: https://github.com/rhkarls/hydrating/issues

General feedback is most welcome, please post that as well under issues.

MIT License

Copyright (c) 2022, Reinert Huseby Karlsen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

hydrating-0.0.2.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

hydrating-0.0.2-py2.py3-none-any.whl (11.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file hydrating-0.0.2.tar.gz.

File metadata

  • Download URL: hydrating-0.0.2.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.4

File hashes

Hashes for hydrating-0.0.2.tar.gz
Algorithm Hash digest
SHA256 545abef4f6771971b8ac0c2ece796ee5d39ac8fc9de57a3e671899e1f681ee75
MD5 652b6bdae2d0d6c1bc4318820d3e40f8
BLAKE2b-256 090149bcb71970e751ca084ba73beaa7dac5495aff56bca5b9a8beedf041ed02

See more details on using hashes here.

File details

Details for the file hydrating-0.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: hydrating-0.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.4

File hashes

Hashes for hydrating-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ab7c8c0f61561e6cd9190ae7b861d890dd963a31bc5c856154b01903b5c7fd6d
MD5 64eb6e0d5e6da975dc176ddf1a6be12f
BLAKE2b-256 cde82dbd53a2c4c74fe2c4375ed678c84e75357a866ad081f9c6d378b845a660

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