import numpy as np
import modelskill as ms
fn = '../tests/testdata/SW/HKZN_local_2017_DutchCoast.dfsu'
mr = ms.model_result(fn, name='HKZN_local', item=0)
mr.data
Dfsu2D number of elements: 958 number of nodes: 570 projection: LONG/LAT number of items: 15 time: 23 steps with dt=10800.0s 2017-10-27 00:00:00 -- 2017-10-29 18:00:00
Configuration of comparison, see SW_DutchCoast.ipynb for more details.
o1 = ms.PointObservation('../tests/testdata/SW/HKNA_Hm0.dfs0', item=0, x=4.2420, y=52.6887, name="HKNA")
o2 = ms.PointObservation("../tests/testdata/SW/eur_Hm0.dfs0", item=0, x=3.2760, y=51.9990, name="EPL")
o3 = ms.TrackObservation("../tests/testdata/SW/Alti_c2_Dutch.dfs0", item=3, name="c2")
cc = ms.match([o1, o2, o3], mr)
cc
<ComparerCollection> Comparer: HKNA Comparer: EPL Comparer: c2
Standard set of metrics
cc.skill().style(precision=2)
n | bias | rmse | urmse | mae | cc | si | r2 | |
---|---|---|---|---|---|---|---|---|
observation | ||||||||
EPL | 67 | -0.07 | 0.22 | 0.21 | 0.19 | 0.97 | 0.08 | 0.93 |
HKNA | 386 | -0.19 | 0.35 | 0.29 | 0.25 | 0.97 | 0.09 | 0.91 |
c2 | 113 | -0.00 | 0.35 | 0.35 | 0.29 | 0.97 | 0.13 | 0.90 |
Select a specific metric
cc.skill(metrics="mean_absolute_error")
n | mean_absolute_error | |
---|---|---|
observation | ||
EPL | 67 | 0.188513 |
HKNA | 386 | 0.251839 |
c2 | 113 | 0.294585 |
Some metrics has parameters, which require a bit special treatment.
import modelskill.metrics as mtr
from modelskill.metrics import hit_ratio
def hit_ratio_05_pct(obs, model):
return hit_ratio(obs, model, 0.5) * 100
def hit_ratio_01_pct(obs, model):
return hit_ratio(obs, model, 0.1) * 100
mtr.add_metric(hit_ratio_05_pct)
mtr.add_metric(hit_ratio_01_pct)
cc.skill(metrics=[hit_ratio_05_pct, hit_ratio_01_pct]).style(precision=0)
n | hit_ratio_05_pct | hit_ratio_01_pct | |
---|---|---|---|
observation | |||
EPL | 67 | 99 | 27 |
HKNA | 386 | 87 | 30 |
c2 | 113 | 86 | 17 |
And you are of course always free to specify your own special metric.
def my_special_metric(obs, model):
res = obs - model
res_clipped = np.clip(res,0,np.inf)
return np.mean(np.abs(res_clipped))
mtr.add_metric(my_special_metric)
cc.skill(metrics=my_special_metric)
n | my_special_metric | |
---|---|---|
observation | ||
EPL | 67 | 0.127555 |
HKNA | 386 | 0.223049 |
c2 | 113 | 0.147897 |