Name | tj-hyd-nam JSON |
Version |
1.1.0
JSON |
| download |
home_page | https://github.com/duynguyen02/tj_hyd_nam |
Summary | Python implementation of NedborAfstromnings Model (NAM) lumped rainfall–runoff model |
upload_time | 2024-08-28 18:28:25 |
maintainer | None |
docs_url | None |
author | Duy Nguyen |
requires_python | <4.0,>=3.10 |
license | None |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# TJ_HYD_NAM
Python implementation of NedborAfstromnings Model (NAM) lumped rainfall–runoff model, based on the original code
from [NAM_Model](https://github.com/hckaraman/NAM_Model) by [hckaraman](https://github.com/hckaraman)
### Installation
```
pip install tj_hyd_nam
```
### Getting Started
#### Prepare the Dataset
The dataset should include columns: Date, Temperature, Precipitation, Evapotranspiration, and Discharge, with column
names customizable.
| Date | Temp | Q | P | E |
|------------|------|---------|-----|------|
| 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 |
| ... | ... | ... | ... | ... |
The time intervals between dates must be equal (e.g., 24 hours) for the model to function accurately.
#### Initialize the NAM Model
```python
import pandas as pd
from tj_hyd_nam import TJHydNAM, NAMColNames, NAMConfig
# Load the dataset
df = pd.read_csv('data_example.csv')
# Specify the column names as required
nam_col_names = NAMColNames(
date='Date',
temperature='Temp',
precipitation='P',
evapotranspiration='E',
discharge='Q'
)
# Configure the model parameters
nam_config = NAMConfig(
area=58.8,
start_date=None,
end_date=None,
interval=24.0,
spin_off=0.0,
umax=0.97,
lmax=721.56,
cqof=0.18,
ckif=495.91,
ck12=25.16,
tof=0.97,
tif=0.11,
tg=0.19,
ckbf=1121.74,
csnow=2.31,
snowtemp=3.51,
)
NAM = TJHydNAM(
dataset=df,
nam_col_names=nam_col_names,
nam_config=nam_config
)
print(NAM)
```
The output will detail the NAM model based on the loaded dataset:
```
TJ_HYD_NAM 🍃 🌧 ☔ 💦
FROM: 2016-10-09 00:00:00+00:00
TO: 2018-09-30 00:00:00+00:00
NAMConfig(area=58.8, start_date=None, end_date=None, flow_rate=0.6805555555555555, interval=24.0, spin_off=0.0, umax=0.97, lmax=721.56, cqof=0.18, ckif=495.91, ck12=25.16, tof=0.97, tif=0.11, tg=0.19, ckbf=1121.74, csnow=2.31, snowtemp=3.51)
NAMStatistic(nse=-0.17835445482281131, rmse=1.7864602332317054, fbias=75.23828249740461)
```
#### Display and Save Graphs
```python
# Plot and save the discharge comparison graph
NAM.show_discharge(save=True, filename='discharge.png')
# Plot and save all calculated model information
NAM.show(save=True, filename='result.png')
```
#### Optimize the Model
```python
NAM.optimize()
print(NAM)
```
```shell
Optimization terminated successfully (Exit mode 0)
Current function value: 2.036882878807083
Iterations: 7
Function evaluations: 70
Gradient evaluations: 7
TJ_HYD_NAM 🍃 🌧 ☔ 💦
FROM: 2016-10-09 00:00:00+00:00
TO: 2018-09-30 00:00:00+00:00
NAMConfig(area=58.8, start_date=None, end_date=None, flow_rate=0.6805555555555555, interval=24.0, spin_off=0.0, umax=0.97, lmax=721.56, cqof=0.18, ckif=495.91, ck12=25.16, tof=0.97, tif=0.11, tg=0.19, ckbf=1121.74, csnow=2.31, snowtemp=3.51)
NAMStatistic(nse=-0.5318680456177058, rmse=2.036882878807083, fbias=91.77841692580132)
```
#### Reconfigure the Model Based on Properties
The model parameters will change and be recalculated based on new properties.
```python
NAM.re_config_by_props(
start_date=pd.to_datetime('09/10/2016', dayfirst=True, utc=True),
end_date=pd.to_datetime('20/10/2016', dayfirst=True, utc=True)
)
```
#### Reconfigure All Parameters
```python
NAM.re_config(
NAMConfig(
area=60,
start_date=None,
end_date=None,
interval=24.0,
spin_off=0.0,
umax=0.8,
lmax=719.56,
cqof=0.14,
ckif=493.86,
ck12=45.16,
tof=0.97,
tif=0.45,
tg=0.19,
ckbf=1121.74,
csnow=2.31,
snowtemp=3.51,
)
)
```
#### Save Calculated Model Data
```python
NAM.save_to_csv('result.csv')
```
#### Convert Calculated Data to DataFrame
```python
nam_df = NAM.to_dataframe()
```
#### Save the Model
```python
NAM.save('nam_model')
```
#### Load a Saved Model
```python
SAVED_NAM = NAM.load('nam_model.tjnam')
```
#### Use the Previous Model's Configuration for Prediction
```python
PRED_NAM = TJHydNAM(
pd.read_csv('future_data.csv'),
NAMColNames(
date='Date',
temperature='Temp',
precipitation='P',
evapotranspiration='E',
discharge='Q'
),
SAVED_NAM.config
)
```
#### Accessing calculated variables (>=1.1.0)
```python
NAM.size # Access the value of _size
NAM.date # Access the value of _date
NAM.T # Access the value of _T (temperature series)
NAM.P # Access the value of _P (precipitation series)
NAM.E # Access the value of _E (evaporation series)
NAM.Q_obs # Access the value of _Q_obs (observed discharge)
NAM.U_soil # Access the value of _U_soil (upper soil layer moisture)
NAM.S_snow # Access the value of _S_snow (snow storage)
NAM.Q_snow # Access the value of _Q_snow (snowmelt discharge)
NAM.Q_inter # Access the value of _Q_inter (interflow discharge)
NAM.E_eal # Access the value of _E_eal (actual evapotranspiration)
NAM.Q_of # Access the value of _Q_of (overland flow)
NAM.Q_g # Access the value of _Q_g (groundwater discharge)
NAM.Q_bf # Access the value of _Q_bf (baseflow)
NAM.Q_sim # Access the value of _Q_sim (simulator discharge)
NAM.L_soil # Access the value of _L_soil (soil moisture)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/duynguyen02/tj_hyd_nam",
"name": "tj-hyd-nam",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": null,
"author": "Duy Nguyen",
"author_email": "duynguyen02.dev@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/3b/64/c2b8d916bf6719e11d15eeba0a7139eb2cc451b8d830c3debaed11937920/tj_hyd_nam-1.1.0.tar.gz",
"platform": null,
"description": "# TJ_HYD_NAM\n\nPython implementation of NedborAfstromnings Model (NAM) lumped rainfall\u2013runoff model, based on the original code\nfrom [NAM_Model](https://github.com/hckaraman/NAM_Model) by [hckaraman](https://github.com/hckaraman)\n\n### Installation\n\n```\npip install tj_hyd_nam\n```\n\n### Getting Started\n\n#### Prepare the Dataset\n\nThe dataset should include columns: Date, Temperature, Precipitation, Evapotranspiration, and Discharge, with column\nnames customizable.\n\n| Date | Temp | Q | P | E |\n|------------|------|---------|-----|------|\n| 10/9/2016 | 15.4 | 0.25694 | 0 | 2.79 |\n| 10/10/2016 | 14.4 | 0.25812 | 0 | 3.46 |\n| 10/11/2016 | 14.9 | 0.30983 | 0 | 3.65 |\n| 10/12/2016 | 16.1 | 0.31422 | 0 | 3.46 |\n| 10/13/2016 | 20.1 | 0.30866 | 0 | 5.64 |\n| 10/14/2016 | 13.9 | 0.30868 | 0 | 3.24 |\n| 10/15/2016 | 11.1 | 0.31299 | 0 | 3.41 |\n| ... | ... | ... | ... | ... |\n\nThe time intervals between dates must be equal (e.g., 24 hours) for the model to function accurately.\n\n#### Initialize the NAM Model\n\n```python\nimport pandas as pd\nfrom tj_hyd_nam import TJHydNAM, NAMColNames, NAMConfig\n\n# Load the dataset\ndf = pd.read_csv('data_example.csv')\n# Specify the column names as required\nnam_col_names = NAMColNames(\n date='Date',\n temperature='Temp',\n precipitation='P',\n evapotranspiration='E',\n discharge='Q'\n)\n# Configure the model parameters\nnam_config = NAMConfig(\n area=58.8,\n start_date=None,\n end_date=None,\n interval=24.0,\n spin_off=0.0,\n umax=0.97,\n lmax=721.56,\n cqof=0.18,\n ckif=495.91,\n ck12=25.16,\n tof=0.97,\n tif=0.11,\n tg=0.19,\n ckbf=1121.74,\n csnow=2.31,\n snowtemp=3.51,\n)\nNAM = TJHydNAM(\n dataset=df,\n nam_col_names=nam_col_names,\n nam_config=nam_config\n)\nprint(NAM)\n```\n\nThe output will detail the NAM model based on the loaded dataset:\n\n```\nTJ_HYD_NAM \ud83c\udf43 \ud83c\udf27 \u2614 \ud83d\udca6\nFROM: 2016-10-09 00:00:00+00:00\nTO: 2018-09-30 00:00:00+00:00\nNAMConfig(area=58.8, start_date=None, end_date=None, flow_rate=0.6805555555555555, interval=24.0, spin_off=0.0, umax=0.97, lmax=721.56, cqof=0.18, ckif=495.91, ck12=25.16, tof=0.97, tif=0.11, tg=0.19, ckbf=1121.74, csnow=2.31, snowtemp=3.51)\nNAMStatistic(nse=-0.17835445482281131, rmse=1.7864602332317054, fbias=75.23828249740461)\n```\n\n#### Display and Save Graphs\n\n```python\n# Plot and save the discharge comparison graph\nNAM.show_discharge(save=True, filename='discharge.png')\n# Plot and save all calculated model information\nNAM.show(save=True, filename='result.png')\n```\n\n#### Optimize the Model\n\n```python\nNAM.optimize()\nprint(NAM)\n```\n\n```shell\nOptimization terminated successfully (Exit mode 0)\n Current function value: 2.036882878807083\n Iterations: 7\n Function evaluations: 70\n Gradient evaluations: 7\nTJ_HYD_NAM \ud83c\udf43 \ud83c\udf27 \u2614 \ud83d\udca6\nFROM: 2016-10-09 00:00:00+00:00\nTO: 2018-09-30 00:00:00+00:00\nNAMConfig(area=58.8, start_date=None, end_date=None, flow_rate=0.6805555555555555, interval=24.0, spin_off=0.0, umax=0.97, lmax=721.56, cqof=0.18, ckif=495.91, ck12=25.16, tof=0.97, tif=0.11, tg=0.19, ckbf=1121.74, csnow=2.31, snowtemp=3.51)\nNAMStatistic(nse=-0.5318680456177058, rmse=2.036882878807083, fbias=91.77841692580132)\n```\n\n#### Reconfigure the Model Based on Properties\n\nThe model parameters will change and be recalculated based on new properties.\n\n```python\nNAM.re_config_by_props(\n start_date=pd.to_datetime('09/10/2016', dayfirst=True, utc=True),\n end_date=pd.to_datetime('20/10/2016', dayfirst=True, utc=True)\n)\n```\n\n#### Reconfigure All Parameters\n\n```python\nNAM.re_config(\n NAMConfig(\n area=60,\n start_date=None,\n end_date=None,\n interval=24.0,\n spin_off=0.0,\n umax=0.8,\n lmax=719.56,\n cqof=0.14,\n ckif=493.86,\n ck12=45.16,\n tof=0.97,\n tif=0.45,\n tg=0.19,\n ckbf=1121.74,\n csnow=2.31,\n snowtemp=3.51,\n )\n)\n```\n\n#### Save Calculated Model Data\n\n```python\nNAM.save_to_csv('result.csv')\n```\n\n#### Convert Calculated Data to DataFrame\n\n```python\nnam_df = NAM.to_dataframe()\n```\n\n#### Save the Model\n\n```python\nNAM.save('nam_model')\n```\n\n#### Load a Saved Model\n\n```python\nSAVED_NAM = NAM.load('nam_model.tjnam')\n```\n\n#### Use the Previous Model's Configuration for Prediction\n\n```python\nPRED_NAM = TJHydNAM(\n pd.read_csv('future_data.csv'),\n NAMColNames(\n date='Date',\n temperature='Temp',\n precipitation='P',\n evapotranspiration='E',\n discharge='Q'\n ),\n SAVED_NAM.config\n)\n```\n\n#### Accessing calculated variables (>=1.1.0)\n```python\nNAM.size # Access the value of _size\nNAM.date # Access the value of _date\nNAM.T # Access the value of _T (temperature series)\nNAM.P # Access the value of _P (precipitation series)\nNAM.E # Access the value of _E (evaporation series)\nNAM.Q_obs # Access the value of _Q_obs (observed discharge)\nNAM.U_soil # Access the value of _U_soil (upper soil layer moisture)\nNAM.S_snow # Access the value of _S_snow (snow storage)\nNAM.Q_snow # Access the value of _Q_snow (snowmelt discharge)\nNAM.Q_inter # Access the value of _Q_inter (interflow discharge)\nNAM.E_eal # Access the value of _E_eal (actual evapotranspiration)\nNAM.Q_of # Access the value of _Q_of (overland flow)\nNAM.Q_g # Access the value of _Q_g (groundwater discharge)\nNAM.Q_bf # Access the value of _Q_bf (baseflow)\nNAM.Q_sim # Access the value of _Q_sim (simulator discharge)\nNAM.L_soil # Access the value of _L_soil (soil moisture)\n```",
"bugtrack_url": null,
"license": null,
"summary": "Python implementation of NedborAfstromnings Model (NAM) lumped rainfall\u2013runoff model",
"version": "1.1.0",
"project_urls": {
"Homepage": "https://github.com/duynguyen02/tj_hyd_nam",
"Repository": "https://github.com/duynguyen02/tj_hyd_nam"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "06de017614ac969c52c51a5d086e362f93e84d60e99842b486c2a344d53557d6",
"md5": "416b2c39eb5b35a69793604d25e8ab93",
"sha256": "ecab740ebffc9af52ce75176419e67942f151284745ca6c6836d0a9997bee8f6"
},
"downloads": -1,
"filename": "tj_hyd_nam-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "416b2c39eb5b35a69793604d25e8ab93",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 8559,
"upload_time": "2024-08-28T18:28:24",
"upload_time_iso_8601": "2024-08-28T18:28:24.159284Z",
"url": "https://files.pythonhosted.org/packages/06/de/017614ac969c52c51a5d086e362f93e84d60e99842b486c2a344d53557d6/tj_hyd_nam-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3b64c2b8d916bf6719e11d15eeba0a7139eb2cc451b8d830c3debaed11937920",
"md5": "83cd0f63ea7dddaaeb2cf40b3c768978",
"sha256": "a07b242d9b4717a38a966b70b1f676f6870983fc3ef4a260dba67d0ae9e12f6d"
},
"downloads": -1,
"filename": "tj_hyd_nam-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "83cd0f63ea7dddaaeb2cf40b3c768978",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 7631,
"upload_time": "2024-08-28T18:28:25",
"upload_time_iso_8601": "2024-08-28T18:28:25.999978Z",
"url": "https://files.pythonhosted.org/packages/3b/64/c2b8d916bf6719e11d15eeba0a7139eb2cc451b8d830c3debaed11937920/tj_hyd_nam-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-28 18:28:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "duynguyen02",
"github_project": "tj_hyd_nam",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "tj-hyd-nam"
}