{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Gridded NetCDF modelresults\n", "\n", "2D modelresults stored in NetCDF or Grib can be loaded to ModelSkill using xarray. In this way, MIKE 21 modelresults in dfsu format can easily be compared to model results from third party providers often stored in NetCDF. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import xarray as xr\n", "import modelskill as ms" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Observations" ] }, { "cell_type": "code", "execution_count": 2, "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\")\n", "o3 = ms.TrackObservation(\"../tests/testdata/SW/Alti_c2_Dutch.dfs0\", item=3, name=\"c2\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## MIKE ModelResult" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "mrMIKE = ms.model_result('../tests/testdata/SW/HKZN_local_2017_DutchCoast.dfsu', name='MIKE21SW', item=0)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## NetCDF ModelResult" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
"Dimensions: (longitude: 20, latitude: 11, time: 67)\n",
"Coordinates:\n",
" * longitude (longitude) float32 -1.0 -0.5 0.0 0.5 1.0 ... 6.5 7.0 7.5 8.0 8.5\n",
" * latitude (latitude) float32 55.0 54.5 54.0 53.5 ... 51.5 51.0 50.5 50.0\n",
" * time (time) datetime64[ns] 2017-10-27 ... 2017-10-29T18:00:00\n",
"Data variables:\n",
" mwd (time, latitude, longitude) float32 ...\n",
" mwp (time, latitude, longitude) float32 ...\n",
" mp2 (time, latitude, longitude) float32 ...\n",
" pp1d (time, latitude, longitude) float32 ...\n",
" swh (time, latitude, longitude) float32 ...\n",
"Attributes:\n",
" Conventions: CF-1.6\n",
" history: 2021-06-07 12:25:02 GMT by grib_to_netcdf-2.16.0: /opt/ecmw...<xarray.DataArray 'swh' (time: 67, y: 11, x: 20)>\n",
"[14740 values with dtype=float32]\n",
"Coordinates:\n",
" * x (x) float32 -1.0 -0.5 0.0 0.5 1.0 1.5 ... 6.0 6.5 7.0 7.5 8.0 8.5\n",
" * y (y) float32 55.0 54.5 54.0 53.5 53.0 52.5 52.0 51.5 51.0 50.5 50.0\n",
" * time (time) datetime64[ns] 2017-10-27 ... 2017-10-29T18:00:00\n",
"Attributes:\n",
" units: m\n",
" long_name: Significant height of combined wind waves and swell<xarray.Dataset>\n",
"Dimensions: (time: 5)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2017-10-27 ... 2017-10-27T04:00:00\n",
" x float64 4.242\n",
" y float64 52.69\n",
" z object None\n",
"Data variables:\n",
" ERA5 (time) float32 1.22 1.347 1.466 1.612 1.793\n",
"Attributes:\n",
" gtype: point\n",
" modelskill_version: 1.0.a2<xarray.Dataset>\n",
"Dimensions: (time: 5)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2017-10-27T12:52:52.337000 ... 2017-10-27T...\n",
" x (time) float64 2.423 2.414 2.405 2.396 2.387\n",
" y (time) float64 51.25 51.31 51.37 51.42 51.48\n",
" z float64 nan\n",
"Data variables:\n",
" ERA5 (time) float64 1.439 1.464 1.489 1.514 1.538\n",
"Attributes:\n",
" gtype: track\n",
" modelskill_version: 1.0.a2| \n", " | \n", " | n | \n", "bias | \n", "rmse | \n", "urmse | \n", "mae | \n", "cc | \n", "si | \n", "r2 | \n", "
|---|---|---|---|---|---|---|---|---|---|
| observation | \n", "model | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
| EPL | \n", "CMEMS | \n", "43 | \n", "-0.441 | \n", "0.519 | \n", "0.273 | \n", "0.443 | \n", "0.920 | \n", "0.090 | \n", "0.445 | \n", "
| ERA5 | \n", "43 | \n", "-0.247 | \n", "0.335 | \n", "0.226 | \n", "0.269 | \n", "0.948 | \n", "0.074 | \n", "0.769 | \n", "|
| MIKE21SW | \n", "43 | \n", "-0.078 | \n", "0.205 | \n", "0.189 | \n", "0.174 | \n", "0.973 | \n", "0.062 | \n", "0.913 | \n", "|
| HKNA | \n", "CMEMS | \n", "242 | \n", "-0.742 | \n", "0.882 | \n", "0.476 | \n", "0.742 | \n", "0.903 | \n", "0.128 | \n", "0.222 | \n", "
| ERA5 | \n", "242 | \n", "-0.551 | \n", "0.654 | \n", "0.352 | \n", "0.556 | \n", "0.954 | \n", "0.094 | \n", "0.572 | \n", "|
| MIKE21SW | \n", "242 | \n", "-0.230 | \n", "0.411 | \n", "0.341 | \n", "0.296 | \n", "0.949 | \n", "0.092 | \n", "0.831 | \n", "|
| c2 | \n", "CMEMS | \n", "33 | \n", "-0.295 | \n", "0.480 | \n", "0.379 | \n", "0.406 | \n", "0.903 | \n", "0.092 | \n", "0.438 | \n", "
| ERA5 | \n", "33 | \n", "-0.529 | \n", "0.628 | \n", "0.338 | \n", "0.547 | \n", "0.906 | \n", "0.082 | \n", "0.038 | \n", "|
| MIKE21SW | \n", "33 | \n", "0.325 | \n", "0.416 | \n", "0.259 | \n", "0.363 | \n", "0.920 | \n", "0.063 | \n", "0.578 | \n", "
| \n", " | n | \n", "bias | \n", "rmse | \n", "urmse | \n", "mae | \n", "cc | \n", "si | \n", "r2 | \n", "
|---|---|---|---|---|---|---|---|---|
| model | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
| CMEMS | \n", "318 | \n", "-0.493 | \n", "0.627 | \n", "0.376 | \n", "0.530 | \n", "0.909 | \n", "0.103 | \n", "0.368 | \n", "
| ERA5 | \n", "318 | \n", "-0.442 | \n", "0.539 | \n", "0.305 | \n", "0.457 | \n", "0.936 | \n", "0.084 | \n", "0.460 | \n", "
| MIKE21SW | \n", "318 | \n", "0.006 | \n", "0.344 | \n", "0.263 | \n", "0.277 | \n", "0.947 | \n", "0.072 | \n", "0.774 | \n", "