Skip to content

Commit

Permalink
Update to match modelskill 1.0 beta
Browse files Browse the repository at this point in the history
  • Loading branch information
ecomodeller committed Dec 16, 2023
1 parent aa603fa commit e2ba9fd
Show file tree
Hide file tree
Showing 9 changed files with 2,648 additions and 1,463 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
jupyter-book build mini_book
4 changes: 2 additions & 2 deletions mini_book/exercises/modelskill_assignment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# FMskill assignment\n",
"# ModelSkill assignment\n",
"\n",
"You are working on a project modelling waves in the Southern North Sea. You have done 6 different calibration runs and want to choose the \"best\". You would also like to see how your best model is performing compared to a third-party model in NetCDF. \n",
"\n",
Expand Down Expand Up @@ -41,7 +41,7 @@
"outputs": [],
"source": [
"import fmskill\n",
"from fmskill import PointObservation, ModelResult, Connector"
"from ModelSkill import PointObservation, ModelResult, Connector"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions mini_book/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This course assumes that you have a working installation Python 3.8+.
2. (On PCs without MIKE Zero) Install [VC redist](https://aka.ms/vs/16/release/vc_redist.x64.exe)
3. Install matplotlib (`pip install matplotlib`)
4. Install netCDF4 (`pip install netCDF4`)
5. Install/upgrade FMSkill (`pip install --upgrade fmskill`)
5. Install/upgrade ModelSkill (`pip install --upgrade fmskill`)

You will need to code in either VS Code or Jupyter Lab in this course.

Expand Down Expand Up @@ -38,4 +38,4 @@ Can you say yes to the following questions?
* My pandas version is 1.0 or greater
* My matplotlib version is 3.2 or greater
* My MIKE IO version is 1.0 or greater
* My FMSkill version is 0.4 or greater
* My ModelSkill version is 0.4 or greater
341 changes: 113 additions & 228 deletions mini_book/model_skill.ipynb

Large diffs are not rendered by default.

60 changes: 20 additions & 40 deletions mini_book/model_skill_visualisation.ipynb

Large diffs are not rendered by default.

2,175 changes: 1,118 additions & 1,057 deletions mini_book/multi_model_comparison.ipynb

Large diffs are not rendered by default.

1,330 changes: 1,226 additions & 104 deletions mini_book/point_observations.ipynb

Large diffs are not rendered by default.

193 changes: 164 additions & 29 deletions mini_book/track_observations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@
"* data type (e.g. water level)\n",
"* unit (e.g. meter)\n",
"\n",
"FMskill is agnostic to the coordinate reference system (CRS) and it is therefore the responsibility of the user to make sure that all data (observations and model) use the same CRS."
"ModelSkill is agnostic to the coordinate reference system (CRS) and it is therefore the responsibility of the user to make sure that all data (observations and model) use the same CRS."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"from modelskillill import TrackObservation\n",
"from mikeio import eum"
"import modelskill as ms"
]
},
{
Expand All @@ -51,9 +50,113 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>lon</th>\n",
" <th>lat</th>\n",
" <th>surface_elevation</th>\n",
" <th>significant_wave_height</th>\n",
" <th>wind_speed</th>\n",
" </tr>\n",
" <tr>\n",
" <th>date</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2017-10-26 04:37:37</th>\n",
" <td>8.757272</td>\n",
" <td>53.926136</td>\n",
" <td>1.6449</td>\n",
" <td>0.426</td>\n",
" <td>6.100000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2017-10-26 04:37:54</th>\n",
" <td>8.221631</td>\n",
" <td>54.948459</td>\n",
" <td>1.1200</td>\n",
" <td>1.634</td>\n",
" <td>9.030000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2017-10-26 04:37:55</th>\n",
" <td>8.189390</td>\n",
" <td>55.008547</td>\n",
" <td>1.0882</td>\n",
" <td>1.717</td>\n",
" <td>9.370000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2017-10-26 04:37:56</th>\n",
" <td>8.157065</td>\n",
" <td>55.068627</td>\n",
" <td>1.0309</td>\n",
" <td>1.869</td>\n",
" <td>9.559999</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2017-10-26 04:37:58</th>\n",
" <td>8.124656</td>\n",
" <td>55.128700</td>\n",
" <td>1.0369</td>\n",
" <td>1.939</td>\n",
" <td>9.980000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" lon lat surface_elevation \\\n",
"date \n",
"2017-10-26 04:37:37 8.757272 53.926136 1.6449 \n",
"2017-10-26 04:37:54 8.221631 54.948459 1.1200 \n",
"2017-10-26 04:37:55 8.189390 55.008547 1.0882 \n",
"2017-10-26 04:37:56 8.157065 55.068627 1.0309 \n",
"2017-10-26 04:37:58 8.124656 55.128700 1.0369 \n",
"\n",
" significant_wave_height wind_speed \n",
"date \n",
"2017-10-26 04:37:37 0.426 6.100000 \n",
"2017-10-26 04:37:54 1.634 9.030000 \n",
"2017-10-26 04:37:55 1.717 9.370000 \n",
"2017-10-26 04:37:56 1.869 9.559999 \n",
"2017-10-26 04:37:58 1.939 9.980000 "
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fn = \"data/SW/altimetry_NorthSea_20171027.csv\"\n",
"df = pd.read_csv(fn, index_col=0, parse_dates=True) # step 1: create DataFrame\n",
Expand All @@ -62,11 +165,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/jan/src/book-learn-mikeio-fmskill/.venv/lib/python3.10/site-packages/modelskill/timeseries/_track.py:135: UserWarning: Removed 22 duplicate timestamps with keep=first\n",
" warnings.warn(\n"
]
},
{
"data": {
"text/plain": [
"TrackObservation: surface_elevation, n=1093"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"o1 = TrackObservation(df, item=\"surface_elevation\") # step 2: create TrackObservation\n",
"o1 = ms.TrackObservation(df, item=\"surface_elevation\") # step 2: create TrackObservation\n",
"o1"
]
},
Expand All @@ -83,7 +205,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -93,9 +215,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "KeyError",
"evalue": "'DHI_ALTIMETRY_API_KEY'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[7], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m api_key \u001b[38;5;241m=\u001b[39m \u001b[43mos\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43menviron\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mDHI_ALTIMETRY_API_KEY\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\n\u001b[1;32m 2\u001b[0m repo \u001b[38;5;241m=\u001b[39m DHIAltimetryRepository(api_key)\n",
"File \u001b[0;32m/usr/lib/python3.10/os.py:680\u001b[0m, in \u001b[0;36m_Environ.__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 677\u001b[0m value \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_data[\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mencodekey(key)]\n\u001b[1;32m 678\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m:\n\u001b[1;32m 679\u001b[0m \u001b[38;5;66;03m# raise KeyError with the original key value\u001b[39;00m\n\u001b[0;32m--> 680\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 681\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdecodevalue(value)\n",
"\u001b[0;31mKeyError\u001b[0m: 'DHI_ALTIMETRY_API_KEY'"
]
}
],
"source": [
"api_key = os.environ[\"DHI_ALTIMETRY_API_KEY\"]\n",
"repo = DHIAltimetryRepository(api_key)"
Expand Down Expand Up @@ -132,12 +267,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "NameError",
"evalue": "name 'data' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[8], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m o1 \u001b[38;5;241m=\u001b[39m ms\u001b[38;5;241m.\u001b[39mTrackObservation(\u001b[43mdata\u001b[49m\u001b[38;5;241m.\u001b[39mdf, item\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msignificant_wave_height\u001b[39m\u001b[38;5;124m\"\u001b[39m, name\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mAlti_from_df\u001b[39m\u001b[38;5;124m'\u001b[39m, quantity\u001b[38;5;241m=\u001b[39mms\u001b[38;5;241m.\u001b[39mQuantity(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSignificant wave height\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mm\u001b[39m\u001b[38;5;124m\"\u001b[39m))\n\u001b[1;32m 2\u001b[0m o1\n",
"\u001b[0;31mNameError\u001b[0m: name 'data' is not defined"
]
}
],
"source": [
"o1 = TrackObservation(data.df, item=\"significant_wave_height\", name='Alti_from_df')\n",
"o1.itemInfo = eum.ItemInfo(eum.EUMType.Significant_wave_height)\n",
"o1 = ms.TrackObservation(data.df, item=\"significant_wave_height\", name='Alti_from_df', quantity=ms.Quantity(\"Significant wave height\", \"m\"))\n",
"o1"
]
},
Expand All @@ -163,20 +309,9 @@
"metadata": {},
"outputs": [],
"source": [
"o2 = TrackObservation('alti_NS_20191001.dfs0', item=\"Significant Wave Height\")\n",
"o2.itemInfo = eum.ItemInfo(eum.EUMType.Significant_wave_height)\n",
"o2 = ms.TrackObservation('alti_NS_20191001.dfs0', item=\"Significant Wave Height\", quantity=ms.Quantity(\"Significant wave height\", \"m\")\n",
"o2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"o1.df[\"significant_wave_height\"].plot(marker='.')\n",
"o2.df[\"Significant Wave Height\"].plot();"
]
}
],
"metadata": {
Expand All @@ -197,7 +332,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.10.12"
},
"orig_nbformat": 4
},
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ netcdf4
xarray
mikeio
shapely
modelskill
modelskill>=1.0.b.*
watobs
geopandas
openpyxl

0 comments on commit e2ba9fd

Please sign in to comment.