Skip to content

Commit

Permalink
Merge pull request #55 from Deltares/pyflwdir_v05
Browse files Browse the repository at this point in the history
compatibility with pyflwdir v0.5
  • Loading branch information
hboisgon authored Oct 4, 2021
2 parents a7a972d + b4cb668 commit 5a7d091
Show file tree
Hide file tree
Showing 25 changed files with 467 additions and 739 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ jobs:
- name: Setup environment
uses: conda-incubator/setup-miniconda@v2
with:
environment-file: envs/hydromt-wflow.yml
python-version: "3.9"
mamba-version: "*"
channels: conda-forge,defaults
channel-priority: true
environment-file: envs/hydromt-wflow.yml
activate-environment: hydromt-wflow

- name: Install hydromt-wflow
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ jobs:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
with:
environment-file: envs/test_env.yml
python-version: ${{ matrix.python-version }}
mamba-version: "*"
channels: conda-forge,defaults
channel-priority: true
environment-file: envs/test_env.yml
activate-environment: hydromt-wflow

- name: Conda info
Expand Down
13 changes: 0 additions & 13 deletions docs/_static/theme_overrides.css

This file was deleted.

18 changes: 18 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ The format is based on `Keep a Changelog`_, and this project adheres to
[Unreleased]
------------

Added
^^^^^

- write data_catalog with the used data when writting model
- tests on staticmaps dtype

Changed
^^^^^^^

- TOML files only contains reservoir/lake/glacier lines when they are setup and present in the model region.

Fixed
^^^^^
- pyflwdir v0.5 compatibility: changes from stream order bugfix and improved river slope
- Fixed docs with rtd v1.0
- Wrong dtype for wflow_gauges
- Removed uncesseray glacier/lake/reservoir lines from the TOML, fixes a bug if missing glacier

v0.1.2 (1 September 2021)
-------------------------
This release implements the new results attributes for Wflow.
Expand Down
6 changes: 1 addition & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
html_context = {
"css_files": [
"_static/theme_overrides.css",
], # override wide tables in RTD theme
}
html_context = {}

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
Expand Down
15 changes: 8 additions & 7 deletions examples/build_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@
"metadata": {},
"outputs": [],
"source": [
"fn_ini = 'wflow_build.ini'\n",
"with open(fn_ini, 'r') as f:\n",
"fn_ini = \"wflow_build.ini\"\n",
"with open(fn_ini, \"r\") as f:\n",
" txt = f.read()\n",
"print(txt)"
]
Expand Down Expand Up @@ -211,13 +211,14 @@
"outputs": [],
"source": [
"import os\n",
"root = 'wflow_test_full'\n",
"\n",
"root = \"wflow_test_full\"\n",
"for path, _, files in os.walk(root):\n",
" print(path)\n",
" for name in files:\n",
" if name.endswith('.xml'):\n",
" if name.endswith(\".xml\"):\n",
" continue\n",
" print(f' - {name}')"
" print(f\" - {name}\")"
]
},
{
Expand All @@ -240,7 +241,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -254,7 +255,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.2"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down
19 changes: 10 additions & 9 deletions examples/build_sediment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
"metadata": {},
"outputs": [],
"source": [
"fn_ini = 'wflow_sediment_build.ini'\n",
"with open(fn_ini, 'r') as f:\n",
"fn_ini = \"wflow_sediment_build.ini\"\n",
"with open(fn_ini, \"r\") as f:\n",
" txt = f.read()\n",
"print(txt)"
]
Expand Down Expand Up @@ -160,13 +160,14 @@
"outputs": [],
"source": [
"import os\n",
"root = 'wflow_test_sediment'\n",
"\n",
"root = \"wflow_test_sediment\"\n",
"for path, _, files in os.walk(root):\n",
" print(path)\n",
" for name in files:\n",
" if name.endswith('.xml'):\n",
" if name.endswith(\".xml\"):\n",
" continue\n",
" print(f' - {name}')"
" print(f\" - {name}\")"
]
},
{
Expand Down Expand Up @@ -213,8 +214,8 @@
"metadata": {},
"outputs": [],
"source": [
"fn_ini = 'wflow_extend_sediment.ini'\n",
"with open(fn_ini, 'r') as f:\n",
"fn_ini = \"wflow_extend_sediment.ini\"\n",
"with open(fn_ini, \"r\") as f:\n",
" txt = f.read()\n",
"print(txt)"
]
Expand Down Expand Up @@ -255,7 +256,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -269,7 +270,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.2"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down
40 changes: 17 additions & 23 deletions examples/clip_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"import matplotlib.pyplot as plt\n",
"import matplotlib as mpl\n",
"import cartopy.crs as ccrs\n",
"import descartes # required to plot polygons\n",
"import descartes # required to plot polygons\n",
"import cartopy.io.img_tiles as cimgt"
]
},
Expand All @@ -147,8 +147,8 @@
"outputs": [],
"source": [
"# Load both models with hydromt\n",
"mod0 = hydromt.WflowModel(root='wflow_piave_subbasin', mode='r')\n",
"mod1 = hydromt.WflowModel(root='wflow_test_clip', mode='r')"
"mod0 = hydromt.WflowModel(root=\"wflow_piave_subbasin\", mode=\"r\")\n",
"mod1 = hydromt.WflowModel(root=\"wflow_test_clip\", mode=\"r\")"
]
},
{
Expand All @@ -173,13 +173,13 @@
"metadata": {},
"outputs": [],
"source": [
"plt.style.use('seaborn-whitegrid') # set nice style\n",
"plt.style.use(\"seaborn-whitegrid\") # set nice style\n",
"# we assume the model maps are in the geographic CRS EPSG:4326\n",
"proj = ccrs.PlateCarree()\n",
"# adjust zoomlevel and figure size to your basis size & aspect\n",
"zoom_level = 10\n",
"figsize=(10, 8)\n",
"shaded= False\n",
"figsize = (10, 8)\n",
"shaded = False\n",
"\n",
"\n",
"# initialize image with geoaxes\n",
Expand All @@ -192,19 +192,13 @@
"ax.add_image(cimgt.QuadtreeTiles(), zoom_level, alpha=0.5)\n",
"\n",
"# plot rivers with increasing width with stream order\n",
"kwargs = dict()\n",
"for strord in np.unique(gdf_riv0['strord']):\n",
" if strord == np.unique(gdf_riv0['strord']).max():\n",
" kwargs.update(label='river')\n",
" gdf_riv0[gdf_riv0['strord']==strord].plot(ax=ax, linewidth=strord/5, color='blue', zorder=3, **kwargs)\n",
"kwargs = dict()\n",
"for strord in np.unique(gdf_riv1['strord']):\n",
" if strord == np.unique(gdf_riv1['strord']).max():\n",
" kwargs.update(label='river clip')\n",
" gdf_riv1[gdf_riv1['strord']==strord].plot(ax=ax, linewidth=strord/5, color='purple', zorder=3, **kwargs)\n",
"gdf_riv0.plot(ax=ax, lw=gdf_riv0[\"strord\"] / 2, color=\"blue\", zorder=3, label=\"river\")\n",
"gdf_riv1.plot(\n",
" ax=ax, lw=gdf_riv1[\"strord\"] / 2, color=\"purple\", zorder=3, label=\"river clip\"\n",
")\n",
"# plot the basin boundary\n",
"gdf_bas0.boundary.plot(ax=ax, color='k', linewidth=0.3, label='basin original')\n",
"gdf_bas1.boundary.plot(ax=ax, color='r', linewidth=0.5, label='basin clip')\n",
"gdf_bas0.boundary.plot(ax=ax, color=\"k\", linewidth=0.8, label=\"basin original\")\n",
"gdf_bas1.boundary.plot(ax=ax, color=\"r\", linewidth=0.8, label=\"basin clip\")\n",
"\n",
"ax.xaxis.set_visible(True)\n",
"ax.yaxis.set_visible(True)\n",
Expand All @@ -214,18 +208,18 @@
"legend = ax.legend(\n",
" handles=[*ax.get_legend_handles_labels()[0]],\n",
" title=\"Legend\",\n",
" loc='lower right',\n",
" loc=\"lower right\",\n",
" frameon=True,\n",
" framealpha=0.7,\n",
" edgecolor='k',\n",
" facecolor='white'\n",
" edgecolor=\"k\",\n",
" facecolor=\"white\",\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -239,7 +233,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.2"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down
38 changes: 19 additions & 19 deletions examples/convert_staticmaps_to_mapstack.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"source": [
"import pandas as pd\n",
"import xarray as xr\n",
"import numpy as np\n",
"import numpy as np\n",
"from os.path import join, dirname\n",
"import os\n",
"import hydromt"
Expand Down Expand Up @@ -62,9 +62,9 @@
"metadata": {},
"outputs": [],
"source": [
"root = 'wflow_piave_subbasin' \n",
"mod = hydromt.WflowModel(root, mode='r')\n",
"ds = mod.staticmaps # here the staticmaps netcdf is loaded \n",
"root = \"wflow_piave_subbasin\"\n",
"mod = hydromt.WflowModel(root, mode=\"r\")\n",
"ds = mod.staticmaps # here the staticmaps netcdf is loaded\n",
"print(ds)"
]
},
Expand All @@ -91,7 +91,7 @@
"metadata": {},
"outputs": [],
"source": [
"outdir =join(root, 'staticmaps')\n",
"outdir = join(root, \"staticmaps\")\n",
"ds.raster.to_mapstack(outdir)"
]
},
Expand Down Expand Up @@ -139,8 +139,8 @@
"outputs": [],
"source": [
"# read the original model\n",
"root = 'wflow_piave_subbasin' \n",
"mod = hydromt.WflowModel(root, mode='r')\n",
"root = \"wflow_piave_subbasin\"\n",
"mod = hydromt.WflowModel(root, mode=\"r\")\n",
"mod.read_staticmaps()\n",
"mod.read_config()"
]
Expand All @@ -154,8 +154,8 @@
"source": [
"# read the updated mapstack\n",
"# NOTE: The mapstack does not have to include all staticmaps, only the once that are found will be updated.\n",
"# The name of the staticmap should however have to be unchanged. \n",
"ds_updated = hydromt.open_mfraster(join(root, 'staticmaps', '*.tif'))"
"# The name of the staticmap should however have to be unchanged.\n",
"ds_updated = hydromt.open_mfraster(join(root, \"staticmaps\", \"*.tif\"))"
]
},
{
Expand All @@ -166,8 +166,8 @@
"outputs": [],
"source": [
"# change root to a new directory\n",
"root_updated = 'wflow_piave_subbasin_updated'\n",
"mod.set_root(root_updated, mode='w') "
"root_updated = \"wflow_piave_subbasin_updated\"\n",
"mod.set_root(root_updated, mode=\"w\")"
]
},
{
Expand Down Expand Up @@ -243,8 +243,8 @@
"outputs": [],
"source": [
"# read the original model\n",
"root = 'wflow_piave_subbasin' \n",
"mod = hydromt.WflowModel(root, mode='r+')\n",
"root = \"wflow_piave_subbasin\"\n",
"mod = hydromt.WflowModel(root, mode=\"r+\")\n",
"mod.read_staticmaps()\n",
"mod.read_config()"
]
Expand Down Expand Up @@ -276,8 +276,8 @@
"outputs": [],
"source": [
"# read the updated staticmaps\n",
"root = 'wflow_piave_subbasin' \n",
"mod = hydromt.WflowModel(root, mode='r')\n",
"root = \"wflow_piave_subbasin\"\n",
"mod = hydromt.WflowModel(root, mode=\"r\")\n",
"mod.read_staticmaps_pcr()\n",
"mod.read_config()"
]
Expand All @@ -290,8 +290,8 @@
"outputs": [],
"source": [
"# change root to a new directory\n",
"root_updated = 'wflow_piave_subbasin_updated'\n",
"mod.set_root(root_updated, mode='w')\n",
"root_updated = \"wflow_piave_subbasin_updated\"\n",
"mod.set_root(root_updated, mode=\"w\")\n",
"# re-generate the basins and rivers staticgeoms, for others (gauges, lakes, reservoirs, glaicers) use the hydromt update method\n",
"mod.basins\n",
"mod.rivers\n",
Expand All @@ -312,7 +312,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -326,7 +326,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.4"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 5a7d091

Please sign in to comment.