IO
DHyDAMO IO API¶
Read input data and write D-HYDRO model files.
common
¶
DataFrames and GeoDataFrames with required columns and a geometry type check.
ExtendedDataFrame
¶
Bases: DataFrame
DataFrame with required columns.
The data is replaced in place (see set_data), so references to the object, e.g.
from a HyDAMO object, stay valid.
Parameters¶
required_columns : str or list[str], optional
Columns the data must have. Defaults to None: no required columns.
*args, **kwargs
Passed on to pd.DataFrame.
Source code in hydrolib/dhydamo/io/common.py
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 | |
add_data(df: pd.DataFrame) -> None
¶
Append the rows of a DataFrame, in place.
Parameters¶
df : pd.DataFrame Rows to add.
Raises¶
KeyError
If df has columns that this DataFrame does not have.
Source code in hydrolib/dhydamo/io/common.py
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 | |
delete_all() -> None
¶
Remove all rows, in place.
Source code in hydrolib/dhydamo/io/common.py
852 853 854 855 856 857 | |
read_gpkg_layer(gpkg_path: str | Path, layer_name: str, column_mapping: dict | None = None, index_col: str | None = None) -> None
¶
Read a GeoPackage table into this object (deprecated).
Use HyDAMO.load_from_gpkg() to load DAMO data.
Source code in hydrolib/dhydamo/io/common.py
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 | |
set_data(df: pd.DataFrame, index_col: Hashable | None) -> None
¶
Replace the data with that of a DataFrame, in place.
Rows and columns that df doesn't have are removed.
Parameters¶
df : pd.DataFrame
New data.
index_col : Hashable or None
Column to use as index; None keeps the index of df.
Raises¶
KeyError If a required column is missing.
Source code in hydrolib/dhydamo/io/common.py
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 | |
ExtendedGeoDataFrame
¶
Bases: GeoDataFrame
GeoDataFrame with required columns and a required geometry type.
The data is replaced in place (see set_data), so references to the object, e.g.
from a HyDAMO object, stay valid.
Parameters¶
geotype : type[BaseGeometry] or UnionType
Required geometry class, or a union of classes such as Polygon | MultiPolygon.
required_columns : str or list[str], optional
Columns the data must have. Defaults to None: no required columns.
logger : ModuleType or logging.Logger, optional
Not used. Defaults to the logging module.
*args, **kwargs
Passed on to gpd.GeoDataFrame.
Source code in hydrolib/dhydamo/io/common.py
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 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 | |
branch_to_prof(offset: float = 0.0, vertex_end: bool = False, rename_col: str | None = None, prefix: str = '', suffix: str = '') -> ExtendedGeoDataFrame
¶
Return a point on each branch, e.g. to place a profile.
Parameters¶
offset : float, optional
Distance of the point from the start of the branch, or from its end with
vertex_end. Stored in the column offset. Defaults to 0.0.
vertex_end : bool, optional
Measure offset from the end of the branch. Defaults to False.
rename_col : str, optional
Column with the branch id. It is copied to branch_id, and the column gets
prefix and suffix around the id. Defaults to None.
prefix, suffix : str, optional
Added around the id in rename_col. Default to "".
Returns¶
ExtendedGeoDataFrame Copy of the branches, with the points as geometry.
Raises¶
ValueError
If rename_col does not exist.
Source code in hydrolib/dhydamo/io/common.py
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 | |
check_projection(crs_out: CRS | str) -> None
¶
Reproject to a CRS, in place, if the data has another CRS.
Source code in hydrolib/dhydamo/io/common.py
705 706 707 708 709 710 711 | |
clip(geometry: Polygon | MultiPolygon, cliptype: str = 'select', clip_and_drop: bool = True) -> None
¶
Keep only the features within a geometry, in place.
Parameters¶
geometry : Polygon or MultiPolygon
Area to keep.
cliptype : str, optional
"select" keeps the features that intersect the area, unchanged;
"clip" cuts them off at its boundary. Defaults to "select".
clip_and_drop : bool, optional
With "clip": keep only parts of the original geometry types (e.g. no
points where a line touches the boundary), and merge the parts of one
feature into one multi-geometry. Defaults to True.
Raises¶
TypeError If the geometry is not a Polygon or MultiPolygon. ValueError If the cliptype is unknown, or no features are left.
Source code in hydrolib/dhydamo/io/common.py
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 | |
copy(deep: bool = True) -> ExtendedGeoDataFrame
¶
Return a copy that keeps the geometry type and the required columns.
Source code in hydrolib/dhydamo/io/common.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
delete_all() -> None
¶
Remove all rows, in place.
Source code in hydrolib/dhydamo/io/common.py
271 272 273 274 275 | |
merge_columns(col1: str, col2: str, rename_col: str) -> None
¶
Add two columns and store the result in a column, in place.
Strings are concatenated, numbers are added.
Parameters¶
col1, col2 : str Names of the columns to add. rename_col : str Name of the column for the result; an existing column is overwritten.
Raises¶
ValueError If a column does not exist, or the columns cannot be added.
Source code in hydrolib/dhydamo/io/common.py
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 | |
read_gpkg_layer(gpkg_path: str | Path, layer_name: str, index_col: str | None = None, groupby_column: str | None = None, order_column: str | None = None, id_col: str = 'code', column_mapping: dict | None = None, check_columns: bool = True, check_geotype: bool = True, clip: Polygon | MultiPolygon | None = None, cliptype: str = 'select', check_3d: bool = True) -> None
¶
Read a GeoPackage layer into this object (deprecated).
Use HyDAMO.load_from_gpkg() to load DAMO data.
Source code in hydrolib/dhydamo/io/common.py
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 | |
read_shp(path: str | Path, index_col: str | None = None, column_mapping: dict | None = None, check_columns: bool = True, proj_crs: CRS | str | None = None, clip: Polygon | MultiPolygon | None = None, check_geotype: bool = True, id_col: str = 'code', filter_cols: bool = False, filter_rows: dict[str, object] | None = None) -> None
¶
Read a shapefile (or another file geopandas can read) into this object, in place.
Features without a geometry are dropped.
Parameters¶
path : str or Path
File to read.
index_col : str, optional
Column to use as index. Defaults to None: keep the index of the file.
column_mapping : dict, optional
Renames columns, from old to new name. Defaults to None.
check_columns : bool, optional
Check that the required columns are present. Defaults to True.
proj_crs : CRS or str, optional
Reproject to this CRS. Defaults to None: keep the CRS of the file.
clip : Polygon or MultiPolygon, optional
Keep only the features that intersect this geometry. Defaults to None.
check_geotype : bool, optional
Check the geometry type. Defaults to True.
id_col : str, optional
Not used. Defaults to "code".
filter_cols : bool, optional
Keep only the required columns. Defaults to False.
filter_rows : dict[str, object], optional
Keep only the rows with these values, as {column: value}. Defaults to None.
Raises¶
OSError If the file has no features with a geometry.
Source code in hydrolib/dhydamo/io/common.py
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 | |
set_data(gdf: gpd.GeoDataFrame, index_col: str | None = None, check_columns: bool = True, check_geotype: bool = True) -> None
¶
Replace the data with that of a GeoDataFrame, in place.
Rows and columns that gdf doesn't have are removed.
Parameters¶
gdf : gpd.GeoDataFrame
New data.
index_col : str, optional
Column to use as index. Defaults to None: keep the index of gdf.
check_columns : bool, optional
Check that the required columns are present. Defaults to True.
check_geotype : bool, optional
Check the geometry type. Defaults to True.
Raises¶
KeyError If a required column is missing. TypeError If a geometry is not of the required type.
Source code in hydrolib/dhydamo/io/common.py
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 | |
show_gpkg(gpkg_path: str | Path) -> None
¶
Log the layers of a GeoPackage, with their geometry type and size.
Parameters¶
gpkg_path : str or Path GeoPackage to show.
Raises¶
OSError If the file does not exist.
Source code in hydrolib/dhydamo/io/common.py
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 | |
snap_to_branch(branches: gpd.GeoDataFrame, snap_method: str, maxdist: float = 5) -> None
¶
Find the nearest branch for each geometry, see spatial.find_nearest_branch.
Fills the columns branch_id and branch_offset, in place.
Parameters¶
branches : gpd.GeoDataFrame
Branches, with the branch id as index.
snap_method : str
"overal", "centroid", "ends" or "intersecting".
maxdist : float, optional
Maximum distance to a branch. Defaults to 5.
Source code in hydrolib/dhydamo/io/common.py
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 | |
damo_versions
¶
Load a DAMO GeoPackage of a supported version into HYDROLIB's data model.
steps holds the renames of each DAMO version, and loader reads a GeoPackage into
HYDROLIB's data model (hydrolib.dhydamo.core.data_model): the HyDAMO tables under
their DAMO 2.2 names and HYDROLIB's extensions. explain reports how a layer becomes
a HyDAMO table, from the same data.
SourceLayer
dataclass
¶
Where a HyDAMO table comes from in a file of one DAMO version.
Parameters¶
layer : str
The layer in that version.
renames : dict[str, str]
{column in that version: DAMO 2.2 name}, for the renamed columns.
Source code in hydrolib/dhydamo/io/damo_versions/steps.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
explain
¶
Report how a layer of a DAMO GeoPackage becomes a HyDAMO table.
The report is built from the data model (hydrolib.dhydamo.core.data_model) and the
version steps (steps) only, the same data loading uses, so it can't drift from the
loading code: the layers and column names come from steps.source_layers, as loading
gets them. It explains the contract, not one file: it doesn't open a GeoPackage, so it
can't say which columns a version's schema has.
explain_table(table: str, version: str) -> str
¶
Return a text report of how HyDAMO table is loaded from a DAMO version file.
The report gives the layer the table is read from and the steps that moved it; per declared column, whether the loaded table requires it, its name in version, the steps that renamed it, and whether the loader fills or derives it; HYDROLIB's extensions with their reasons; the values the code compares against; and the relations the table takes part in.
Parameters¶
table : str
HyDAMO attribute of the table, e.g. "management_device".
version : str
DAMO version, one of SUPPORTED_HYDAMO_VERSIONS, e.g. "2.5".
Returns¶
str The report, one table, several lines.
Raises¶
ValueError If version is not supported, or table isn't a HyDAMO table.
Examples¶
print(explain_table("management_device", "2.5")) # doctest: +SKIP
Source code in hydrolib/dhydamo/io/damo_versions/explain.py
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 | |
explain_tables(version: str) -> str
¶
Return the report of explain_table for every HyDAMO table, for DAMO version.
Parameters¶
version : str
DAMO version, one of SUPPORTED_HYDAMO_VERSIONS, e.g. "2.6".
Returns¶
str
The reports, in the order of data_model.TABLES, separated by a blank line.
Raises¶
ValueError If version is not supported.
Source code in hydrolib/dhydamo/io/damo_versions/explain.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
explain_table(table: str, version: str) -> str
¶
Return a text report of how HyDAMO table is loaded from a DAMO version file.
The report gives the layer the table is read from and the steps that moved it; per declared column, whether the loaded table requires it, its name in version, the steps that renamed it, and whether the loader fills or derives it; HYDROLIB's extensions with their reasons; the values the code compares against; and the relations the table takes part in.
Parameters¶
table : str
HyDAMO attribute of the table, e.g. "management_device".
version : str
DAMO version, one of SUPPORTED_HYDAMO_VERSIONS, e.g. "2.5".
Returns¶
str The report, one table, several lines.
Raises¶
ValueError If version is not supported, or table isn't a HyDAMO table.
Examples¶
print(explain_table("management_device", "2.5")) # doctest: +SKIP
Source code in hydrolib/dhydamo/io/damo_versions/explain.py
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 | |
explain_tables(version: str) -> str
¶
Return the report of explain_table for every HyDAMO table, for DAMO version.
Parameters¶
version : str
DAMO version, one of SUPPORTED_HYDAMO_VERSIONS, e.g. "2.6".
Returns¶
str
The reports, in the order of data_model.TABLES, separated by a blank line.
Raises¶
ValueError If version is not supported.
Source code in hydrolib/dhydamo/io/damo_versions/explain.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
load_layers(hydamo: HyDAMO, gpkg_path: str | Path, sources: dict[str, SourceLayer], hydamo_version: str, clip_layers: dict | None = None, check_3d: bool = True) -> None
¶
Read the layers of a DAMO GeoPackage into hydamo, under their DAMO 2.2 names.
Then rewrites values and computes the derived columns, as declared on the tables
(Column.rewrite, Table.derived_columns).
Parameters¶
hydamo : HyDAMO
The HyDAMO instance whose tables are filled.
gpkg_path : str or Path
Path to the GeoPackage.
sources : dict[str, SourceLayer]
The layers and renames of the GeoPackage's DAMO version, from
source_layers.
hydamo_version : str
DAMO version of the GeoPackage, for the messages.
clip_layers : dict, optional
Per-table spatial clip: maps a HyDAMO attribute to a (geometry, cliptype)
tuple. Tables absent from the dict are loaded without clipping.
check_3d : bool
Whether to require Z coordinates on profile points when grouping them into
lines. Default is True.
Raises¶
KeyError
If a loaded layer lacks a required column (data_model.TABLES); the message
names the layer and the column. Raised at once.
ValueError
If a layer that is not optional is missing, or a layer of points lacks the
column that groups or orders them into lines; the message names the layer.
Also if a table's identity, or the column that groups points into lines, is
empty in some rows; the message names the layer and the first rows. These
errors are collected over all layers and raised together, one line each.
Source code in hydrolib/dhydamo/io/damo_versions/loader.py
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 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 | |
loader
¶
Load a DAMO GeoPackage of any supported version into HYDROLIB's data model.
load_layers(hydamo: HyDAMO, gpkg_path: str | Path, sources: dict[str, SourceLayer], hydamo_version: str, clip_layers: dict | None = None, check_3d: bool = True) -> None
¶
Read the layers of a DAMO GeoPackage into hydamo, under their DAMO 2.2 names.
Then rewrites values and computes the derived columns, as declared on the tables
(Column.rewrite, Table.derived_columns).
Parameters¶
hydamo : HyDAMO
The HyDAMO instance whose tables are filled.
gpkg_path : str or Path
Path to the GeoPackage.
sources : dict[str, SourceLayer]
The layers and renames of the GeoPackage's DAMO version, from
source_layers.
hydamo_version : str
DAMO version of the GeoPackage, for the messages.
clip_layers : dict, optional
Per-table spatial clip: maps a HyDAMO attribute to a (geometry, cliptype)
tuple. Tables absent from the dict are loaded without clipping.
check_3d : bool
Whether to require Z coordinates on profile points when grouping them into
lines. Default is True.
Raises¶
KeyError
If a loaded layer lacks a required column (data_model.TABLES); the message
names the layer and the column. Raised at once.
ValueError
If a layer that is not optional is missing, or a layer of points lacks the
column that groups or orders them into lines; the message names the layer.
Also if a table's identity, or the column that groups points into lines, is
empty in some rows; the message names the layer and the first rows. These
errors are collected over all layers and raised together, one line each.
Source code in hydrolib/dhydamo/io/damo_versions/loader.py
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 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 | |
source_layers(version: str) -> dict[str, SourceLayer]
¶
Return, per HyDAMO table, its layer and column renames in a DAMO version.
Chains the steps between DAMO 2.2 and version.
Parameters¶
version : str
DAMO version, one of SUPPORTED_HYDAMO_VERSIONS, e.g. "2.4".
Returns¶
dict[str, SourceLayer]
By HyDAMO attribute, in the order of data_model.TABLES.
Raises¶
ValueError If the version is not supported, a step names a table that isn't a HyDAMO table, or two tables read the same layer: the steps are keyed by table, so each table needs its own layer.
Source code in hydrolib/dhydamo/io/damo_versions/steps.py
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 | |
steps
¶
The DAMO version steps: the renames DAMO made in each version, for what HYDROLIB reads.
A step is written forward, from the older version to the newer, like the DAMO release notes. Each rename is written once, in the step where DAMO made it.
Loading doesn't convert the data step by step. source_layers chains the steps into,
per HyDAMO table, the layer to read in the file's version and the renames from that
version's column names to DAMO 2.2, the version of HYDROLIB's data model
(data_model). The layer is then read and renamed once.
SourceLayer
dataclass
¶
Where a HyDAMO table comes from in a file of one DAMO version.
Parameters¶
layer : str
The layer in that version.
renames : dict[str, str]
{column in that version: DAMO 2.2 name}, for the renamed columns.
Source code in hydrolib/dhydamo/io/damo_versions/steps.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
Step
dataclass
¶
The layer and column renames from DAMO version old to new.
Parameters¶
old : str
The older DAMO version, e.g. "2.4".
new : str
The newer DAMO version, e.g. "2.5".
layers : dict[str, str]
The tables whose layer changed: {HyDAMO attribute: layer in new}.
columns : dict[str, dict[str, str]]
The tables whose columns were renamed:
{HyDAMO attribute: {column in old: column in new}}. For a table that moves
to another layer (see layers), the old names are those of its old layer.
Source code in hydrolib/dhydamo/io/damo_versions/steps.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
source_layers(version: str) -> dict[str, SourceLayer]
¶
Return, per HyDAMO table, its layer and column renames in a DAMO version.
Chains the steps between DAMO 2.2 and version.
Parameters¶
version : str
DAMO version, one of SUPPORTED_HYDAMO_VERSIONS, e.g. "2.4".
Returns¶
dict[str, SourceLayer]
By HyDAMO attribute, in the order of data_model.TABLES.
Raises¶
ValueError If the version is not supported, a step names a table that isn't a HyDAMO table, or two tables read the same layer: the steps are keyed by table, so each table needs its own layer.
Source code in hydrolib/dhydamo/io/damo_versions/steps.py
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 | |
dimrwriter
¶
Write the DIMR configuration and a run.bat for a coupled FM, RR and RTC model.
DIMRWriter
¶
Temporary files for DIMR-configuration - to be superseded by Hydrolib-core functionality.
Source code in hydrolib/dhydamo/io/dimrwriter.py
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 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 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 | |
__init__(dimr_path: str | None = None, output_path: str | Path | None = None) -> None
¶
Create a DIMR writer.
This is a temporary fix to include writers for RR and RTC, which are not yet fully included in HYDROLIB-core, or have bugs. Eventually this class should be redundant, when HYDROLIB-core includes this functionality.
Parameters¶
dimr_path : str, optional
The run_dimr.bat script that write_runbat calls. Defaults to None: the
script of a D-HYDRO Suite 2022.04 installation.
output_path : str or Path, optional
Model folder in which the files are written. Defaults to None: the current
working directory.
Source code in hydrolib/dhydamo/io/dimrwriter.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 | |
add_crs(netcdf_path: str | Path | None = None) -> None
¶
Add the coordinate reference system EPSG:28992 (RD New) to the network file, in place.
Parameters¶
netcdf_path : str or Path, optional
Network file, or a folder with it (the first *.nc file is used). Defaults
to None: the first *.nc file in the dflowfm folder of the output path.
Raises¶
FileNotFoundError If no netCDF file is found.
Source code in hydrolib/dhydamo/io/dimrwriter.py
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 | |
write_dimrconfig(fm: FMModel, rr_model: DRRModel | None = None, rtc_model: DRTCModel | None = None) -> None
¶
Write dimr_config.xml for the FM model, coupled with RR and RTC if given.
Parameters¶
fm : FMModel The D-Flow FM model. Without RR and RTC, only FM is run. rr_model : DRRModel, optional The RR model. Defaults to None. rtc_model : DRTCModel, optional The RTC model. Defaults to None.
Source code in hydrolib/dhydamo/io/dimrwriter.py
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 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 | |
write_runbat(debuglevel: int = 6, runlog: str | Path | None = None) -> None
¶
Write a run.bat that runs the model with DIMR.
The script calls the run_dimr.bat given when creating the writer.
Parameters¶
debuglevel : int, optional
DIMR debug level (-d). Defaults to 6.
runlog : str or Path, optional
File to which the output of DIMR is redirected. Defaults to None: no
redirection.
Source code in hydrolib/dhydamo/io/dimrwriter.py
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 85 86 87 88 89 | |
drrreader
¶
Derive the RR nodes, meteo and boundaries of a D-RR model from catchments and rasters.
ExternalForcingsIO
¶
Fill the meteo, seepage and boundary nodes of an RR model.
Parameters¶
external_forcings : drr.ExternalForcings The external forcings of the RR model, filled in place.
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
boundary_from_input(boundary_nodes: ExtendedGeoDataFrame, catchments: ExtendedGeoDataFrame, drrmodel: drr.DRRModel, overflows: ExtendedGeoDataFrame | None = None, greenhouse_laterals: ExtendedGeoDataFrame | None = None) -> None
¶
Add the RR boundary nodes, which link the RR nodes to the FM laterals.
Call this after the RR nodes are added. Catchments without any RR node with an
area are removed from catchments, in place.
Parameters¶
boundary_nodes : ExtendedGeoDataFrame
Laterals, linked to the catchments by their key.
catchments : ExtendedGeoDataFrame
Catchment areas, with a boundary_node column.
drrmodel : drr.DRRModel
The RR model, with its nodes added.
overflows : ExtendedGeoDataFrame, optional
Overflow locations, each added as a boundary node. Defaults to None.
greenhouse_laterals : ExtendedGeoDataFrame, optional
Outlet points of greenhouse areas, each added as a boundary node. Defaults to
None.
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
evap_from_input(areas: ExtendedGeoDataFrame, evap_folder: Path | str | None = None, evap_file: Path | str | None = None, *, min_coverage_frac: float = 0.0, coverage_weight: zonal.CoverageWeight = 'fraction') -> None
¶
Add an evaporation time series per meteo area, or use an existing meteo file.
Parameters¶
areas : ExtendedGeoDataFrame
Meteo areas for which time series are created.
evap_folder : str or Path, optional
Folder with evaporation rasters, one per time step. Only used without
evap_file. Defaults to None.
evap_file : str or Path, optional
Existing meteo file (.evp), used instead of the rasters. Defaults to None.
min_coverage_frac : float, optional
Smallest fraction of a pixel a zone 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 zone covers,
"none" counts them fully. Defaults to "fraction".
Raises¶
ValueError
If neither evap_folder nor evap_file is given.
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
precip_from_input(areas: ExtendedGeoDataFrame, precip_folder: Path | str | None = None, precip_file: Path | str | None = None, *, min_coverage_frac: float = 0.0, coverage_weight: zonal.CoverageWeight = 'fraction') -> None
¶
Add a precipitation time series per meteo area, or use an existing meteo file.
Parameters¶
areas : ExtendedGeoDataFrame
Meteo areas for which time series are created.
precip_folder : str or Path, optional
Folder with precipitation rasters, one per time step. Only used without
precip_file. Defaults to None.
precip_file : str or Path, optional
Existing meteo file (.bui), used instead of the rasters. Defaults to None.
min_coverage_frac : float, optional
Smallest fraction of a pixel a zone 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 zone covers,
"none" counts them fully. Defaults to "fraction".
Raises¶
ValueError
If neither precip_folder nor precip_file is given.
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
seepage_from_input(catchments: ExtendedGeoDataFrame, seepage_folder: Path | str, *, min_coverage_frac: float = 0.0, coverage_weight: zonal.CoverageWeight = 'fraction') -> None
¶
Add a seepage time series per catchment, the mean of each raster in a folder.
The time of each step is read from the raster (IDF or netCDF).
Parameters¶
catchments : ExtendedGeoDataFrame
Catchment areas.
seepage_folder : str or Path
Folder with the seepage rasters, one per time step.
min_coverage_frac : float, optional
Smallest fraction of a pixel a zone 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 zone covers,
"none" counts them fully. Defaults to "fraction".
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
GreenhouseIO
¶
Fill the greenhouse nodes of an RR model from catchments, greenhouse areas and rasters.
Parameters¶
greenhouse : drr.Greenhouse The greenhouse nodes of the RR model, filled in place.
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
greenhouse_from_input(catchments: ExtendedGeoDataFrame, landuse: Path | str, surface_level: Path | str, roof_storage: StrictStr | float, meteo_areas: ExtendedGeoDataFrame, greenhouse_areas: ExtendedGeoDataFrame | None = None, greenhouse_laterals: ExtendedGeoDataFrame | None = None, basin_storage_class: int = 2, *, min_coverage_frac: float = 0.0, coverage_weight: zonal.CoverageWeight = 'fraction') -> None
¶
Add the greenhouse nodes: one per greenhouse area, and one per catchment.
The catchment node gets the greenhouse area of the land use raster, minus what is already in the greenhouse areas.
Parameters¶
catchments : ExtendedGeoDataFrame
Catchment areas.
landuse : str or Path
Land use raster.
surface_level : str or Path
Surface level raster.
roof_storage : str or float
Roof storage (mm): a number for a uniform value, or a raster.
meteo_areas : ExtendedGeoDataFrame
Meteo areas; each node gets the meteo station of the area that contains its
centroid.
greenhouse_areas : ExtendedGeoDataFrame, optional
Known greenhouse areas, optionally with a basin_storage_class column.
Defaults to None.
greenhouse_laterals : ExtendedGeoDataFrame, optional
Outlet points of the greenhouse areas, required with greenhouse_areas.
Defaults to None.
basin_storage_class : int, optional
Basin storage class of greenhouses without their own. Defaults to 2.
min_coverage_frac : float, optional
Smallest fraction of a pixel a zone 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 zone covers,
"none" counts them fully. Defaults to "fraction".
Raises¶
ValueError
If greenhouse_areas is given without greenhouse_laterals.
Source code in hydrolib/dhydamo/io/drrreader.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 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 | |
OpenwaterIO
¶
Fill the open water nodes of an RR model from catchments and a land use raster.
Parameters¶
openwater : drr.Openwater The open water nodes of the RR model, filled in place.
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
openwater_from_input(catchments: ExtendedGeoDataFrame, landuse: Path | str, meteo_areas: ExtendedGeoDataFrame, *, min_coverage_frac: float = 0.0, coverage_weight: zonal.CoverageWeight = 'fraction') -> None
¶
Add an open water node per catchment, with the open water area of the land use raster.
Parameters¶
catchments : ExtendedGeoDataFrame
Catchment areas.
landuse : str or Path
Land use raster.
meteo_areas : ExtendedGeoDataFrame
Meteo areas; each node gets the meteo station of the area that contains its
centroid.
min_coverage_frac : float, optional
Smallest fraction of a pixel a zone 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 zone covers,
"none" counts them fully. Defaults to "fraction".
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
PavedIO
¶
Fill the paved nodes of an RR model from catchments, sewer areas and rasters.
Parameters¶
paved : drr.Paved The paved nodes of the RR model, filled in place.
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
paved_from_input(catchments: ExtendedGeoDataFrame, landuse: StrictStr | Path, surface_level: StrictStr | Path, street_storage: StrictStr | Path | float, sewer_storage: StrictStr | Path | float, pump_capacity: StrictStr | Path | float, meteo_areas: ExtendedGeoDataFrame, overflows: ExtendedGeoDataFrame | None = None, sewer_areas: ExtendedGeoDataFrame | None = None, *, min_coverage_frac: float = 0.0, coverage_weight: zonal.CoverageWeight = 'fraction') -> None
¶
Add the paved nodes: one per overflow of each sewer area, and one per catchment.
The paved area of a catchment outside the sewer areas gets a node that drains to the catchment's boundary node.
Parameters¶
catchments : ExtendedGeoDataFrame
Catchment areas.
landuse : str or Path
Land use raster.
surface_level : str or Path
Surface level raster.
street_storage : str, Path or float
Street storage (mm): a number for a uniform value, or a raster.
sewer_storage : str, Path or float
Sewer storage (mm): a number for a uniform value, or a raster.
pump_capacity : str, Path or float
Pump capacity (mm/h): a number for a uniform value, or a raster.
meteo_areas : ExtendedGeoDataFrame
Meteo areas; each node gets the meteo station of the area that contains its
centroid.
overflows : ExtendedGeoDataFrame, optional
Overflow locations, required with sewer_areas. Defaults to None.
sewer_areas : ExtendedGeoDataFrame, optional
Sewer areas. Defaults to None.
min_coverage_frac : float, optional
Smallest fraction of a pixel a zone 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 zone covers,
"none" counts them fully. Defaults to "fraction".
Raises¶
ValueError
If sewer_areas is given without overflows.
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
UnpavedIO
¶
Fill the unpaved nodes of an RR model from catchments and rasters.
Parameters¶
unpaved : drr.Unpaved The unpaved nodes of the RR model, filled in place.
Source code in hydrolib/dhydamo/io/drrreader.py
63 64 65 66 67 68 69 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 | |
ernst_from_input(catchments: ExtendedGeoDataFrame, depths: list, resistance: list, infiltration_resistance: float | None = None, runoff_resistance: float | None = None) -> None
¶
Add the same Ernst definition for the unpaved node of each catchment.
Parameters¶
catchments : ExtendedGeoDataFrame Catchment areas. depths : list Layer depths (m). resistance : list Ernst resistance of each layer (d). infiltration_resistance : float, optional Resistance to infiltration (d). Defaults to None: 300. runoff_resistance : float, optional Resistance to surface runoff (d). Defaults to None: 1.
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
unpaved_from_input(catchments: ExtendedGeoDataFrame, landuse: StrictStr | Path, surface_level: StrictStr | Path, soiltype: StrictStr | Path, surface_storage: StrictStr | Path | float, infiltration_capacity: StrictStr | Path | float, initial_gwd: StrictStr | Path | float, meteo_areas: ExtendedGeoDataFrame, greenhouse_areas: ExtendedGeoDataFrame | None = None, *, min_coverage_frac: float = 0.0, coverage_weight: zonal.CoverageWeight = 'fraction') -> None
¶
Add an unpaved node per catchment, with values from rasters.
Parameters¶
catchments : ExtendedGeoDataFrame
Catchment areas.
landuse : str or Path
Land use raster.
surface_level : str or Path
Surface level raster.
soiltype : str or Path
Soil type raster.
surface_storage : str, Path or float
Surface storage (mm): a number for a uniform value, or a raster.
infiltration_capacity : str, Path or float
Infiltration capacity (mm/d): a number for a uniform value, or a raster.
initial_gwd : str, Path or float
Initial groundwater depth (m): a number for a uniform value, or a raster.
meteo_areas : ExtendedGeoDataFrame
Meteo areas; each catchment gets the meteo station of the area that contains
its centroid.
greenhouse_areas : ExtendedGeoDataFrame, optional
Greenhouse areas. Where they are not greenhouse in the land use raster, their
area is subtracted from the most common land use of the catchment. Defaults
to None.
min_coverage_frac : float, optional
Smallest fraction of a pixel a zone 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 zone covers,
"none" counts them fully. Defaults to "fraction".
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
drrwriter
¶
Write the files of a D-RR model.
DRRWriter
¶
Write the files of an RR model to the rr folder of a model.
An existing rr folder is removed when the writer is created.
Parameters¶
rrmodel : DRRModel
The RR model to write.
output_dir : str or Path
Model folder; the files are written to its rr subfolder.
name : str, optional
Deprecated, not used. Defaults to None.
wwtp : tuple[float, float], optional
Coordinates of the waste water treatment plant node, to which the paved nodes
are linked. Defaults to None: (100000, 500000).
Source code in hydrolib/dhydamo/io/drrwriter.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 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 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 | |
change_d3b_parameter(parameter: str, value: str | float) -> None
¶
Change the value of a parameter in delft_3b.ini, in place.
Parameters¶
parameter : str Parameter name, case-insensitive. value : str or float New value.
Source code in hydrolib/dhydamo/io/drrwriter.py
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 | |
copyRRFiles() -> bool
¶
Copy the standard RR files from the resources folder to the output folder.
Returns¶
bool Always True.
Source code in hydrolib/dhydamo/io/drrwriter.py
96 97 98 99 100 101 102 103 104 105 106 107 | |
write_all() -> None
¶
Write all RR files and set the parameters of delft_3b.ini.
Source code in hydrolib/dhydamo/io/drrwriter.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
write_greenhouse() -> None
¶
Write the files of the greenhouse nodes.
GREENHSE.3B, GREENHSE.RF and GREENHSE.SIL. The latter has only one
definition.
Source code in hydrolib/dhydamo/io/drrwriter.py
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 | |
write_meteo() -> None
¶
Write the meteo files DEFAULT.BUI and DEFAULT.EVP.
From the time series per meteo area, or as a copy of the meteo file given to the RR model.
Source code in hydrolib/dhydamo/io/drrwriter.py
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 | |
write_openwater() -> None
¶
Write OPENWATE.3B, the file of the open water nodes.
Source code in hydrolib/dhydamo/io/drrwriter.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | |
write_paved() -> None
¶
Write the files of the paved nodes.
PAVED.3B, PAVED.STO and PAVED.DWA. The latter has only one definition.
Source code in hydrolib/dhydamo/io/drrwriter.py
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 | |
write_topology() -> None
¶
Write the topology files of the RR model.
3B_NOD.TP: ids and coordinates of all nodes: unpaved, paved, greenhouse, open water and boundary. Only nodes with a total area > 0 are written. Nodes are placed up to 20 m east and west of the catchment centroid.3B_LINK.TP: links between all nodes and their boundaries.BOUND3B.3B: coupling information for every RR boundary.BoundaryConditions.bc: seeBOUND3B.3B.
Source code in hydrolib/dhydamo/io/drrwriter.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 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 | |
write_unpaved() -> None
¶
Write the files of the unpaved nodes.
UNPAVED.3B, UNPAVED.ALF, UNPAVED.STO, UNPAVED.INF and
UNPAVED.SEP. All files have a definition for every node, because the values
may be spatially distributed.
Source code in hydrolib/dhydamo/io/drrwriter.py
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 | |
idfreader
¶
Functions for reading and writing iMOD Data Files (IDFs) to xarray objects.
The primary functions to use are :func:imod.idf.open and
:func:imod.idf.save, though lower level functions are also available.
The function in this file are taken from the imod-python package version 0.10.1.
The only functionality needed in dhydamo is the capability to read IDF files. imod itself is not a dependency: it needs Python >= 3.12 and brings gdal, numba, pymetis and more.
Compared with imod 1.1.0 (November 2026), whose reading code was restructured but is otherwise the same, this copy:
- takes
.item()of the top and bottom in_scalar_z_coord, as 1.1.0 does (numpy deprecatesfloat()of a one-element array); - has type hints only for
openandaffine_from_idf, the functions dhydamo uses; mypy does not require them for the rest of this module (see pyproject.toml); - adds
affine_from_idf.
affine_from_idf(dataset: xr.DataArray) -> Affine
¶
Build a rasterio affine transform from an opened IDF dataset.
Parameters¶
dataset : xarray.DataArray
Single-time, single-layer array as returned by
idfreader.open(...).squeeze(), with scalar dx/dy
coordinates and pixel-centre x/y coordinates.
Returns¶
affine.Affine Geotransform for the raster, derived from its pixel-centre coordinates and cell size.
Source code in hydrolib/dhydamo/io/idfreader.py
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 | |
decompose(path, pattern=None)
¶
Parse a path, returning a dict of the parts, following the iMOD conventions.
Parameters¶
path : str or pathlib.Path Path to the file. Upper case is ignored. pattern : str, regex pattern, optional If the path is not made up of standard paths, and the default decompose does not produce the right result, specify the used pattern here. See the examples below.
Returns¶
d : dict Dictionary with name of variable and dimensions
Examples¶
Decompose a path, relying on default conventions:
decompose("head_20010101_l1.idf")
Do the same, by specifying a format string pattern, excluding extension:
decompose("head_20010101_l1.idf", pattern="{name}_{time}_l{layer}")
This supports an arbitrary number of variables:
decompose("head_slr_20010101_l1.idf", pattern="{name}{scenario}{time}_l{layer}")
The format string pattern will only work on tidy paths, where variables are
separated by underscores. You can also pass a compiled regex pattern.
Make sure to include the re.IGNORECASE flag since all paths are lowered.
import re pattern = re.compile(r"(?P
[\w]+)L(?P [\d+]*)") decompose("headL11", pattern=pattern)
However, this requires constructing regular expressions, which is generally a fiddly process. The website https://regex101.com is a nice help. Alternatively, the most pragmatic solution may be to just rename your files.
Source code in hydrolib/dhydamo/io/idfreader.py
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 | |
header(path, pattern)
¶
Read the IDF header information into a dictionary
Source code in hydrolib/dhydamo/io/idfreader.py
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 | |
open(path: str | pathlib.Path | list[pathlib.Path], use_cftime: bool = False, pattern: str | re.Pattern[str] | None = None) -> xr.DataArray
¶
Open one or more IDF files as an xarray.DataArray.
In accordance with xarray's design, open loads the data of IDF files
lazily. This means the data of the IDFs are not loaded into memory until the
data is needed. This allows for easier handling of large datasets, and
more efficient computations.
Parameters¶
path : str, Path or list
This can be a single file, 'head_l1.idf', a glob pattern expansion,
'head_l*.idf', or a list of files, ['head_l1.idf', 'head_l2.idf'].
Note that each file needs to be of the same name (part before the
first underscore) but have a different layer and/or timestamp,
such that they can be combined in a single xarray.DataArray.
use_cftime : bool, optional
Use cftime.DatetimeProlepticGregorian instead of np.datetime64[ns]
for the time axis.
Dates are normally encoded as ``np.datetime64[ns]``; however, if dates
fall before 1678 or after 2261, they are automatically encoded as
``cftime.DatetimeProlepticGregorian`` objects rather than
``np.datetime64[ns]``.
pattern : str, regex pattern, optional If the filenames do match default naming conventions of {name}_{time}_l{layer}, a custom pattern can be defined here either as a string, or as a compiled regular expression pattern. See the examples below.
Returns¶
xarray.DataArray A float xarray.DataArray of the values in the IDF file(s). All metadata needed for writing the file to IDF or other formats using imod.rasterio are included in the xarray.DataArray.attrs.
Examples¶
Open an IDF file:
da = imod.idf.open("example.idf")
Open an IDF file, relying on default naming conventions to identify layer:
da = imod.idf.open("example_l1.idf")
Open an IDF file, relying on default naming conventions to identify layer and time:
head = imod.idf.open("head_20010101_l1.idf")
Open multiple IDF files, in this case files for the year 2001 for all layers, again relying on default conventions for naming:
head = imod.idf.open("head_2001_l.idf")
The same, this time explicitly specifying name, time, and layer:
head = imod.idf.open("head_2001_l.idf", pattern="{name}_{time}_l{layer}")
The format string pattern will only work on tidy paths, where variables are
separated by underscores. You can also pass a compiled regex pattern.
Make sure to include the re.IGNORECASE flag since all paths are lowered.
import re pattern = re.compile(r"(?P
[\w]+)L(?P [\d+]*)", re.IGNORECASE) head = imod.idf.open("headL11", pattern=pattern)
However, this requires constructing regular expressions, which is generally a fiddly process. Regex notation is also impossible to remember. The website https://regex101.com is a nice help. Alternatively, the most pragmatic solution may be to just rename your files.
Source code in hydrolib/dhydamo/io/idfreader.py
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 | |
read(path, pattern=None)
¶
Read a single IDF file to a numpy.ndarray
Parameters¶
path : str or Path
Path to the IDF file to be read
pattern : str, regex pattern, optional
If the filenames do match default naming conventions of
{name}_{time}_l{layer}, a custom pattern can be defined here either
as a string, or as a compiled regular expression pattern. Please refer
to the examples for imod.idf.open.
Returns¶
numpy.ndarray A float numpy.ndarray with shape (nrow, ncol) of the values in the IDF file. On opening all nodata values are changed to NaN in the numpy.ndarray. dict A dict with all metadata.
Source code in hydrolib/dhydamo/io/idfreader.py
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 | |
netcdfreader
¶
Read D-Flow FM output files.
time_index(dataset: Dataset, time: datetime | pd.Timestamp | str, tolerance: float = 1.0) -> int
¶
Return the index of the time step closest to a given time.
Works for D-Flow FM output files: map, his or fou.
Parameters¶
dataset : Dataset
Opened netCDF file with a time variable.
time : datetime, pd.Timestamp or str
Requested time, e.g. "2016-06-02 12:00". A time without a time zone is
taken in the time zone of the file (usually UTC).
tolerance : float, optional
Maximum difference in seconds that is accepted without a warning. Defaults to
1.0.
Returns¶
int Index of the nearest time step.
Raises¶
ValueError If the file has no time variable, or the time is outside its period.
Source code in hydrolib/dhydamo/io/netcdfreader.py
13 14 15 16 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 | |
rasterwriter
¶
Write rasters.
write_raster(path: Path | str, array: np.ndarray, transform: Affine, crs: CRS | str | None = None, nodata: float = -999.0, compress: bool = True) -> Path
¶
Write a single band raster.
The format follows from the extension: GeoTIFF for .tif and .tiff, ASCII
grid for .asc. Missing folders are created.
Parameters¶
path : Path or str Output file. array : np.ndarray 2D array with values. transform : Affine Raster transform. crs : CRS or str, optional Coordinate reference system. Defaults to None. nodata : float, optional Nodata value. Defaults to -999.0. compress : bool, optional Deflate compression for GeoTIFF. Defaults to True.
Returns¶
Path Path of the written raster.
Raises¶
ValueError If the extension is not supported.
Source code in hydrolib/dhydamo/io/rasterwriter.py
13 14 15 16 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 | |