Commit 0c8d660c authored by Thibault Hallouin's avatar Thibault Hallouin
Browse files

discard examples as now redundant with online docs

keeping them presents a high chance of them being outdated every other
time, so it is safer to rely only on the online docs as demonstration
No related merge requests found
Pipeline #38620 passed with stage
in 1 minute and 49 seconds
Showing with 0 additions and 518 deletions
+0 -518
%% Cell type:code id: tags:
``` python
import numpy
import evalhyd
```
%% Cell type:markdown id: tags:
## Calculate Nash-Sutcliffe efficiency on 1D arrays
%% Cell type:code id: tags:
``` python
# streamflow observations
obs = numpy.array(
[4.7, 4.3, 5.5, 2.7]
)
# streamflow predictions
prd = numpy.array(
[5.3, 4.2, 5.7, 2.3]
)
print(obs.shape, prd.shape)
```
%% Output
(4,) (4,)
%% Cell type:code id: tags:
``` python
nse, = evalhyd.evald(obs, prd, ['NSE'])
print(nse)
```
%% Output
[0.86298077]
%% Cell type:markdown id: tags:
## Calculate Nash-Sutcliffe efficiency on 2D arrays
%% Cell type:code id: tags:
``` python
# streamflow observations
obs = numpy.array(
[[4.7, 4.3, 5.5, 2.7]]
)
# streamflow predictions
prd = numpy.array(
[[5.3, 4.2, 5.7, 2.3],
[4.3, 4.2, 4.7, 4.3],
[5.3, 5.2, 5.7, 2.3]]
)
print(obs.shape, prd.shape)
```
%% Output
(1, 4) (3, 4)
%% Cell type:code id: tags:
``` python
nse, = evalhyd.evald(obs, prd, ['NSE'])
print(nse)
```
%% Output
[[0.86298077]
[0.18990385]
[0.67067308]]
%% Cell type:code id: tags:
``` python
import numpy
import pandas
import evalhyd
```
%% Cell type:markdown id: tags:
## Calculate Brier score and Brier skill score at once
%% Cell type:code id: tags:
``` python
# streamflow observations (1 site)
obs = numpy.array(
[[4.7, 4.3, 5.5, 2.7, 4.1]]
)
# streamflow predictions (1 site, 1 lead time, 3 forecast members)
prd = numpy.array(
[[[[5.3, 4.2, 5.7, 2.3, 3.1],
[4.3, 4.2, 4.7, 4.3, 3.3],
[5.3, 5.2, 5.7, 2.3, 3.9]]]]
)
# streamflow thresholds (2)
thr = [4., 5.]
print(obs.shape, prd.shape)
```
%% Output
(1, 5) (1, 1, 3, 5)
%% Cell type:code id: tags:
``` python
bs, bss = evalhyd.evalp(obs, prd, ['BS', 'BSS'], thr)
```
%% Cell type:code id: tags:
``` python
print(
pandas.DataFrame(
bs[0, 0, 0], [f"q > {thr[0]}", f"q > {thr[1]}"],
["Brier score"]
)
)
```
%% Output
Brier score
q > 4.0 0.222222
q > 5.0 0.133333
%% Cell type:code id: tags:
``` python
print(
pandas.DataFrame(
bss[0, 0, 0], [f"q > {thr[0]}", f"q > {thr[1]}"],
["Brier skill score"]
)
)
```
%% Output
Brier skill score
q > 4.0 -0.388889
q > 5.0 0.166667
%% Cell type:markdown id: tags:
## Calculate decompositions of Brier score
%% Cell type:code id: tags:
``` python
bs_crd, bs_lbd = evalhyd.evalp(obs, prd, ['BS_CRD', 'BS_LBD'], [4., 5.])
```
%% Cell type:markdown id: tags:
### calibration-refinement decomposition
%% Cell type:code id: tags:
``` python
print(
pandas.DataFrame(
bs_crd[0, 0, 0], [f"q > {thr[0]}", f"q > {thr[1]}"],
["reliability", "resolution", "uncertainty"]
)
)
```
%% Output
reliability resolution uncertainty
q > 4.0 0.222222 0.16 0.16
q > 5.0 0.033333 0.06 0.16
%% Cell type:markdown id: tags:
#### bs = rel - res + unc?
%% Cell type:code id: tags:
``` python
numpy.allclose(
bs, bs_crd[..., 0] - bs_crd[..., 1] + bs_crd[..., 2]
)
```
%% Output
True
%% Cell type:markdown id: tags:
### likelihood-base rate decomposition
%% Cell type:code id: tags:
``` python
print(
pandas.DataFrame(
bs_lbd[0, 0, 0], [f"q > {thr[0]}", f"q > {thr[1]}"],
["type 2 bias", "discrimination", "sharpness"]
)
)
```
%% Output
type 2 bias discrimination sharpness
q > 4.0 0.072222 0.027778 0.177778
q > 5.0 0.072222 0.027778 0.088889
%% Cell type:markdown id: tags:
#### bs = t2b - dis + shr?
%% Cell type:code id: tags:
``` python
numpy.allclose(
bs, bs_lbd[..., 0] - bs_lbd[..., 1] + bs_lbd[..., 2]
)
```
%% Output
True
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment