Example: Working with models in Python#
The main feature of HydroMT is to facilitate the process of building and analyzing spatial geoscientific models with a focus on water system models. It does so by automating the workflow to go from raw data to a complete model instance which is ready to run and to analyse model results once the simulation has finished.
This notebook will explore how to work with HydroMT models in Python.
[1]:
# import hydromt and setup logging
import hydromt
from hydromt.log import setuplog
# other imports
import matplotlib.pyplot as plt
import geopandas as gpd
logger = setuplog("working with models", log_level=10)
2024-06-14 08:22:34,006 - working with models - log - INFO - HydroMT version: 0.10.0
Available models in HydroMT#
To know which models are available within your active environment, you can use global MODELS
variable in hydromt
[2]:
# generic model classes
print(f"Generic model classes: {hydromt.MODELS.generic}")
# model classes from external plugin
print(f"Model classes from plugins: {hydromt.MODELS.plugins}")
Generic model classes: ['grid_model', 'vector_model', 'mesh_model', 'network_model']
Model classes from plugins: []
Here you may only see the generic models grid_model
, vector_model
and network_model
. There is one more generic model within HydroMT mesh_model
which is only available if the additional python mesh dependency xugrid is available in the activated environment.
Model components#
HydroMT defines any model through the model-agnostic Model API based on several general model components and computational unit components, see Model API. Below is a scheme representing the Model API and general model classes available in HydroMT (without any plugin):
Let’s discover how models are constructed within HydroMT and take the example of grid_model
. We will first instantiate a GridModel
object called mod
. The api
property helps us discover the available components and their type. You can do the same with any other HydroMT Model class or plugin (give it a try!).
[3]:
mod = hydromt.GridModel()
mod.api
[3]:
{'grid': xarray.core.dataset.Dataset,
'crs': pyproj.crs.crs.CRS,
'config': typing.Dict[str, typing.Any],
'geoms': typing.Dict[str, geopandas.geodataframe.GeoDataFrame],
'tables': typing.Dict[str, pandas.core.frame.DataFrame],
'maps': typing.Dict[str, typing.Union[xarray.core.dataarray.DataArray, xarray.core.dataset.Dataset]],
'forcing': typing.Dict[str, typing.Union[xarray.core.dataarray.DataArray, xarray.core.dataset.Dataset]],
'region': geopandas.geodataframe.GeoDataFrame,
'results': typing.Dict[str, typing.Union[xarray.core.dataarray.DataArray, xarray.core.dataset.Dataset]],
'states': typing.Dict[str, typing.Union[xarray.core.dataarray.DataArray, xarray.core.dataset.Dataset]]}
Here you see all the general components from the Model
class like config, geoms, forcing etc. as well as the GridModel
specific computational unit grid
. You can see that most components are dictionaries of either xarray DataArray or Datasets or of geopandas GeoDataFrame. For now we are starting from an empty model so all these components will be empty but here is how you can access them:
[4]:
print(type(mod.grid))
mod.grid
<class 'xarray.core.dataset.Dataset'>
[4]:
<xarray.Dataset> Size: 0B Dimensions: () Data variables: *empty*
[5]:
mod.geoms
[5]:
{}
Model setup_* methods#
To fill in our model components with data, HydroMT uses setup_ methods. These methods go from reading input data using the DataAdapter, transforming the data using workflows (e.g. reprojection, deriving model parameters, etc…) and adding the new model data to the right model component. An overview of available setup methods can be found in the API reference for the GridModel, VectorModel, and MeshModel
Note that these methods for the generic model classes are still quite limited. To get an idea of potential setup_ methods, checkout the model plugins
Let’s have a look at some examples of the setup_ functions to start populating our model like setup_grid
. This method parses the HydroMT region option to define the geographic region of interest and grid of the GridModel to build and once done adds region into the geoms
component and grid mask into the grid
component. You can check the required arguments in the
docs.
Let’s now setup a region for our model using for example a subbasin for any point in the Piave basin. We first initialize a GridModel
instance in writing mode at a model root folder. Data is sourced from the artifact_data catalog.
[6]:
root = "tmp_grid_model_py"
mod = hydromt.GridModel(
root=root,
mode="w",
data_libs=["artifact_data=v0.0.8", "data/vito_reclass.yml"],
logger=logger,
)
2024-06-14 08:22:34,091 - working with models - data_catalog - INFO - Reading data catalog artifact_data v0.0.8
2024-06-14 08:22:34,091 - working with models - data_catalog - INFO - Parsing data catalog from /home/runner/.hydromt_data/artifact_data/v0.0.8/data_catalog.yml
2024-06-14 08:22:34,680 - working with models - data_catalog - INFO - Parsing data catalog from data/vito_reclass.yml
2024-06-14 08:22:34,682 - working with models - log - DEBUG - Writing log messages to new file /home/runner/work/hydromt/hydromt/docs/_examples/tmp_grid_model_py/hydromt.log.
2024-06-14 08:22:34,682 - working with models - model_api - INFO - Initializing grid_model model from hydromt (v0.10.0).
[7]:
xy = [12.2051, 45.8331]
region = {"subbasin": xy, "uparea": 50}
mod.setup_grid(
region=region,
res=1000,
crs="utm",
hydrography_fn="merit_hydro",
basin_index_fn="merit_hydro_index",
)
print(mod.geoms)
print(mod.grid)
2024-06-14 08:22:34,688 - working with models - model_grid - INFO - Preparing 2D grid.
2024-06-14 08:22:34,688 - working with models - basin_mask - DEBUG - Parsed region (kind=subbasin): {'uparea': 50, 'xy': [12.2051, 45.8331]}
2024-06-14 08:22:34,690 - working with models - rasterdataset - INFO - Reading merit_hydro raster data from /home/runner/.hydromt_data/artifact_data/v0.0.8/data.tar/merit_hydro/{variable}.tif
2024-06-14 08:22:34,839 - working with models - basin_mask - DEBUG - Getting basin IDs at point locations.
2024-06-14 08:22:38,122 - working with models - basin_mask - INFO - subbasin bbox: [11.7750, 45.8042, 12.7450, 46.6900]
2024-06-14 08:22:38,158 - working with models - rasterdataset - INFO - Reading merit_hydro raster data from /home/runner/.hydromt_data/artifact_data/v0.0.8/data.tar/merit_hydro/{variable}.tif
2024-06-14 08:22:38,174 - working with models - rasterdataset - DEBUG - Clip to [11.775, 45.804, 12.745, 46.690] (epsg:4326))
{'region': geometry value
0 POLYGON ((304637.761 5173886.488, 304634.754 5... 1.0}
<xarray.Dataset> Size: 10kB
Dimensions: (y: 102, x: 80)
Coordinates:
* y (y) float64 816B 5.176e+06 5.174e+06 ... 5.076e+06 5.074e+06
* x (x) float64 640B 2.495e+05 2.505e+05 ... 3.275e+05 3.285e+05
spatial_ref int64 8B 0
Data variables:
mask (y, x) bool 8kB False False False False ... False False False
[8]:
# Plot
fig = plt.figure(figsize=(5, 6))
ax = plt.subplot()
mod.region.boundary.plot(ax=ax)
# grid mask
mod.grid["mask"].plot(ax=ax)
# grid vector cells using hydromt.raster.vector_grid method
mod.grid["mask"].raster.vector_grid().boundary.plot(ax=ax, color="black", linewidth=0.1)
# the outlet point we used to derive region
gdf_xy = gpd.GeoDataFrame(geometry=gpd.points_from_xy(x=[xy[0]], y=[xy[1]]), crs=4326)
gdf_xy.to_crs(mod.crs).plot(ax=ax, markersize=40, c="red", zorder=2)
[8]:
<Axes: title={'center': 'spatial_ref = 0'}, xlabel='x', ylabel='y'>
![../_images/_examples_working_with_models_21_1.png](../_images/_examples_working_with_models_21_1.png)
Similarly, we can also populate the config component using the setup_config
method. For HydroMT config represents the configuration of the model kernel, e.g. the file that would fix your model kernel run settings or list of outputs etc. For most models, this is usually a text file (for example .yaml, .ini, .toml, .inp formats) that can be ordered in sections. Within HydroMT we then use the dictionary object to represent each header/setting/value.
Let’s populate our config with some simple settings:
[9]:
config = {
"header": {"setting": "value"},
"timers": {"start": "2010-02-05", "end": "2010-02-15"},
}
mod.setup_config(**config)
mod.config
2024-06-14 08:22:38,824 - working with models - model_api - DEBUG - Setting model config options.
2024-06-14 08:22:38,825 - working with models - model_api - ERROR - Default config file not found at grid_model/model.ini
[9]:
{'header': {'setting': 'value'},
'timers': {'start': '2010-02-05', 'end': '2010-02-15'}}
We can setup maps data using the setup_maps_from_raster
and setup_maps_from_raster_reclass
methods. Both methods add data to the maps component based on input raster data (RasterDataset type), but the second method additionally reclassifies the input data based on a reclassification table. The maps component gathers any raster input data without any requirements for a specific grid (CRS and resolution). It can contain, for example, direct model input data for models like
Delft3D-FM that will interpolate input data on the fly to the model mesh, or auxiliary data that are not used by the model kernel but can be used by HydroMT to build the model (e.g. a gridded DEM), etc.
For models that require all their input data to be resampled to the exact computation grid (all raster at the same resolution and projection), then the input data would go into the grid component. The corresponding setup_grid_from_raster
and setup_grid_from_raster_reclass
functions for the grid components are also available.
But back to our example, let’s add both a DEM map from the data source merit_hydro_1k and a manning roughness map based on reclassified landuse data from the vito dataset to our model grid object.
[10]:
mod.setup_grid_from_rasterdataset(
raster_fn="merit_hydro_1k",
variables="elevtn",
fill_method=None,
reproject_method="bilinear",
rename={"elevtn": "DEM"},
)
mod.setup_grid_from_raster_reclass(
raster_fn="vito",
fill_method="nearest",
reclass_table_fn="vito_reclass", # Note: from local data catalog
reclass_variables=["manning"],
reproject_method="average",
)
2024-06-14 08:22:38,831 - working with models - model_grid - INFO - Preparing grid data from raster source merit_hydro_1k
2024-06-14 08:22:38,832 - working with models - rasterdataset - INFO - Reading merit_hydro_1k raster data from /home/runner/.hydromt_data/artifact_data/v0.0.8/data.tar/merit_hydro_1k/{variable}.tif
2024-06-14 08:22:38,850 - working with models - rasterdataset - DEBUG - Clip to [11.775, 45.804, 12.745, 46.690] (epsg:4326))
2024-06-14 08:22:38,877 - working with models - model_grid - INFO - Preparing grid data by reclassifying the data in vito based on vito_reclass
2024-06-14 08:22:38,878 - working with models - rasterdataset - INFO - Reading vito raster data from /home/runner/.hydromt_data/artifact_data/v0.0.8/data.tar/vito.tif
2024-06-14 08:22:38,895 - working with models - rasterdataset - DEBUG - Clip to [11.775, 45.804, 12.745, 46.690] (epsg:4326))
2024-06-14 08:22:38,896 - working with models - dataframe - INFO - Reading vito_reclass csv data from /home/runner/work/hydromt/hydromt/docs/_examples/data/vito_reclass.csv
[10]:
['manning']
[11]:
# check which maps are read
print(f"model grid: {list(mod.grid.data_vars)}")
mod.grid["manning"]
model grid: ['mask', 'DEM', 'manning']
[11]:
<xarray.DataArray 'manning' (y: 102, x: 80)> Size: 33kB array([[-999., -999., -999., ..., -999., -999., -999.], [-999., -999., -999., ..., -999., -999., -999.], [-999., -999., -999., ..., -999., -999., -999.], ..., [-999., -999., -999., ..., -999., -999., -999.], [-999., -999., -999., ..., -999., -999., -999.], [-999., -999., -999., ..., -999., -999., -999.]], dtype=float32) Coordinates: * y (y) float64 816B 5.176e+06 5.174e+06 ... 5.076e+06 5.074e+06 * x (x) float64 640B 2.495e+05 2.505e+05 ... 3.275e+05 3.285e+05 spatial_ref int64 8B 0 Attributes: _FillValue: -999.0
[12]:
# Plot
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(10, 4))
mod.grid["DEM"].raster.mask_nodata().plot(ax=axes[0], cmap="terrain")
mod.region.boundary.plot(ax=axes[0], color="k")
gdf_xy = gpd.GeoDataFrame(geometry=gpd.points_from_xy(x=[xy[0]], y=[xy[1]]), crs=4326).to_crs(mod.crs)
gdf_xy.plot(ax=axes[0], markersize=40, c="red", zorder=2)
axes[0].set_title("Elevation")
mod.grid["manning"].plot(ax=axes[1], cmap="viridis")
mod.region.boundary.plot(ax=axes[1], color="k")
gdf_xy.plot(ax=axes[1], markersize=40, c="red", zorder=2)
axes[1].set_title("Manning roughness")
[12]:
Text(0.5, 1.0, 'Manning roughness')
![../_images/_examples_working_with_models_27_1.png](../_images/_examples_working_with_models_27_1.png)
Model read & write methods#
Once our model is filled up with data, we can then write it down using either the general write
method or component specific write_ methods. Similarly, our model can be read back with the general read
method or component specific ones.
Let’s now write our model into a model root folder.
[13]:
mod.write(components=["grid", "geoms", "config"])
2024-06-14 08:22:39,569 - working with models - model_api - INFO - Writing model data to /home/runner/work/hydromt/hydromt/docs/_examples/tmp_grid_model_py
2024-06-14 08:22:39,569 - working with models - model_api - DEBUG - Writing file grid/grid.nc
2024-06-14 08:22:39,599 - working with models - model_api - DEBUG - Writing file geoms/region.geojson
2024-06-14 08:22:39,621 - working with models - model_api - INFO - Writing model config to /home/runner/work/hydromt/hydromt/docs/_examples/tmp_grid_model_py/model.ini
[14]:
# print MODEL_ROOT folder
import os
def print_dir(root):
for path, _, files in os.walk(root):
print(path)
for name in files:
if name.endswith(".xml"):
continue
print(f" - {name}")
print_dir(root)
tmp_grid_model_py
- hydromt.log
- model.ini
tmp_grid_model_py/grid
- grid.nc
tmp_grid_model_py/geoms
- region.geojson
And now let’s read it back in a new GridModel
instance:
[15]:
mod2 = hydromt.GridModel(root=root, mode="r", logger=logger)
mod2.read(components=["config", "geoms", "grid"])
2024-06-14 08:22:39,633 - working with models - model_api - INFO - Initializing grid_model model from hydromt (v0.10.0).
2024-06-14 08:22:39,633 - working with models - model_api - INFO - Reading model data from /home/runner/work/hydromt/hydromt/docs/_examples/tmp_grid_model_py
2024-06-14 08:22:39,634 - working with models - model_api - DEBUG - Model config read from /home/runner/work/hydromt/hydromt/docs/_examples/tmp_grid_model_py/model.ini
2024-06-14 08:22:39,635 - working with models - model_api - DEBUG - Reading model file region.
2024-06-14 08:22:39,650 - working with models - model_api - DEBUG - Reading model file grid.
2024-06-14 08:22:39,678 - working with models - model_api - DEBUG - Reading model file grid.
2024-06-14 08:22:39,683 - working with models - model_grid - WARNING - Replacing grid map: mask
2024-06-14 08:22:39,684 - working with models - model_grid - WARNING - Replacing grid map: DEM
2024-06-14 08:22:39,685 - working with models - model_grid - WARNING - Replacing grid map: manning
[16]:
# check which grid are read
print(f"model grid: {list(mod2.grid.data_vars)}")
model grid: ['mask', 'DEM', 'manning']
Building / updating a model with python#
Using the same functionalities, it is also possible to build or update a model within python instead of using the command line, using the build
and update
methods. Let’s see how we could rebuild our previous GridModel
with the build
method.
First let’s start with writing a HydroMT build configuration (ini-file) with the GridModel (setup) methods we want to use.
[17]:
from hydromt.config import configread
from pprint import pprint
# Read the build configuration
config = configread("grid_model_build.yaml")
pprint(
config,
)
{'setup_config': {'header.settings': 'value',
'timers.end': '2010-02-15',
'timers.start': '2010-02-05'},
'setup_grid': {'basin_index_fn': 'merit_hydro_index',
'crs': 4326,
'hydrography_fn': 'merit_hydro',
'res': 0.05},
'setup_grid_from_constant': {'constant': 0.01,
'dtype': 'float32',
'name': 'c1',
'nodata': -99.0},
'setup_grid_from_geodataframe': {'nodata': [-1, -999.0],
'rasterize_method': 'value',
'rename': {'Detph_avg': 'lake_depth',
'waterbody_id': 'lake_id'},
'variables': ['waterbody_id', 'Depth_avg'],
'vector_fn': 'hydro_lakes'},
'setup_grid_from_geodataframe2': {'rasterize_method': 'fraction',
'rename': {'hydro_lakes': 'water_frac'},
'vector_fn': 'hydro_lakes'},
'setup_grid_from_raster_reclass': {'raster_fn': 'vito',
'reclass_table_fn': 'vito_reclass',
'reclass_variables': ['manning'],
'reproject_method': ['average']},
'setup_grid_from_rasterdataset': {'raster_fn': 'merit_hydro_1k',
'reproject_method': ['average', 'mode'],
'variables': ['elevtn', 'basins']},
'setup_grid_from_rasterdataset2': {'fill_method': 'nearest',
'raster_fn': 'vito',
'rename': {'vito': 'landuse'},
'reproject_method': 'mode'},
'write': {'components': ['config', 'geoms', 'grid']}}
And now let’s build our model:
[18]:
# First we instantiate GridModel with the output folder and use the write mode (build from scratch)
root3 = "tmp_grid_model_py1"
mod3 = hydromt.GridModel(
root=root3,
mode="w",
data_libs=["artifact_data=v0.0.8", "data/vito_reclass.yml"],
logger=logger,
)
# Now let's build it with the config file
mod3.build(region=region, opt=config)
2024-06-14 08:22:39,742 - working with models - data_catalog - INFO - Reading data catalog artifact_data v0.0.8
2024-06-14 08:22:39,742 - working with models - data_catalog - INFO - Parsing data catalog from /home/runner/.hydromt_data/artifact_data/v0.0.8/data_catalog.yml
2024-06-14 08:22:40,332 - working with models - data_catalog - INFO - Parsing data catalog from data/vito_reclass.yml
2024-06-14 08:22:40,334 - working with models - log - DEBUG - Writing log messages to new file /home/runner/work/hydromt/hydromt/docs/_examples/tmp_grid_model_py1/hydromt.log.
2024-06-14 08:22:40,335 - working with models - model_api - INFO - Initializing grid_model model from hydromt (v0.10.0).
2024-06-14 08:22:40,335 - working with models - model_api - DEBUG - Setting model config options.
2024-06-14 08:22:40,336 - working with models - model_api - ERROR - Default config file not found at grid_model/model.ini
2024-06-14 08:22:40,337 - working with models - model_api - INFO - setup_grid.region: {'subbasin': [12.2051, 45.8331], 'uparea': 50}
2024-06-14 08:22:40,337 - working with models - model_api - INFO - setup_grid.res: 0.05
2024-06-14 08:22:40,338 - working with models - model_api - INFO - setup_grid.crs: 4326
2024-06-14 08:22:40,338 - working with models - model_api - INFO - setup_grid.rotated: False
2024-06-14 08:22:40,339 - working with models - model_api - INFO - setup_grid.hydrography_fn: merit_hydro
2024-06-14 08:22:40,339 - working with models - model_api - INFO - setup_grid.basin_index_fn: merit_hydro_index
2024-06-14 08:22:40,340 - working with models - model_api - INFO - setup_grid.add_mask: True
2024-06-14 08:22:40,340 - working with models - model_api - INFO - setup_grid.align: True
2024-06-14 08:22:40,340 - working with models - model_api - INFO - setup_grid.dec_origin: 0
2024-06-14 08:22:40,341 - working with models - model_api - INFO - setup_grid.dec_rotation: 3
2024-06-14 08:22:40,341 - working with models - model_grid - INFO - Preparing 2D grid.
2024-06-14 08:22:40,342 - working with models - basin_mask - DEBUG - Parsed region (kind=subbasin): {'uparea': 50, 'xy': [12.2051, 45.8331]}
2024-06-14 08:22:40,344 - working with models - rasterdataset - INFO - Reading merit_hydro raster data from /home/runner/.hydromt_data/artifact_data/v0.0.8/data.tar/merit_hydro/{variable}.tif
2024-06-14 08:22:40,445 - working with models - basin_mask - DEBUG - Getting basin IDs at point locations.
2024-06-14 08:22:40,732 - working with models - basin_mask - INFO - subbasin bbox: [11.7750, 45.8042, 12.7450, 46.6900]
2024-06-14 08:22:40,768 - working with models - rasterdataset - INFO - Reading merit_hydro raster data from /home/runner/.hydromt_data/artifact_data/v0.0.8/data.tar/merit_hydro/{variable}.tif
2024-06-14 08:22:40,784 - working with models - rasterdataset - DEBUG - Clip to [11.775, 45.804, 12.745, 46.690] (epsg:4326))
2024-06-14 08:22:40,803 - working with models - model_api - INFO - setup_grid_from_constant.constant: 0.01
2024-06-14 08:22:40,803 - working with models - model_api - INFO - setup_grid_from_constant.name: c1
2024-06-14 08:22:40,804 - working with models - model_api - INFO - setup_grid_from_constant.dtype: float32
2024-06-14 08:22:40,804 - working with models - model_api - INFO - setup_grid_from_constant.nodata: -99.0
2024-06-14 08:22:40,805 - working with models - model_api - INFO - setup_grid_from_constant.mask_name: mask
2024-06-14 08:22:40,811 - working with models - model_api - INFO - setup_grid_from_rasterdataset.raster_fn: merit_hydro_1k
2024-06-14 08:22:40,812 - working with models - model_api - INFO - setup_grid_from_rasterdataset.variables: ['elevtn', 'basins']
2024-06-14 08:22:40,812 - working with models - model_api - INFO - setup_grid_from_rasterdataset.fill_method: None
2024-06-14 08:22:40,813 - working with models - model_api - INFO - setup_grid_from_rasterdataset.reproject_method: ['average', 'mode']
2024-06-14 08:22:40,813 - working with models - model_api - INFO - setup_grid_from_rasterdataset.mask_name: mask
2024-06-14 08:22:40,814 - working with models - model_api - INFO - setup_grid_from_rasterdataset.rename: None
2024-06-14 08:22:40,814 - working with models - model_grid - INFO - Preparing grid data from raster source merit_hydro_1k
2024-06-14 08:22:40,815 - working with models - rasterdataset - INFO - Reading merit_hydro_1k raster data from /home/runner/.hydromt_data/artifact_data/v0.0.8/data.tar/merit_hydro_1k/{variable}.tif
2024-06-14 08:22:40,841 - working with models - rasterdataset - DEBUG - Clip to [11.775, 45.804, 12.745, 46.690] (epsg:4326))
2024-06-14 08:22:41,035 - working with models - model_api - INFO - setup_grid_from_rasterdataset.raster_fn: vito
2024-06-14 08:22:41,036 - working with models - model_api - INFO - setup_grid_from_rasterdataset.variables: None
2024-06-14 08:22:41,036 - working with models - model_api - INFO - setup_grid_from_rasterdataset.fill_method: nearest
2024-06-14 08:22:41,037 - working with models - model_api - INFO - setup_grid_from_rasterdataset.reproject_method: mode
2024-06-14 08:22:41,037 - working with models - model_api - INFO - setup_grid_from_rasterdataset.mask_name: mask
2024-06-14 08:22:41,038 - working with models - model_api - INFO - setup_grid_from_rasterdataset.rename: {'vito': 'landuse'}
2024-06-14 08:22:41,039 - working with models - model_grid - INFO - Preparing grid data from raster source vito
2024-06-14 08:22:41,040 - working with models - rasterdataset - INFO - Reading vito raster data from /home/runner/.hydromt_data/artifact_data/v0.0.8/data.tar/vito.tif
2024-06-14 08:22:41,054 - working with models - rasterdataset - DEBUG - Clip to [11.775, 45.804, 12.745, 46.690] (epsg:4326))
2024-06-14 08:22:41,175 - working with models - model_api - INFO - setup_grid_from_raster_reclass.raster_fn: vito
2024-06-14 08:22:41,176 - working with models - model_api - INFO - setup_grid_from_raster_reclass.reclass_table_fn: vito_reclass
2024-06-14 08:22:41,176 - working with models - model_api - INFO - setup_grid_from_raster_reclass.reclass_variables: ['manning']
2024-06-14 08:22:41,176 - working with models - model_api - INFO - setup_grid_from_raster_reclass.variable: None
2024-06-14 08:22:41,177 - working with models - model_api - INFO - setup_grid_from_raster_reclass.fill_method: None
2024-06-14 08:22:41,177 - working with models - model_api - INFO - setup_grid_from_raster_reclass.reproject_method: ['average']
2024-06-14 08:22:41,177 - working with models - model_api - INFO - setup_grid_from_raster_reclass.mask_name: mask
2024-06-14 08:22:41,178 - working with models - model_api - INFO - setup_grid_from_raster_reclass.rename: None
2024-06-14 08:22:41,178 - working with models - model_grid - INFO - Preparing grid data by reclassifying the data in vito based on vito_reclass
2024-06-14 08:22:41,179 - working with models - rasterdataset - INFO - Reading vito raster data from /home/runner/.hydromt_data/artifact_data/v0.0.8/data.tar/vito.tif
2024-06-14 08:22:41,194 - working with models - rasterdataset - DEBUG - Clip to [11.775, 45.804, 12.745, 46.690] (epsg:4326))
2024-06-14 08:22:41,196 - working with models - dataframe - INFO - Reading vito_reclass csv data from /home/runner/work/hydromt/hydromt/docs/_examples/data/vito_reclass.csv
2024-06-14 08:22:41,374 - working with models - model_api - INFO - setup_grid_from_geodataframe.vector_fn: hydro_lakes
2024-06-14 08:22:41,375 - working with models - model_api - INFO - setup_grid_from_geodataframe.variables: ['waterbody_id', 'Depth_avg']
2024-06-14 08:22:41,375 - working with models - model_api - INFO - setup_grid_from_geodataframe.nodata: [-1, -999.0]
2024-06-14 08:22:41,376 - working with models - model_api - INFO - setup_grid_from_geodataframe.rasterize_method: value
2024-06-14 08:22:41,376 - working with models - model_api - INFO - setup_grid_from_geodataframe.mask_name: mask
2024-06-14 08:22:41,376 - working with models - model_api - INFO - setup_grid_from_geodataframe.rename: {'waterbody_id': 'lake_id', 'Detph_avg': 'lake_depth'}
2024-06-14 08:22:41,377 - working with models - model_api - INFO - setup_grid_from_geodataframe.all_touched: True
2024-06-14 08:22:41,377 - working with models - model_grid - INFO - Preparing grid data from vector 'hydro_lakes'.
2024-06-14 08:22:41,380 - working with models - geodataframe - INFO - Reading hydro_lakes vector data from /home/runner/.hydromt_data/artifact_data/v0.0.8/data.tar/hydro_lakes.gpkg
2024-06-14 08:22:41,396 - working with models - geodataframe - DEBUG - Clip intersects [11.775, 45.804, 12.745, 46.690] (EPSG:4326)
2024-06-14 08:22:41,397 - working with models - geodataframe - DEBUG - Convert units for 1 columns.
2024-06-14 08:22:41,415 - working with models - model_api - INFO - setup_grid_from_geodataframe.vector_fn: hydro_lakes
2024-06-14 08:22:41,416 - working with models - model_api - INFO - setup_grid_from_geodataframe.variables: None
2024-06-14 08:22:41,416 - working with models - model_api - INFO - setup_grid_from_geodataframe.nodata: -1
2024-06-14 08:22:41,417 - working with models - model_api - INFO - setup_grid_from_geodataframe.rasterize_method: fraction
2024-06-14 08:22:41,417 - working with models - model_api - INFO - setup_grid_from_geodataframe.mask_name: mask
2024-06-14 08:22:41,418 - working with models - model_api - INFO - setup_grid_from_geodataframe.rename: {'hydro_lakes': 'water_frac'}
2024-06-14 08:22:41,418 - working with models - model_api - INFO - setup_grid_from_geodataframe.all_touched: True
2024-06-14 08:22:41,419 - working with models - model_grid - INFO - Preparing grid data from vector 'hydro_lakes'.
2024-06-14 08:22:41,420 - working with models - geodataframe - INFO - Reading hydro_lakes vector data from /home/runner/.hydromt_data/artifact_data/v0.0.8/data.tar/hydro_lakes.gpkg
2024-06-14 08:22:41,436 - working with models - geodataframe - DEBUG - Clip intersects [11.775, 45.804, 12.745, 46.690] (EPSG:4326)
2024-06-14 08:22:41,438 - working with models - geodataframe - DEBUG - Convert units for 1 columns.
2024-06-14 08:22:46,904 - working with models - model_api - INFO - write.components: ['config', 'geoms', 'grid']
2024-06-14 08:22:46,905 - working with models - model_api - INFO - Writing model data to /home/runner/work/hydromt/hydromt/docs/_examples/tmp_grid_model_py1
2024-06-14 08:22:46,905 - working with models - model_api - INFO - Writing model config to /home/runner/work/hydromt/hydromt/docs/_examples/tmp_grid_model_py1/model.ini
2024-06-14 08:22:46,906 - working with models - model_api - DEBUG - Writing file geoms/region.geojson
2024-06-14 08:22:46,926 - working with models - model_api - DEBUG - Writing file grid/grid.nc
2024-06-14 08:22:47,174 - working with models - model_api - INFO - Writing model data to /home/runner/work/hydromt/hydromt/docs/_examples/tmp_grid_model_py1
2024-06-14 08:22:47,174 - working with models - model_api - INFO - Writing model config to /home/runner/work/hydromt/hydromt/docs/_examples/tmp_grid_model_py1/model.ini
2024-06-14 08:22:47,176 - working with models - model_api - DEBUG - No maps data found, skip writing.
2024-06-14 08:22:47,176 - working with models - model_api - DEBUG - Writing file grid/grid.nc
2024-06-14 08:22:47,463 - working with models - model_api - DEBUG - Writing file geoms/region.geojson
2024-06-14 08:22:47,483 - working with models - model_api - DEBUG - No tables found, skip writing.
2024-06-14 08:22:47,483 - working with models - model_api - DEBUG - No forcing data found, skip writing.
2024-06-14 08:22:47,483 - working with models - model_api - DEBUG - No states data found, skip writing.
[19]:
print_dir(root3)
tmp_grid_model_py1
- hydromt.log
- model.ini
tmp_grid_model_py1/grid
- grid.nc
tmp_grid_model_py1/geoms
- region.geojson
And check that the results are similar to our one-by-one setup earlier:
[20]:
mod3.config
[20]:
{'header': {'settings': 'value'},
'timers': {'end': '2010-02-15', 'start': '2010-02-05'}}
[21]:
# Plot
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(10, 4))
mod3.grid["elevtn"].raster.mask_nodata().plot(ax=axes[0], cmap="terrain")
mod3.region.boundary.plot(ax=axes[0], color="k")
axes[0].set_title("Elevation")
mod3.grid["manning"].plot(ax=axes[1], cmap="viridis")
mod3.region.boundary.plot(ax=axes[1], color="k")
axes[1].set_title("Manning roughness")
[21]:
Text(0.5, 1.0, 'Manning roughness')
![../_images/_examples_working_with_models_44_1.png](../_images/_examples_working_with_models_44_1.png)