Skip to content

Commit 06d1307

Browse files
committed
initial commit
1 parent 65eff4b commit 06d1307

File tree

138 files changed

+35935
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+35935
-0
lines changed

.gitignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# file extensions
2+
**/*.pyc
3+
**/*.h5
4+
**/*.p
5+
!test/test_data/*.p
6+
*.swp
7+
.coverage
8+
9+
# folder
10+
build/*
11+
dist/*
12+
neuralhydrology.egg-info/*
13+
.vscode/*
14+
.idea/*
15+
runs/*
16+
configs/*
17+
.ipynb_checkpoints/*
18+
data/*
19+
docs/build/*

.style.yapf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[style]
2+
column_limit = 120
3+
based_on_style = google

CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @kratzert

README.md

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
![#](docs/source/_static/img/neural-hyd-logo-black.png)
2+
3+
Python library to train neural networks with a strong focus on hydrological applications.
4+
5+
This package has been used extensively in research over the last year and was used in various academic publications.
6+
The core idea of this package is modularity in all places to allow easy integration of new datasets, new model
7+
architectures or any training related aspects (e.g. loss functions, optimizer, regularization).
8+
One of the core concepts of this code base are configuration files, which lets anyone train neural networks without
9+
touching the code itself. The `NeuralHydrology` package is build on top of the deep learning framework
10+
[Pytorch](https://pytorch.org/), since it has proven to be the most flexible and useful for research purposes.
11+
12+
We (AI for Earth Science group at Institute for Machine Learning, Johannes Kepler University, Linz, Austria) are using
13+
this code in our day-to-day research and will continue to integrate our new research findings into this public repository.
14+
15+
**Note:** We will gradually add more examples/documentation over the next couple of days/weeks.
16+
17+
- Documentation: [neuralhydrology.readthedocs.io](neuralhydrology.readthedocs.io)
18+
- Research Blog: [neuralhydrology.github.io](neuralhydrology.github.io)
19+
- Bug reports/Feature requests [https://github.com/neuralhydrology/neuralhydrology/issues](https://github.com/neuralhydrology/neuralhydrology/issues)
20+
21+
# Getting started
22+
23+
## Requirements
24+
25+
We recommend to use Anaconda/Miniconda. With one of the two installed, a dedicated environment with all requirements
26+
installed can be set up from the environment files provided in
27+
[environments](https://github.com/neuralhydrology/neuralhydrology/environments).
28+
29+
If you have no CUDA capable GPU available run
30+
31+
```bash
32+
conda env create -f environments/environment_cpu.yml
33+
```
34+
35+
With a CUDA capable GPU available, check which CUDA version your GPU supports and then run e.g. (for CUDA 10.2)
36+
37+
```bash
38+
conda env create -f environments/environment_cuda10_2.yml
39+
```
40+
41+
If neither Minicoda/Anaconda are available, make sure to Python environment with all packages installed that are listed
42+
in one of the environment files.
43+
44+
## Installation
45+
46+
For now download or clone the repository to your local machine and install a local, editable copy.
47+
This is a good idea if you want to edit the ``neuralhydrology`` code (e.g., adding new models or datasets).::
48+
49+
```bash
50+
git clone https://github.com/neuralhydrology/neuralhydrology.git
51+
cd neuralhydrology
52+
pip install -e .
53+
```
54+
Besides adding the package to your Python environment, it will also add three bash scripts:
55+
`nh-run`, `nh-run-scheduler` and `nh-results-ensemble`. For details, see below.
56+
57+
58+
## Data
59+
60+
Training and evaluating models requires a dataset.
61+
If you're unsure where to start, a common dataset is CAMELS US, available at
62+
[CAMELS US (NCAR)](https://ral.ucar.edu/solutions/products/camels).
63+
Download the "CAMELS time series meteorology, observed flow, meta data" and place the actual data folder
64+
(`basin_dataset_public_v1p2`) in a directory.
65+
This directory will be referred to as the "data directory", or `data_dir`.
66+
67+
## Configuration file
68+
69+
One of the core concepts of this package is the usage of configuration files (`.yml`). Basically, all configurations
70+
required to train a neural network can be specified via these configuration files and no code has to be touched.
71+
Training a model does require a `.yml` file that specifies the run configuration. We will add a detailed explanation
72+
for within the next weeks that explains the config files and arguments in more detail. For now refer to the
73+
[example config](https://github.com/neuralhydrology/neuralhydrology/blob/master/examples/config.yml.example) for a full
74+
list of all available arguments (with inline documentation). For an example of a configuration file that can be used to
75+
train a standard LSTM for a single CAMELS US basin, check
76+
[1_basin_config.yml](https://github.com/neuralhydrology/neuralhydrology/blob/master/examples/1_basin_config.yml.example).
77+
78+
## Train a model
79+
80+
To train a model, prepare a configuration file, then run::
81+
82+
```bash
83+
nh-run train --config-file /path/to/config.yml
84+
```
85+
If you want to train multiple models, you can make use of the ``nh-run-scheduler`` command.
86+
Place all configs in a folder, then run::
87+
```bash
88+
nh-run-scheduler train --config-dir /path/to/config_dir/ --runs-per-gpu X --gpu-ids Y
89+
```
90+
With X, you can specify how many models should be trained on parallel on a single GPU.
91+
With Y, you can specify which GPUs to use for training (use the id as specified in ``nvidia-smi``).
92+
93+
## Evaluate a model
94+
95+
To evaluate a trained model on the test set, run::
96+
97+
nh-run evaluate --run-dir /path/to/run_dir/
98+
99+
If the optional argument ``--epoch N`` (where N is the epoch to evaluate) is not specified,
100+
the weights of the last epoch are used. You can also use ``--period `` if you want to evaluate the model on the
101+
train period ``--period train``) or validation period (``--period validation``)
102+
103+
To evaluate all runs in a specific directory you can, similarly to training, run::
104+
105+
nh-run-scheduler evaluate --run-dir /path/to/config_dir/ --runs-per-gpu X --gpu-ids Y
106+
107+
108+
To merge the predictons of a number of runs (stored in ``$DIR1``, ...) into one averaged ensemble,
109+
use the ``nh-results-ensemble`` script::
110+
111+
nh-results-ensemble --run-dirs $DIR1 $DIR2 ... --save-file /path/to/target/file.p --metrics NSE MSE ...
112+
113+
``--metrics`` specifies which metrics will be calculated for the averaged predictions.
114+
115+
# Contact
116+
117+
If you have any questions regarding the usage of this repository, feature requests or comments, please open an issue.
118+
You can also reach out to Frederik Kratzert (kratzert(at)ml.jku.at) by email.

docs/Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/make.bat

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=source
11+
set BUILDDIR=build
12+
13+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.http://sphinx-doc.org/
25+
exit /b 1
26+
)
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
BaseDataset
2+
===========
3+
4+
.. automodule:: neuralhydrology.data.basedataset
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CamelsGB
2+
========
3+
4+
.. automodule:: neuralhydrology.data.camelsgb
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CamelsUS
2+
========
3+
4+
.. automodule:: neuralhydrology.data.camelsus
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Caravan
2+
=======
3+
4+
.. automodule:: neuralhydrology.data.caravan
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
climateindices
2+
==============
3+
4+
.. automodule:: neuralhydrology.data.climateindices
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dischargeinput
2+
==============
3+
4+
.. automodule:: neuralhydrology.data.dischargeinput
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
HourlyCamelsUS
2+
==============
3+
4+
.. automodule:: neuralhydrology.data.hourlycamelsus
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pet
2+
===
3+
4+
.. automodule:: neuralhydrology.data.pet
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
nh.data
2+
=======
3+
4+
.. automodule:: neuralhydrology.data
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
9+
.. toctree::
10+
:maxdepth: 4
11+
12+
neuralhydrology.data.basedataset
13+
neuralhydrology.data.camelsus
14+
neuralhydrology.data.hourlycamelsus
15+
neuralhydrology.data.camelsgb
16+
neuralhydrology.data.caravan
17+
neuralhydrology.data.climateindices
18+
neuralhydrology.data.dischargeinput
19+
neuralhydrology.data.pet
20+
neuralhydrology.data.utils
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
utils
2+
=====
3+
4+
.. automodule:: neuralhydrology.data.utils
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
evaluate
2+
========
3+
4+
.. automodule:: neuralhydrology.evaluation.evaluate
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
metrics
2+
=======
3+
4+
.. automodule:: neuralhydrology.evaluation.metrics
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plots
2+
=====
3+
4+
.. automodule:: neuralhydrology.evaluation.plots
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
nh.evaluation
2+
=============
3+
4+
.. automodule:: neuralhydrology.evaluation
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
9+
.. toctree::
10+
:maxdepth: 4
11+
12+
neuralhydrology.evaluation.evaluate
13+
neuralhydrology.evaluation.metrics
14+
neuralhydrology.evaluation.plots
15+
neuralhydrology.evaluation.signatures
16+
neuralhydrology.evaluation.tester
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
signatures
2+
==========
3+
4+
.. automodule:: neuralhydrology.evaluation.signatures
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Tester
2+
======
3+
4+
.. automodule:: neuralhydrology.evaluation.tester
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
BaseModel
2+
=========
3+
4+
.. automodule:: neuralhydrology.modelzoo.basemodel
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CudaLSTM
2+
========
3+
4+
.. automodule:: neuralhydrology.modelzoo.cudalstm
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
EALSTM
2+
======
3+
4+
.. automodule:: neuralhydrology.modelzoo.ealstm
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
EmbCudaLSTM
2+
===========
3+
4+
.. automodule:: neuralhydrology.modelzoo.embcudalstm
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FC
2+
==
3+
4+
.. automodule:: neuralhydrology.modelzoo.fc
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

0 commit comments

Comments
 (0)