Reference for SWMManywhere/swmmanywhere.py
The main SWMManywhere module to generate and run a synthetic network.
check_address_overrides(config)
Check the address overrides in the config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
The configuration. |
required |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If an address override path does not exist. |
Source code in swmmanywhere/swmmanywhere.py
check_and_register_custom_graphfcns(config)
Check, register and validate custom graphfcns in the config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
The configuration. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If a graphfcn module does not exist. |
ValueError
|
If a custom graphfcn is not successfully registered. |
Source code in swmmanywhere/swmmanywhere.py
check_and_register_custom_metrics(config)
Check, register and validate custom metrics in the config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
The configuration. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the custom metrics module does not exist. |
Source code in swmmanywhere/swmmanywhere.py
check_parameter_overrides(config)
Check the parameter overrides in the config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
The configuration. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If a parameter override is not in the parameters dictionary. |
Source code in swmmanywhere/swmmanywhere.py
check_real_network_paths(config)
Check the paths to the real network in the config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
The configuration. |
required |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If a real network path does not exist. |
Source code in swmmanywhere/swmmanywhere.py
check_starting_graph(config)
Check the starting graph in the config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
The configuration. |
required |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the starting graph path does not exist. |
Source code in swmmanywhere/swmmanywhere.py
check_top_level_paths(config)
Check the top level paths (base_dir
) in the config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
The configuration. |
required |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If a top level path does not exist. |
Source code in swmmanywhere/swmmanywhere.py
load_config(config_path=Path(__file__).parent / 'defs' / 'demo_config.yml', validation=True, schema_fid=None)
Load, validate, and convert Paths in a configuration file.
Note, if using a custom graphfcn, load_config must be called with validation=True.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_path
|
Path
|
The path to the configuration file. |
parent / 'defs' / 'demo_config.yml'
|
validation
|
bool
|
Whether to validate the configuration. Defaults to True. |
True
|
schema_fid
|
Path
|
The path to the schema file. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
The configuration. |
Source code in swmmanywhere/swmmanywhere.py
run(model, reporting_iters=50, duration=86400, storevars=['flooding', 'flow'])
Run a SWMM model and store the results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Path
|
The path to the SWMM model .inp file. |
required |
reporting_iters
|
int
|
The number of iterations between storing results. Defaults to 50. |
50
|
duration
|
int
|
The duration of the simulation in seconds. Starts at the 'START_DATE' and 'START_TIME' defined in the 'model' .inp file Defaults to 86400. |
86400
|
storevars
|
list[str]
|
The variables to store. Defaults to ['flooding','flow']. |
['flooding', 'flow']
|
Returns:
Type | Description |
---|---|
pd.DataFrame: A DataFrame containing the results. |
Source code in swmmanywhere/swmmanywhere.py
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 |
|
save_config(config, config_path)
Save the configuration to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
The configuration. |
required |
config_path
|
Path
|
The path to save the configuration. |
required |
Source code in swmmanywhere/swmmanywhere.py
swmmanywhere(config)
Run SWMManywhere processes.
This function runs the SWMManywhere processes, including downloading data, preprocessing the graphfcns, running the model, and comparing the results to real data using metrics. The function will always return the path to the generated .inp file. If real data (either a results file or the .inp, as well as graph, and subcatchments) is provided, the function will also return the metrics comparing the synthetic network with the real.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
The loaded config as a dict. |
required |
Returns:
Type | Description |
---|---|
tuple[Path, dict | None]
|
tuple[Path, dict | None]: The address of generated .inp and metrics. |
Source code in swmmanywhere/swmmanywhere.py
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 |
|