Skip to main content

HydNAM

PyPI - Version

HydNAM is a Python implementation of the NedborAfstromnings Model (NAM), a lumped rainfall–runoff model.

This project is based on the NAM_Model created by hckaraman.

Installation

pip install hydnam

Getting Started

1. Prepare the Dataset

The dataset must contain the following properties: Date, Temperature, Precipitation, Evapotranspiration, and Discharge.

Date Temperature Discharge Precipitation Evapotranspiration
10/9/2016 15.4 0.25694 0 2.79
10/10/2016 14.4 0.25812 0 3.46
10/11/2016 14.9 0.30983 0 3.65
10/12/2016 16.1 0.31422 0 3.46
10/13/2016 20.1 0.30866 0 5.64
10/14/2016 13.9 0.30868 0 3.24
10/15/2016 11.1 0.31299 0 3.41
... ... ... ... ...

Ensure that the time intervals between dates are consistent (e.g., 24 hours) for accurate model performance.

2. Initialize the NAM Model

from datetime import datetime

from hydnam.dataset import Dataset
from hydnam.hydnam import HydNAM
from hydnam.parameters import Parameters

dataset = Dataset(
    timestamp=[
        datetime(2016, 10, 9),
        datetime(2016, 10, 10),
        datetime(2016, 10, 11),
    ],
    temperature=[15.4, 14.4, 14.9],
    precipitation=[0.0, 0.0, 0.0],
    evapotranspiration=[2.79, 3.46, 3.65],
    discharge=[0.25694, 0.25812, 0.30983]
)

params = Parameters(
    umax=0.01,
    lmax=0.01,
    cqof=0.01,
    ckif=200.0,
    ck12=10.0,
    tof=0.0,
    tif=0.0,
    tg=0.0,
    ckbf=500.0,
    csnow=0.0,
    snowtemp=0.0,
    qofmin=0.4,
    pmm=10.0,
    carea=0.9
)

nam = HydNAM(
    dataset=dataset,
    parameters=Parameters(),
    area=58.8,
    interval=24.0,
    start=None,
    end=None,
    spin_off=0.0,
    name="NAM"
)

print(f'Parameters: {nam.get_parameters().__dict__}')
print(f'Statistics: {nam.get_statistical_metrics().__dict__}')
print(nam.model_is_broken())

nam.plot_q(only_obs_and_sim=False).show()
nam.get_model_output().to_dataframe().to_csv("result.csv")

3. Optimize the Model

for m in ['SLSQP', 'L-BFGS-B']:
    nam.optimize(method=m)
    print(nam.get_parameters().__dict__)
    print(nam.get_statistical_metrics().__dict__)
    nam.plot_q(only_obs_and_sim=True).show()

The model will calculate and check which Parameters are optimal for the model and use it as the main Parameters for the model.

4. Customize Properties

nam.update_dataset(dataset, interval=24.0)
nam.update_parameters(Parameters())
nam.update_area(59.0)
nam.update_name("New NAM")
nam.update_spin_off(0.0)
nam.update_time_range(datetime(2016, 10, 9), datetime(2016, 10, 10))

5. Show Discharge

nam.plot_q(only_obs_and_sim=True).show()

6. Reload Model

When the model performs calculations incorrectly and throws an error, you should reset the properties to more reasonable ones and recalculate.

nam.reload()

License

This library is released under the MIT License.

Contact

If you have any questions or issues, please open an issue on GitHub or email us at duynguyen02.dev@gmail.com.

Metadata

Release files for hydnam 2.0.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 hydnam 2.0.0
File Size Uploaded Provenance Actions
hydnam-2.0.0.tar.gz 8.4 kB Without provenance Details for hydnam-2.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 17.0 kB

Release files / hydnam-2.0.0.tar.gz

Download URL hydnam-2.0.0.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e1be16e1546e08b880d30019212a9875a6d92b15833307af0e9817d930faf0d5
BLAKE2b-256 checksum
How to use checksums
47da408ec1fec14c51a32a022ec33286e4c8fbc9760590815259bf050380fd81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.12.3 Linux/6.8.0-51-generic

Release files / hydnam-2.0.0-py3-none-any.whl

Download URL hydnam-2.0.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e87366a8a2857bcb6917a87453b70bab339117dd805f84d179a3f4719a486664
BLAKE2b-256 checksum
How to use checksums
b98872f66336c1ab6de1c102708cf9ab597e907d036ebd62ca3b6987b3b18eb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.12.3 Linux/6.8.0-51-generic

Security for hydnam 2.0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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