%load_ext autoreload
%autoreload 2
import numpy as np
from fmskill import PointObservation, TrackObservation
from fmskill import ModelResult, Connector
import matplotlib.pyplot as plt
from matplotlib_inline.backend_inline import set_matplotlib_formats
set_matplotlib_formats('png')
%matplotlib inline
fn = '../tests/testdata/SW/HKZN_local_2017_DutchCoast.dfsu'
mr = ModelResult(fn, name='HKZN_local', item=0)
mr.dfs
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
o1 = PointObservation('../tests/testdata/SW/HKNA_Hm0.dfs0', item=0, x=4.2420, y=52.6887, name="HKNA")
o2 = PointObservation("../tests/testdata/SW/eur_Hm0.dfs0", item=0, x=3.2760, y=51.9990, name="EPL")
o1.hist();
o1.plot();
o3 = TrackObservation("../tests/testdata/SW/Alti_c2_Dutch.dfs0", item=3, name="c2")
o3.df.head()
Longitude | Latitude | swh | |
---|---|---|---|
2017-10-27 12:52:52.337 | 2.422854 | 51.253353 | 1.638 |
2017-10-27 12:52:53.280 | 2.413789 | 51.310268 | 1.383 |
2017-10-27 12:52:54.224 | 2.404711 | 51.367184 | 1.791 |
2017-10-27 12:52:55.167 | 2.395619 | 51.424099 | 1.700 |
2017-10-27 12:52:56.111 | 2.386516 | 51.481014 | 1.800 |
con = Connector([o1, o2, o3], mr)
con.observations
{'HKNA': PointObservation: HKNA, x=4.242, y=52.6887, 'EPL': PointObservation: EPL, x=3.276, y=51.999, 'c2': TrackObservation: c2, n=298}
con.plot_observation_positions();
cc = con.extract()
cc
<ComparerCollection> PointComparer: HKNA PointComparer: EPL TrackComparer: c2
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.12 | 0.90 |
cc["c2"].skill(metrics="mean_absolute_error")
n | mean_absolute_error | |
---|---|---|
observation | ||
c2 | 113 | 0.294585 |
cc["HKNA"].plot_timeseries(figsize=(10,5));
cc["HKNA"].plot_timeseries(width=1000,backend="plotly")
cc["EPL"].scatter(figsize=(8,8), show_hist=True) #, ylim=[2,8], xlim=[1,10])
cc["EPL"].scatter(show_hist=True, backend='plotly', width=600, height=600) #,xlim=[-1,11])
cc["c2"].hist(bins=20)
cc["HKNA"].scatter(binsize=0.25, cmap="viridis")
con.plot_temporal_coverage();
con.plot_temporal_coverage(limit_to_model_period=False);
from fmskill.report import Reporter
rep = Reporter(con)
%%capture
rep.to_markdown();