hydrodl2 1.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hydrodl2/__init__.py +122 -0
- hydrodl2/_version.py +34 -0
- hydrodl2/api/__init__.py +3 -0
- hydrodl2/api/methods.py +144 -0
- hydrodl2/core/calc/__init__.py +11 -0
- hydrodl2/core/calc/batch_jacobian.pye +501 -0
- hydrodl2/core/calc/fdj.py +92 -0
- hydrodl2/core/calc/uh_routing.py +105 -0
- hydrodl2/core/calc/utils.py +59 -0
- hydrodl2/core/utils/__init__.py +7 -0
- hydrodl2/core/utils/clean_temp.sh +8 -0
- hydrodl2/core/utils/utils.py +63 -0
- hydrodl2/models/hbv/hbv.py +596 -0
- hydrodl2/models/hbv/hbv_1_1p.py +608 -0
- hydrodl2/models/hbv/hbv_2.py +670 -0
- hydrodl2/models/hbv/hbv_2_hourly.py +897 -0
- hydrodl2/models/hbv/hbv_2_mts.py +377 -0
- hydrodl2/models/hbv/hbv_adj.py +712 -0
- hydrodl2/modules/__init__.py +2 -0
- hydrodl2/modules/data_assimilation/variational_prcp_da.py +1 -0
- hydrodl2-1.3.0.dist-info/METADATA +184 -0
- hydrodl2-1.3.0.dist-info/RECORD +24 -0
- hydrodl2-1.3.0.dist-info/WHEEL +4 -0
- hydrodl2-1.3.0.dist-info/licenses/LICENSE +31 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Note: If adding new public methods, please add them to __all__
|
|
3
|
+
at the top of the file and in calc/__init__.py.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import torch
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def change_param_range(param: torch.Tensor, bounds: list[float]) -> torch.Tensor:
|
|
10
|
+
"""Change the range of a parameter to the specified bounds.
|
|
11
|
+
|
|
12
|
+
Parameters
|
|
13
|
+
----------
|
|
14
|
+
param
|
|
15
|
+
The parameter.
|
|
16
|
+
bounds
|
|
17
|
+
The parameter bounds.
|
|
18
|
+
|
|
19
|
+
Returns
|
|
20
|
+
-------
|
|
21
|
+
torch.Tensor
|
|
22
|
+
The parameter with the specified bounds.
|
|
23
|
+
"""
|
|
24
|
+
return param * (bounds[1] - bounds[0]) + bounds[0]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def param_bounds_2d(
|
|
28
|
+
params: torch.Tensor,
|
|
29
|
+
num: int,
|
|
30
|
+
bounds: list,
|
|
31
|
+
ndays: int,
|
|
32
|
+
nmul: int,
|
|
33
|
+
) -> torch.Tensor:
|
|
34
|
+
"""Convert a 2D parameter array to a 3D parameter array.
|
|
35
|
+
|
|
36
|
+
Parameters
|
|
37
|
+
----------
|
|
38
|
+
params
|
|
39
|
+
The 2D parameter array.
|
|
40
|
+
num
|
|
41
|
+
The number of parameters.
|
|
42
|
+
bounds
|
|
43
|
+
The parameter bounds.
|
|
44
|
+
ndays
|
|
45
|
+
The number of days.
|
|
46
|
+
nmul
|
|
47
|
+
The number of parallel models.
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
torch.Tensor
|
|
52
|
+
The 3D parameter array.
|
|
53
|
+
"""
|
|
54
|
+
out_temp = (
|
|
55
|
+
params[:, num * nmul : (num + 1) * nmul] * (bounds[1] - bounds[0]) + bounds[0]
|
|
56
|
+
)
|
|
57
|
+
return (
|
|
58
|
+
out_temp.unsqueeze(0).repeat(ndays, 1, 1).reshape(ndays, params.shape[0], nmul)
|
|
59
|
+
)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
# Recursively remove all cache files (.pyc, __pycache__/) in the working dir.
|
|
4
|
+
# Usage: sh path/to/clean_temp.sh
|
|
5
|
+
|
|
6
|
+
find . | grep -E "(__pycache__|\.pyc$)" | xargs rm -rf
|
|
7
|
+
find . | grep -E "(.ruff_cache$)" | xargs rm -rf
|
|
8
|
+
find . | grep -E "(.pytest_cache$)" | xargs rm -rf
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Note: If adding new public methods, please add them to __all__
|
|
3
|
+
at the top of the file and in utils/__init__.py.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Union
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_model_dirs(directory: Union[Path, str]) -> tuple[list[Path], list[str]]:
|
|
12
|
+
"""Get all subdirectories in a given directory.
|
|
13
|
+
|
|
14
|
+
Parameters
|
|
15
|
+
----------
|
|
16
|
+
directory
|
|
17
|
+
The parent directory.
|
|
18
|
+
"""
|
|
19
|
+
if isinstance(directory, str):
|
|
20
|
+
directory = Path(directory)
|
|
21
|
+
|
|
22
|
+
dirs = []
|
|
23
|
+
dir_names = []
|
|
24
|
+
avoid_list = ['__pycache__']
|
|
25
|
+
|
|
26
|
+
for item in directory.iterdir():
|
|
27
|
+
if item.is_dir() and (item.name not in avoid_list):
|
|
28
|
+
dirs.append(item)
|
|
29
|
+
dir_names.append(item.name)
|
|
30
|
+
|
|
31
|
+
return dirs, dir_names
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def get_model_files(directory: Union[Path, str]) -> tuple[list[Path], list[str]]:
|
|
35
|
+
"""Get all files in a given directory.
|
|
36
|
+
|
|
37
|
+
Parameters
|
|
38
|
+
----------
|
|
39
|
+
directory
|
|
40
|
+
The parent directory.
|
|
41
|
+
"""
|
|
42
|
+
if isinstance(directory, str):
|
|
43
|
+
directory = Path(directory)
|
|
44
|
+
|
|
45
|
+
files = []
|
|
46
|
+
file_names = []
|
|
47
|
+
avoid_list = ['__init__', '.DS_Store', 'README.md', '.git']
|
|
48
|
+
|
|
49
|
+
for item in directory.iterdir():
|
|
50
|
+
if item.is_file() and (item.name not in avoid_list):
|
|
51
|
+
files.append(item)
|
|
52
|
+
|
|
53
|
+
# Remove file extension
|
|
54
|
+
name = os.path.splitext(item.name)[0]
|
|
55
|
+
file_names.append(name)
|
|
56
|
+
return files, file_names
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _get_dir(dir_name: str) -> Path:
|
|
60
|
+
"""Get the path for the given directory name."""
|
|
61
|
+
dir = Path(os.path.dirname(os.path.abspath(__file__)))
|
|
62
|
+
dir = dir.parent.parent / dir_name
|
|
63
|
+
return dir
|