<jupyter_start><jupyter_text>Track ComparisonAnd spatial skill assessments<jupyter_code>import pandas as pd
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<jupyter_output><empty_output><jupyter_text>Extract track without having observation as dfs0<jupyter_code>fn = '../tests/testdata/NorthSeaHD_and_windspeed.dfsu'
mr = ModelResult(fn, name='HD', item=0)
mr
fn = '../tests/testdata/altimetry_NorthSea_20171027.csv'
df = pd.read_csv(fn, index_col=0, parse_dates=True)
o1 = TrackObservation(df, item=2, name='alti')
o1.itemInfo = ItemInfo(EUMType.Surface_Elevation)    # if TrackObservation is created with a df, itemInfo needs to be added manually
con = Connector(o1, mr)
con
con.plot_observation_positions();
cc = con.extract()
cc['alti'].scatter()<jupyter_output><empty_output><jupyter_text>Extract track from dfs0ModelResult is now a dfs0<jupyter_code>fn = '../tests/testdata/NorthSeaHD_extracted_track.dfs0'
mr = ModelResult(fn, name='HD', item=2)
mr.dfs
mr.dfs.read()
fn = '../tests/testdata/altimetry_NorthSea_20171027.csv'
df = pd.read_csv(fn, index_col=0, parse_dates=True)
o1 = TrackObservation(df, item=2, name='alti')
o1.geometry
con = Connector(o1, mr)
cc = con.extract()
cc['alti'].scatter()<jupyter_output><empty_output><jupyter_text>Spatial skillLoad model, load observation, add observation to model and extract.<jupyter_code>fn = '../tests/testdata/NorthSeaHD_and_windspeed.dfsu'
mr = ModelResult(fn, name='HD', item=0)
fn = '../tests/testdata/altimetry_NorthSea_20171027.csv'
df = pd.read_csv(fn, index_col=0, parse_dates=True)
o1 = TrackObservation(df, item=2, name='alti')
con = Connector(o1, mr)
cc = con.extract()<jupyter_output>c:\users\jem\source\fmskill\fmskill\utils.py:38: UserWarning: Time axis has duplicate entries. Now adding milliseconds to non-unique entries to make index unique.
  warnings.warn(<jupyter_text>Get metrics binned by a regular spatial grid, returns xarray Dataset<jupyter_code>ss = cc.spatial_skill(metrics=['bias'])
ss.ds['n']<jupyter_output><empty_output><jupyter_text>Plot using xarray - convenient methods coming soon!<jupyter_code>fig, axes = plt.subplots(ncols=2, nrows=1, figsize = (10, 5))
ss.plot('n', ax=axes[0])
ss.plot('bias', ax=axes[1]);<jupyter_output><empty_output><jupyter_text>Minimum number of observations<jupyter_code>ss = cc.spatial_skill(metrics=['bias'], n_min=25)
fig, axes = plt.subplots(ncols=2, nrows=1, figsize=(10, 5))
ss.plot('n', ax=axes[0])
ss.plot('bias', ax=axes[1]);<jupyter_output><empty_output><jupyter_text>Multiple bins - spatial skill for water level categoriesAdd water level category to comparer's all_df.<jupyter_code>all_df = cc.all_df
all_df['water level'] = 'high'
all_df.loc[all_df['mod_val']<0, 'water level'] = 'low'<jupyter_output><empty_output><jupyter_text>Pass custom df with water level category to .spatial_skill and select for 'by'.<jupyter_code>ss = cc.spatial_skill(by=['water level'],metrics=['bias'],n_min=5)
ss.plot('n');
ss.plot('bias');<jupyter_output><empty_output><jupyter_text>Multiple observationsAdd fake 2nd observation to model<jupyter_code>df2 = df.copy()
df2['surface_elevation'] = df2['surface_elevation'] - 0.2
o2 = TrackObservation(df2, item=2, name='alti2')
con.add(o2, mr)<jupyter_output>c:\users\jem\source\fmskill\fmskill\utils.py:38: UserWarning: Time axis has duplicate entries. Now adding milliseconds to non-unique entries to make index unique.
  warnings.warn(<jupyter_text>Extract, spatial skill, add attrs, plot.<jupyter_code>cc = con.extract()
ss = cc.spatial_skill(metrics=['bias'],n_min=20)
ss.ds['bias'].attrs = dict(long_name="Bias of surface elevation",units="m")
ss.plot('bias', figsize=(10,5));<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14049586776859505, 'fraction_numerical': 0.021435950413223142, 'mean_word_length': 7.88302752293578, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '640218', 'license': 'MIT', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1428, 'n_words': 281, 'path': 'notebooks/Track_comparison.ipynb', 'repo_name': 'caichac-dhi/fmskill', 'size': '3872'}