#!/usr/bin/env python # coding: utf-8 # # Metocean MIKE21SW DutchCoast # # Validate MIKE 21 Spectral wave model for the Dutch coast. # # Including saving comparison collection to disk and loading again. # In[1]: import os from matplotlib_inline.backend_inline import set_matplotlib_formats set_matplotlib_formats('png') import modelskill as ms # In[2]: fn = '../tests/testdata/SW/HKZN_local_2017_DutchCoast.dfsu' mr = ms.model_result(fn, name='HKZN_local', item=0) mr.data # ## Define observations # In[3]: 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") # In[4]: o1.plot.hist(); # In[5]: o1.plot(); # In[6]: o3 = ms.TrackObservation("../tests/testdata/SW/Alti_c2_Dutch.dfs0", item=3, name="c2") o3.data.head() # In[7]: ms.plotting.spatial_overview([o1, o2, o3], mr); # In[8]: ms.plotting.temporal_coverage([o1, o2, o3], mr); # In[9]: ms.plotting.temporal_coverage([o1, o2, o3], mr, limit_to_model_period=False); # ## Compare observations and model result # In[10]: cc = ms.match([o1, o2, o3], mr) # # Save the comparison to a file # # Extracting model results¶ can be a time-consuming process. Therefore, it is recommended to save the results to a file. This can be done using the save method of the comparison object. # # Each comparer can be saved as a NetCDF file, and a `ComparerCollection` can be saved as a zip file, preferably with the extension `.msk`. # In[11]: cc.save("SW_DutchCoast.msk") # In[12]: cc2 = ms.load("SW_DutchCoast.msk") cc2 # In[13]: cc.skill().style() # In[14]: cc["c2"].skill(metrics="mean_absolute_error") # In[15]: cc["HKNA"].plot.timeseries(figsize=(10,5)); # In[16]: cc["HKNA"].plot.timeseries(width=1000, backend="plotly") # In[17]: cc["EPL"].plot.scatter(figsize=(8,8), show_hist=True); # In[18]: cc["EPL"].plot.scatter(show_hist=True, backend='plotly', width=600, height=600); #,xlim=[-1,11]) # In[19]: cc["c2"].plot.hist(bins=20); # In[20]: cc["HKNA"].plot.scatter(bins=0.25, cmap="viridis"); # ### Clean up # In[21]: os.remove("SW_DutchCoast.msk")