
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/hbv.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_hbv.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_hbv.py:


====================
HBV Model Example
====================

.. GENERATED FROM PYTHON SOURCE LINES 6-21

.. code-block:: Python


    import time

    import numpy as np
    import pandas as pd
    from SeqMetrics import RegressionMetrics

    import rain2flow
    from rain2flow import hbv

    print(time.asctime(), "\n")
    print("np: ", np.__version__)
    print("pd: ", pd.__version__)
    print("rain2flow: ", rain2flow.__version__)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Mon Feb 16 12:16:49 2026 

    np:  2.0.1
    pd:  3.0.0
    rain2flow:  0.1.0




.. GENERATED FROM PYTHON SOURCE LINES 22-23

Read the data from disk which contains `pcp`, `temp` and `pet` columns.

.. GENERATED FROM PYTHON SOURCE LINES 23-27

.. code-block:: Python


    data = pd.read_csv('data.csv', 
                       comment='#', parse_dates=['date'], index_col='date')








.. GENERATED FROM PYTHON SOURCE LINES 28-29

specify the model parameters.

.. GENERATED FROM PYTHON SOURCE LINES 29-55

.. code-block:: Python


    parameters = {
        "BETA": 2.254272145204868,
        "CFMAX": 2.634558463081481,
        "CFR": 0.05316989970760903,
        "CWH": 0.06320640559590592,
        "FC": 938.4151865045613,
        "K0": 0.5533421892716448,
        "K1": 0.25566454560982704,
        "K2": 0.18448187501298327,
        "LP": 0.9976204042760504,
        "MAXBAS": 4.399887139522522,
        "PCORR": 1.991169069794055,
        "PERC": 5.256982141549575,
        "SFCF": 1.9656441421578075,
        "TT": 1.0041306252448585,
        "UZL": 36.983252412038695
    }

    # run the model
    sim = hbv(
        data['pcp'].values,
        data['temp'].values,
        data['pet'].values,
        parameters=parameters)








.. GENERATED FROM PYTHON SOURCE LINES 56-57

evaluate the model performance using KGE, NSE and PBIAS metrics.

.. GENERATED FROM PYTHON SOURCE LINES 57-61

.. code-block:: Python


    metrics = RegressionMetrics(data['Qobs'].values, sim.flatten())

    for metric in ['kge', 'nse', 'pbias']:
        print(f"{metric} : {round(getattr(metrics, metric)(), 4)}")



.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    kge : 0.8411
    nse : 0.7452
    pbias : 7.4699





.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 0.762 seconds)


.. _sphx_glr_download_auto_examples_hbv.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: hbv.ipynb <hbv.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: hbv.py <hbv.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: hbv.zip <hbv.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
