Skip to content

Commit

Permalink
Merge pull request #114 from Deltares/update_notebooks
Browse files Browse the repository at this point in the history
Update notebooks
  • Loading branch information
hboisgon committed Oct 18, 2022
2 parents 703eb86 + 24d88ab commit 94842f2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -63,7 +63,7 @@ happy to discuss how it can be implemented for your model.
:target: https://pypi.org/project/hydromt_wflow/
:alt: PyPI

.. |conda_forge| image:: https://anaconda.org/conda-forge/hydromt_wflow/badges/installer/conda.svg
.. |conda_forge| image:: https://anaconda.org/conda-forge/hydromt_wflow/badges/version.svg
:target: https://anaconda.org/conda-forge/hydromt_wflow
:alt: Conda-Forge

Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Expand Up @@ -21,6 +21,8 @@ Fixed
- write_forcing with time of type cftime.DatetimeNoLeap #109
- bug in setup_gauges in update mode with crs.is_epsg_code #108
- bug in self.rivers if no staticgeoms and rivmsk is found #113
- bug in wflow_build_sediment.ini template in examples
- temporary fix to update staticgeoms basins+rivers in clip_staticmaps (update when moving away from deprecated staticgeoms).

Deprecated
----------
Expand Down
11 changes: 6 additions & 5 deletions examples/build_model.ipynb
Expand Up @@ -47,7 +47,8 @@
"metadata": {},
"outputs": [],
"source": [
"# this should return \"wflow, wflow_sediment\"\n",
"# this should return \"wflow, wflow_sediment\" \n",
"# as well as the generic HydroMT models \"grid_model, lumped_model, network_model, (mesh_model)\"\n",
"!hydromt --models"
]
},
Expand Down Expand Up @@ -158,9 +159,9 @@
"source": [
"The `<...>_fn` arguments correspond to a data source from the `DataCatalog` which is based on a yml-file with references to the data paths/urls and how the data should be read. This file can be provided to hydromt using `-d <path_to_yml_file>`. \n",
"\n",
"By default some example data for the Piave basin will be downloaded to `~/.hydromt_data/` which is also used for this example. An overview of the available example data is provided [here](https://deltares.github.io/hydromt/latest/user_guide/data_existing_cat.html)\n",
"This example data is a based on the data which available from the Deltares p-drive. \n",
"If you have acces to this drive, a pre-configured catalog file can be loaded using the `--dd` flag. \n",
"By default, the pre-defined `artifact_data` catalog containing some example data for the Piave basin will be downloaded to `~/.hydromt_data/` which is also used for this example. An overview of the available example data is provided [here](https://deltares.github.io/hydromt/latest/user_guide/data_existing_cat.html)\n",
"This example data is a based on the data which is available from the Deltares p-drive. \n",
"If you have acces to this drive, a pre-configured catalog file can be loaded using the `-d deltares_data` pre-defined catalog. \n",
"\n",
"More background how to write a data catalog yml file can be found in the [HydroMT core docs](https://deltares.github.io/hydromt/latest/user_guide/data_prepare_cat.html) "
]
Expand All @@ -183,7 +184,7 @@
"outputs": [],
"source": [
"# NOTE: copy this line (without !) to your shell for more direct feedback\n",
"!hydromt build wflow \"./wflow_test_full\" \"{'subbasin': [12.2051, 45.8331], 'strord': 4, 'bounds': [11.70, 45.35, 12.95, 46.70]}\" -r 0.00833 -i wflow_build.ini -vv"
"!hydromt build wflow \"./wflow_test_full\" \"{'subbasin': [12.2051, 45.8331], 'strord': 4, 'bounds': [11.70, 45.35, 12.95, 46.70]}\" -r 0.00833 -i wflow_build.ini -d artifact_data -vv"
]
},
{
Expand Down
9 changes: 6 additions & 3 deletions examples/build_sediment.ipynb
Expand Up @@ -48,6 +48,7 @@
"outputs": [],
"source": [
"# this should return \"wflow, wflow_sediment\"\n",
"# as well as hydromt generic models \"grid_model, lumped_model, network_model (mesh_model)\"\n",
"!hydromt --models"
]
},
Expand Down Expand Up @@ -126,7 +127,7 @@
"outputs": [],
"source": [
"# NOTE: copy this line (without !) to your shell for more direct feedback\n",
"!hydromt build wflow_sediment \"./wflow_test_sediment\" \"{'subbasin': [12.2051, 45.8331], 'strord': 4, 'bounds': [11.70, 45.35, 12.95, 46.70]}\" -r 0.00833 -i wflow_sediment_build.ini -vv"
"!hydromt build wflow_sediment \"./wflow_test_sediment\" \"{'subbasin': [12.2051, 45.8331], 'strord': 4, 'bounds': [11.70, 45.35, 12.95, 46.70]}\" -r 0.00833 -i wflow_sediment_build.ini -d artifact_data -vv"
]
},
{
Expand All @@ -140,7 +141,8 @@
"* `./wflow_test_sediment` : output model folder\n",
"* `\"{'subbasin': [12.2051, 45.8331], 'strord': 4, 'bounds': [11.70, 45.35, 12.95, 46.70]}\"` : derive a subbasin with its outlet at the given x,y coordinates and within the given bounds [xmin, ymin, xmax, ymax] (WGS84) snapped to a river with minimum stream order (strord) of 4. All *REGION* options are described in the [docs](https://deltares.github.io/hydromt/latest/user_guide/model_region)\n",
"* `-r 0.0083333` : build the model at a 30 arc sec (~1km) resolution\n",
"* `-i wflow_sediment_build.ini` : setup configuration file using\n",
"* `-i wflow_sediment_build.ini` : model setup configuration file\n",
"* `-d artifact_data` : use pre-defined artifact_data catalog.\n",
"* `-vv` : give some extra verbosity (2 * v) to display feedback on screen. Now debug messages are provided.\n"
]
},
Expand Down Expand Up @@ -236,7 +238,7 @@
"outputs": [],
"source": [
"# NOTE: copy this line (without !) to your shell for more direct feedback\n",
"!hydromt update wflow_sediment \"wflow_piave_subbasin\" -o \"./wflow_test_extend_sediment\" -i wflow_extend_sediment.ini -vv"
"!hydromt update wflow_sediment \"wflow_piave_subbasin\" -o \"./wflow_test_extend_sediment\" -i wflow_extend_sediment.ini -d artifact_data -vv"
]
},
{
Expand All @@ -250,6 +252,7 @@
"* `wflow_piave_subbasin` : hydrological wflow model folder\n",
"* `-o \"./wflow_test_extend_sediment\"`: output combined wflow hydrology+sediment models\n",
"* `-i wflow_extend_sediment.ini` : setup configuration file containing wflow sediment specific components\n",
"* `-d artifact_data` : use the pre-defined artifact_data catalog\n",
"* `-vv` : give some extra verbosity (2 * v) to display feedback on screen. Now debug messages are provided."
]
}
Expand Down
2 changes: 0 additions & 2 deletions examples/wflow_sediment_build.ini
Expand Up @@ -46,8 +46,6 @@ canopy_fn = simard # source for vegetation canopy height: {sima
soil_fn = soilgrids # source for soilmaps: {soilgrids}
usleK_method = renard # method to compute the USLE K factor: {renard, epic}

[setup_hydrodem] # adds hydrologically conditioned elevation FloodplainZ

[setup_gauges]
gauges_fn = grdc # If not None add gaugemap. Either a path or known gauges_fn: {grdc}
snap_to_river = True # If True snaps gauges from source to river
Expand Down
20 changes: 18 additions & 2 deletions hydromt_wflow/wflow.py
Expand Up @@ -2181,9 +2181,25 @@ def clip_staticmaps(
self._flwdir = None # make sure old flwdir object is removed
self.staticmaps[self._MAPS["flwdir"]].data = self.flwdir.to_array("ldd")

# Reinitiliase staticgeoms and re-create basins/rivers
self._staticgeoms = dict()
self.basins
self.rivers
# self.basins
# self.rivers
# now staticgeoms links to geoms which does not exist in every hydromt version
# remove when updating wflow to new objects
basins = flw.basin_shape(
self.staticmaps, self.flwdir, basin_name=self._MAPS["basins"]
)
self.set_staticgeoms(basins, name="basins")
rivmsk = self.staticmaps[self._MAPS["rivmsk"]].values != 0
# Check if there are river cells in the model before continuing
if np.any(rivmsk):
# add stream order 'strord' column
strord = self.flwdir.stream_order(mask=rivmsk)
feats = self.flwdir.streams(mask=rivmsk, strord=strord)
gdf = gpd.GeoDataFrame.from_features(feats)
gdf.crs = pyproj.CRS.from_user_input(self.crs)
self.set_staticgeoms(gdf, name="rivers")

# Update reservoir and lakes
remove_reservoir = False
Expand Down

0 comments on commit 94842f2

Please sign in to comment.