-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/olivierbonte/HydroModels.jl
- Loading branch information
Showing
40 changed files
with
1,153 additions
and
518 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "HydroModels" | ||
uuid = "7e3cde01-c141-467b-bff6-5350a0af19fc" | ||
authors = ["jingx <[email protected]>"] | ||
version = "0.1.1" | ||
version = "0.1.2" | ||
|
||
[deps] | ||
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# HydroModels.jl Concepts | ||
|
||
HydroModels.jl implements a modular and extensible architecture, designed to support diverse hydrological modeling paradigms. The framework's core structure comprises four main classes: Flux, Bucket, Route, Model and Wrapper, each playing a vital role in constructing comprehensive hydrological systems. The framework is implemented in Julia programming language for model development, computation, and parameter optimization. It leverages Lux.jl as the deep learning framework and integrates with SciML for scientific computing, symbolic programming, and parameter optimization capabilities. The conceptual framework of the model design philosophy is illustrated in the following diagram: | ||
|
||
![Framework Concept](assets/concept.jpg) | ||
Architecture and ecosystem of the HydroModels.jl framework. (a) illustrates the supporting ecosystem and its functional capabilities, highlighting the key dependencies and their roles in the framework; (b) shows the core architectural design of HydroModels.jl, demonstrating the main components and their interactions. | ||
|
||
## Flux class: Water Process Transfer Representation | ||
|
||
The Flux class serves as the fundamental building block of HydroModels.jl, drawing inspiration from flux library of the MARRMoT while extending its capabilities. This class encapsulates the physical equations governing water movement throughout the hydrological cycle. The conceptual formulation of the Flux class can be expressed as: | ||
|
||
|
||
```math | ||
\begin{aligned} | ||
Y(t) = f(X(t),\theta) && (1) \\ | ||
\end{aligned} | ||
``` | ||
|
||
where the functional representation $f$ maps input variables $X(t)$ and parameters $\theta$ to output variables $Y(t)$. Here, $X(t)$ represents input variables like precipitation and temperature, $\theta$ denotes the parameters that can be calibrated, and $Y(t)$ represents output variables like runoff and infiltration. Based on different applications, the Flux class includes: | ||
|
||
- HydroFlux: Implements fundamental hydrological processes through mathematical formulations | ||
- StateFlux: Handles mass-balance equations for state variables like soil moisture and snowpack | ||
- NeuralFlux: Uses neural networks to model processes or predict parameters, leveraging Lux.jl capabilities | ||
|
||
## Bucket Class: Storage Volume Change Simulation | ||
|
||
The Bucket class represents fundamental water storage components within the hydrological system. It consists of multiple HydroFlux components (including NeuralFlux) and StateFlux components, which collectively define the water balance dynamics through coupled differential equations. These components can represent various hydrological stores such as soil moisture, groundwater reservoirs, and surface water bodies. | ||
|
||
The Bucket class generates two essential functions: | ||
1. An ODE solver function for state variables | ||
2. A hydrological flux computation function for output calculations | ||
|
||
This dual-function architecture enables efficient computation of hydrological processes, following a two-step process of solving ODEs and computing output fluxes. | ||
|
||
## Route Class: Spatial Flow Propagation | ||
|
||
The Route class simulates lateral water fluxes across landscapes and river networks, supporting both lumped "integral" and distributed "differential" models. Its core components include: | ||
|
||
```math | ||
\begin{aligned} | ||
Q_{out}(t) &= f_{rflux}(S_{route}(t),Q_{gen}(t); ps) && (2) \\ | ||
\frac{dS_{route}}{dt} &= Q_{in}(t) - Q_{out}(t) && (3) \\ | ||
Q_{in}(t+1) &= f_{aggr}(Q_{out}(t)) && (4) \\ | ||
\end{aligned} | ||
``` | ||
|
||
Where: $Q_{in}$ is inflow, $Q_{out}$ is outflow, $S_{route}$ is the routing state variable, and $f_{aggr}$ is the aggregation function. | ||
|
||
The class supports various routing methods including: | ||
- Standard state-update approaches | ||
- Unit hydrograph through convolution operations | ||
- Dynamic routing methods (Muskingum, kinematic wave) | ||
|
||
## Model Class: Hydrological Process Integration | ||
|
||
The Model class serves as the central management component, orchestrating the integration of Flux, Bucket, and Route components. It facilitates: | ||
- Construction of distributed hydrological models | ||
- Integration of vertical water movement with lateral connectivity | ||
- Systematic parameter optimization and sensitivity analysis | ||
- Efficient computation through metadata-driven approaches | ||
|
||
## Wrapper Class: Enhanced Component Capabilities | ||
|
||
The Wrapper class extends component customization capabilities while maintaining interface uniformity. Key features include: | ||
- NamedTupleIO wrapper for customized input/output specifications | ||
- EstimateParam wrapper for parameter prediction based on basin characteristics | ||
- RecordComponentState wrapper for state variable storage, supporting both batch training and online forecasting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# HydroModels.jl与ModelingToolkit.jl | ||
|
||
## 为什么不直接使用[ModelingToolkit.jl](https://github.com/SciML/ModelingToolkit.jl) | ||
|
||
HydroModels.jl的设计理念事实上是与ModelingToolkit.jl完全一致的,两者都是使用Symbolics.jl进行符号计算的框架,ModelingToolkit.jl是一个更通用符号系统,支持多种问题的构建,同时针对特定领域[ModelingToolkitStandardLibrary.jl](https://github.com/SciML/ModelingToolkitStandardLibrary.jl)提供了基础组件的支持. | ||
但是我之前在ModelingToolkit.jl的使用中存在一些问题: | ||
|
||
- 尽管ModelingToolkit.jl同样能够根据符号编程表达水文模型的常微分方程,但对水文模型中单位线计算,汇流过程计算等计算过程的支持却并不是特别理想 | ||
- 在同一种模块中,比如蒸发计算公式和土壤计算模块,不同区域所需要构建的模块会因为公式的不同存在差异,需要分别构建计算公式支撑模型模型构建 | ||
- 水文模型通常包括多个常微分方程,使用一个ODESystem构建会相对混乱,使用多个ODESystem会相对复杂 | ||
- 同时对于多节点输入,空间汇流过程计算,ODESystem或无法直接支持. | ||
- 对于神经网络模型的嵌入,尽管存在ModelingToolkitNeuralNets.jl,然而嵌入性却没有想象的那么简单 | ||
- 基于ModelingToolkit.jl对于自动微分的支持,尤其是Zygote.jl我在使用时也存在问题. | ||
|
||
因此我决定自己构建一个模型库,参考了符号编程的模型构建方式,使其更能够支撑水文模型的一些建模需求. | ||
|
||
## 未来的工作 | ||
|
||
不可否认ModelingToolkit.jl是一个非常好的框架,在满足了水文模型的需求之后,我会尽量将HydroModels.jl中的模块能够成为 ModelingToolkitStandardLibrary.jl中相似的模块,并继承ModelingToolkit.jl提供的AbstractSystem类的支持,提供一致的功能支持,从而兼容更多SciML生态的计算功能. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# HydroModels.jl and ModelingToolkit.jl | ||
|
||
## Why Not Use [ModelingToolkit.jl](https://github.com/SciML/ModelingToolkit.jl) Directly | ||
|
||
The design philosophy of HydroModels.jl is actually completely aligned with ModelingToolkit.jl. Both frameworks use Symbolics.jl for symbolic computation. ModelingToolkit.jl is a more general symbolic system that supports the construction of various problems, and [ModelingToolkitStandardLibrary.jl](https://github.com/SciML/ModelingToolkitStandardLibrary.jl) provides support for basic components in specific domains. | ||
|
||
However, I encountered several issues when using ModelingToolkit.jl: | ||
|
||
- Although ModelingToolkit.jl can express the ordinary differential equations of hydrological models through symbolic programming, its support for calculations like unit hydrograph and routing processes in hydrological models is not particularly ideal | ||
- Within the same module, such as evaporation calculation formulas and soil calculation modules, the modules needed for different regions may differ due to different formulas, requiring separate construction of calculation formulas to support model building | ||
- Hydrological models typically include multiple ordinary differential equations. Using a single ODESystem becomes relatively chaotic, while using multiple ODESystems becomes relatively complex | ||
- Additionally, ODESystem may not directly support multi-node input and spatial routing process calculations | ||
- Although ModelingToolkitNeuralNets.jl exists for neural network model embedding, the integration is not as straightforward as imagined | ||
- I also encountered issues with automatic differentiation support based on ModelingToolkit.jl, especially with Zygote.jl | ||
|
||
Therefore, I decided to build my own model library, referencing the symbolic programming model construction approach, to better support the modeling needs of hydrological models. | ||
|
||
## Future Work | ||
|
||
It's undeniable that ModelingToolkit.jl is an excellent framework. After meeting the requirements of hydrological models, I will try to make the modules in HydroModels.jl become similar modules in ModelingToolkitStandardLibrary.jl, and inherit the support of ModelingToolkit.jl's AbstractSystem class to provide consistent functional support, thereby maintaining compatibility with more computational capabilities in the SciML ecosystem. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.