Core
DHyDAMO Core API¶
Core model classes: HyDAMO data, the RR model and the RTC model.
data_model
¶
HYDROLIB's data model: the HyDAMO tables, under their DAMO 2.2 names, and HYDROLIB's extensions.
Every DAMO version is loaded into this one model: the version steps
(hydrolib.dhydamo.io.damo_versions.steps) rename a file's layers and columns back to
DAMO 2.2. The model is plain data and independent of any DAMO version.
HyDAMO.__init__ builds its tables from it.
Column
dataclass
¶
A declared column with something to say beyond its name.
Ordinary columns are declared by name only; a column is declared as a Column
when HYDROLIB has a reason to note, or treats it in a special way.
Parameters¶
name : str
The column, under its DAMO 2.2 name, or its name in the version that
introduced it (see since).
reason : str
Why HYDROLIB needs it, or treats it this way.
hydrolib_only : bool
Whether the column is HYDROLIB's own: no DAMO version defines it. Default is
False.
fill_from_globalid : bool
Whether the column is filled from globalid where it is absent or empty,
before duplicates get a suffix. Default is False.
rewrite : tuple[str, str], optional
(old, new): a value rewritten when loading, whatever the DAMO version.
Only the exact value is rewritten, so no general stripping of whitespace or
commas.
identity : bool
Whether the column is the table's identity: its index and the id of its model
objects. An empty value raises an error, duplicates get a suffix. Default is
False.
values : tuple[str, ...]
The values the code compares the column against, as DAMO spells them. The
contract test checks that each DAMO version allows them. Default is none.
since : str, optional
The first DAMO version with the column, e.g. "2.5", for a column DAMO
added rather than renamed. Default is None: every version has it.
Source code in hydrolib/dhydamo/core/data_model.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
in_version(version: str) -> bool
¶
Return whether DAMO version has the column (see since).
Source code in hydrolib/dhydamo/core/data_model.py
67 68 69 | |
DamoRelations
¶
The DAMO relations between the HyDAMO tables.
A DAMO foreign key holds the parent's globalid. The one exception is the
parameterised-profile values, which share normgeparamprofielid with their
profile, so that is the parent key.
Source code in hydrolib/dhydamo/core/data_model.py
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 | |
Extension
dataclass
¶
A column HYDROLIB defines or treats on top of DAMO 2.2, from extensions.
Parameters¶
table : str HyDAMO attribute of the table. column : str The column. kind : ExtensionKind What HYDROLIB does with it. reason : str Why HYDROLIB needs it.
Source code in hydrolib/dhydamo/core/data_model.py
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 | |
OwnRelations
¶
The relations of HYDROLIB's own tables (OWN_TABLES), an extension.
These tables aren't DAMO and have no globalid: a child refers to its
parent's code in codegerelateerdobject.
Source code in hydrolib/dhydamo/core/data_model.py
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 | |
OwnTable
dataclass
¶
A table HYDROLIB defines itself: not DAMO, and loaded from its own files.
Parameters¶
geotype : type[BaseGeometry] Geometry type of the table. required_columns : tuple[str, ...] Columns the table must have. reason : str Why HYDROLIB needs it. optional_columns : tuple[Column, ...] Other columns HYDROLIB reads when present, each with its reason.
Source code in hydrolib/dhydamo/core/data_model.py
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | |
optional_names: tuple[str, ...]
property
¶
The names of the optional columns.
Relation
dataclass
¶
A foreign-key relation from a child table to a parent table.
Following a relation is in hydrolib.dhydamo.core.relations; the two methods
here only say how its keys match.
Attributes¶
name : str
Name of the relation, for messages.
child_table : str
HyDAMO attribute of the table with the foreign key.
foreign_key : str
Column of the child table that refers to the parent.
parent_table : str
HyDAMO attribute of the table that is referred to.
parent_key : str
Column of the parent table that is referred to. Defaults to "globalid".
Source code in hydrolib/dhydamo/core/data_model.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 | |
children_of(parent_rows: pd.DataFrame, child_table: pd.DataFrame) -> pd.DataFrame
¶
Return child rows that reference one or more parent rows.
The of in children_of refers to the first argument,
parent_rows. This relation supplies the traversal metadata: values
from its parent_key on parent_rows are matched against its
foreign_key on child_table.
Parameters¶
parent_rows : pandas.DataFrame
One or more rows from this relation's parent_table. The
relation's parent_key must be present as a column.
child_table : pandas.DataFrame
Candidate rows from this relation's child_table. The
relation's foreign_key must be present as a column.
Returns¶
pandas.DataFrame
Rows from child_table whose foreign key references
parent_rows. The original index, column order, and dataframe
type are preserved. Null parent-key values never match.
Raises¶
KeyError
If parent_key is missing from parent_rows or
foreign_key is missing from child_table.
Notes¶
This method does not enforce relation cardinality. It can return zero, one, or multiple child rows; the caller decides how those cases are handled.
Source code in hydrolib/dhydamo/core/data_model.py
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 | |
parents_of(child_rows: pd.DataFrame, parent_table: pd.DataFrame) -> pd.DataFrame
¶
Return parent rows referenced by one or more child rows.
The of in parents_of refers to the first argument,
child_rows. This relation supplies the traversal metadata: values
from its foreign_key on child_rows are matched against its
parent_key on parent_table.
Parameters¶
child_rows : pandas.DataFrame
One or more rows from this relation's child_table. The
relation's foreign_key must be present as a column.
parent_table : pandas.DataFrame
Candidate rows from this relation's parent_table. The
relation's parent_key must be present as a column.
Returns¶
pandas.DataFrame
Rows from parent_table whose parent key is referenced by
child_rows. The original index, column order, and dataframe
type are preserved. Null foreign-key values never match.
Raises¶
KeyError
If foreign_key is missing from child_rows or parent_key
is missing from parent_table.
Notes¶
This method does not enforce relation cardinality. It can return zero, one, or multiple parent rows; the caller decides how those cases are handled.
Source code in hydrolib/dhydamo/core/data_model.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 | |
Table
dataclass
¶
A HyDAMO table: its DAMO 2.2 layer, the columns HYDROLIB reads, and how it is read.
A column is declared by its name, or as a Column when there is more to say.
Parameters¶
layer : str
DAMO 2.2 layer, matched case-insensitively.
geotype : type[BaseGeometry] or UnionType or None
Geometry type of a spatial table, e.g. Point or Polygon | MultiPolygon;
None for a table without geometry.
required_columns : tuple[str or Column, ...]
Columns a loaded layer must have; a missing one is an error.
optional_columns : tuple[str or Column, ...]
Other columns HYDROLIB reads. Loading doesn't need them: a missing one is
absent after loading. Building the model may still need one for some
objects, e.g. debiet for a discharge boundary; it then fails on the
missing column.
derived_columns : tuple[Column, ...]
Columns computed after loading, whatever the DAMO version (see
hydrolib.dhydamo.io.damo_versions.loader). A derived column may also be
read; its reason then says how the two combine, e.g. overwritten or only
filled where empty.
group_by : str, optional
Column whose points are grouped into one line each.
order_by : str, optional
Column that orders the points of a line.
optional_layer : bool
Whether a file may lack the layer. Default is True.
check_geotype : bool
Whether the geometries must have the table's geometry type. Default is
True.
Source code in hydrolib/dhydamo/core/data_model.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
__post_init__() -> None
¶
Check that at most one column is filled from globalid.
Raises¶
ValueError If more than one column is: the loader fills one column per table.
Source code in hydrolib/dhydamo/core/data_model.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
column_filled_from_globalid: str | None
property
¶
The column filled from globalid, if any.
columns: tuple[Column, ...]
property
¶
The read columns, required then optional, each as a Column.
identity_column: str | None
property
¶
The read column that is the table's identity and index, if any.
A derived identity, such as the profile's code, isn't read: its
derivation sets the index.
optional_names: tuple[str, ...]
property
¶
The names of the optional columns.
required_names: tuple[str, ...]
property
¶
The names of the required columns.
extensions() -> list[Extension]
¶
Return HYDROLIB's extensions to DAMO 2.2, as declared on the tables' columns.
Returns¶
list[Extension]
Per table in TABLES order: its identity, HYDROLIB-only columns, value
rewrites and columns filled from globalid, in column order, then its
derived columns.
Source code in hydrolib/dhydamo/core/data_model.py
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 | |
drr
¶
The D-RR model: unpaved, paved, greenhouse and open water nodes, and their forcings.
DRRModel
¶
The D-RR model.
Holds the unpaved, paved, greenhouse and open water nodes, and the external forcings
(seepage, precipitation, evaporation and boundary nodes). Write it with
DRRWriter.
Source code in hydrolib/dhydamo/core/drr.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
__init__() -> None
¶
Create an empty RR model.
Source code in hydrolib/dhydamo/core/drr.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
read_raster(file: str | Path, static: bool = False) -> tuple
¶
Read the first band of a raster with rasterio.
Parameters¶
file : str or Path
Raster file. Without static, its name holds the time after the first
_, e.g. precip_20160601.tif.
static : bool, optional
The raster has no time. Defaults to False.
Returns¶
tuple
The array and its transform, and without static also the time.
Source code in hydrolib/dhydamo/core/drr.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
ExternalForcings
¶
External forcings of the RR model: meteo, seepage and boundary nodes.
Parameters¶
drrmodel : DRRModel The RR model they belong to.
Source code in hydrolib/dhydamo/core/drr.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
add_boundary_node(id: str, px: str, py: str) -> None
¶
Add a boundary node, which couples RR nodes to a lateral of the FM model.
Parameters¶
id : str Id of the boundary node. px, py : str Coordinates of the node.
Source code in hydrolib/dhydamo/core/drr.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
add_evap(id: str, series: pd.Series) -> None
¶
Add the evaporation time series of a meteo area.
Parameters¶
id : str Id of the meteo area. series : pd.Series Evaporation, with a time index.
Raises¶
TypeError If the evaporation is already read from a meteo file.
Source code in hydrolib/dhydamo/core/drr.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
add_precip(id: str, series: pd.Series) -> None
¶
Add the precipitation time series of a meteo area.
Parameters¶
id : str Id of the meteo area. series : pd.Series Precipitation, with a time index.
Raises¶
TypeError If the precipitation is already read from a meteo file.
Source code in hydrolib/dhydamo/core/drr.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
add_seepage(id: str, series: pd.Series) -> None
¶
Add the seepage time series of a catchment.
Parameters¶
id : str Id of the catchment. series : pd.Series Seepage, with a time index.
Source code in hydrolib/dhydamo/core/drr.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
Greenhouse
¶
Greenhouse nodes of the RR model.
Parameters¶
drrmodel : DRRModel The RR model they belong to.
Source code in hydrolib/dhydamo/core/drr.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | |
add_greenhouse(id: str, area: str, surface_level: str, roof_storage: str, basin_storage_class: str, meteo_area: str, px: str, py: str, boundary_node: str) -> None
¶
Add a greenhouse node.
Parameters¶
id : str Catchment or greenhouse area id. area : str Greenhouse area (m2). surface_level : str Surface level (m). roof_storage : str Roof storage (mm). basin_storage_class : str Basin storage class. meteo_area : str Id of the meteo area, to which a station in the meteo file is assigned. px, py : str Coordinates of the node. boundary_node : str Boundary node to which the node drains.
Source code in hydrolib/dhydamo/core/drr.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | |
Openwater
¶
Open water nodes of the RR model.
Parameters¶
drrmodel : DRRModel The RR model they belong to.
Source code in hydrolib/dhydamo/core/drr.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
add_openwater(id: str, area: str, meteo_area: str, px: str, py: str, boundary_node: str) -> None
¶
Add an open water node.
Parameters¶
id : str Catchment id. area : str Open water area (m2). meteo_area : str Id of the meteo area, to which a station in the meteo file is assigned. px, py : str Coordinates of the node. boundary_node : str Boundary node to which the node drains.
Source code in hydrolib/dhydamo/core/drr.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
Paved
¶
Paved nodes of the RR model.
Parameters¶
drrmodel : DRRModel The RR model they belong to.
Source code in hydrolib/dhydamo/core/drr.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |
add_paved(id: str, area: str, surface_level: str, street_storage: str, sewer_storage: str, pump_capacity: str, meteo_area: str, px: str, py: str, boundary_node: str) -> None
¶
Add a paved node.
Parameters¶
id : str
Catchment or overflow id.
area : str
Paved area (m2).
surface_level : str
Surface level (m).
street_storage : str
Street storage (mm).
sewer_storage : str
Sewer storage (mm).
pump_capacity : str
Sewer pump capacity (m3/s); PavedIO computes it from mm/h and the area.
meteo_area : str
Id of the meteo area, to which a station in the meteo file is assigned.
px, py : str
Coordinates of the node.
boundary_node : str
Boundary node to which the node drains.
Source code in hydrolib/dhydamo/core/drr.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |
Unpaved
¶
Unpaved nodes of the RR model, with their Ernst definitions.
Parameters¶
drrmodel : DRRModel The RR model they belong to.
Source code in hydrolib/dhydamo/core/drr.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
add_ernst_def(id: str, cvo: str, lv: str, cvi: str, cvs: str) -> None
¶
Add an Ernst definition for the unpaved node of a catchment.
Parameters¶
id : str Catchment id. cvo : str Drainage resistance per layer (d), space separated. lv : str Depth of each layer (m), space separated. cvi : str Infiltration resistance (d). cvs : str Surface runoff resistance (d).
Source code in hydrolib/dhydamo/core/drr.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
add_unpaved(id: str, total_area: str, lu_areas: str, surface_level: str, soiltype: str, surface_storage: str, infiltration_capacity: str, initial_gwd: str, meteo_area: str, px: str, py: str, boundary_node: str) -> None
¶
Add an unpaved node.
Parameters¶
id : str Catchment id. total_area : str Total node area (m2). lu_areas : str Area per land use class (m2), space separated. surface_level : str Surface level (m). soiltype : str Soil type (class id). surface_storage : str Surface storage (mm). infiltration_capacity : str Infiltration capacity (mm/d). initial_gwd : str Initial groundwater depth below the surface (m, positive is below the surface). meteo_area : str Id of the meteo area, to which a station in the meteo file is assigned. px, py : str Coordinates of the node. boundary_node : str Boundary node to which the node drains.
Source code in hydrolib/dhydamo/core/drr.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
drtc
¶
The D-RTC model: time, PID and interval controllers, complex controllers and their XML files.
ComplexControllers
¶
Bases: TypedDict
XML of the complex controllers: fragments per RTC file, and the parsed DIMR config roots.
pydantic needs typing_extensions.TypedDict (not typing.TypedDict) on Python < 3.12.
Source code in hydrolib/dhydamo/core/drtc.py
80 81 82 83 84 85 86 87 88 89 90 91 92 | |
DRTCModel
¶
Main class to generate RTC-module files.
Source code in hydrolib/dhydamo/core/drtc.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 | |
__init__(hydamo: HyDAMO, fm: FMModel, output_path: str | Path | None = None, rtc_onlytimeseries: bool = False, rtc_timeseriesdata: pd.DataFrame | None = None, complex_controllers_folder: list[str | Path] | str | Path | None = None, id_limit_complex_controllers: list[str] | None = None, rtc_timestep: float = 60) -> None
¶
Initialize the DRTCModel.
Internal controller dictionaries and output paths are initialized, optional complex-controller XML is parsed, and RTC template files are copied to the output folder.
Parameters¶
hydamo : HyDAMO
The HyDAMO data, with the structures and management.
fm : FMModel
The FM model; its reference date and times set the RTC period.
output_path : str or Path, optional
Folder in which an rtc subfolder is created for the RTC files. Defaults to
None: the current working directory.
rtc_onlytimeseries : bool, optional
Build the RTC control from rtc_timeseriesdata only;
complex_controllers_folder is then ignored. Defaults to False.
rtc_timeseriesdata : pd.DataFrame, optional
Time series used with rtc_onlytimeseries, with the structure ids as
columns. Defaults to None.
complex_controllers_folder : list[Path or str], Path or str, optional
Folder(s) with custom RTC XML files to import, without
rtc_onlytimeseries. Defaults to None.
id_limit_complex_controllers : list[str], optional
Ids that may be coupled to complex controllers. Required with
complex_controllers_folder; an empty list allows no ids. Defaults to None.
rtc_timestep : float, optional
Time step of the RTC model (s). Defaults to 60.
Source code in hydrolib/dhydamo/core/drtc.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
add_interval_controller(*, structure_id: str, steering_variable: str, target_variable: str, deadband: Annotated[float | str | None, Field(union_mode=left_to_right)] = None, setpoint: Annotated[float | str | pd.Series, Field(union_mode=left_to_right)], setting_below: Annotated[float | str, Field(union_mode=left_to_right)], setting_above: Annotated[float | str, Field(union_mode=left_to_right)], max_speed: Annotated[float | str | None, Field(union_mode=left_to_right)] = None, observation_location: str, interpolation_option: str = 'LINEAR', extrapolation_option: str = 'BLOCK') -> None
¶
Add an interval controller to a structure.
All arguments are keyword-only.
Parameters¶
structure_id : str
Structure id.
steering_variable : str
Variable that is controlled, usually the crest level.
target_variable : str
Target variable, usually the water level.
deadband : float or str, optional
Dead band around the setpoint. Defaults to None.
setpoint : float, str or pd.Series
Setpoint, or a time series of the setpoint.
setting_below, setting_above : float or str
Setting when the target variable is below or above the setpoint.
max_speed : float or str, optional
Maximum speed of change of the setting. Defaults to None.
observation_location : str
Id of the observation point.
interpolation_option : str, optional
Interpolation option. Defaults to "LINEAR".
extrapolation_option : str, optional
Extrapolation option. Defaults to "BLOCK".
Source code in hydrolib/dhydamo/core/drtc.py
1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 | |
add_pid_controller(*, structure_id: str, steering_variable: str, target_variable: str, setpoint: Annotated[float | str | pd.Series, Field(union_mode=left_to_right)], lower_bound: Annotated[float | str | None, Field(union_mode=left_to_right)] = None, upper_bound: Annotated[float | str | None, Field(union_mode=left_to_right)] = None, observation_location: str, ki: float = 0.001, kp: float = 0.0, kd: float = 0.0, max_speed: float = 0.00033, interpolation_option: str = 'LINEAR', extrapolation_option: str = 'BLOCK') -> None
¶
Add a PID controller to a structure.
All arguments are keyword-only.
Parameters¶
structure_id : str
Structure id.
steering_variable : str
Variable that is controlled, usually the crest level.
target_variable : str
Target variable, usually the water level.
setpoint : float, str or pd.Series
Setpoint, or a time series of the setpoint.
lower_bound, upper_bound : float or str, optional
Lowest and highest allowed setting. Default to None.
observation_location : str
Id of the observation point.
ki, kp, kd : float, optional
Gain factors. Default to 0.001, 0.0 and 0.0.
max_speed : float, optional
Maximum speed of change of the setting. Defaults to 0.00033.
interpolation_option : str, optional
Interpolation option. Defaults to "LINEAR".
extrapolation_option : str, optional
Extrapolation option. Defaults to "BLOCK".
Source code in hydrolib/dhydamo/core/drtc.py
1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 | |
add_time_controller(structure_id: str, steering_variable: str, data: pd.Series, interpolation_option: str = 'LINEAR', extrapolation_option: str = 'BLOCK') -> None
¶
Add a time controller to a structure.
Parameters¶
structure_id : str
Structure id.
steering_variable : str
Variable that is controlled, usually the crest level.
data : pd.Series
Time series of the setting.
interpolation_option : str, optional
Interpolation option. Defaults to "LINEAR".
extrapolation_option : str, optional
Extrapolation option. Defaults to "BLOCK".
Source code in hydrolib/dhydamo/core/drtc.py
1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 | |
allow_struct(cc_id: str, allow_observations: bool = False, allow_if_filter_inactive: bool = True, allow_if_not_referenced: bool = False) -> bool
¶
Return whether a structure id is allowed by the complex-controller filter.
Parameters¶
cc_id : str
Structure or observation id to evaluate.
allow_observations : bool, optional
Pass through observation ids that exist in the HyDAMO model. Defaults to
False.
allow_if_filter_inactive : bool, optional
Return value when no complex controller filter is active
(cc_referenced_ids or cc_id_limit is None). Defaults to True.
allow_if_not_referenced : bool, optional
Return value when filtering is active, but cc_id is not in
cc_referenced_ids. Defaults to False.
Returns¶
bool Whether the id is allowed.
Source code in hydrolib/dhydamo/core/drtc.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
check_timeseries(timeseries: pd.DataFrame) -> None
¶
Warn for each structure with a controller in hydamo.management but no time series.
Parameters¶
timeseries : pd.DataFrame Time series, with the structure ids as columns.
Source code in hydrolib/dhydamo/core/drtc.py
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
find_complex_controller_ids(complex_controllers_folder: list[str | Path] | str | Path, hydamo: HyDAMO) -> set[str]
staticmethod
¶
Return the ids of the structures that the complex controllers refer to.
Only structures that exist in the HyDAMO model are returned; observation points are left out.
Parameters¶
complex_controllers_folder : list[str or Path], str or Path
Folder(s) with the complex controllers (their dimr_config.xml).
hydamo : HyDAMO
The HyDAMO data, with the structures.
Returns¶
set[str] Structure ids.
Source code in hydrolib/dhydamo/core/drtc.py
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 | |
finish_file(xmlroot: ET.Element, filename: Path | str) -> None
staticmethod
¶
Write an XML tree to a file, with an XML declaration, pretty-printed.
Parameters¶
xmlroot : ET.Element Root of the XML tree. filename : Path or str File to write.
Source code in hydrolib/dhydamo/core/drtc.py
1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 | |
from_hydamo(pid_settings: dict | None = None, interval_settings: dict | None = None, timeseries: pd.DataFrame | None = None) -> None
¶
Add the time, PID and interval controllers of hydamo.management.
The settings that HyDAMO lacks are keyed by D-Flow FM structure id: the weir,
orifice, pump or culvert code, or for a weir with several openings the id of
the opening's structure (e.g. S_98740_3). Structures without their own key
get the settings under "global". Keys that match no structure with that
type of controller are listed in one warning per settings dict.
A structure gets one controller: when several Sturing rows with a supported controller type (PID, interval or time) resolve to the same structure, the first of them is used and the others are skipped with a warning. Rows with another type are skipped with a warning before any other check.
Parameters¶
pid_settings : dict, optional
ki, kp, kd and maxspeed of the PID controllers, per structure
id and under "global". Defaults to None.
interval_settings : dict, optional
deadband and maxspeed of the interval controllers, per structure id
and under "global". Defaults to None.
timeseries : pd.DataFrame, optional
Time series of the time controllers, with the structure ids as columns.
Defaults to None.
Raises¶
ValueError
For inconsistent input, e.g. a PID controller without pid_settings.
Source code in hydrolib/dhydamo/core/drtc.py
1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 | |
get_item_pair(item: ET.Element) -> tuple[str, str] | None
staticmethod
¶
Return the source and target name of a DIMR coupler item.
Parameters¶
item : ET.Element
An item element of a coupler.
Returns¶
tuple[str, str] or None
(sourceName, targetName), or None if one of them is missing.
Source code in hydrolib/dhydamo/core/drtc.py
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 | |
parse_complex_controller(xml_folder: Path | str) -> ComplexControllers
¶
Read user-specified 'complex' controllers from the RTC XML files in a folder.
Items that refer to structures that are not allowed (see allow_struct) are
skipped and logged.
Parameters¶
xml_folder : Path or str Folder with the custom XML files.
Returns¶
ComplexControllers The XML fragments per RTC file, and the parsed DIMR config.
Source code in hydrolib/dhydamo/core/drtc.py
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 | |
set_initial_state(values: dict[str, float]) -> None
¶
Set the initial setting of controlled structures, e.g. {"S_96840": 16.2}.
The value is written to state_import.xml for the steered variable of the structure. It overrides the default initial setting and a state read with set_state_from_file.
Parameters¶
values : dict[str, float] Initial setting per structure id.
Source code in hydrolib/dhydamo/core/drtc.py
1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 | |
set_state_from_file(state_export: str | Path, check_time: bool = True) -> None
¶
Use the RTC state of an earlier model run as initial state (warm start).
The state_export.xml of the earlier run is written as state_import.xml, including the internal state of the rules (e.g. the integral term of PID controllers). This assumes that the RTC configuration is the same as in the earlier run: state items that do not occur in the new rtcDataConfig.xml are skipped, and controllers that are missing in the state keep their default initial setting. Both are reported as a warning.
Parameters¶
state_export : str or Path Path to state_export.xml, or the rtc folder of the earlier run. check_time : bool, optional Compare the time of the state (from statePI.xml next to the state file) with the start time of this model, and warn if they differ. Defaults to True.
Source code in hydrolib/dhydamo/core/drtc.py
1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 | |
set_state_from_modelrun(his_path: str | Path, time: dt | pd.Timestamp | str | None = None, netcdf_index: int | None = None) -> dict[str, float]
¶
Use the structure settings of an earlier model run (his-file) as initial setting of the controllers.
For every controlled structure, the steered variable (crest level, gate lower edge level, valve opening or pump capacity) is read from the his-file at the given time and passed to set_initial_state. Unlike set_state_from_file, any time step can be used, but the internal state of the rules (e.g. the integral term of PID controllers) is not restored.
Parameters¶
his_path : str or Path Path to the his file of the earlier run. time : datetime, pd.Timestamp or str, optional Time of the settings; the nearest time step is used. Defaults to None. netcdf_index : int, optional Time index instead of a time. Defaults to None: without a time, the last time step.
Returns¶
dict[str, float] Initial setting per structure id.
Source code in hydrolib/dhydamo/core/drtc.py
1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 | |
write_dataconfig() -> None
¶
Write rtcDataConfig.xml, from the template, with the series of all controllers.
Source code in hydrolib/dhydamo/core/drtc.py
2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 | |
write_runtimeconfig() -> None
¶
Write rtcRuntimeConfig.xml, from the template, with the model period and time step.
Source code in hydrolib/dhydamo/core/drtc.py
1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 | |
write_state_import() -> None
¶
Write state_import.xml, from the template, with the initial state of the controllers.
Source code in hydrolib/dhydamo/core/drtc.py
2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 | |
write_timeseries_import() -> None
¶
Write timeseries_import.xml, from the template, with the time series of the controllers.
Source code in hydrolib/dhydamo/core/drtc.py
2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 | |
write_toolsconfig() -> None
¶
Write rtcToolsConfig.xml, from the template, with the rules of all controllers.
Source code in hydrolib/dhydamo/core/drtc.py
1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 | |
write_xml_v1() -> None
¶
Write all RTC XML files.
Source code in hydrolib/dhydamo/core/drtc.py
1923 1924 1925 1926 1927 1928 1929 | |
DRTCStructure
dataclass
¶
A flow structure referenced in a complex controller.
Source code in hydrolib/dhydamo/core/drtc.py
147 148 149 150 151 152 153 | |
IntervalController
¶
Bases: TypedDict
Interval controller of a structure, added with DRTCModel.add_interval_controller.
Source code in hydrolib/dhydamo/core/drtc.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
PIDController
¶
Bases: TypedDict
PID controller of a structure, added with DRTCModel.add_pid_controller.
Source code in hydrolib/dhydamo/core/drtc.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
TimeController
¶
Bases: TypedDict
Time controller of a structure, added with DRTCModel.add_time_controller.
Source code in hydrolib/dhydamo/core/drtc.py
103 104 105 106 107 108 109 110 | |
TimeSettings
¶
Bases: TypedDict
Start and end time of the model, and the RTC time step in seconds.
Source code in hydrolib/dhydamo/core/drtc.py
95 96 97 98 99 100 | |
hydamo
¶
The HyDAMO data model: input data, cross sections, structures, forcings and storage nodes.
CrossSections
¶
Cross section definitions and locations of the model.
Parameters¶
hydamo : HyDAMO The HyDAMO object they belong to.
Source code in hydrolib/dhydamo/core/hydamo.py
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 | |
__init__(hydamo: HyDAMO) -> None
¶
Create empty cross section definitions and locations.
Source code in hydrolib/dhydamo/core/hydamo.py
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 | |
add_circle_definition(diameter: float, roughnesstype: str, roughnessvalue: float, name: str | None = None) -> str
¶
Add a circle cross section definition.
Without a name, the name is derived from the shape only, so a definition with the same shape but another roughness replaces the earlier one.
Source code in hydrolib/dhydamo/core/hydamo.py
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 | |
add_crosssection_location(branchid: str, chainage: float, definition: str, minz: float = np.nan, shift: float = 0.0) -> None
¶
Add a cross section location, with the id {branchid}_{chainage:.1f}.
Parameters¶
branchid : str Branch id. chainage : float Chainage on the branch. definition : str Name of the cross section definition. minz : float, optional Not used. Defaults to NaN. shift : float, optional Vertical shift of the definition. Defaults to 0.0.
Source code in hydrolib/dhydamo/core/hydamo.py
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 | |
add_rectangle_definition(height: float, width: float, closed: bool | int, roughnesstype: str, roughnessvalue: float, name: str | None = None) -> str
¶
Add a rectangle cross section definition.
Without a name, the name is derived from the shape only, so a definition with the same shape but another roughness replaces the earlier one.
Source code in hydrolib/dhydamo/core/hydamo.py
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 | |
add_trapezium_definition(slope: float, maximumflowwidth: float, bottomwidth: float, closed: bool | int, roughnesstype: str, roughnessvalue: float, bottomlevel: float | None = None, name: str | None = None) -> str
¶
Add a trapezium cross section definition.
Without a name, the name is derived from the shape only, so a definition with the same shape but another roughness replaces the earlier one.
Source code in hydrolib/dhydamo/core/hydamo.py
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 | |
add_yz_definition(yz: np.ndarray | None = None, thalweg: float | None = None, roughnesstype: str | None = None, roughnessvalue: float | None = None, name: str | None = None) -> str
¶
Add a yz cross section definition.
Parameters¶
code : str Id of cross section branch : str Name of branch offset : float Position of cross section along branch. If not given, the position is determined from the branches in the network. These should thus be given in this case. crds : np.array Nx2 array with y, z coordinates
Source code in hydrolib/dhydamo/core/hydamo.py
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 | |
add_zw_definition(numLevels: int, levels: str, flowWidths: str, totalWidths: str, roughnesstype: str, roughnessvalue: float, name: str | None = None) -> str
¶
Add a zw cross section definition.
Give a name: without one, building the name raises an error.
Source code in hydrolib/dhydamo/core/hydamo.py
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 | |
crosssection_to_yzprofiles(crosssections: gpd.GeoDataFrame | ExtendedGeoDataFrame, roughness: ExtendedDataFrame, branches: ExtendedGeoDataFrame | None, roughness_variant: RoughnessVariant | None = None) -> dict
¶
Convert the HyDAMO cross sections (dwarsprofiel) to D-Flow FM input.
Parameters¶
crosssections : gpd.GeoDataFrame GeoDataFrame with x,y,z-coordinates of cross sections
Returns¶
dictionary Dictionary with attributes of cross sections, usable for dflowfm
Source code in hydrolib/dhydamo/core/hydamo.py
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 | |
get_bottom_levels()
¶
Determine bottom levels from cross sections (legacy from delft3dfmpy, not working).
Source code in hydrolib/dhydamo/core/hydamo.py
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 | |
get_branches_without_crosssection() -> list[str]
¶
Return the ids of the branches without a cross section location.
Source code in hydrolib/dhydamo/core/hydamo.py
1398 1399 1400 1401 1402 1403 1404 1405 1406 | |
get_roughness_description(roughnesstype: str, value: float) -> str
¶
Return the name of a roughness definition, added if it is new.
Parameters¶
roughnesstype : str HyDAMO roughness type, mapped to the D-HYDRO type. value : float Roughness value.
Returns¶
str
Name of the definition, e.g. "Manning_0.03".
Raises¶
ValueError If the value is NaN.
Source code in hydrolib/dhydamo/core/hydamo.py
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 | |
get_structures_without_crosssection() -> list[str]
¶
Return the cross section definition ids of bridges and culverts that do not exist.
Source code in hydrolib/dhydamo/core/hydamo.py
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 | |
parametrised_to_profiles(parametrised: ExtendedDataFrame, parametrised_values: ExtendedDataFrame, branches: list, roughness_variant: RoughnessVariant | None = None, with_crosssection: Collection[Hashable] = ()) -> dict
¶
Generate the parametrised cross sections of branches.
Each link row gives its branch a profile, so a profile linked to several branches applies to each of them. A branch linked to several profiles gets the first, with a warning. A link is resolved against all branches; if its branch is in with_crosssection, it is skipped. Links to other branches are skipped too.
A profile without taludhelling linkerzijde is a rectangle, otherwise
a trapezium. A profile that lacks a dimension it needs (a bottom width and
both bottom levels, and for a trapezium also the right slope and both
insteek heights) is skipped with a warning.
Parameters¶
parametrised : ExtendedDataFrame
The links of branches to their parametrised profile
(hydroobject_normgp): hydroobjectid and normgeparamprofielid.
parametrised_values : ExtendedDataFrame
The values of the profiles (NormgeparamProfielWaarde).
branches : list
The branches, as rows of DataFrame.itertuples.
roughness_variant : RoughnessVariant, optional
Use the high or the low roughness value of the profiles.
with_crosssection : Collection[Hashable], optional
The indices of the branches that already have a cross section, and so
get no parametrised one. Default is none.
Returns¶
dict The attributes of the cross section of each branch, by branch index, usable for D-Flow FM.
Source code in hydrolib/dhydamo/core/hydamo.py
1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 | |
set_default_definition(definition: str, shift: float = 0.0) -> None
¶
Set the cross section definition for branches without a cross section.
It is used by Df2HydrolibModel(assign_default_profiles=True).
Parameters¶
definition : str Name of an existing cross section definition. shift : float, optional Vertical shift of the definition. Defaults to 0.0.
Raises¶
KeyError If the definition does not exist.
Source code in hydrolib/dhydamo/core/hydamo.py
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 | |
set_default_locations(locations: list[str]) -> None
¶
Set the branches that get the default cross section definition.
Parameters¶
locations : list[str] Branch ids.
Source code in hydrolib/dhydamo/core/hydamo.py
1143 1144 1145 1146 1147 1148 1149 1150 1151 | |
ExternalForcings
¶
Boundary conditions, laterals and initial and parameter fields of the model.
Parameters¶
hydamo : HyDAMO The HyDAMO object they belong to.
Source code in hydrolib/dhydamo/core/hydamo.py
1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 | |
add_boundary_condition(name: str, pt: tuple[float, float] | Point, quantity: str, value: float | pd.Series | dict[str, list[float]], mesh1d: netmodels.Network | None = None) -> None
¶
Add a boundary condition at the 1D node nearest to a location.
Parameters¶
name : str
Id of the boundary condition.
pt : tuple[float, float] or Point
Location of the boundary condition.
quantity : str
"dischargebnd", "waterlevelbnd" or "qhbnd".
value : float, pd.Series or dict[str, list[float]]
A constant, a time series with a datetime index, or a Q-H table
{"Q": [...], "H": [...]}.
mesh1d : Network, optional
Network with the 1D mesh. Required; the default None raises a ValueError.
Raises¶
KeyError If a boundary condition with this name exists, or the network has no 1D mesh. ValueError If no network is given.
Source code in hydrolib/dhydamo/core/hydamo.py
2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 | |
add_lateral(id: str, branchid: str, chainage: str, discharge: Annotated[pd.Series | float | str, Field(union_mode='left_to_right')]) -> None
¶
Add a lateral.
Parameters¶
id : str
Id of the lateral.
branchid : str
Branch on which the lateral lies.
chainage : str
Chainage on the branch.
discharge : pd.Series, float or str
"realtime" when coupled to RR, a constant discharge, or a time series with
a datetime index.
Source code in hydrolib/dhydamo/core/hydamo.py
3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 | |
add_rain_series(name: str, values: list, times: list) -> None
¶
Add a rain series as a boundary condition.
Parameters¶
name : str ID of the condition values : list of floats Values of the rain intensity times : list of datetime Times for the values
Source code in hydrolib/dhydamo/core/hydamo.py
3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 | |
add_rainfall_2D(fName, bctype='rainfall')
¶
Add 2D rainfall from a netCDF file (legacy from delft3dfmpy, not working).
Parameters¶
fName : str Location of netcdf file containing rainfall rasters bctype : str Type of boundary condition. Currently only rainfall is supported
Source code in hydrolib/dhydamo/core/hydamo.py
2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 | |
correct_values_from_modelrun(model_values: gpd.GeoDataFrame, correction_polygons: gpd.GeoDataFrame, value_column: str, boundary_step: float | None = 0.01) -> gpd.GeoDataFrame
¶
Replace values from a model result by the values of correction polygons.
All points within the polygons get the value of the polygon.
If the points have the columns 'branchid' and 'chainage' (as from read_values_from_modelrun) and the HyDAMO branches are available, two points are added where a polygon boundary crosses a branch, boundary_step apart: the point inside gets the polygon value, the point outside the model value interpolated along the branch. The value then changes at the polygon boundary instead of gradually between the nearest model points.
Parameters¶
model_values : gpd.GeoDataFrame
Points with a column value, e.g. from read_values_from_modelrun.
correction_polygons : gpd.GeoDataFrame
Polygons with the corrected values.
value_column : str
Column in correction_polygons with the corrected values.
boundary_step : float, optional
Distance between the two points at a polygon boundary; None adds no points.
Defaults to 0.01.
Returns¶
gpd.GeoDataFrame
Copy of model_values with corrected values (and the points at the polygon
boundaries). Where polygons overlap, the last polygon is used.
Source code in hydrolib/dhydamo/core/hydamo.py
2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 | |
read_values_from_modelrun(netcdf_path: str | Path, netcdf_field: str, netcdf_index: int | None = None, crs: CRS | str | int | None = None, time: datetime | pd.Timestamp | str | None = None) -> gpd.GeoDataFrame
¶
Read the values of a 1D variable from a model result (map or fou file).
Variables on the 1D nodes (e.g. 'mesh1d_s1', 'mesh1d_waterdepth') are returned at the node locations, variables on the 1D edges/flow links (e.g. 'mesh1d_u1') at the edge locations.
If 'mesh1d_s1' is requested but the file only contains the water depth, the water level is computed as bed level + water depth.
Missing values (dry nodes or links in a map-file) are replaced by the bed level for water levels, and by 0 for water depths, velocities and discharges; for other variables they are left out.
If the file contains the 1D network topology, the columns 'branchid' and 'chainage' are added, so the values can be written per branch with set_spatial_field(..., filetype="branch"). For edge variables, the column 'direction' (angle of the link in radians) is added, as used by set_initial_velocity.
Parameters¶
netcdf_path : str or Path
Path to the netCDF file.
netcdf_field : str
Variable to read, e.g. "mesh1d_s1" (map) or "mesh1d_fourier001_max" (fou).
netcdf_index : int, optional
Time index, e.g. 0 for the first time step. Defaults to None: without a
time, the last time step.
crs : CRS, str or int, optional
Coordinate reference system of the model. Defaults to None.
time : datetime, pd.Timestamp or str, optional
Time for which the values are read, e.g. "2016-06-02 12:00"; the nearest
time step is used. Defaults to None.
Returns¶
gpd.GeoDataFrame Points with the columns x, y and value (and branchid, chainage and direction, if available).
Source code in hydrolib/dhydamo/core/hydamo.py
2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 | |
set_initial_velocity(velocities: gpd.GeoDataFrame, column: str = 'value') -> None
¶
Set the initial velocity on the 1D flow links from a model result.
E.g. "mesh1d_u1" read with read_values_from_modelrun.
D-Flow FM (2026.02) does not accept 'initialvelocity' in the initial fields file, only the components 'initialvelocityx' and 'initialvelocityy'. The velocity along each link is therefore decomposed with the link direction and written as two sample files (triangulation). Tested with DIMR: on links that are in both models, the initial velocity equals the velocity of the model result within 1 cm/s. The effect of an initial velocity is short: the flow adapts within the first minutes.
Parameters¶
velocities : gpd.GeoDataFrame
Points at the link locations with the velocity and the column direction
(angle of the link in radians), as returned by read_values_from_modelrun.
column : str, optional
Column with the velocity along the link. Defaults to "value".
Source code in hydrolib/dhydamo/core/hydamo.py
2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 | |
set_initial_waterdepth(initial_values: float | gpd.GeoDataFrame, *, locationtype: str = '1d', value_column: str | None = None) -> None
¶
Set the initial water depth: a uniform value, or a value per polygon.
A uniform value for 1D (locationtype '1d') is written per branch for all branches, as a spatial field at the position of this call: fields added after it override it where they apply, fields added before it are overridden. Calling it again replaces the earlier uniform water depth. For 2D or 'all', a uniform value is written as a [Global] value; D-HYDRO 2026.02 then lets it override spatial water levels.
Polygons (1D only) are passed on to set_spatial_field and written per branch. For other spatially varying input, such as a model result, use set_spatial_field directly.
Parameters¶
initial_values : float or gpd.GeoDataFrame
Uniform water depth, or polygons with water depths.
locationtype : str, optional
"1d", "2d" or "all". Defaults to "1d".
value_column : str, optional
Column with the water depths, required for polygons. Defaults to None.
Source code in hydrolib/dhydamo/core/hydamo.py
1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 | |
set_initial_waterlevel(initial_values: float | gpd.GeoDataFrame, *, locationtype: str = '1d', value_column: str | None = None) -> None
¶
Set the initial water level: a uniform value, or a value per polygon.
A uniform value for 1D (locationtype '1d') is written per branch for all branches, as a spatial field at the position of this call: fields added after it override it where they apply, fields added before it are overridden. Calling it again replaces the earlier uniform water level. For 2D or 'all', a uniform value is written as a [Global] value.
Polygons (1D only) are passed on to set_spatial_field and written per branch. For other spatially varying input, such as a model result, use set_spatial_field directly.
Parameters¶
initial_values : float or gpd.GeoDataFrame
Uniform water level, or polygons with water levels.
locationtype : str, optional
"1d", "2d" or "all". Defaults to "1d".
value_column : str, optional
Column with the water levels, required for polygons. Defaults to None.
Source code in hydrolib/dhydamo/core/hydamo.py
1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 | |
set_missing_waterlevel(missing)
¶
Set the missing value for the water level (legacy from delft3dfmpy, not working).
This overwrites the water level at missing value in the mdu file.
Parameters¶
missing : float Water depth
Source code in hydrolib/dhydamo/core/hydamo.py
1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 | |
set_spatial_field(gdf: gpd.GeoDataFrame | Path | str, column: str | None = None, quantity: str = 'waterlevel', kind: str = 'initial', filetype: str | None = None, cellsize: float | None = None, locationtype: str = '1d', interpolationmethod: str | None = None, averagingtype: str = 'nearestNb', operand: str = 'O', nodata: float = -999.0, max_snap_distance: float = 5.0, averagingrelsize: float | None = None, averagingnummin: int | None = None, averagingpercentile: float | None = None, extrapolationmethod: bool | None = None) -> None
¶
Add a spatially varying field to the initial fields file (initialFields.ini).
By default, values are written per branch and chainage in a 1dField file (filetype 'branch'), for polygons and points. D-Flow FM interpolates them linearly along each branch only, and keeps them constant beyond the first and last chainage of a branch. For polygons, each part of a branch inside a polygon gets the polygon value, with a step at the polygon boundary. For points, the columns 'branchid' and 'chainage' are used if present (e.g. from read_values_from_modelrun); otherwise points are snapped to the nearest branch within max_snap_distance. In DIMR tests (D-HYDRO 2026.02) this gave the most reliable result for polygons, for model results on the same network and on a changed 1D grid, and for combining water level and water depth.
Advanced: the other file types are kept for special cases (e.g. 2D, or if a future D-Flow FM version does not accept 1dField files), but are not recommended for 1D:
- 'sample': points as samples (.xyz) with triangulation, which fills the convex hull of the points, so values spread to other branches.
- 'polygon': .pol files with interpolationMethod=constant, one file and block per distinct value.
- 'raster': polygons rasterized to a GeoTIFF (.tif) or ArcInfo grid (.asc), requires a cellsize. D-Flow FM (2026.02) uses the nodata value as data.
Tested with D-HYDRO 2026.02 on 1D nodes: interpolationMethod=averaging assigns no values, so it is refused for locationtype '1d'; triangulation fills the convex hull of the samples; nodes that get no value from any field keep the default water level (WaterLevIni in the MDU), which leaves them dry when it is below the bed level, so cover all nodes. Fields are applied in the order they are added (the last one wins). A uniform 1D value from set_initial_waterlevel/-depth is a field per branch over all branches, at the position of that call, so use it first as a background. A water depth from polygons or samples removes earlier water levels from polygons or samples everywhere, also outside its own area; water levels per branch are kept. Add water depth fields before water level fields.
For samples and rasters on 2D cells, choose the interpolation by the density of the data: 'averaging' for dense data (several values per cell, e.g. a point cloud or a fine raster), 'triangulation' for sparse data (fewer values than cells, e.g. measured points). Averaging combines the values inside each cell, as set by averagingtype and the averaging settings below; triangulation interpolates linearly between the values, and only within their convex hull unless extrapolationmethod is True. Settings left at None are not written, so D-Flow FM uses its defaults.
The data files are written by Df2HydrolibModel.write_initial_fields().
Parameters¶
gdf : gpd.GeoDataFrame or Path or str
Polygons or points with values, or the path to an existing .xyz file (x, y
and value per line). An .xyz file becomes a sample field (filetype
"sample", no column) and is copied unchanged under the generated name
when the model is written. For initial water levels and depths, only with
locationtype "2d": D-HyDAMO does not read its values, so it cannot check
them against other water level and depth fields on the 1D nodes.
column : str, optional
Column with the values. For points, None means the Z coordinate is used.
quantity : str, optional
D-Flow FM quantity, e.g. "waterlevel" or "waterdepth". For velocities,
use set_initial_velocity. Defaults to "waterlevel".
kind : str, optional
"initial" ([Initial] block) or "parameter" ([Parameter] block).
Defaults to "initial".
filetype : str, optional
"branch" (default), or the advanced types "sample", "polygon" or
"raster".
cellsize : float, optional
Raster cell size, required for filetype "raster".
locationtype : str, optional
"1d", "2d" or "all". Defaults to "1d".
interpolationmethod : str, optional
"constant" (polygon), "triangulation" or "averaging". Not used for
"branch". Defaults to "triangulation" for samples, "constant" for
polygon files, and "averaging" for rasters (2D) or "triangulation" (1D).
averagingtype : str, optional
Averaging type, if interpolationmethod is "averaging". Defaults to
"nearestNb".
operand : str, optional
How the field is combined with previous fields. Defaults to "O" (override).
nodata : float, optional
Nodata value for rasters, and the [Global] value of 1dField files (branch),
which D-Flow FM treats as no value. Defaults to -999.0.
max_snap_distance : float, optional
Maximum distance to snap points to a branch for filetype "branch". Defaults
to 5.0.
averagingrelsize : float, optional
With "averaging", the size of the area around a cell that is searched for
values, relative to the cell size (D-Flow FM default 1.01). Larger values
smooth more, and fill cells with few values. Defaults to None (not written).
averagingnummin : int, optional
With "averaging", the minimum number of values in that area; a cell with
fewer gets no value from this field (D-Flow FM default 1). Defaults to None
(not written).
averagingpercentile : float, optional
With "averaging", the percentile of the values to use instead of all
values, e.g. a low percentile for the lowest part of a cell (D-Flow FM
default 0, off). Defaults to None (not written).
extrapolationmethod : bool, optional
With "triangulation", True also gives values outside the convex hull of
the data. Defaults to None: not set, which hydrolib-core writes as
extrapolationMethod = 0.
Source code in hydrolib/dhydamo/core/hydamo.py
2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 | |
HyDAMO
¶
The HyDAMO input data and the model objects derived from it.
Holds the DAMO tables (branches, structures, profiles, management, catchments, ...) and the cross sections, structures, observation points, storage nodes and external forcings of the model.
Source code in hydrolib/dhydamo/core/hydamo.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
__init__(extent_file: Path | str | None = None) -> None
¶
Create an empty HyDAMO object.
Parameters¶
extent_file : Path or str, optional Model extent, used to clip the data. Defaults to None.
Source code in hydrolib/dhydamo/core/hydamo.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
create_laterals(qspec_file: str | Path | None = None, *, min_coverage_frac: float = 0.0, coverage_weight: zonal.CoverageWeight = 'fraction') -> None
¶
Create laterals at the catchments, with the mean specific discharge per catchment.
Parameters¶
qspec_file : str, optional
Raster of specific discharge (mm/d). Without it, the discharges are NaN.
min_coverage_frac : float, optional
Smallest fraction of a pixel a catchment must cover for the pixel to count in
the zonal statistics. Defaults to 0: every touched pixel.
coverage_weight : str, optional
"fraction" counts pixels by the fraction of them the catchment covers,
"none" counts them fully. Defaults to "fraction".
Source code in hydrolib/dhydamo/core/hydamo.py
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
dict_to_dataframe(dictionary: dict) -> pd.DataFrame
¶
Return a dictionary of dictionaries as a DataFrame, with the keys as rows.
Parameters¶
dictionary : dict Input dictionary.
Returns¶
pd.DataFrame Output DataFrame.
Source code in hydrolib/dhydamo/core/hydamo.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
list_to_str(lst: list | np.ndarray) -> str
¶
Return numbers as a space separated string, with 3 decimals.
Parameters¶
lst : list or np.ndarray Numbers.
Returns¶
str
The numbers, or str(lst) for a single number.
Source code in hydrolib/dhydamo/core/hydamo.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
load_from_gpkg(gpkg_path: Path | str, hydamo_version: str, clip_layers: dict | None = None, check_3d: bool = True, validation_mode: ValidationMode = 'off', validation_coverages: dict | None = None, validation_rules_path: Path | str | None = None) -> HyDAMO
¶
Load HyDAMO data from a GeoPackage of a supported DAMO version.
Parameters¶
gpkg_path : str or Path
Path to the GeoPackage file.
hydamo_version : str
DAMO schema version, one of SUPPORTED_HYDAMO_VERSIONS (2.2 to 2.6),
e.g. "2.6". Required: it selects the renames back to DAMO 2.2, the
names HYDROLIB uses; it does not detect or verify the source schema
version.
clip_layers : dict, optional
Per-table spatial clip. Maps a HyDAMO table name to a
(geometry, cliptype) tuple, e.g.
{"branches": (gpd.read_file(extent).union_all(), "clip")}.
Layers absent from the dict are loaded without clipping.
check_3d : bool
Whether to require Z coordinates on profile points when grouping
them into lines. Other layers are not checked for Z coordinates.
Pass False to allow 2D profile points. Default is True.
validation_mode : str
"off" skips validation (default). Both other modes act on the
values the syntax check rejected in columns HYDROLIB reads (its
required columns, globalid and, for spatial tables, the
geometry): "warn" logs them as one warning per layer, by the
hydrolib.dhydamo.validation logger, and continues; "strict"
raises HyDAMOValidationError before loading layers, as it does
when the validation run fails. Rejected values in other columns
only give one INFO line with their number. Inspect
validation_result.syntax_findings for all of them. Validation
setup errors can raise in either enabled mode.
validation_coverages : dict, optional
Coverage dict forwarded to the validator.
validation_rules_path : str or Path, optional
Path to a custom validation-rules JSON file for the source DAMO
version. If omitted, generated rules check ID presence on recognized
layers with an ID column. Strict mode changes failure handling,
not the rules or their coverage.
Returns¶
HyDAMO This instance, to allow method chaining.
Raises¶
HyDAMOValidationError
In "strict" mode, if the validation run fails or rejected values
in a column HYDROLIB reads.
ImportError
If validation is enabled and its optional dependency is unavailable.
KeyError
If a loaded layer lacks a required column, such as the code of a
table whose code is its identity; the message names the layer.
ValueError
If the DAMO version is unsupported, or generated validation
rules require a version unsupported by the installed validator. Also
if the identity (code) or the column that groups points into
lines (profiellijnid) is empty in some rows, also when it is only
whitespace; the message names the layer and the rows by globalid.
Notes¶
A load replaces every DAMO table, also those whose layer the GeoPackage
lacks: nothing of an earlier load is left in them. HYDROLIB's own tables
(sewer areas, overflows, greenhouses, storage areas) are kept, and so are
model objects built from an earlier load, such as structures and cross
sections. For a new model, use a new HyDAMO.
Validation requires Python 3.12 and pip install "hydrolib[validation]".
After enabled validation returns normally, self.validation_result
contains success, status, errors and syntax_findings
(per layer, column and error code). It is None when
validation is off. Use validate_gpkg() to inspect validation failures
without loading data. Comprehensive schema, type, and relation checks
require appropriate custom rules; selecting a DAMO version or using strict
mode alone does not establish that the input is valid DAMO data.
Examples¶
Given a rules file for DAMO 2.2, load and inspect reported failures:
hydamo = HyDAMO().load_from_gpkg( ... "model.gpkg", ... hydamo_version="2.2", ... validation_mode="warn", ... validation_rules_path="validationrules.json", ... ) result = hydamo.validation_result print(result.success, result.status, result.errors)
Use validation_mode="strict" to raise HyDAMOValidationError
instead of loading after a reported validation failure.
Source code in hydrolib/dhydamo/core/hydamo.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
snap_to_branch_and_drop(extendedgdf: ExtendedGeoDataFrame, branches: ExtendedGeoDataFrame, snap_method: str, maxdist: float = 5, drop_related: bool = True, source_table: str | None = None) -> None
¶
Snap geometries to branches and drop loose objects and cascades.
Parameters¶
extendedgdf : ExtendedGeoDataFrame
HyDAMO dataframe to snap and potentially prune.
branches : ExtendedGeoDataFrame
Branch geometries used for snapping.
snap_method : str
Method passed to :meth:ExtendedGeoDataFrame.snap_to_branch.
maxdist : float, default=5
Maximum snapping distance passed to snap_to_branch.
drop_related : bool, default=True
Whether to drop rows reached through the configured cascade paths.
source_table : str, optional
Canonical HyDAMO table name. If omitted, the name is determined
from the dataframe object stored on this HyDAMO instance.
Supply this when extendedgdf is a dataframe copy; the named
table must still exist as an attribute on this instance.
Source code in hydrolib/dhydamo/core/hydamo.py
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | |
validate_gpkg(gpkg_path: Path | str, hydamo_version: str, validation_coverages: dict | None = None, validation_rules_path: Path | str | None = None) -> HydamoValidationResult
¶
Validate a GeoPackage without loading its layers.
Requires Python 3.12 and the optional dependency installed with
pip install "hydrolib[validation]".
Parameters¶
gpkg_path : str or Path
Path to the GeoPackage file.
hydamo_version : str
DAMO version to validate against, e.g. "2.6". Required: it selects
the version; it does not detect the source version. Any version that the
installed validatiemodule has a schema for is accepted, which can include
versions that load_from_gpkg cannot load yet (see
SUPPORTED_HYDAMO_VERSIONS). For such a version no column counts as
read by HYDROLIB, so every finding goes into the INFO line.
validation_coverages : dict, optional
Coverage dict forwarded to the validator.
validation_rules_path : str or Path, optional
Path to a validation-rules JSON file for the requested DAMO version.
If omitted, generated rules check ID presence on recognized layers
with an ID column. Supply custom rules for more comprehensive checks.
Returns¶
HydamoValidationResult
Also stored as self.validation_result. Inspect success,
status, errors and syntax_findings to handle validation
failures. Findings in columns HYDROLIB reads are logged as one
warning per layer by the hydrolib.dhydamo.validation logger, the
number of other findings as one INFO line. A reported failure is
returned rather than raised as HyDAMOValidationError. The
validatiemodule's own diagnostics are logged by the
hydamo_validation.validator logger.
Raises¶
ImportError If the optional validation dependency is unavailable. ValueError If generated rules are requested for a version unsupported by the installed validator's schemas.
Source code in hydrolib/dhydamo/core/hydamo.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
Network
¶
Legacy 1D network helpers, taken over from delft3dfmpy. Not functional.
The methods use self.mesh1d, self.branches, self.schematised and
self.str2chars, which came from the gridgeom-based network in delft3dfmpy and
are never set here: every method raises AttributeError. Nothing in this package,
its tests or notebooks uses HyDAMO.network; the 1D network is the hydrolib-core
Network (see hydrolib.dhydamo.geometry.mesh).
The methods are marked @no_type_check, so mypy skips them, like the deprecated
gridgeom module. Remove this class together with gridgeom.
Source code in hydrolib/dhydamo/core/hydamo.py
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 | |
__init__(hydamo: HyDAMO) -> None
¶
Create the legacy network helpers (not functional, see the class docstring).
Source code in hydrolib/dhydamo/core/hydamo.py
599 600 601 602 603 604 605 | |
generate_nodes_with_bedlevels(resolve_at_bifurcation_method: str = 'min', return_reversed_branches: bool = False)
¶
Generate nodes with upstream and downstream bed levels from the cross sections on a branch.
It takes into account whether or not branch order is specified (so interpolation over nodes is set).
Nodes in between cross-sections on same branch/branch-group are linearly interpolated. Outside are extrapolated constant (e.g. end points of branch).
Branch groups which include branch with reversed direction compared to whole group will be taken into account. Use return_reversed_branches=True to return that information
Specify with resolve_at_bifurcation_method how to resolve bedlevel at bifurcation of more than 2 branches using options 'min' (minimum), 'max' (maximum), 'mean' (average).
Source code in hydrolib/dhydamo/core/hydamo.py
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 | |
get_grouped_branches() -> None
¶
Get grouped branch ids to use in set_branch_order function.
Source code in hydrolib/dhydamo/core/hydamo.py
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 | |
get_node_idx_offset(branch_id: str, pt: shapely.geometry.Point, nnodes: int = 1) -> tuple
¶
Get the index and offset of the nearest node on a 1d branch.
Source code in hydrolib/dhydamo/core/hydamo.py
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 | |
make_branches_to_node_map() -> None
¶
Map branches connected to each node.
Source code in hydrolib/dhydamo/core/hydamo.py
662 663 664 665 666 667 668 669 | |
make_nodes_to_branch_map() -> None
¶
Map nodes connected to each branch.
Source code in hydrolib/dhydamo/core/hydamo.py
650 651 652 653 654 655 656 657 658 659 660 | |
set_branch_interpolation_modelwide() -> None
¶
Set cross-section interpolation over nodes on all branches model-wide.
Note
- Interpolation will be set using branchorder property.
- Branches are grouped between bifurcations where multiple branches meet.
- No interpolation is applied over these type of bifurcations.
- No branch order is set on branch groups consisting of 1 branch.
Source code in hydrolib/dhydamo/core/hydamo.py
635 636 637 638 639 640 641 642 643 644 645 646 647 648 | |
set_branch_order(branchids: list, idx: int | None = None) -> None
¶
Group branch ids so that the cross sections are interpolated along the branch.
Parameters¶
branchids : list List of branches to group idx : int Order number with which to update a branch
Source code in hydrolib/dhydamo/core/hydamo.py
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 | |
ObservationPoints
¶
Observation points of the model.
Parameters¶
hydamo : HyDAMO The HyDAMO object they belong to.
Source code in hydrolib/dhydamo/core/hydamo.py
3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 | |
add_points(crds: list, names: list, locationTypes: str | list[str] | None = None, snap_distance: float = 5.0) -> None
¶
Add observation points, of type '1d' or '2d'; 1d points are snapped to a branch.
Parameters¶
crds : Nx2 list or array x and y coordinates of observation points names : str or list names of the observation points locationTypes: str or list type of the observationpoints: 1d or 2d snap_distance : float (default is 5 m) 1d observation poinst within this distance to a branch will be snapped to it. Otherwise they are discarded.
Source code in hydrolib/dhydamo/core/hydamo.py
3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 | |
StorageNodes
¶
Storage nodes of the model.
Parameters¶
hydamo : HyDAMO The HyDAMO object they belong to.
Source code in hydrolib/dhydamo/core/hydamo.py
3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 | |
add_storagenode(id: str, xy: tuple[float, float] | Point | None = None, branchid: str | None = None, chainage: float | None = None, nodeid: str | None = None, usestreetstorage: str | bool = 'true', nodetype: str = 'unspecified', manholeid: str | None = None, name: str | float = np.nan, usetable: str = 'false', bedlevel: float = np.nan, area: float = np.nan, streetlevel: float = np.nan, streetstoragearea: float = np.nan, storagetype: str = 'reservoir', levels: str | float = np.nan, storagearea: str | float = np.nan, interpolate: str = 'linear', network: netmodels.Network | None = None) -> None
¶
Add a storage node, at a 1D node.
The node is nodeid, or the 1D node nearest to xy or to branchid and
chainage. The other arguments correspond to the D-Flow FM keywords of a
storage node; with usetable="true", levels and storagearea are space
separated numbers.
Raises¶
ValueError
Without a nodeid, a network or a location; or with a table but without
levels and storagearea.
Source code in hydrolib/dhydamo/core/hydamo.py
3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 | |
Structures
¶
Structures of the model, one DataFrame per type.
The add_* methods take keyword arguments only; they correspond to the keywords
of the D-Flow FM structure file.
Parameters¶
hydamo : HyDAMO The HyDAMO object they belong to.
Source code in hydrolib/dhydamo/core/hydamo.py
3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 | |
add_bridge(*, id: str, name: str | None = None, branchid: str, chainage: float, length: float | None = None, inletlosscoeff: float | None = None, outletlosscoeff: float | None = None, csdefid: str | None = None, shift: float | None = None, allowedflowdir: str = 'both', frictiontype: str, friction: float | None = None) -> None
¶
Add a bridge.
id, branchid, chainage and frictiontype (HyDAMO roughness type)
are required; the other arguments correspond to the D-Flow FM keywords of a
bridge. csdefid is the id of its cross section definition.
Source code in hydrolib/dhydamo/core/hydamo.py
3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 | |
add_compound(*, id: str, structureids: list) -> None
¶
Add a compound structure of existing structures.
Parameters¶
id : str Id of the compound structure. structureids : list Ids of its structures.
Source code in hydrolib/dhydamo/core/hydamo.py
3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 | |
add_culvert(*, id: str, name: str | None = None, branchid: str, chainage: float, leftlevel: float | None = None, rightlevel: float | None = None, length: float | None = None, inletlosscoeff: float | None = None, outletlosscoeff: float | None = None, crosssection: dict, allowedflowdir: str = 'both', valveonoff: int = 0, numlosscoeff: int | None = None, valveopeningheight: float = 0, relopening: list | None = None, losscoeff: list | None = None, bedfrictiontype: str, bedfriction: float) -> None
¶
Add a culvert, and a cross section definition named after it.
id, branchid, chainage, crosssection, bedfrictiontype
(HyDAMO roughness type) and bedfriction are required; the other arguments
correspond to the D-Flow FM keywords of a culvert. crosssection is
{"shape": "circle", "diameter": ...} or
{"shape": "rectangle", "height": ..., "width": ..., "closed": ...}.
Raises¶
NotImplementedError For another cross section shape.
Source code in hydrolib/dhydamo/core/hydamo.py
3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 | |
add_orifice(*, id: str, name: str | None = None, branchid: str, chainage: float, crestlevel: float | None = None, crestwidth: float | None = None, corrcoeff: float | None = None, usevelocityheight: bool = True, allowedflowdir: str = 'both', gateloweredgelevel: float | None = None, uselimitflowpos: bool | None = None, limitflowpos: float | None = None, uselimitflowneg: bool | None = None, limitflowneg: float | None = None) -> None
¶
Add an orifice.
id, branchid and chainage are required; the other arguments correspond
to the D-Flow FM keywords of an orifice.
Source code in hydrolib/dhydamo/core/hydamo.py
3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 | |
add_pump(*, id: str, name: str | None = None, branchid: str, chainage: float, orientation: str = 'positive', numstages: int = 1, controlside: str = 'suctionSide', capacity: float | None = None, startlevelsuctionside: list | None = None, stoplevelsuctionside: list | None = None, startleveldeliveryside: list | None = None, stopleveldeliveryside: list | None = None) -> None
¶
Add a pump.
id, branchid and chainage are required; the other arguments correspond
to the D-Flow FM keywords of a pump.
Source code in hydrolib/dhydamo/core/hydamo.py
3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 | |
add_rweir(*, id: str, name: str | None = None, branchid: str, chainage: float, crestlevel: float | None = None, crestwidth: float | None = None, corrcoeff: float | None = None, usevelocityheight: bool = True, allowedflowdir: str = 'both') -> None
¶
Add a regular weir.
id, branchid and chainage are required; the other arguments correspond
to the D-Flow FM keywords of a weir.
Source code in hydrolib/dhydamo/core/hydamo.py
3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 | |
add_uweir(*, id: str, name: str | None = None, branchid: str, chainage: float, crestlevel: float | None = None, crestwidth: float | None = None, dischargecoeff: float | None = None, usevelocityheight: bool = True, allowedflowdir: str = 'both', numlevels: float | None = None, yvalues: str | None = None, zvalues: str | None = None) -> None
¶
Add a universal weir.
id, branchid and chainage are required; the other arguments correspond
to the D-Flow FM keywords of a universal weir.
Source code in hydrolib/dhydamo/core/hydamo.py
3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 | |
as_dataframe(generalstructures: bool = False, pumps: bool = False, rweirs: bool = False, bridges: bool = False, culverts: bool = False, uweirs: bool = False, orifices: bool = False, compounds: bool = False) -> pd.DataFrame | None
¶
Return the structures of the given types in one DataFrame, with a column structype.
Returns None if there are no such structures.
Source code in hydrolib/dhydamo/core/hydamo.py
3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 | |
check_branchid_chainage(branchid: str, chainage: float) -> None
¶
Raise a ValueError if the branch does not exist or the chainage is outside it.
Parameters¶
branchid : str Branch id. chainage : float Chainage on the branch.
Source code in hydrolib/dhydamo/core/hydamo.py
3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 | |
remove_nan_values(base: Mapping[str, object]) -> dict[str, object]
¶
Return a copy of a mapping without the NaN values.
Parameters¶
base : Mapping[str, object] Input data, with NaN values.
Returns¶
dict[str, object] Copy without the float NaN values.
Source code in hydrolib/dhydamo/core/hydamo.py
3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 | |
relations
¶
Follow the relations between the HyDAMO tables, and plan cascading drops.
The relations themselves, and the cascade paths, are in the data model
(hydrolib.dhydamo.core.data_model).
build_cascade_plan(hydamo: HyDAMO, source_table: str, source_index: pd.Index) -> dict[str, pd.Index]
¶
Return the configured, bounded cascade plan for selected rows.
This helper exists to separate deciding what may be deleted from the
subsequent dataframe mutation. Cascade policy is expressed as explicit
paths in the data model's CASCADE_PATHS. Each configured path starts from the
original source_index and is followed independently. Rows reached
through the same table are merged by index, and this function never mutates
a dataframe.
Parameters¶
hydamo : HyDAMO
Object containing the source and related table dataframes.
source_table : str
Name of the source dataframe, such as "profile" or
"pumpstations". Its cascade paths are looked up in
CASCADE_PATHS.
source_index : pandas.Index
Index labels identifying the source rows from which to build the
plan.
Returns¶
dict[str, pandas.Index] Mapping from each related table name to the unique index labels that would be affected. The source table itself is not included. A table without cascade paths returns an empty dictionary.
Raises¶
ValueError
If source_table is not a HyDAMO table (TABLES or OWN_TABLES),
e.g. a typo: read as a table without cascade paths, it would let the
caller drop the source rows and leave their related rows behind.
Source code in hydrolib/dhydamo/core/relations.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
follow_relation(hydamo: HyDAMO, relation: Relation, from_table: str, rows: pd.DataFrame) -> tuple[str, pd.DataFrame]
¶
Return rows related to rows through a direct relation.
This helper exists because a relation is defined once in foreign-key direction (child to parent), but callers may start from either endpoint. It selects the correct source and target columns for that direction, so callers do not need duplicate forward and reverse relation definitions.
Matching is performed on relation key columns, not on dataframe indices.
For example, following profile_line from profile matches
profile.profiellijnid to profile_line.globalid; following it in
reverse matches profile_line.globalid to profile.profiellijnid.
Parameters¶
hydamo : HyDAMO
Object containing the dataframe for the other relation endpoint.
relation : Relation
Direct relation to follow. Its foreign_key belongs to
child_table and its parent_key belongs to parent_table.
from_table : str
Name of the endpoint represented by rows. It must equal either
relation.child_table or relation.parent_table.
rows : pandas.DataFrame
Selected rows from from_table. The relevant relation key must be
present as a column. An empty dataframe with that column returns an
empty dataframe for the other endpoint.
Returns¶
tuple[str, pandas.DataFrame]
The name of the other endpoint table and the rows whose relation key
matches a key value in rows. The target dataframe's index and
columns are preserved.
Raises¶
ValueError
If from_table is not an endpoint of relation.
KeyError
If the required source or target relation key is missing.
Source code in hydrolib/dhydamo/core/relations.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |