IO
DHyDAMO IO API¶
common
¶
ExtendedDataFrame
¶
Bases: DataFrame
Source code in hydrolib/dhydamo/io/common.py
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 | |
delete_all()
¶
Empty the dataframe
Source code in hydrolib/dhydamo/io/common.py
492 493 494 495 496 497 498 499 | |
read_gpkg_layer(gpkg_path: str | Path, layer_name: str = None, column_mapping: dict = None, index_col: str = None)
¶
Deprecated. Use HyDAMO.load_from_gpkg() for DAMO data loading.
Source code in hydrolib/dhydamo/io/common.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | |
ExtendedGeoDataFrame
¶
Bases: GeoDataFrame
Source code in hydrolib/dhydamo/io/common.py
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 | |
branch_to_prof(offset=0.0, vertex_end=False, rename_col=None, prefix='', suffix='')
¶
Create profiles on branches from branch data
Source code in hydrolib/dhydamo/io/common.py
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 | |
check_projection(crs_out)
¶
Check if reprojection is required
Source code in hydrolib/dhydamo/io/common.py
421 422 423 424 425 426 427 428 429 | |
clip(geometry: Polygon | MultiPolygon, cliptype: str = 'select', clip_and_drop: bool = True)
¶
Clip geometry
Source code in hydrolib/dhydamo/io/common.py
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 | |
copy(deep=True)
¶
Create a copy
Source code in hydrolib/dhydamo/io/common.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
delete_all()
¶
Empty the dataframe
Source code in hydrolib/dhydamo/io/common.py
108 109 110 111 112 113 114 | |
merge_columns(col1, col2, rename_col)
¶
merge columns
Source code in hydrolib/dhydamo/io/common.py
459 460 461 462 463 464 465 466 467 468 | |
read_gpkg_layer(gpkg_path: str | Path, layer_name: str, index_col: str = None, groupby_column: str = None, order_column: str = None, id_col: str = 'code', column_mapping: dict = None, check_columns: bool = True, check_geotype: bool = True, clip: Polygon | MultiPolygon = None, cliptype: str = 'select', check_3d: bool = True)
¶
Deprecated. Use HyDAMO.load_from_gpkg() for DAMO data loading.
Source code in hydrolib/dhydamo/io/common.py
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 | |
read_shp(path: str | Path, index_col: str = None, column_mapping: dict = None, check_columns: bool = True, proj_crs=None, clip: Polygon | MultiPolygon = None, check_geotype: bool = True, id_col: str = 'code', filter_cols: bool = False, filter_rows=None)
¶
Import function, extended with type checks. Does not destroy reference to object.
Source code in hydrolib/dhydamo/io/common.py
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 | |
snap_to_branch(branches, snap_method, maxdist=5)
¶
Snap the geometries to the branch
Source code in hydrolib/dhydamo/io/common.py
470 471 472 473 474 | |
damo_converters
¶
base
¶
BaseDamoConverter
¶
Bases: ABC
Abstract base class for versioned HyDAMO GeoPackage converters.
Subclasses declare hydamo_version and layer_specs, and optionally
override postprocess for any column-level canonicalization required
after all layers are loaded.
Source code in hydrolib/dhydamo/io/damo_converters/base.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 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 | |
load_into(hydamo, gpkg_path: str | Path, clip_layers: dict | None = None, check_3d: bool = True) -> None
¶
Read all declared layer specs from gpkg_path into hydamo.
Parameters¶
hydamo : HyDAMO
The HyDAMO instance whose attributes are populated.
gpkg_path : str or Path
Path to the source GeoPackage.
clip_layers : dict, optional
Per-layer spatial clip. Maps target_attr to a
(geometry, cliptype) tuple. 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.
Source code in hydrolib/dhydamo/io/damo_converters/base.py
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 | |
postprocess(hydamo) -> None
¶
Hook for version-specific canonicalization after all layers are loaded.
Override in subclasses to rename, copy, or derive columns on any
HyDAMO attribute that requires post-load normalisation.
Source code in hydrolib/dhydamo/io/damo_converters/base.py
125 126 127 128 129 130 | |
LayerSpec
dataclass
¶
Schema descriptor for a single HyDAMO GeoPackage layer.
Parameters¶
target_attr : str
Name of the HyDAMO instance attribute to populate.
source_layer : str
GeoPackage layer name to read (case-insensitive match).
index_col : str, optional
Column to set as the DataFrame index after loading.
groupby_column : str, optional
Column used to group point rows into line geometries.
order_column : str, optional
Column that defines point order within each group.
column_mapping : dict[str, str], optional
{source_col: target_col} renames applied before writing to the
attribute.
check_geotype : bool
Whether to validate that geometries match the expected type declared
on the target ExtendedGeoDataFrame. Default is True.
optional : bool
When True, a missing GeoPackage layer is logged and skipped
rather than raising an error. Default is True.
Source code in hydrolib/dhydamo/io/damo_converters/base.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 | |
replace_layer_specs(base_specs: tuple[LayerSpec, ...], *overrides: LayerSpec) -> tuple[LayerSpec, ...]
¶
Merge overrides into base_specs, replacing entries by target_attr.
Specs present in base_specs are replaced in-place by the matching override if one exists. Overrides with no matching base spec are appended at the end.
Parameters¶
base_specs : tuple[LayerSpec, ...]
The canonical spec tuple from the parent converter.
*overrides : LayerSpec
Replacement LayerSpec objects keyed by target_attr.
Returns¶
tuple[LayerSpec, ...] New tuple with overrides applied.
Source code in hydrolib/dhydamo/io/damo_converters/base.py
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 | |
v22
¶
Damo22Converter
¶
Bases: BaseDamoConverter
DAMO v2.2 converter.
Defines the canonical layer-to-attribute mapping used as the baseline for all other version converters. Post-processing copies soortregelmiddel to soortafsluitmiddel on management_device to normalise the column name.
Source code in hydrolib/dhydamo/io/damo_converters/v22.py
7 8 9 10 11 12 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 | |
v23
¶
Damo23Converter
¶
Bases: Damo22Converter
DAMO v2.3 converter.
Schema is identical to v2.2. This class exists as a version sentinel so that files tagged 2.3 load correctly without raising an unsupported-version error. If v2.3 introduces schema differences in the future, override layer_specs here.
Source code in hydrolib/dhydamo/io/damo_converters/v23.py
6 7 8 9 10 11 12 13 14 | |
v24
¶
Damo24Converter
¶
Bases: Damo22Converter
DAMO v2.4 converter.
Schema is identical to v2.2. This class exists as a version sentinel so that files tagged 2.4 load correctly without raising an unsupported-version error. If v2.4 introduces schema differences in the future, override layer_specs here.
Source code in hydrolib/dhydamo/io/damo_converters/v24.py
6 7 8 9 10 11 12 13 14 | |
v25
¶
Damo25Converter
¶
Bases: Damo22Converter
DAMO v2.5 converter.
Schema changes relative to v2.2: - HydroObject: categorieoppervlaktewater → categorieoppwaterlichaam - Kunstwerkopening: afsluitmiddelid → regelmiddelid - Afsluitmiddel replaces Regelmiddel as the management device layer; typeafsluitmiddel → soortafsluitmiddel, typeregelbaarheid → soortregelbaarheid - Sturing: afsluitmiddelid → regelmiddelid, typestuurvariabele → stuurvariabele
Source code in hydrolib/dhydamo/io/damo_converters/v25.py
7 8 9 10 11 12 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 | |
dimrwriter
¶
DIMRWriter
¶
Temporary files for DIMR-configuration - to be superseded by Hydrolib-core functionality.
Source code in hydrolib/dhydamo/io/dimrwriter.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 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 | |
__init__(dimr_path: str = None, output_path: str | Path = None) -> None
¶
Class initialization for the DIMR writer. This is a temporary fix to include writers for RR and RTC, that are not yet fully included in Hydrolib-core, or have bugs. Eventually, this file should be redundant as this functionality is fully included in Hydrolib-core
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimr_path
|
Union[str, Path]
|
description. Defaults to None. |
None
|
output_path
|
Union[str, Path]
|
description. Defaults to None. |
None
|
Source code in hydrolib/dhydamo/io/dimrwriter.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
add_crs(netcdf_path: str | Path = None) -> None
¶
Reads the Netcdf file and addes the required attributes for a valid CRS.
Source code in hydrolib/dhydamo/io/dimrwriter.py
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 | |
write_dimrconfig(fm: FMModel, rr_model: DRRModel = None, rtc_model: DRTCModel = None) -> None
¶
Construct the contents of a DIMR-config file, using elements from FM, RTC and RR models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fm
|
instance of class FM-model
|
Hydrolib-core model object. When only fm is set, only a 1d2d model is generated. |
required |
rr_model
|
instance of a DRRModel object
|
Class containig all information from the RR-model. Defaults to None. |
None
|
rtc_model
|
instance of a DRTCmodel
|
Class containig all information from the RTC-model. Defaults to None. |
None
|
Source code in hydrolib/dhydamo/io/dimrwriter.py
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 | |
write_runbat(debuglevel=6, runlog=None) -> None
¶
Generates a run.bat to run the model in DIMR. The path to the executable is provided by the user in the class initialization, or set to the default D-Hydro installation folder.
Source code in hydrolib/dhydamo/io/dimrwriter.py
42 43 44 45 46 47 48 49 50 51 52 | |
drrreader
¶
ExternalForcingsIO
¶
Source code in hydrolib/dhydamo/io/drrreader.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 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 | |
boundary_from_input(boundary_nodes: ExtendedGeoDataFrame, catchments: ExtendedGeoDataFrame, drrmodel, overflows: ExtendedGeoDataFrame = None, greenhouse_laterals: ExtendedGeoDataFrame = None) -> None
¶
Generate RR-boundary nodes to link to RR-nodes and to FM-laterals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundary_nodes
|
ExtendedGeoDataFrame
|
boundary nodes |
required |
catchments
|
ExtendedGeoDataFrame
|
catchment areas associated with them |
required |
drrmodel
|
_type_
|
drrmodel object |
required |
overflows
|
ExtendedGeoDataFrame
|
overflow locations, if applicable. Defaults to None. |
None
|
greenhouse_laterals
|
ExtendedGeoDataFrame
|
overflow locations, if applicable. Defaults to None. |
None
|
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
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
¶
Create time series of evaporation for every meteo_area, based on zonal statistics from rasters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
areas
|
ExtendedGeoDataFrame
|
meteo areas for which time series are created |
required |
evap_folder
|
str
|
folder where precipitation rasters are stored. Only used if no precip_file is given. Defaults to None. |
None
|
evap_file
|
str
|
existing meteo-file, which is used if available. |
None
|
min_coverage_frac
|
float
|
smallest fraction of a pixel a zone must cover for the pixel to count in the zonal statistics. Defaults to 0, every touched pixel. |
0.0
|
coverage_weight
|
str
|
"fraction" counts pixels by the fraction of them the zone covers, "none" counts them fully. Defaults to "fraction". |
'fraction'
|
Source code in hydrolib/dhydamo/io/drrreader.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 960 961 962 963 964 965 966 967 968 969 970 971 972 973 | |
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
¶
Create time series of precipitation for every meteo_area, based on zonal statistics from rasters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
areas
|
ExtendedGeoDataFrame
|
meteo areas for which time series are created |
required |
precip_folder
|
str
|
folder where precipitation rasters are stored. Only used if no precip_file is given. Defaults to None. |
None
|
precip_file
|
str
|
existing meteo-file, which is used if available. |
None
|
min_coverage_frac
|
float
|
smallest fraction of a pixel a zone must cover for the pixel to count in the zonal statistics. Defaults to 0, every touched pixel. |
0.0
|
coverage_weight
|
str
|
"fraction" counts pixels by the fraction of them the zone covers, "none" counts them fully. Defaults to "fraction". |
'fraction'
|
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
seepage_from_input(catchments: ExtendedGeoDataFrame, seepage_folder: Path | str, *, min_coverage_frac: float = 0.0, coverage_weight: zonal.CoverageWeight = 'fraction') -> None
¶
Perform zonal statistics to derive seepage time series per catchment. Time steps are derived from the data
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catchments
|
ExtendedGeoDataFrame
|
catchment areas |
required |
seepage_folder
|
str
|
folder where the seepage rasters are stored |
required |
min_coverage_frac
|
float
|
smallest fraction of a pixel a zone must cover for the pixel to count in the zonal statistics. Defaults to 0, every touched pixel. |
0.0
|
coverage_weight
|
str
|
"fraction" counts pixels by the fraction of them the zone covers, "none" counts them fully. Defaults to "fraction". |
'fraction'
|
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
GreenhouseIO
¶
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
greenhouse_from_input(catchments: ExtendedGeoDataFrame, landuse: Path | str, surface_level: Path | str, roof_storage: StrictStr | float, meteo_areas: ExtendedGeoDataFrame, greenhouse_areas: ExtendedGeoDataFrame = None, greenhouse_laterals: ExtendedGeoDataFrame = None, basin_storage_class: int = 2, *, min_coverage_frac: float = 0.0, coverage_weight: zonal.CoverageWeight = 'fraction') -> None
¶
Generate contents of an RR greenhouse node
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catchments
|
ExtendedGeoDataFrame
|
catchment areas |
required |
greenhouuse_areas
|
ExtendedGeoDataFrame
|
known set of greenhouse areas with attiributes |
required |
greenhouse_laterals (ExtendedGeoDataFrame)
|
known set of outlet points for greenhouses |
required | |
landuse
|
str
|
filename of land use raster |
required |
surface_level
|
str
|
filename of surface level raster |
required |
roofstorage
|
Union
|
float for spatially uniform sewer storage (mm), or raster for distributed values |
required |
meteo_areas
|
ExtendedGeoDataFrame
|
meteo areas, for each station a meteo time series is assigned |
required |
min_coverage_frac
|
float
|
smallest fraction of a pixel a zone must cover for the pixel to count in the zonal statistics. Defaults to 0, every touched pixel. |
0.0
|
coverage_weight
|
str
|
"fraction" counts pixels by the fraction of them the zone covers, "none" counts them fully. Defaults to "fraction". |
'fraction'
|
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
OpenwaterIO
¶
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
openwater_from_input(catchments: ExtendedGeoDataFrame, landuse: Path | str, meteo_areas: ExtendedGeoDataFrame, *, min_coverage_frac: float = 0.0, coverage_weight: zonal.CoverageWeight = 'fraction') -> None
¶
Generate contents of an RR open water node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catchments
|
ExtendedGeoDataFrame
|
catchment areas |
required |
landuse
|
str
|
filename of landuse raster |
required |
meteo_areas
|
ExtendedGeoDataFrame
|
meteo areas, for each station a meteo time series is assigned |
required |
min_coverage_frac
|
float
|
smallest fraction of a pixel a zone must cover for the pixel to count in the zonal statistics. Defaults to 0, every touched pixel. |
0.0
|
coverage_weight
|
str
|
"fraction" counts pixels by the fraction of them the zone covers, "none" counts them fully. Defaults to "fraction". |
'fraction'
|
Returns:
| Name | Type | Description |
|---|---|---|
_type_ |
None
|
description |
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
PavedIO
¶
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
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, sewer_areas: ExtendedGeoDataFrame = None, *, min_coverage_frac: float = 0.0, coverage_weight: zonal.CoverageWeight = 'fraction') -> None
¶
Generate contents of RR paved nodes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catchments
|
ExtendedGeoDataFrame
|
catchment areas |
required |
landuse
|
str
|
filename of landuse raster |
required |
surface_level
|
str
|
file name of suface level raster |
required |
street_storage
|
Union
|
numeric for spatially uniform street storage (mm), or raster for distributed values |
required |
sewer_storage
|
Union
|
numeric for spatially uniform sewer storage (mm), or raster for distributed values |
required |
pump_capacity
|
Union
|
numeric for spatially uniform pump capaities (mm), or raster for distributed values |
required |
meteo_areas
|
ExtendedGeoDataFrame
|
meteo areas, for each station a meteo time series is assigned |
required |
overflows
|
ExtendedGeoDataFrame
|
overflow locations. Defaults to None. |
None
|
sewer_areas
|
ExtendedGeoDataFrame
|
sewer area locations. Defaults to None. |
None
|
min_coverage_frac
|
float
|
smallest fraction of a pixel a zone must cover for the pixel to count in the zonal statistics. Defaults to 0, every touched pixel. |
0.0
|
coverage_weight
|
str
|
"fraction" counts pixels by the fraction of them the zone covers, "none" counts them fully. Defaults to "fraction". |
'fraction'
|
Returns:
| Name | Type | Description |
|---|---|---|
_type_ |
None
|
description |
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
UnpavedIO
¶
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
ernst_from_input(catchments: ExtendedGeoDataFrame, depths: list, resistance: list, infiltration_resistance: float | None = None, runoff_resistance: float | None = None) -> None
¶
Generate an Ernst definition for an unpaved node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catchments
|
ExtendedGeoDataFrame
|
Cahchment areas |
required |
depths
|
list
|
list of layer depths (m) |
required |
resistance
|
list
|
list of layer Ernst resistances (d-1) |
required |
infiltration_resistance
|
int or float
|
resistance to infiltration. Defaults to 300 d-1. |
None
|
runoff_resistance
|
int or float
|
resistance to suface runoff. Defaults to 1 d-1. |
None
|
Source code in hydrolib/dhydamo/io/drrreader.py
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 | |
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, *, min_coverage_frac: float = 0.0, coverage_weight: zonal.CoverageWeight = 'fraction')
¶
Generate contents of an unpaved node from raster data
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catchments
|
ExtendedGeoDataFrame
|
catchment areas |
required |
landuse
|
str
|
filename of land use raster |
required |
surface_level
|
str
|
file name of surface level raster |
required |
soiltype
|
str
|
file name of soiltype raster |
required |
surface_storage
|
Union
|
numeric for spatially uniform surface storage (mm), or raster for distributed values |
required |
infiltration_capacity
|
Union
|
numeric for spatially uniform infiltration capacity (mm/d), or raster for distributed values |
required |
initial_gwd
|
Union
|
numeric for spatially uniform initial groundwater levels (m), or raster for distributed values |
required |
meteo_areas
|
ExtendedGeoDataFrame
|
meteo areas, for each station a meteo time series is assigned |
required |
min_coverage_frac
|
float
|
smallest fraction of a pixel a zone must cover for the pixel to count in the zonal statistics. Defaults to 0, every touched pixel. |
0.0
|
coverage_weight
|
str
|
"fraction" counts pixels by the fraction of them the zone covers, "none" counts them fully. Defaults to "fraction". |
'fraction'
|
Source code in hydrolib/dhydamo/io/drrreader.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 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 | |
drrwriter
¶
DRRWriter
¶
Writer for RR files
Source code in hydrolib/dhydamo/io/drrwriter.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 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 | |
change_d3b_parameter(parameter, value)
¶
Change parameter value in delft3b.ini file
Source code in hydrolib/dhydamo/io/drrwriter.py
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 | |
copyRRFiles()
¶
Method to copy the RR-files from resources.
Returns¶
bool Succesfull or not.
Source code in hydrolib/dhydamo/io/drrwriter.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
write_all()
¶
Wrapper method to write all components
Source code in hydrolib/dhydamo/io/drrwriter.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
write_greenhouse()
¶
Method to write all files associated with greenhouse nodes: GREENHSE.3B, GREENHSE.RF and GREENHSE.SIL. The latter contains only one definition.
Returns¶
None.
Source code in hydrolib/dhydamo/io/drrwriter.py
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 | |
write_meteo()
¶
Method to write meteofiles (DEFAULT.BUI and DEFAULT.EVP) based on values per catchment.
Returns¶
None.
Source code in hydrolib/dhydamo/io/drrwriter.py
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 | |
write_openwater()
¶
Method to write OPENWATE.3B file.
Returns¶
None.
Source code in hydrolib/dhydamo/io/drrwriter.py
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 | |
write_paved()
¶
Method to write all files associated with paved nodes: PAVED.3B, PAVED.STO and PAVED.DWA. The latter contains only one definition.
Returns¶
None.
Source code in hydrolib/dhydamo/io/drrwriter.py
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 | |
write_topology()
¶
Wrapper to write the topolgy files for RR. The following files are written: 3B_NOD.TP: IDs and coordinates of all nodes: unpaved, paved, greenhouse, open water and boundary. Only nodes with a total area of >0 are written. Nodes are placed up to 20 m to the east and west of the catchment centroid. 3B_LINK.TP: Links between all nodes and the correct boundaries. BOUND3B.3B: coupling information for every RR boundary. BoundaryConditions.bc: see bound3b.3b Returns
None.
Source code in hydrolib/dhydamo/io/drrwriter.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 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 | |
write_unpaved()
¶
Method to write all files associated with unpaved nodes: UNPAVED.3B, UNPAVED.ALF, UNPAVED.STO, UNPAVED.INF and UNPAVED.SEP. All files contain a definition for every node because they may or may not be spatially distributed.
Returns¶
None.
Source code in hydrolib/dhydamo/io/drrwriter.py
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 | |
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.
affine_from_idf(dataset)
¶
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
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 | |
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
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 | |
header(path, pattern)
¶
Read the IDF header information into a dictionary
Source code in hydrolib/dhydamo/io/idfreader.py
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 | |
open(path, use_cftime=False, pattern=None)
¶
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
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 | |
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
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 | |