Skip to content

Commit 9e78f0a

Browse files
committed
WIP
1 parent c11b048 commit 9e78f0a

File tree

1 file changed

+39
-45
lines changed

1 file changed

+39
-45
lines changed

docs/tutorials/dsd_2023/magdalena_workflow/magdalena_answers.ipynb

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221
"\n",
222222
"In the previous step we read the geometry and attributes of the branches from the shape file. This branch data will become the network input for our D-Flow FM model. \n",
223223
"\n",
224-
"Since the model does not have a network yet, we need to create a new `Network` object and assign it to the model. A network may contain a 1D network, a 2D mesh and 1D2D links.\n",
224+
"Since the model does not have a network yet, we need to create a new network object and assign it to the model. A network may contain a 1D network, a 2D mesh and 1D2D links.\n",
225225
"\n",
226226
"**Exercise 🧩**\n",
227227
"* Create a new network\n",
@@ -231,21 +231,17 @@
231231
" * For each branch, the name, geometry and computational grid points should be provided. \n",
232232
" * The computational points are not included in the data, we will need to generate those with a grid point distance as specified:\n",
233233
"\n",
234-
" | **Branch name** | **dx [m]** |\n",
235-
" |-----------------|------------|\n",
236-
" | Channel_1D_1_A | 1000 |\n",
237-
" | Channel_1D_1_B | 1000 |\n",
238-
" | Channel_1D_1 | 500 |\n",
234+
"| **Branch name** | **dx [m]** |\n",
235+
"|-----------------|------------|\n",
236+
"| Channel_1D_1_A | 1000 |\n",
237+
"| Channel_1D_1_B | 1000 |\n",
238+
"| Channel_1D_1 | 500 |\n",
239239
"\n",
240-
"Hint 💡: The MDU file contains a [Geometry] section which has the `NetFile` reference, e.g.:\n",
240+
"Hint 💡: The MDU file contains a [Geometry] section which has the network file reference, e.g.:\n",
241241
"\n",
242242
"```\n",
243243
"[Geometry]\n",
244244
"netFile = FlowFM_net.nc\n",
245-
"bathymetryFile =\n",
246-
"dryPointsFile =\n",
247-
"structureFile = structures.ini\n",
248-
"iniFieldFile = initialFields.ini\n",
249245
"...\n",
250246
"```\n",
251247
"\n",
@@ -254,7 +250,10 @@
254250
"* [NetworkModel](https://deltares.github.io/HYDROLIB-core/0.5.2/reference/net/#hydrolib.core.dflowfm.net.models.NetworkModel)\n",
255251
"* [Branch](https://deltares.github.io/HYDROLIB-core/0.5.2/reference/net/#hydrolib.core.dflowfm.net.models.Branch)\n",
256252
"* [Branch.generate_nodes()](https://deltares.github.io/HYDROLIB-core/0.5.2/reference/net/#hydrolib.core.dflowfm.net.models.Branch.generate_nodes)\n",
257-
"* [Network.mesh1d_add_branch()](TODO)"
253+
"* `Network.mesh1d_add_branch()` (undocumented): Adds a branch to the 1D network.\n",
254+
" The function needs two arguments:\n",
255+
" 1. `Branch`: the branch to be added\n",
256+
" 2. `str`: The name of the branch that is added"
258257
]
259258
},
260259
{
@@ -279,9 +278,9 @@
279278
"# Assign geometry of the branches and generate the computational grid on top of the branches.\n",
280279
"for index, branch_data in branches_gdf.iterrows():\n",
281280
" xy = np.transpose(branch_data.geometry.xy) \n",
282-
" branch_new = Branch(geometry=xy) \n",
283-
" branch_new.generate_nodes(mesh1d_edge_length=dx_per_branch[branch_data.Name])\n",
284-
" network.mesh1d_add_branch(branch_new, name=branch_data.Name)\n",
281+
" branch = Branch(geometry=xy) \n",
282+
" branch.generate_nodes(mesh1d_edge_length=dx_per_branch[branch_data.Name])\n",
283+
" network.mesh1d_add_branch(branch, name=branch_data.Name)\n",
285284
"\n",
286285
"network._mesh1d._set_mesh1d()"
287286
]
@@ -358,8 +357,7 @@
358357
"* Print the cross-section location data, to answer the following questions:\n",
359358
" * How many cross-section does the model contain in total, and how many does each branch have?\n",
360359
" * Do the cross-section have shared cross-section definitions? A shared cross-section definition is a definition used by more than one cross-section.\n",
361-
"* Convert the CSV data (a pd.DataFrame) into a HYDROLIB-core `CrossSection`\n",
362-
"* Assign a file path to the cross section location file\n",
360+
"* Convert the CSV data (a pd.DataFrame) into HYDROLIB-core `CrossSection` objects\n",
363361
"* Assign the cross section locations to the model\n",
364362
"\n",
365363
"Hint 💡: The MDU file contains a [Geometry] section which has the `crossDefFile` and `crossLocFile` reference, e.g.:\n",
@@ -372,10 +370,10 @@
372370
"```\n",
373371
"\n",
374372
"API references: \n",
375-
"* [CrossLocModel](https://deltares.github.io/HYDROLIB-core/0.5.2/reference/crosssection/#hydrolib.core.dflowfm.crosssection.models.CrossLocModel)\n",
376-
"* [CrossSection](https://deltares.github.io/HYDROLIB-core/0.5.2/reference/crosssection/#hydrolib.core.dflowfm.crosssection.models.CrossSection)\n",
377373
"* [pd.read_csv()](https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html#pandas-read-csv)\n",
378-
"* [pd.to_dict()](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_dict.html#pandas-dataframe-to-dict)"
374+
"* [pd.to_dict()](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_dict.html#pandas-dataframe-to-dict)\n",
375+
"* [CrossLocModel](https://deltares.github.io/HYDROLIB-core/0.5.2/reference/crosssection/#hydrolib.core.dflowfm.crosssection.models.CrossLocModel)\n",
376+
"* [CrossSection](https://deltares.github.io/HYDROLIB-core/0.5.2/reference/crosssection/#hydrolib.core.dflowfm.crosssection.models.CrossSection)"
379377
]
380378
},
381379
{
@@ -385,19 +383,18 @@
385383
"metadata": {},
386384
"outputs": [],
387385
"source": [
388-
"cross_section_location_file = data_dir / 'cross_section_locations.csv'\n",
389-
"cross_section_locations_df = pd.read_csv(cross_section_location_file, index_col=False)\n",
386+
"cross_section_data_file = data_dir / 'cross_section_locations.csv'\n",
387+
"cross_section_df = pd.read_csv(cross_section_data_file, index_col=False)\n",
390388
"\n",
391-
"print(cross_section_locations_df)\n",
389+
"print(cross_section_df)\n",
392390
"# Answers:\n",
393391
"# * There are 6 cross-sections in the model and each branch has two cross-sections \n",
394392
"# * There are no shared cross-section definitions; each cross-section has a unique definition ID.\n",
395393
"\n",
396394
"cross_loc_model = CrossLocModel()\n",
397-
"cross_loc_model.filepath = 'crsloc.ini'\n",
395+
"model.geometry.crosslocfile = cross_loc_model\n",
398396
"\n",
399-
"cross_loc_model.crosssection = cross_section_locations_df.to_dict(\"records\")\n",
400-
"model.geometry.crosslocfile = cross_loc_model"
397+
"cross_loc_model.crosssection = cross_section_df.to_dict(\"records\")"
401398
]
402399
},
403400
{
@@ -407,8 +404,7 @@
407404
"source": [
408405
"### 6. Adding cross-section definitions\n",
409406
"\n",
410-
"In the following exercise we will add the cross-section definitions to the D-Flow FM model. These belong to the cross-section we added in the previous step. These cross-sections all have YZ-profiles in order to define a natural shape of the river. \n",
411-
"\n",
407+
"In the following exercise we will add the cross-section definitions to the D-Flow FM model. These belong to the cross-sections we added in the previous step. These cross-sections all have YZ-profiles in order to define a natural shape of the river. \n",
412408
"\n",
413409
"Please finish the code below.\n",
414410
"\n",
@@ -433,10 +429,10 @@
433429
"profiles_file = data_dir / '1D_YZ_CrossSections.xlsx'\n",
434430
"profile_excel_data = pd.read_excel(profiles_file, sheet_name=None)\n",
435431
"profile_names = list(profile_excel_data)\n",
436-
"print(profile_names)\n",
432+
"print(f\"Profile names: {profile_names}\")\n",
437433
"\n",
438434
"cross_def_model = CrossDefModel()\n",
439-
"cross_def_model.filepath = 'crsdef.ini'\n",
435+
"model.geometry.crossdeffile = cross_def_model\n",
440436
"\n",
441437
"# Properties for each YZ profile\n",
442438
"type_crs = 'yz'\n",
@@ -453,6 +449,7 @@
453449
" y_coords = profile_data.y.to_list()\n",
454450
" z_coords = profile_data.z.to_list()\n",
455451
"\n",
452+
" # Define friction positions at begin and end of profile \n",
456453
" friction_positions = [profile_data.y[0], profile_data.y[num_coords-1]]\n",
457454
"\n",
458455
" # Create an YZ profile\n",
@@ -468,9 +465,7 @@
468465
" frictionIds = friction_ids,\n",
469466
" frictionPositions=friction_positions)\n",
470467
" \n",
471-
" cross_def_model.definition.append(cross_section)\n",
472-
"\n",
473-
"model.geometry.crossdeffile = cross_def_model\n"
468+
" cross_def_model.definition.append(cross_section)"
474469
]
475470
},
476471
{
@@ -502,6 +497,7 @@
502497
"\n",
503498
"channel_friction_model = FrictionModel()\n",
504499
"channel_friction_model.filepath = \"roughness-channels.ini\" # It is conventional to specify the file names as \"roughness-[friction ID].ini\"\n",
500+
"model.geometry.frictfile = [channel_friction_model]\n",
505501
"\n",
506502
"# Create global friction model and add it to frictionmodel\n",
507503
"channel_global_friction = FrictGlobal(frictionId=channel_friction_id,\n",
@@ -521,17 +517,17 @@
521517
" numLocations=1,\n",
522518
" functionType=function_type)\n",
523519
" \n",
524-
" channel_friction_model.branch.append(friction_per_branch)\n",
525-
" \n",
526-
"model.geometry.frictfile = [channel_friction_model]"
520+
" channel_friction_model.branch.append(friction_per_branch)"
527521
]
528522
},
529523
{
530524
"cell_type": "markdown",
531525
"id": "51751aad",
532526
"metadata": {},
533527
"source": [
534-
"We want to defined another global friction definition for the Canal del Dique. This friction model assumes Chezy as global friction type and a friction value of 45.\n",
528+
"We want to define another global friction definition for the Canal del Dique. This friction model assumes Chezy as global friction type and a friction value of 45.0.\n",
529+
"\n",
530+
"You can use the code above as an example.\n",
535531
"\n",
536532
"**Exercise 🧩** \n",
537533
"* Create a new friction model for Canal del Dique\n",
@@ -551,20 +547,18 @@
551547
"metadata": {},
552548
"outputs": [],
553549
"source": [
554-
"\n",
555550
"dique_friction_id = 'dique'\n",
556551
"dique_global_type = FrictionType.chezy\n",
557552
"dique_global_value = 45.0\n",
558553
"\n",
559554
"dique_friction_model = FrictionModel()\n",
560555
"dique_friction_model.filepath = 'roughness-dique.ini'\n",
556+
"model.geometry.frictfile.append(dique_friction_model)\n",
561557
"\n",
562558
"dique_global_friction = FrictGlobal(frictionId=dique_friction_id,\n",
563559
" frictionType=dique_global_type,\n",
564560
" frictionValue=dique_global_value)\n",
565-
"dique_friction_model.global_ = dique_global_friction\n",
566-
"\n",
567-
"model.geometry.frictfile.append(dique_friction_model)"
561+
"dique_friction_model.global_ = dique_global_friction"
568562
]
569563
},
570564
{
@@ -576,7 +570,7 @@
576570
"\n",
577571
"**Exercise 🧩** \n",
578572
"* Use the cross-section locations and definitions in the D-Flow FM model to find the cross-sections on the Channel_1D_1 branch\n",
579-
"* Reassign the friction ID of the correct cross sections to one used for the Canal del Dique"
573+
"* Reassign the friction ID of the correct cross sections to the one used for the Canal del Dique"
580574
]
581575
},
582576
{
@@ -783,7 +777,6 @@
783777
"metadata": {},
784778
"outputs": [],
785779
"source": [
786-
"\n",
787780
"weir.crestlevel = 10.0\n",
788781
"weir.allowedflowdir = FlowDirection.positive"
789782
]
@@ -839,8 +832,9 @@
839832
"source": [
840833
"### 12. Creating a 2D flexible mesh\n",
841834
"\n",
842-
"Here, we demonstrate how to create a 2D mesh using `MeshKernel`.\n",
843-
"Note that the network and mesh functionality in HYDROLIB-core is still in development. \n",
835+
"Here, we demonstrate how to create a 2D mesh using MeshKernel.\n",
836+
"\n",
837+
"⚠️ *Network and mesh functionality in HYDROLIB-core is still in development.* \n",
844838
"\n",
845839
"We use a shape file with the area of interest to define the extent of the new 2D mesh that is to be generated.\n",
846840
"First, a uniform rectilinear mesh with a grid cell size of 2500x2500m is generated.\n",

0 commit comments

Comments
 (0)