{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# SW_DutchCoast\n", "\n", "Validate MIKE 21 Spectral wave model for the Dutch coast." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "ename": "IndentationError", "evalue": "unindent does not match any outer indentation level (__init__.py, line 56)", "output_type": "error", "traceback": [ "Traceback \u001b[0;36m(most recent call last)\u001b[0m:\n", "\u001b[0m File \u001b[1;32m~/.local/lib/python3.11/site-packages/IPython/core/interactiveshell.py:3433\u001b[0m in \u001b[1;35mrun_code\u001b[0m\n exec(code_obj, self.user_global_ns, self.user_ns)\u001b[0m\n", "\u001b[0;36m Cell \u001b[0;32mIn[2], line 1\u001b[0;36m\n\u001b[0;31m import modelskill as ms\u001b[0;36m\n", "\u001b[0;36m File \u001b[0;32m~/src/modelskill/modelskill/__init__.py:56\u001b[0;36m\u001b[0m\n\u001b[0;31m return ComparerCollection.load(fn)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m unindent does not match any outer indentation level\n" ] } ], "source": [ "import modelskill as ms" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from matplotlib_inline.backend_inline import set_matplotlib_formats\n", "set_matplotlib_formats('png')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fn = '../tests/testdata/SW/HKZN_local_2017_DutchCoast.dfsu'\n", "mr = ms.ModelResult(fn, name='HKZN_local', item=0)\n", "mr.data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Define observations" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "o1 = ms.PointObservation('../tests/testdata/SW/HKNA_Hm0.dfs0', item=0, x=4.2420, y=52.6887, name=\"HKNA\")\n", "o2 = ms.PointObservation(\"../tests/testdata/SW/eur_Hm0.dfs0\", item=0, x=3.2760, y=51.9990, name=\"EPL\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "o1.plot.hist();" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "o1.plot(); " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "o3 = ms.TrackObservation(\"../tests/testdata/SW/Alti_c2_Dutch.dfs0\", item=3, name=\"c2\")\n", "o3.data.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ms.plotting.spatial_overview([o1, o2, o3], mr);" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ms.plotting.temporal_coverage([o1, o2, o3], mr);" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ms.plotting.temporal_coverage([o1, o2, o3], mr, limit_to_model_period=False);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Compare observations and model result" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cc = ms.compare([o1, o2, o3], mr)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Save the comparison to a file\n", "\n", "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.\n", "\n", "Each comparer can be saved as a NetCDF file, and a `ComparerCollection` can be saved as a zip file, preferably with the extension `.msk`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cc.save(\"SW_DutchCoast.msk\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cc2 = ms.load(\"SW_DutchCoast.msk\")\n", "cc2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cc.skill().style()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cc.save" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cc[\"c2\"].skill(metrics=\"mean_absolute_error\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cc[\"HKNA\"].plot.timeseries(figsize=(10,5));" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cc[\"HKNA\"].plot.timeseries(width=1000, backend=\"plotly\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cc[\"EPL\"].plot.scatter(figsize=(8,8), show_hist=True); " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cc[\"EPL\"].plot.scatter(show_hist=True, backend='plotly', width=600, height=600); #,xlim=[-1,11])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cc[\"c2\"].hist(bins=20);" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cc[\"HKNA\"].plot.scatter(bins=0.25, cmap=\"viridis\");" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.1" }, "vscode": { "interpreter": { "hash": "7aec4f91c09090e98e6ae8203c38529831bb4a3ce54cd1b69639b53cb01a6aa9" } } }, "nbformat": 4, "nbformat_minor": 4 }