Skip to content

Commit

Permalink
Merge pull request #3 from DHI/use-watobs
Browse files Browse the repository at this point in the history
Use WatObs instead of FMskill.data
  • Loading branch information
jsmariegaard committed Jun 9, 2022
2 parents 2afb926 + 3223d42 commit 3dbd86d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 61 deletions.
2 changes: 1 addition & 1 deletion mini_book/exercises/exercise_track_observation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"\n",
"* [altimetry.dhigroup.com](https://altimetry.dhigroup.com/) \n",
"* The REST API (requires API key)\n",
"* fmskill.data.DHIAltimetryRepository (which wraps the REST API)"
"* watobs.DHIAltimetryRepository (which wraps the REST API)"
]
},
{
Expand Down
122 changes: 62 additions & 60 deletions mini_book/track_observations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Track observations\n",
"\n",
Expand All @@ -22,22 +23,22 @@
"* 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."
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"from fmskill import TrackObservation\n",
"from mikeio import eum"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Data from file\n",
"\n",
Expand All @@ -46,159 +47,160 @@
"**dfs0** files can be read directly by TrackObservation. \n",
"\n",
"**csv** files needs to be read by pandas first and passed to TrackObservation as a DataFrame. "
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"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",
"df.head()"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"o1 = TrackObservation(df, item=\"surface_elevation\") # step 2: create TrackObservation\n",
"o1"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## DHI Altimetry API\n",
"\n",
"See [Altimetry_data.ipynb](https://nbviewer.jupyter.org/github/DHI/fmskill/blob/main/notebooks/Altimetry_data.ipynb) example notebook.\n"
],
"metadata": {}
"You need to pip install \"watobs\" for this part!\n",
"\n",
"See [Altimetry_data.ipynb](https://nbviewer.jupyter.org/github/DHI/watobs/blob/main/notebooks/Altimetry_data.ipynb) example notebook.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from fmskill.data import DHIAltimetryRepository"
],
"outputs": [],
"metadata": {}
"from watobs import DHIAltimetryRepository"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"api_key = os.environ[\"DHI_ALTIMETRY_API_KEY\"]\n",
"repo = DHIAltimetryRepository(api_key)"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"repo.time_of_newest_data"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data = repo.get_altimetry_data(area=\"lon=2.9&lat=53.9&radius=100\", start_time=\"2019-10-1\", \n",
"end_time=\"2019-10-8\")\n",
"data.df.head()"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data.plot_map()"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"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"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Or you can save the data to a dfs0 first..."
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data.to_dfs0('alti_NS_20191001.dfs0')"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"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"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"o1.df[\"significant_wave_height\"].plot(marker='.')\n",
"o2.df[\"Significant Wave Height\"].plot();"
],
"outputs": [],
"metadata": {}
]
}
],
"metadata": {
"orig_nbformat": 4,
"interpreter": {
"hash": "fa576ebcd40e010bdc0ae86b06ce09151f3424f9e9aed6893ff04f39a9299d89"
},
"kernelspec": {
"display_name": "Python 3.8.10 64-bit ('base': conda)",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.8.10",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3.8.10 64-bit ('base': conda)"
"pygments_lexer": "ipython3",
"version": "3.8.10"
},
"interpreter": {
"hash": "fa576ebcd40e010bdc0ae86b06ce09151f3424f9e9aed6893ff04f39a9299d89"
}
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ xarray
mikeio
shapely
fmskill
watobs
geopandas
openpyxl

0 comments on commit 3dbd86d

Please sign in to comment.