import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib_inline.backend_inline import set_matplotlib_formats
set_matplotlib_formats('png')
%matplotlib inline
from mikeio.eum import EUMType, ItemInfo
from fmskill import ModelResult, TrackObservation, Connector
Run the download.ipynb first
fn = '../data/SW_gwm_3a_extracted_2018.dfs0'
mr = ModelResult(fn, name='GWM')
fn = '../data/altimetry_3a_2018_filter1.dfs0'
o1 = TrackObservation(fn, item=2, name='3a')
con = Connector(o1, mr[2])
cc = con.extract()
cc['3a'].skill(end='2018-1-15')
n | bias | rmse | urmse | mae | cc | si | r2 | |
---|---|---|---|---|---|---|---|---|
observation | ||||||||
3a | 372399 | -0.475266 | 0.633188 | 0.418388 | 0.510794 | 0.940363 | 0.116908 | 0.719939 |
cc['3a'].skill()
n | bias | rmse | urmse | mae | cc | si | r2 | |
---|---|---|---|---|---|---|---|---|
observation | ||||||||
3a | 9111762 | -0.490248 | 0.647898 | 0.42359 | 0.521119 | 0.942401 | 0.116337 | 0.719179 |
Spatial skill with 1 deg bins and default bin edges.
ss = cc.spatial_skill(metrics=['bias'], bins=(np.arange(-180,180,1), np.arange(-90,90,1)), n_min=20)
Add attrs and plot
ss.ds['bias'].attrs = dict(long_name="Bias of significant wave height, Hm0",units="m")
ss.ds['n'].attrs = dict(long_name="N of significant wave height",units="-")
fig, axes = plt.subplots(ncols=1, nrows=2, figsize = (8, 10))
ss.plot('n', ax=axes[0])
ss.plot('bias', ax=axes[1]);
Use all_df to obtain and df argument to pass customized data back to comparer.
all_df = cc.all_df.copy()
mean_val = all_df[['mod_val','obs_val']].mean(axis=1)
all_df['val_cat'] = pd.cut(mean_val,[0,2,5,np.inf],labels=["Hm0[m]=[0, 2)","Hm0[m]=[2, 5)","Hm0[m]=[5, inf)"])
all_df.head()
model | observation | x | y | mod_val | obs_val | xBin | yBin | val_cat | |
---|---|---|---|---|---|---|---|---|---|
datetime | |||||||||
2018-01-01 00:00:00 | GWM | 3a | -33.706020 | 23.181158 | 2.292599 | 2.611 | -33.5 | 23.5 | Hm0[m]=[2, 5) |
2018-01-01 00:00:01 | GWM | 3a | -33.720741 | 23.240074 | 2.292612 | 2.608 | -33.5 | 23.5 | Hm0[m]=[2, 5) |
2018-01-01 00:00:02 | GWM | 3a | -33.735474 | 23.298990 | 2.292624 | 2.518 | -33.5 | 23.5 | Hm0[m]=[2, 5) |
2018-01-01 00:00:03 | GWM | 3a | -33.750214 | 23.357904 | 2.292637 | 2.729 | -33.5 | 23.5 | Hm0[m]=[2, 5) |
2018-01-01 00:00:04 | GWM | 3a | -33.764965 | 23.416819 | 2.292650 | 2.593 | -33.5 | 23.5 | Hm0[m]=[2, 5) |
ss = cc.spatial_skill(df=all_df, by=["val_cat"], metrics=["bias"], bins=(np.arange(-180,180,5), np.arange(-90,90,5)), n_min=20)
ss.ds['bias'].attrs = dict(long_name="Bias of significant wave height, Hm0", units="m")
ss.ds['n'].attrs = dict(long_name="N of significant wave height", units="-")
ss.ds['val_cat'].attrs = dict(long_name="Range of sign. wave height, Hm0", units="m")
ss.plot('n', figsize=(12,4));
<xarray.plot.facetgrid.FacetGrid at 0x218e3400880>
ss.plot('bias', figsize=(12,4));
<xarray.plot.facetgrid.FacetGrid at 0x2189b8b1ee0>