Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
veenstrajelmer committed Nov 1, 2023
1 parent 39f3b8d commit efcda9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 272 deletions.
275 changes: 12 additions & 263 deletions examples/build_1d2dmodel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,10 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "40470302",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"model plugins:\n",
" - dflowfm (hydromt_delft3dfm 0.1.3.dev0)\n",
"generic models (hydromt 0.9.0):\n",
" - grid_model\n",
" - vector_model\n",
" - mesh_model\n",
" - network_model\n",
"\n"
]
}
],
"outputs": [],
"source": [
"# this should return \"dflowfm\" to build DFlowFM components of Delft3D FM\n",
"# as well as the generic HydroMT models \"grid_model, lumped_model, mesh_model, network_model\"\n",
Expand All @@ -79,48 +64,10 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "1d39e4a1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Usage: hydromt build [OPTIONS] MODEL MODEL_ROOT\n",
"\n",
" Build models from scratch.\n",
"\n",
" Example usage: --------------\n",
"\n",
" To build a wflow model for a subbasin using a point coordinates snapped to\n",
" cells with upstream area >= 50 km2 hydromt build wflow /path/to/model_root\n",
" -i /path/to/wflow_config.ini -r \"{'subbasin': [-7.24, 62.09], 'uparea':\n",
" 50}\" -d deltares_data -d /path/to/data_catalog.yml -v\n",
"\n",
" To build a sfincs model based on a bbox hydromt build sfincs\n",
" /path/to/model_root -i /path/to/sfincs_config.ini -r \"{'bbox':\n",
" [4.6891,52.9750,4.9576,53.1994]}\" -d /path/to/data_catalog.yml -v\n",
"\n",
"Options:\n",
" --opt TEXT Method specific keyword arguments, see the method\n",
" documentation of the specific model for more\n",
" information about the arguments.\n",
" -i, --config PATH Path to hydroMT configuration file, for the model\n",
" specific implementation.\n",
" -r, --region TEXT Set the region for which to build the model, e.g.\n",
" {'subbasin': [-7.24, 62.09]}\n",
" -d, --data TEXT Path to local yaml data catalog file OR name of\n",
" predefined data catalog.\n",
" --dd, --deltares-data Flag: Shortcut to add the \"deltares_data\" catalog\n",
" --fo, --force-overwrite Flag: If provided overwrite existing model files\n",
" --cache Flag: If provided cache tiled rasterdatasets\n",
" -v, --verbose Increase verbosity.\n",
" -q, --quiet Decrease verbosity.\n",
" --help Show this message and exit.\n"
]
}
],
"outputs": [],
"source": [
"!hydromt build --help"
]
Expand Down Expand Up @@ -177,86 +124,10 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "e88d4aed",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"global:\n",
" crs: 3857\n",
" network_snap_offset: 25\n",
" openwater_computation_node_distance: 40\n",
"\n",
"setup_rivers_from_dem:\n",
" region: \n",
" bbox: [12.4331, 46.4661, 12.5212, 46.5369]\n",
" hydrography_fn: merit_hydro\n",
" river_geom_fn: rivers_lin2019_v1\n",
" rivers_defaults_fn: rivers_defaults\n",
" rivdph_method: gvf\n",
" rivwth_method: geom\n",
" river_upa: 25.0\n",
" friction_type: \"Manning\"\n",
" friction_value: 0.023\n",
" rivbankq: 25\n",
"\n",
"setup_pipes:\n",
" region: \n",
" bbox: [12.4331, 46.4661, 12.5212, 46.5369]\n",
" pipes_fn: grip_roads\n",
" pipes_defaults_fn: pipes_defaults\n",
" pipe_filter: pipe\n",
" spacing: 50\n",
" friction_type: WhiteColeBrook\n",
" friction_value: 0.003\n",
" crosssections_shape: circle\n",
" crosssections_value: 0.5\n",
" dem_fn: merit_hydro # [copdem30, merit]\n",
" pipes_depth: 2.0\n",
" snap_offset: 0.5\n",
" pipes_invlev: 3. \n",
"\n",
"setup_manholes:\n",
" manholes_fn:\n",
" manhole_defaults_fn: manholes_defaults\n",
" dem_fn: merit_hydro\n",
" bedlevel_shift: 0.5\n",
"\n",
"setup_1dboundary:\n",
" boundary_value: -2.0\n",
" branch_type: river\n",
" boundary_type: waterlevel\n",
" boundary_unit: m\n",
" boundary_locs: both\n",
"\n",
"setup_mesh2d:\n",
" region: \n",
" bbox: [12.4331, 46.4661, 12.5212, 46.5369]\n",
" res: 500\n",
"\n",
"setup_maps_from_rasterdataset:\n",
" raster_fn: merit_hydro\n",
" variables: [\"elevtn\"]\n",
" fill_method: nearest\n",
" interpolation_method: nearestNb\n",
"\n",
"setup_maps_from_raster_reclass:\n",
" raster_fn: vito\n",
" reclass_table_fn: vito_mapping\n",
" reclass_variables: ['roughness_manning', 'infiltcap']\n",
" interpolation_method: triangulation\n",
"\n",
"setup_rainfall_from_constant:\n",
" constant_value: 150\n",
"\n",
"setup_link1d2d:\n",
" link_direction: 1d_to_2d\n"
]
}
],
"outputs": [],
"source": [
"fn_yml = \"dflowfm_build.yml\"\n",
"with open(fn_yml, \"r\") as f:\n",
Expand Down Expand Up @@ -309,122 +180,12 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "hundred-trailer",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2023-11-01 15:33:21,158 - build - log - DEBUG - Writing log messages to new file C:\\SnapVolumesTemp\\MountPoints\\{45c63495-0000-0000-0000-100000000000}\\{79DE0690-9470-4166-B9EE-4548DC416BBD}\\SVROOT\\DATA\\hydromt_delft3dfm\\examples\\build\\dflowfm_1d2d\\hydromt.log.\n",
"2023-11-01 15:33:21,159 - build - log - INFO - HydroMT version: 0.9.0\n",
"2023-11-01 15:33:21,159 - build - main - INFO - Building instance of dflowfm model at C:\\SnapVolumesTemp\\MountPoints\\{45c63495-0000-0000-0000-100000000000}\\{79DE0690-9470-4166-B9EE-4548DC416BBD}\\SVROOT\\DATA\\hydromt_delft3dfm\\examples\\build\\dflowfm_1d2d.\n",
"2023-11-01 15:33:21,159 - build - main - INFO - User settings:\n",
"2023-11-01 15:33:28,139 - build - data_catalog - INFO - Reading data catalog archive artifact_data v0.0.8\n",
"2023-11-01 15:33:28,141 - build - data_catalog - INFO - Parsing data catalog from C:\\Users\\veenstra\\.hydromt_data\\artifact_data\\v0.0.8\\data_catalog.yml\n",
"2023-11-01 15:33:28,243 - build - model_api - INFO - Initializing dflowfm model from hydromt_delft3dfm (v0.1.3.dev0).\n",
"2023-11-01 15:33:28,243 - build - data_catalog - INFO - Parsing data catalog from C:\\SnapVolumesTemp\\MountPoints\\{45c63495-0000-0000-0000-100000000000}\\{79DE0690-9470-4166-B9EE-4548DC416BBD}\\SVROOT\\DATA\\hydromt_delft3dfm\\hydromt_delft3dfm\\data\\parameters_data.yml\n",
"2023-11-01 15:33:28,251 - build - dflowfm - INFO - Initialising empty mdu file\n",
"2023-11-01 15:33:28,258 - build - dflowfm - INFO - project crs: 3857\n",
"2023-11-01 15:33:28,258 - build - model_api - INFO - setup_rivers_from_dem.region: {'bbox': [12.4331, 46.4661, 12.5212, 46.5369]}\n",
"2023-11-01 15:33:28,258 - build - model_api - INFO - setup_rivers_from_dem.hydrography_fn: merit_hydro\n",
"2023-11-01 15:33:28,258 - build - model_api - INFO - setup_rivers_from_dem.river_geom_fn: rivers_lin2019_v1\n",
"2023-11-01 15:33:28,258 - build - model_api - INFO - setup_rivers_from_dem.rivers_defaults_fn: rivers_defaults\n",
"2023-11-01 15:33:28,258 - build - model_api - INFO - setup_rivers_from_dem.rivdph_method: gvf\n",
"2023-11-01 15:33:28,259 - build - model_api - INFO - setup_rivers_from_dem.rivwth_method: geom\n",
"2023-11-01 15:33:28,259 - build - model_api - INFO - setup_rivers_from_dem.river_upa: 25.0\n",
"2023-11-01 15:33:28,259 - build - model_api - INFO - setup_rivers_from_dem.river_len: 1000\n",
"2023-11-01 15:33:28,259 - build - model_api - INFO - setup_rivers_from_dem.min_rivwth: 50.0\n",
"2023-11-01 15:33:28,259 - build - model_api - INFO - setup_rivers_from_dem.min_rivdph: 1.0\n",
"2023-11-01 15:33:28,259 - build - model_api - INFO - setup_rivers_from_dem.rivbank: True\n",
"2023-11-01 15:33:28,259 - build - model_api - INFO - setup_rivers_from_dem.rivbankq: 25\n",
"2023-11-01 15:33:28,259 - build - model_api - INFO - setup_rivers_from_dem.segment_length: 3000.0\n",
"2023-11-01 15:33:28,259 - build - model_api - INFO - setup_rivers_from_dem.smooth_length: 10000.0\n",
"2023-11-01 15:33:28,259 - build - model_api - INFO - setup_rivers_from_dem.friction_type: Manning\n",
"2023-11-01 15:33:28,259 - build - model_api - INFO - setup_rivers_from_dem.friction_value: 0.023\n",
"2023-11-01 15:33:28,259 - build - model_api - INFO - setup_rivers_from_dem.constrain_rivbed: True\n",
"2023-11-01 15:33:28,259 - build - model_api - INFO - setup_rivers_from_dem.constrain_estuary: True\n",
"2023-11-01 15:33:28,259 - build - dflowfm - INFO - Preparing river shape from hydrography data.\n",
"2023-11-01 15:33:28,272 - build - rasterdataset - INFO - Reading merit_hydro raster data from C:\\Users\\veenstra\\.hydromt_data\\artifact_data\\v0.0.8\\merit_hydro\\{variable}.tif\n",
"2023-11-01 15:33:28,485 - build - rasterdataset - DEBUG - Clip to [12.433, 46.466, 12.521, 46.537] (epsg:4326))\n",
"2023-11-01 15:33:28,488 - build - geodataframe - INFO - Reading rivers_lin2019_v1 vector data from C:\\Users\\veenstra\\.hydromt_data\\artifact_data\\v0.0.8\\rivers_lin2019_v1.gpkg\n",
"2023-11-01 15:33:28,745 - build - geodataframe - DEBUG - Clip intersects [1384045.361, 5855358.290, 1393854.608, 5866810.259] (EPSG:3857)\n",
"2023-11-01 15:33:40,052 - build - dem - INFO - Deriving bankfull river surface elevation from its banks.\n",
"2023-11-01 15:33:48,976 - build - dem - INFO - Smoothing river width (n=2).\n",
"2023-11-01 15:33:51,169 - build - main - ERROR - No such file found: C:\\SnapVolumesTemp\\MountPoints\\{{45c63495-0000-0000-0000-100000000000}}\\{{79DE0690-9470-4166-B9EE-4548DC416BBD}}\\SVROOT\\DATA\\hydromt_delft3dfm\\hydromt_delft3dfm\\data\\branches\\rivers_defaults.csv\n",
"Traceback (most recent call last):\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\hydromt\\cli\\main.py\", line 207, in build\n",
" mod.build(region, opt=opt)\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\hydromt\\models\\model_api.py\", line 240, in build\n",
" self._run_log_method(method, **kwargs)\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\hydromt\\models\\model_api.py\", line 182, in _run_log_method\n",
" return func(*args, **kwargs)\n",
" ^^^^^^^^^^^^^^^^^^^^^\n",
" File \"C:\\SnapVolumesTemp\\MountPoints\\{45c63495-0000-0000-0000-100000000000}\\{79DE0690-9470-4166-B9EE-4548DC416BBD}\\SVROOT\\DATA\\hydromt_delft3dfm\\hydromt_delft3dfm\\dflowfm.py\", line 567, in setup_rivers_from_dem\n",
" defaults = self.data_catalog.get_dataframe(rivers_defaults_fn)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\hydromt\\data_catalog.py\", line 1534, in get_dataframe\n",
" obj = source.get_data(\n",
" ^^^^^^^^^^^^^^^^\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\hydromt\\data_adapter\\dataframe.py\", line 206, in get_data\n",
" fns = self._resolve_paths(variables)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\hydromt\\data_adapter\\data_adapter.py\", line 393, in _resolve_paths\n",
" raise FileNotFoundError(f\"No such file found: {path}{postfix}\")\n",
"FileNotFoundError: No such file found: C:\\SnapVolumesTemp\\MountPoints\\{{45c63495-0000-0000-0000-100000000000}}\\{{79DE0690-9470-4166-B9EE-4548DC416BBD}}\\SVROOT\\DATA\\hydromt_delft3dfm\\hydromt_delft3dfm\\data\\branches\\rivers_defaults.csv\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Traceback (most recent call last):\n",
" File \"<frozen runpy>\", line 198, in _run_module_as_main\n",
" File \"<frozen runpy>\", line 88, in _run_code\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Scripts\\hydromt.exe\\__main__.py\", line 7, in <module>\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\click\\core.py\", line 1157, in __call__\n",
" return self.main(*args, **kwargs)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\click\\core.py\", line 1078, in main\n",
" rv = self.invoke(ctx)\n",
" ^^^^^^^^^^^^^^^^\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\click\\core.py\", line 1688, in invoke\n",
" return _process_result(sub_ctx.command.invoke(sub_ctx))\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\click\\core.py\", line 1434, in invoke\n",
" return ctx.invoke(self.callback, **ctx.params)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\click\\core.py\", line 783, in invoke\n",
" return __callback(*args, **kwargs)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\click\\decorators.py\", line 33, in new_func\n",
" return f(get_current_context(), *args, **kwargs)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\hydromt\\cli\\main.py\", line 207, in build\n",
" mod.build(region, opt=opt)\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\hydromt\\models\\model_api.py\", line 240, in build\n",
" self._run_log_method(method, **kwargs)\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\hydromt\\models\\model_api.py\", line 182, in _run_log_method\n",
" return func(*args, **kwargs)\n",
" ^^^^^^^^^^^^^^^^^^^^^\n",
" File \"C:\\SnapVolumesTemp\\MountPoints\\{45c63495-0000-0000-0000-100000000000}\\{79DE0690-9470-4166-B9EE-4548DC416BBD}\\SVROOT\\DATA\\hydromt_delft3dfm\\hydromt_delft3dfm\\dflowfm.py\", line 567, in setup_rivers_from_dem\n",
" defaults = self.data_catalog.get_dataframe(rivers_defaults_fn)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\hydromt\\data_catalog.py\", line 1534, in get_dataframe\n",
" obj = source.get_data(\n",
" ^^^^^^^^^^^^^^^^\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\hydromt\\data_adapter\\dataframe.py\", line 206, in get_data\n",
" fns = self._resolve_paths(variables)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"C:\\Users\\veenstra\\Anaconda3\\envs\\dsd_env\\Lib\\site-packages\\hydromt\\data_adapter\\data_adapter.py\", line 393, in _resolve_paths\n",
" raise FileNotFoundError(f\"No such file found: {path}{postfix}\")\n",
"FileNotFoundError: No such file found: C:\\SnapVolumesTemp\\MountPoints\\{{45c63495-0000-0000-0000-100000000000}}\\{{79DE0690-9470-4166-B9EE-4548DC416BBD}}\\SVROOT\\DATA\\hydromt_delft3dfm\\hydromt_delft3dfm\\data\\branches\\rivers_defaults.csv\n"
]
}
],
"outputs": [],
"source": [
"# NOTE: copy this line (without !) to your shell for more direct feedback - should take about 1 minute or 2 to run\n",
"!hydromt build dflowfm \"./build/dflowfm_1d2d\" -i dflowfm_build.yml -d artifact_data --fo -vv"
Expand Down Expand Up @@ -457,22 +218,10 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"id": "f496aa74",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"./build/dflowfm_1d2d/\n",
" - hydromt.log\n",
"./build/dflowfm_1d2d/dflowfm\n",
"./build/dflowfm_1d2d/geoms\n",
"./build/dflowfm_1d2d/maps\n"
]
}
],
"outputs": [],
"source": [
"import os\n",
"\n",
Expand Down Expand Up @@ -518,7 +267,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "waterbom",
"language": "python",
"name": "python3"
},
Expand All @@ -532,7 +281,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.9.18"
},
"vscode": {
"interpreter": {
Expand Down
9 changes: 0 additions & 9 deletions hydromt_delft3dfm/workflows/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ def mesh1d_network1d_from_branches(
branch_orders=closedsystem.branchorder.to_list(),
)

# derive mesh1d
# dfm_network._mesh1d._set_mesh1d()

# Mesh1d to mesh1d and network1d xugrid
uds_mesh1d, uds_network1d = mutils.mesh1d_network1d_from_hydrolib_network(
dfm_network, crs
Expand Down Expand Up @@ -382,8 +379,6 @@ def links1d2d_add_links_1d_to_2d(
"""
# Initialise hydrolib network object
network = mutils.hydrolib_network_from_mesh(mesh)
# Load 1d and 2d in meshkernel
# network._mesh1d._set_mesh1d()

if within is None:
# If not provided, create a box from the maximum bounds
Expand Down Expand Up @@ -481,8 +476,6 @@ def links1d2d_add_links_2d_to_1d_embedded(
"""
# Initialise hydrolib network object
network = mutils.hydrolib_network_from_mesh(mesh)
# Load 1d and 2d in meshkernel
# network._mesh1d._set_mesh1d()

# Get the max edge distance
nodes2d = np.stack(
Expand Down Expand Up @@ -597,8 +590,6 @@ def links1d2d_add_links_2d_to_1d_lateral(
"""
# Initialise hydrolib network object
network = mutils.hydrolib_network_from_mesh(mesh)
# Load 1d and 2d in meshkernel
# network._mesh1d._set_mesh1d()

geometrylist = network.meshkernel.mesh2d_get_mesh_boundaries_as_polygons()
mpboundaries = GeometryList(**geometrylist.__dict__).to_geometry()
Expand Down

0 comments on commit efcda9d

Please sign in to comment.