Skip to content

Commit

Permalink
use hydrodatasource package and update redme for this version
Browse files Browse the repository at this point in the history
  • Loading branch information
OuyangWenyu committed Mar 28, 2024
1 parent 7b8e430 commit ba006a8
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 28 deletions.
34 changes: 23 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@ $ conda activate hydromodel
$ pip install hydromodel
```

If you want to run notebooks in your jupyter notebook, please install jupyter kenel in your jupyter lab:
If you want to run the model as a developer, you can clone the repository

```Shell
# if you don't have a jupyterlab in your PC, please install it at first
# $ conda install -c conda-forge jupyterlab
# fork hydromodel to your GitHub, and clone it to your computer
$ git clone <address of hydromodel in your github>
# move to it
$ cd hydromodel
# if updating from upstream, pull the new version to local
$ git pull
# create python environment
$ mamba env create -f env-dev.yml
# if mamba is not installed:
# $ conda install -c conda-forge mamba
# activate it
$ conda activate hydromodel
$ conda install -c conda-forge ipykernel
$ python -m ipykernel install --user --name hydromodel --display-name "hydromodel"
```

### Prepare data
Expand Down Expand Up @@ -83,7 +90,7 @@ No more unnecessary columns are allowed.
For time series csv files, et and node1_flow are optional. If you don't have them, you can ignore them.
The units of all variables could be different, but they cannot be missed and should be put in `()` in the column name.

2. Download [prepare_data.py](https://github.com/OuyangWenyu/hydro-model-xaj/tree/master/scripts) and run the following code to transform the data format to the required format:
1. Use [prepare_data.py](https://github.com/OuyangWenyu/hydro-model-xaj/tree/master/scripts) -- run the following code to transform the data format to the required format:
```Shell
$ python prepare_data.py --origin_data_dir <your_data_directory_for_hydromodel>
```
Expand All @@ -101,23 +108,28 @@ To use your own data, run the following code:

```Shell
# you can change the algorithm parameters:
$ python calibrate_xaj.py --exp example --warmup_length 365 --model {\"name\":\"xaj_mz\",\"source_type\":\"sources\",\"source_book\":\"HF\"} --algorithm {\"name\":\"SCE_UA\",\"random_seed\":1234,\"rep\":5000,\"ngs\":20,\"kstop\":3,\"peps\":0.1,\"pcento\":0.1}
$ python calibrate_xaj.py --data_type owndata --data_dir "C:/Users/wenyu/OneDrive/data/biliuhe" --exp expbiliuhe001 --cv_fold 1 --warmup 720 --period "2012-06-10 00:00" "2022-08-31 23:00" --calibrate_period "2012-06-10 00:00" "2017-08-31 23:00" --test_period "2017-09-01 00:00" "2022-08-31 23:00" --basin_id 21401550 --model "{\"name\": \"xaj\", \"source_type\": \"sources5mm\", \"source_book\": \"HF\"}" --param_range_file "C:/Users/wenyu/OneDrive/data/biliuhe/param_range.yaml" --algorithm "{\"name\": \"SCE_UA\", \"random_seed\": 1234, \"rep\": 10, \"ngs\": 10, \"kstop\": 5, \"peps\": 0.1, \"pcento\": 0.1}" --loss "{\"type\": \"time_series\", \"obj_func\": \"RMSE\", \"events\": null}"
# for advices of hyper-parameters of sceua, please see the comment of the function 'calibrate_xaj.py'
# python calibrate_xaj.py --exp <name of directory of the prepared data> --warmup_length <hydromodel need some warm-up period> --model <model function parameters> --algorithm <calibration algorithm parameters>
```

**NOTE**: For the parameter range in the `param_range_file` file. You can copy it from "hydromodel/models/param.yaml" of this repo and put it anywhere you want. Then you can modify the parameter range in the file. The parameter range is used to limit the parameter space of the hydromodels. If you don't provide the file, the default parameter range will be used.

Then you can evaluate the calibrated model with the following code:

```Shell
$ python evaluate_xaj.py --exp expcamels001
# $ python evaluate_xaj.py --exp expcamels001
# for your own data
$ python evaluate_xaj.py --exp expbiliuhe001
```

### See the results

Run the following code to see the results of the evaluation:

```Shell
$ python visualize.py --exp expcamels001
# $ python visualize.py --exp expcamels001
# for your own data
$ python visualize.py --exp expbiliuhe001
```

You will see the results in the `example` directory.
Expand Down Expand Up @@ -152,7 +164,7 @@ More English references could be seen at the end of this README file.

The model mainly includes three parts:

![](docs/source/img/xaj.jpg)
![](docs/img/xaj.jpg)

For the first part, we use an evaporation coefficient K (ratio of potential evapotranspiration to reference crop
evaporation generally from Allen, 1998) rather than Kc (the ratio of potential evapotranspiration to pan evaporation)
Expand Down
Binary file added docs/img/xaj.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/xaj_.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions env-dev.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: xaj
name: hydromodel
channels:
- pytorch
- conda-forge
Expand Down Expand Up @@ -26,4 +26,4 @@ dependencies:
- twine
- bump2version
- muskingumcunge
- hydrodata
- hydrodatasource
6 changes: 3 additions & 3 deletions hydromodel/datasets/data_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

import os
import re
from hydrodataset import Camels
import numpy as np
import pandas as pd
from pint import UnitRegistry
from sklearn.model_selection import KFold
import xarray as xr

from hydrodata.utils.utils import streamflow_unit_conv
from hydrodata.cleaner.dmca_esr import rainfall_runoff_event_identify
from hydrodataset import Camels
from hydrodatasource.utils.utils import streamflow_unit_conv
from hydrodatasource.cleaner.dmca_esr import rainfall_runoff_event_identify

from hydromodel import CACHE_DIR, SETTING
from hydromodel.datasets import *
Expand Down
6 changes: 3 additions & 3 deletions hydromodel/trainers/evaluate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
Author: Wenyu Ouyang
Date: 2022-10-25 21:16:22
LastEditTime: 2024-03-27 16:18:48
LastEditTime: 2024-03-28 09:55:58
LastEditors: Wenyu Ouyang
Description: Plots for calibration and testing results
FilePath: \hydro-model-xaj\hydromodel\trainers\evaluate.py
FilePath: \hydromodel\hydromodel\trainers\evaluate.py
Copyright (c) 2021-2022 Wenyu Ouyang. All rights reserved.
"""

Expand All @@ -17,7 +17,7 @@
import yaml

from hydroutils import hydro_file, hydro_stat
from hydrodata.utils.utils import streamflow_unit_conv
from hydrodatasource.utils.utils import streamflow_unit_conv

from hydromodel.datasets import *
from hydromodel.datasets.data_preprocess import (
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ requests

muskingumcunge

hydrodata
hydrodatasource
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ requests

muskingumcunge

hydrodata
hydrodatasource
8 changes: 4 additions & 4 deletions test/test_data_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from hydromodel.datasets.data_preprocess import (
process_and_save_data_as_nc,
split_train_test,
check_tsdata_format,
check_basin_attr_format,
check_folder_contents,
cross_valid_data,
)
from hydromodel.datasets.data_preprocess import check_tsdata_format
from hydromodel.datasets.data_preprocess import check_basin_attr_format
from hydromodel.datasets.data_preprocess import check_folder_contents
from hydromodel.datasets.data_preprocess import cross_valid_data


@pytest.fixture()
Expand Down
6 changes: 3 additions & 3 deletions test/test_data_postprocess.py → test/test_data_visualize.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
Author: Wenyu Ouyang
Date: 2022-10-25 21:16:22
LastEditTime: 2024-03-27 10:59:29
LastEditTime: 2024-03-28 09:57:58
LastEditors: Wenyu Ouyang
Description: Test for data preprocess
FilePath: \hydro-model-xaj\test\test_data_postprocess.py
Description: Test for results visualization
FilePath: \hydromodel\test\test_data_visualize.py
Copyright (c) 2021-2022 Wenyu Ouyang. All rights reserved.
"""

Expand Down

0 comments on commit ba006a8

Please sign in to comment.