Skip to content

Commit

Permalink
Merge pull request #158 from DassHydro/gr-beta-percolation-time-step-…
Browse files Browse the repository at this point in the history
…dependent

FIX: Beta parameter in GR percolation
  • Loading branch information
nghi-truyen authored Apr 2, 2024
2 parents 1284604 + df02982 commit fad6dae
Show file tree
Hide file tree
Showing 12 changed files with 534 additions and 504 deletions.
2 changes: 1 addition & 1 deletion doc/source/user_guide/others/input_data_convention.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Below is the most basic directory structure you can have, with one subdirectory
│ ├── V3504010.csv
│ └── ...
└── descriptor
├── slope.ti
├── slope.tif
└── dd.tif
This results in the following ``setup``:
Expand Down
16 changes: 9 additions & 7 deletions doc/source/user_guide/quickstart/cance_first_simulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -670,17 +670,19 @@ First, several information were displayed on the screen during optimization

.. code-block:: text
At iterate 0 nfg = 1 J = 0.643190 ddx = 0.64
At iterate 1 nfg = 30 J = 0.097397 ddx = 0.64
At iterate 2 nfg = 59 J = 0.052158 ddx = 0.32
At iterate 3 nfg = 88 J = 0.043086 ddx = 0.08
At iterate 4 nfg = 118 J = 0.040684 ddx = 0.02
At iterate 5 nfg = 152 J = 0.040604 ddx = 0.01
At iterate 0 nfg = 1 J = 0.695010 ddx = 0.64
At iterate 1 nfg = 30 J = 0.098411 ddx = 0.64
At iterate 2 nfg = 59 J = 0.045409 ddx = 0.32
At iterate 3 nfg = 88 J = 0.038182 ddx = 0.16
At iterate 4 nfg = 117 J = 0.037362 ddx = 0.08
At iterate 5 nfg = 150 J = 0.037087 ddx = 0.02
At iterate 6 nfg = 183 J = 0.036800 ddx = 0.02
At iterate 7 nfg = 216 J = 0.036763 ddx = 0.01
CONVERGENCE: DDX < 0.01
These lines show the different iterations of the optimization with information on the number of iterations, the number of cumulative evaluations ``nfg``
(number of foward runs performed within each iteration of the optimization algorithm), the value of the cost function to minimize ``J`` and the value of the adaptive descent step ``ddx`` of this heuristic search algorihtm.
So, to summarize, the optimization algorithm has converged after 5 iterations by reaching the descent step tolerance criterion of 0.01. This optimization required to perform 152 forward run evaluations and leads to a final cost function value on the order of 0.04.
So, to summarize, the optimization algorithm has converged after 7 iterations by reaching the descent step tolerance criterion of 0.01. This optimization required to perform 216 forward run evaluations and leads to a final cost function value on the order of 0.04.

Then, we can ask which cost function ``J`` has been minimized and which parameters have been optimized. So, by default, the cost function to be minimized is one minus the Nash-Sutcliffe efficiency ``nse`` (:math:`1 - \text{NSE}`)
and the optimized parameters are the set of rainfall-runoff parameters (``cp``, ``ct``, ``kexc`` and ``llr``). In the current configuration spatially
Expand Down
60 changes: 33 additions & 27 deletions smash/core/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,8 +1134,8 @@ def response(self) -> ResponseDT:
>>> ind
0
>>> model.response.q[ind, :]
array([1.9826430e-03, 1.3466669e-07, 6.7617895e-12, ..., 3.2273201e+01,
3.2118713e+01, 3.1965160e+01], dtype=float32)
array([1.9826430e-03, 1.3466669e-07, 6.7617895e-12, ..., 2.2796249e+01,
2.2655941e+01, 2.2517307e+01], dtype=float32)
If you are using IPython, tab completion allows you to visualize all the attributes and methods
Expand Down Expand Up @@ -1190,11 +1190,13 @@ def rr_final_states(self) -> RR_StatesDT:
`get_rr_final_states <Model.get_rr_final_states>`
>>> model.get_rr_final_states("hp")
array([[0.01 , 0.01 , 0.01 , 0.01 , 0.01 ,
0.01 , 0.01 , 0.01 , 0.01 , 0.01 ,
0.01 , 0.01 , 0.5892611 , 0.60285664, 0.01 ,
array([[-99. , -99. , -99. , -99. ,
-99. , -99. , -99. , -99. ,
-99. , -99. , -99. , -99. ,
0.8682228 , 0.88014543, -99. , -99. ,
...
0.01 , 0.01 , 0.01 ]], dtype=float32)
-99. , -99. , -99. , -99. ]],
dtype=float32)
.. note::
Unlike rainfall-runoff initial states, there is no setter for rainfall-runoff final states.
Expand Down Expand Up @@ -1999,11 +2001,13 @@ def get_rr_final_states(self, key: str) -> NDArray[np.float32]:
Access to a specific rainfall-runoff final state grid
>>> model.get_rr_final_states("hp")
array([[0.01 , 0.01 , 0.01 , 0.01 , 0.01 ,
0.01 , 0.01 , 0.01 , 0.01 , 0.01 ,
0.01 , 0.01 , 0.5892611 , 0.60285664, 0.01 ,
array([[-99. , -99. , -99. , -99. ,
-99. , -99. , -99. , -99. ,
-99. , -99. , -99. , -99. ,
0.8682228 , 0.88014543, -99. , -99. ,
...
0.01 , 0.01 , 0.01 ]], dtype=float32)
-99. , -99. , -99. , -99. ]],
dtype=float32)
.. note::
This method is equivalent to directly slicing the ``rr_final_states.values`` array (as shown
Expand All @@ -2023,11 +2027,13 @@ def get_rr_final_states(self, key: str) -> NDArray[np.float32]:
Slice the ``rr_final_states.values`` array on the last axis
>>> model.rr_final_states.values[..., ind]
array([[0.01 , 0.01 , 0.01 , 0.01 , 0.01 ,
0.01 , 0.01 , 0.01 , 0.01 , 0.01 ,
0.01 , 0.01 , 0.5892611 , 0.60285664, 0.01 ,
array([[-99. , -99. , -99. , -99. ,
-99. , -99. , -99. , -99. ,
-99. , -99. , -99. , -99. ,
0.8682228 , 0.88014543, -99. , -99. ,
...
0.01 , 0.01 , 0.01 ]], dtype=float32)
-99. , -99. , -99. , -99. ]],
dtype=float32)
"""

key = _standardize_get_rr_final_states_args(self, key)
Expand Down Expand Up @@ -2205,18 +2211,18 @@ def get_serr_mu(self) -> NDArray[np.float32]:
Set arbitrary values to structural error mu parameters
>>> model.set_serr_mu_parameters("mg0", 1)
>>> model.set_serr_mu_paramters("mg1", 2)
>>> model.set_serr_mu_parameters("mg1", 2)
Retrieve the mu value with the `get_serr_mu <Model.get_serr_mu>` method
>>> mu = model.get_serr_mu()
>>> mu
array([[ 1.0039653, 1.0000002, 1. , ..., 65.5464 , 65.23743 ,
64.93032 ],
[ 1.0004755, 1. , 1. , ..., 16.804424 , 16.740883 ,
16.677677 ],
[ 1.0000595, 1. , 1. , ..., 5.186602 , 5.1694865,
5.1524224]], dtype=float32)
array([[ 1.0039653, 1.0000002, 1. , ..., 46.5925 , 46.311882 ,
46.034615 ],
[ 1.0004755, 1. , 1. , ..., 10.65963 , 10.61587 ,
10.572574 ],
[ 1.0000595, 1. , 1. , ..., 3.563775 , 3.5520396,
3.5404253]], dtype=float32)
This is equivalent to
Expand Down Expand Up @@ -2276,12 +2282,12 @@ def get_serr_sigma(self) -> NDArray[np.float32]:
>>> sigma = model.get_serr_sigma()
>>> sigma
array([[1.0003965, 1. , 1. , ..., 7.4546404, 7.423743 ,
7.393032 ],
[1.0000476, 1. , 1. , ..., 2.5804424, 2.5740883,
2.5677679],
[1.000006 , 1. , 1. , ..., 1.4186602, 1.4169487,
1.4152422]], dtype=float32)
array([[1.0003965, 1. , 1. , ..., 5.55925 , 5.5311885,
5.5034614],
[1.0000476, 1. , 1. , ..., 1.965963 , 1.9615871,
1.9572574],
[1.000006 , 1. , 1. , ..., 1.2563775, 1.255204 ,
1.2540425]], dtype=float32)
This is equivalent to
Expand Down
22 changes: 12 additions & 10 deletions smash/core/signal_analysis/metrics/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,25 @@ def metrics(model: Model, metric: str = "nse", end_warmup: str | Timestamp | Non
>>> model.optimize()
</> Optimize
At iterate 0 nfg = 1 J = 0.643190 ddx = 0.64
At iterate 1 nfg = 30 J = 0.097397 ddx = 0.64
At iterate 2 nfg = 59 J = 0.052158 ddx = 0.32
At iterate 3 nfg = 88 J = 0.043086 ddx = 0.08
At iterate 4 nfg = 118 J = 0.040684 ddx = 0.02
At iterate 5 nfg = 152 J = 0.040604 ddx = 0.01
At iterate 0 nfg = 1 J = 0.695010 ddx = 0.64
At iterate 1 nfg = 30 J = 0.098411 ddx = 0.64
At iterate 2 nfg = 59 J = 0.045409 ddx = 0.32
At iterate 3 nfg = 88 J = 0.038182 ddx = 0.16
At iterate 4 nfg = 117 J = 0.037362 ddx = 0.08
At iterate 5 nfg = 150 J = 0.037087 ddx = 0.02
At iterate 6 nfg = 183 J = 0.036800 ddx = 0.02
At iterate 7 nfg = 216 J = 0.036763 ddx = 0.01
CONVERGENCE: DDX < 0.01
Compute the Mean Squared Error for all catchments
>>> smash.metrics(model, metric="mse")
array([49.50750351, 4.31146955, 0.57386672])
array([44.78328323, 4.38410997, 0.50611502])
The Kling-Gupta Efficiency
>>> smash.metrics(model, metric="kge")
array([0.96001273, 0.86749017, 0.81862521])
array([0.94752783, 0.84582865, 0.8045246 ])
Add end warm-up date (1 month)
Expand All @@ -89,9 +91,9 @@ def metrics(model: Model, metric: str = "nse", end_warmup: str | Timestamp | Non
Compute the Nash-Sutcliffe Efficiency with and without warm-up
>>> smash.metrics(model, metric="nse")
array([0.95939589, 0.90611488, 0.82942516])
array([0.96327233, 0.90453297, 0.84956211])
>>> smash.metrics(model, metric="nse", end_warmup=end_warmup)
array([0.9774977 , 0.92978942, 0.87382156])
array([0.97294462, 0.91321117, 0.86573941])
"""
metric, end_warmup = _standardize_metrics_args(metric, end_warmup, model.setup)

Expand Down
30 changes: 15 additions & 15 deletions smash/core/signal_analysis/signatures/signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,46 +154,46 @@ def signatures(
Access simulated flood event signatures as a `pandas.DataFrame`
>>> sign.event
code season start ... Erch2r Elt Epf
0 V3524010 autumn 2014-11-03 03:00:00 ... 0.214772 3.0 85.736832
1 V3515010 autumn 2014-11-03 10:00:00 ... 0.202139 0.0 17.256138
2 V3517010 autumn 2014-11-03 08:00:00 ... 0.187440 1.0 4.770674
code season start ... Erch2r Elt Epf
0 V3524010 autumn 2014-11-03 03:00:00 ... 0.324836 3.0 100.448631
1 V3515010 autumn 2014-11-03 10:00:00 ... 0.339471 0.0 20.168104
2 V3517010 autumn 2014-11-03 08:00:00 ... 0.319605 1.0 5.356519
[3 rows x 12 columns]
Access simulated continuous signatures as a `pandas.DataFrame`
>>> sign.cont
code Crc Crchf ... Cfp10 Cfp50 Cfp90
0 V3524010 0.316813 0.058713 ... 0.013092 5.895140 39.439846
1 V3515010 0.251831 0.048244 ... 0.001120 1.072775 9.016475
2 V3517010 0.251551 0.048258 ... 0.000020 0.242764 2.433439
code Crc Crchf ... Cfp10 Cfp50 Cfp90
0 V3524010 0.208410 0.064490 ... 6.270661e-04 1.767450 27.806826
1 V3515010 0.139829 0.049087 ... 4.919724e-05 0.150414 5.161743
2 V3517010 0.139431 0.047900 ... 6.545733e-07 0.031947 1.355473
[3 rows x 9 columns]
Access specific simulated continuous signature for each gauge
>>> sign.cont["Crc"]
0 0.516206
1 0.509181s
2 0.514302
0 0.208410
1 0.139829
2 0.139431
Name: Crc, dtype: float64
Access all simulated continuous signatures for a single gauge
>>> sign.cont[sign.cont["code"] == "V3524010"]
code Crc Crchf ... Cfp10 Cfp50 Cfp90
0 V3524010 0.516206 0.191349 ... 1.1709 3.3225 42.631798
code Crc Crchf ... Cfp10 Cfp50 Cfp90
0 V3524010 0.20841 0.06449 ... 0.000627 1.76745 27.806826
[1 rows x 9 columns]
Access specific simulated continuous signatures for a single gauge
>>> sign.cont["Crc"][sign.cont["code"] == "V3524010"]
0 0.516206
0 0.20841
Name: Crc, dtype: float64
Use the `item <pandas.Series.item>` method to return the underlying data as a Python scalar
>>> sign.cont["Crc"][sign.cont["code"] == "V3524010"].item()
0.5162064433097839
0.20841039717197418
"""

cs, es, domain, event_seg = _standardize_signatures_args(sign, domain, event_seg)
Expand Down
Loading

0 comments on commit fad6dae

Please sign in to comment.