#!/usr/bin/env python # coding: utf-8 # # Multi variable comparison # Assessing both wave height and wind speed at the same time # In[1]: import matplotlib.pyplot as plt import pandas as pd import numpy as np from fmskill import ModelResult, PointObservation, TrackObservation, Connector # In[2]: get_ipython().run_line_magic('load_ext', 'autoreload') get_ipython().run_line_magic('autoreload', '2') get_ipython().run_line_magic('matplotlib', 'inline') # ## Define observations # Below, the observations will take the default variable names from the eum type of the item. Alternatively, the user can give another variable name by providing the `variable_name` argument. # In[3]: # wave height o1 = PointObservation('../tests/testdata/SW/HKNA_Hm0.dfs0', item=0, x=4.2420, y=52.6887, name="HKNA_Hm0") o2 = PointObservation("../tests/testdata/SW/eur_Hm0.dfs0", item=0, x=3.2760, y=51.9990, name="EPL_Hm0") o3 = TrackObservation("../tests/testdata/SW/Alti_c2_Dutch.dfs0", item=3, name="c2_Hm0") # wind speed wind1 = PointObservation('../tests/testdata/SW/HKNA_wind.dfs0', item=0, x=4.2420, y=52.6887, name="HKNA_wind") wind2 = PointObservation('../tests/testdata/SW/F16_wind.dfs0', item=0, x=4.01222, y=54.1167, name="F16_wind") wind3 = TrackObservation("../tests/testdata/SW/Alti_c2_Dutch.dfs0", item=2, name="c2_wind") # In[4]: o1.variable_name # ## Define model results # Two different model results are defined. # In[5]: mr1 = ModelResult('../tests/testdata/SW/HKZN_local_2017_DutchCoast.dfsu', name='SW_1') mr2 = ModelResult('../tests/testdata/SW/HKZN_local_2017_DutchCoast_v2.dfsu', name='SW_2') # In[6]: mr1.dfs.items # ## Connect model and observations and extract # We connect the observation item and model item by refering to the item name in the ModelResult. Item number can also be used. # In[7]: con = Connector() con.add([o1, o2, o3], [mr1['Sign. Wave Height'], mr2['Sign. Wave Height']]) con.add([wind1, wind2, wind3], [mr1['Wind speed'], mr2['Wind speed']]) con # In[8]: cc = con.extract() # In[9]: cc.n_variables # In[10]: cc.var_names # ## Analysis # Now that the result has been extracted, we can do analysis. Multiple variables means an extra level in the multi-index of the skill dataframe. # In[11]: s = cc.skill() s.round(3) # In[12]: s.index.names # In[13]: s = cc.skill(variable='Significant_wave_height') s.style() # In[14]: s.sel(observation='c2_Hm0').style(columns='rmse') # In[15]: s.plot_line('rmse', ylabel='Hm0 RMSE [m]'); # In[16]: cc.scatter(model=1) # ## mean skill # The `mean_skill()` method will return a weighted average of the skill score per model and variable. You can get the "normal" mean_skill (per model) by selecting a specific variable either by id or name. # In[17]: s = cc.mean_skill() s # In[18]: s.plot_bar('si', title='scatter index'); # In[19]: cc.mean_skill(model='SW_2') # In[20]: cc.mean_skill(variable='Significant_wave_height').style(columns=[]) # ## score # In[21]: cc.score() # In[22]: cc.score(model='SW_1') # In[23]: cc.score(variable='Wind_speed') # In[ ]: