API Documentation ¶
Core Classes ¶
The fundamental classes that form the backbone of Network Wrangler:
Scenario objects manage how a collection of projects is applied to the networks.
Scenarios are built from a base scenario and a list of project cards.
A project card is a YAML file (or similar) that describes a change to the network. The project card can contain multiple changes, each of which is applied to the network in sequence.
Create a Scenario ¶
Instantiate a scenario by seeding it with a base scenario and optionally some project cards.
from network_wrangler import create_scenario
my_scenario = create_scenario(
base_scenario=my_base_year_scenario,
card_search_dir=project_card_directory,
filter_tags=["baseline2050"],
)
A base_year_scenario
is a dictionary representation of key components of a scenario:
road_net
: RoadwayNetwork instancetransit_net
: TransitNetwork instanceapplied_projects
: list of projects that have been applied to the base scenario so that the scenario knows if there will be conflicts with future projects or if a future project’s pre-requisite is satisfied.conflicts
: dictionary of conflicts for project that have been applied to the base scenario so that the scenario knows if there will be conflicts with future projects.
my_base_year_scenario = {
"road_net": load_from_roadway_dir(STPAUL_DIR),
"transit_net": load_transit(STPAUL_DIR),
"applied_projects": [],
"conflicts": {},
}
Add Projects to a Scenario ¶
In addition to adding projects when you create the scenario, project cards can be added to a
scenario using the add_project_cards
method.
from projectcard import read_cards
project_card_dict = read_cards(card_location, filter_tags=["Baseline2030"], recursive=True)
my_scenario.add_project_cards(project_card_dict.values())
Where card_location
can be a single path, list of paths, a directory, or a glob pattern.
Apply Projects to a Scenario ¶
Projects can be applied to a scenario using the apply_all_projects
method. Before applying
projects, the scenario will check that all pre-requisites are satisfied, that there are no conflicts,
and that the projects are in the planned projects list.
If you want to check the order of projects before applying them, you can use the queued_projects
prooperty.
You can review the resulting scenario, roadway network, and transit networks.
my_scenario.applied_projects
my_scenario.road_net.links_gdf.explore()
my_scenario.transit_net.feed.shapes_gdf.explore()
Write a Scenario to Disk ¶
Scenarios (and their networks) can be written to disk using the write
method which
in addition to writing out roadway and transit networks, will serialize the scenario to
a yaml-like file and can also write out the project cards that have been applied.
my_scenario.write(
"output_dir",
"scenario_name_to_use",
overwrite=True,
projects_write=True,
file_format="parquet",
)
Example Serialized Scenario File
applied_projects: &id001
- project a
- project b
base_scenario:
applied_projects: *id001
roadway:
dir: /Users/elizabeth/Documents/urbanlabs/MetCouncil/NetworkWrangler/working/network_wrangler/examples/small
file_format: geojson
transit:
dir: /Users/elizabeth/Documents/urbanlabs/MetCouncil/NetworkWrangler/working/network_wrangler/examples/small
config:
CPU:
EST_PD_READ_SPEED:
csv: 0.03
geojson: 0.03
json: 0.15
parquet: 0.005
txt: 0.04
IDS:
ML_LINK_ID_METHOD: range
ML_LINK_ID_RANGE: &id002 !!python/tuple
- 950000
- 999999
ML_LINK_ID_SCALAR: 15000
ML_NODE_ID_METHOD: range
ML_NODE_ID_RANGE: *id002
ML_NODE_ID_SCALAR: 15000
ROAD_SHAPE_ID_METHOD: scalar
ROAD_SHAPE_ID_SCALAR: 1000
TRANSIT_SHAPE_ID_METHOD: scalar
TRANSIT_SHAPE_ID_SCALAR: 1000000
MODEL_ROADWAY:
ADDITIONAL_COPY_FROM_GP_TO_ML: []
ADDITIONAL_COPY_TO_ACCESS_EGRESS: []
ML_OFFSET_METERS: -10
conflicts: {}
corequisites: {}
name: first_scenario
prerequisites: {}
roadway:
dir: /Users/elizabeth/Documents/urbanlabs/MetCouncil/NetworkWrangler/working/network_wrangler/tests/out/first_scenario/roadway
file_format: parquet
transit:
dir: /Users/elizabeth/Documents/urbanlabs/MetCouncil/NetworkWrangler/working/network_wrangler/tests/out/first_scenario/transit
file_format: txt
Load a scenario from disk ¶
And if you want to reload scenario that you “wrote”, you can use the load_scenario
function.
from network_wrangler import load_scenario
my_scenario = load_scenario("output_dir/scenario_name_to_use_scenario.yml")
network_wrangler.scenario.BASE_SCENARIO_SUGGESTED_PROPS
module-attribute
¶
List of card types that that will be applied to the transit network.
network_wrangler.scenario.ROADWAY_CARD_TYPES
module-attribute
¶
List of card types that that will be applied to the transit network AFTER being applied to the roadway network.
network_wrangler.scenario.TRANSIT_CARD_TYPES
module-attribute
¶
TRANSIT_CARD_TYPES = ['transit_property_change', 'transit_routing_change', 'transit_route_addition', 'transit_service_deletion']
List of card types that that will be applied to the roadway network.
network_wrangler.scenario.Scenario ¶
Holds information about a scenario.
Typical usage example:
my_base_year_scenario = {
"road_net": load_roadway(
links_file=STPAUL_LINK_FILE,
nodes_file=STPAUL_NODE_FILE,
shapes_file=STPAUL_SHAPE_FILE,
),
"transit_net": load_transit(STPAUL_DIR),
}
# create a future baseline scenario from base by searching for all cards in dir w/ baseline tag
project_card_directory = Path(STPAUL_DIR) / "project_cards"
my_scenario = create_scenario(
base_scenario=my_base_year_scenario,
card_search_dir=project_card_directory,
filter_tags=["baseline2050"],
)
# check project card queue and then apply the projects
my_scenario.queued_projects
my_scenario.apply_all_projects()
# check applied projects, write it out, and create a summary report.
my_scenario.applied_projects
my_scenario.write("baseline")
my_scenario.summary
# Add some projects to create a build scenario based on a list of files.
build_card_filenames = [
"3_multiple_roadway_attribute_change.yml",
"road.prop_changes.segment.yml",
"4_simple_managed_lane.yml",
]
my_scenario.add_projects_from_files(build_card_filenames)
my_scenario.write("build2050")
my_scenario.summary
Attributes:
-
base_scenario
(dict
) –dictionary representation of a scenario
-
road_net
(Optional[RoadwayNetwork]
) –instance of RoadwayNetwork for the scenario
-
transit_net
(Optional[TransitNetwork]
) –instance of TransitNetwork for the scenario
-
project_cards
(dict[str, ProjectCard]
) –Mapping[ProjectCard.name,ProjectCard] Storage of all project cards by name.
-
queued_projects
–Projects which are “shovel ready” - have had pre-requisits checked and done any required re-ordering. Similar to a git staging, project cards aren’t recognized in this collecton once they are moved to applied.
-
applied_projects
(list[str]
) –list of project names that have been applied
-
projects
–list of all projects either planned, queued, or applied
-
prerequisites
(dict[str, list[str]]
) –dictionary storing prerequiste info as
projectA: [prereqs-for-projectA]
-
corequisites
(dict[str, list[str]]
) –dictionary storing corequisite info as
projectA: [coreqs-for-projectA]
-
conflicts
(dict[str, list[str]]
) –dictionary storing conflict info as
projectA: [conflicts-for-projectA]
-
config
–WranglerConfig instance.
Source code in network_wrangler/scenario.py
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 |
|
network_wrangler.scenario.Scenario.projects
property
¶
Returns a list of all projects in the scenario: applied and planned.
network_wrangler.scenario.Scenario.queued_projects
property
¶
Returns a list version of _queued_projects queue.
Queued projects are thos that have been planned, have all pre-requisites satisfied, and have been ordered based on pre-requisites.
If no queued projects, will dynamically generate from planned projects based on pre-requisites and return the queue.
network_wrangler.scenario.Scenario.summary
property
¶
A high level summary of the created scenario and public attributes.
network_wrangler.scenario.Scenario.__init__ ¶
Constructor.
Parameters:
-
base_scenario
(Union[Scenario, dict]
) –A base scenario object to base this isntance off of, or a dict which describes the scenario attributes including applied projects and respective conflicts.
{"applied_projects": [],"conflicts":{...}}
-
project_card_list
(Optional[list[ProjectCard]]
, default:None
) –Optional list of ProjectCard instances to add to planned projects. Defaults to None.
-
config
(Optional[Union[WranglerConfig, dict, Path, list[Path]]]
, default:None
) –WranglerConfig instance or a dictionary of configuration settings or a path to one or more configuration files. Configurations that are not explicity set will default to the values in the default configuration in
/configs/wrangler/default.yml
. -
name
(str
, default:''
) –Optional name for the scenario.
Source code in network_wrangler/scenario.py
network_wrangler.scenario.Scenario.__str__ ¶
network_wrangler.scenario.Scenario.add_project_cards ¶
Adds a list of ProjectCard instances to the Scenario.
Checks that a project of same name is not already in scenario. If selected, will validate ProjectCard before adding. If provided, will only add ProjectCard if it matches at least one filter_tags.
Parameters:
-
project_card_list
(list[ProjectCard]
) –List of ProjectCard instances to add to scenario.
-
validate
(bool
, default:True
) –If True, will require each ProjectCard is validated before being added to scenario. Defaults to True.
-
filter_tags
(Optional[list[str]]
, default:None
) –If used, will filter ProjectCard instances and only add those whose tags match one or more of these filter_tags. Defaults to [] - which means no tag-filtering will occur.
Source code in network_wrangler/scenario.py
network_wrangler.scenario.Scenario.apply_all_projects ¶
Applies all planned projects in the queue.
Source code in network_wrangler/scenario.py
network_wrangler.scenario.Scenario.apply_projects ¶
Applies a specific list of projects from the planned project queue.
Will order the list of projects based on pre-requisites.
NOTE: does not check co-requisites b/c that isn’t possible when applying a single project.
Parameters:
-
project_list
(list[str]
) –List of projects to be applied. All need to be in the planned project queue.
Source code in network_wrangler/scenario.py
network_wrangler.scenario.Scenario.order_projects ¶
Orders a list of projects based on moving up pre-requisites into a deque.
Parameters:
-
project_list
(list[str]
) –list of projects to order
Source code in network_wrangler/scenario.py
network_wrangler.scenario.Scenario.write ¶
write(path, name, overwrite=True, roadway_write=True, transit_write=True, projects_write=True, roadway_convert_complex_link_properties_to_single_field=False, roadway_out_dir=None, roadway_prefix=None, roadway_file_format='parquet', roadway_true_shape=False, transit_out_dir=None, transit_prefix=None, transit_file_format='txt', projects_out_dir=None)
Writes scenario networks and summary to disk and returns path to scenario file.
Parameters:
-
path
(Path
) –Path to write scenario networks and scenario summary to.
-
name
(str
) –Name to use.
-
overwrite
(bool
, default:True
) –If True, will overwrite the files if they already exist.
-
roadway_write
(bool
, default:True
) –If True, will write out the roadway network.
-
transit_write
(bool
, default:True
) –If True, will write out the transit network.
-
projects_write
(bool
, default:True
) –If True, will write out the project cards.
-
roadway_convert_complex_link_properties_to_single_field
(bool
, default:False
) –If True, will convert complex link properties to a single field.
-
roadway_out_dir
(Optional[Path]
, default:None
) –Path to write the roadway network files to.
-
roadway_prefix
(Optional[str]
, default:None
) –Prefix to add to the file name.
-
roadway_file_format
(RoadwayFileTypes
, default:'parquet'
) –File format to write the roadway network to
-
roadway_true_shape
(bool
, default:False
) –If True, will write the true shape of the roadway network
-
transit_out_dir
(Optional[Path]
, default:None
) –Path to write the transit network files to.
-
transit_prefix
(Optional[str]
, default:None
) –Prefix to add to the file name.
-
transit_file_format
(TransitFileTypes
, default:'txt'
) –File format to write the transit network to
-
projects_out_dir
(Optional[Path]
, default:None
) –Path to write the project cards to.
Source code in network_wrangler/scenario.py
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 |
|
network_wrangler.scenario.build_scenario_from_config ¶
Builds a scenario from a dictionary configuration.
Parameters:
-
scenario_config
(Union[Path, list[Path], ScenarioConfig, dict]
) –Path to a configuration file, list of paths, or a dictionary of configuration.
Source code in network_wrangler/scenario.py
network_wrangler.scenario.create_base_scenario ¶
create_base_scenario(roadway=None, transit=None, applied_projects=None, conflicts=None, config=DefaultConfig)
Creates a base scenario dictionary from roadway and transit network files.
Parameters:
-
roadway
(Optional[dict]
, default:None
) –kwargs for load_roadway_from_dir
-
transit
(Optional[dict]
, default:None
) –kwargs for load_transit from dir
-
applied_projects
(Optional[list]
, default:None
) –list of projects that have been applied to the base scenario.
-
conflicts
(Optional[dict]
, default:None
) –dictionary of conflicts that have been identified in the base scenario. Takes the format of
{"projectA": ["projectB", "projectC"]}
showing that projectA, which has been applied, conflicts with projectB and projectC and so they shouldn’t be applied in the future. -
config
(WranglerConfig
, default:DefaultConfig
) –WranglerConfig instance.
Source code in network_wrangler/scenario.py
network_wrangler.scenario.create_scenario ¶
create_scenario(base_scenario=None, name=datetime.now().strftime('%Y%m%d%H%M%S'), project_card_list=None, project_card_filepath=None, filter_tags=None, config=None)
Creates scenario from a base scenario and adds project cards.
Project cards can be added using any/all of the following methods: 1. List of ProjectCard instances 2. List of ProjectCard files 3. Directory and optional glob search to find project card files in
Checks that a project of same name is not already in scenario. If selected, will validate ProjectCard before adding. If provided, will only add ProjectCard if it matches at least one filter_tags.
Parameters:
-
base_scenario
(Optional[Union[Scenario, dict]]
, default:None
) –base Scenario scenario instances of dictionary of attributes.
-
name
(str
, default:strftime('%Y%m%d%H%M%S')
) –Optional name for the scenario. Defaults to current datetime.
-
project_card_list
–List of ProjectCard instances to create Scenario from. Defaults to [].
-
project_card_filepath
(Optional[Union[list[Path], Path]]
, default:None
) –where the project card is. A single path, list of paths,
-
filter_tags
(Optional[list[str]]
, default:None
) –If used, will only add the project card if its tags match one or more of these filter_tags. Defaults to [] which means no tag-filtering will occur.
-
config
(Optional[Union[dict, Path, list[Path], WranglerConfig]]
, default:None
) –Optional wrangler configuration file or dictionary or instance. Defaults to default config.
Source code in network_wrangler/scenario.py
network_wrangler.scenario.extract_base_scenario_metadata ¶
Extract metadata from base scenario rather than keeping all of big files.
Useful for summarizing a scenario.
Source code in network_wrangler/scenario.py
network_wrangler.scenario.load_scenario ¶
Loads a scenario from a file written by Scenario.write() as the base scenario.
Parameters:
-
scenario_data
(Union[dict, Path]
) –Scenario data as a dict or path to scenario data file
-
name
(str
, default:strftime('%Y%m%d%H%M%S')
) –Optional name for the scenario. Defaults to current datetime.
Source code in network_wrangler/scenario.py
network_wrangler.scenario.write_applied_projects ¶
Summarizes all projects in a scenario to folder.
Parameters:
-
scenario
(Scenario
) –Scenario instance to summarize.
-
out_dir
(Path
) –Path to write the project cards.
-
overwrite
(bool
, default:True
) –If True, will overwrite the files if they already exist.
Source code in network_wrangler/scenario.py
Roadway Network class and functions for Network Wrangler.
Used to represent a roadway network and perform operations on it.
Usage:
from network_wrangler import load_roadway_from_dir, write_roadway
net = load_roadway_from_dir("my_dir")
net.get_selection({"links": [{"name": ["I 35E"]}]})
net.apply("my_project_card.yml")
write_roadway(net, "my_out_prefix", "my_dir", file_format="parquet")
network_wrangler.roadway.network.RoadwayNetwork ¶
Bases: BaseModel
Representation of a Roadway Network.
Typical usage example:
net = load_roadway(
links_file=MY_LINK_FILE,
nodes_file=MY_NODE_FILE,
shapes_file=MY_SHAPE_FILE,
)
my_selection = {
"link": [{"name": ["I 35E"]}],
"A": {"osm_node_id": "961117623"}, # start searching for segments at A
"B": {"osm_node_id": "2564047368"},
}
net.get_selection(my_selection)
my_change = [
{
'property': 'lanes',
'existing': 1,
'set': 2,
},
{
'property': 'drive_access',
'set': 0,
},
]
my_net.apply_roadway_feature_change(
my_net.get_selection(my_selection),
my_change
)
net.model_net
net.is_network_connected(mode="drive", nodes=self.m_nodes_df, links=self.m_links_df)
_, disconnected_nodes = net.assess_connectivity(
mode="walk",
ignore_end_nodes=True,
nodes=self.m_nodes_df,
links=self.m_links_df
)
write_roadway(net,filename=my_out_prefix, path=my_dir, for_model = True)
Attributes:
-
nodes_df
(RoadNodesTable
) –dataframe of of node records.
-
links_df
(RoadLinksTable
) –dataframe of link records and associated properties.
-
shapes_df
(RoadShapesTable
) –dataframe of detailed shape records This is lazily created iff it is called because shapes files can be expensive to read.
-
_selections
(dict
) –dictionary of stored roadway selection objects, mapped by
RoadwayLinkSelection.sel_key
orRoadwayNodeSelection.sel_key
in case they are made repeatedly. -
network_hash
(str
) –dynamic property of the hashed value of links_df and nodes_df. Used for quickly identifying if a network has changed since various expensive operations have taken place (i.e. generating a ModelRoadwayNetwork or a network graph)
-
model_net
(ModelRoadwayNetwork
) –referenced
ModelRoadwayNetwork
object which will be lazily created if None or if thenetwork_hash
has changed. -
config
(WranglerConfig
) –wrangler configuration object
Source code in network_wrangler/roadway/network.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 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 |
|
network_wrangler.roadway.network.RoadwayNetwork.link_shapes_df
property
¶
Add shape geometry to links if available.
returns: shapes merged to links dataframe
network_wrangler.roadway.network.RoadwayNetwork.model_net
property
¶
Return a ModelRoadwayNetwork object for this network.
network_wrangler.roadway.network.RoadwayNetwork.network_hash
property
¶
Hash of the links and nodes dataframes.
network_wrangler.roadway.network.RoadwayNetwork.shapes_df
property
writable
¶
Load and return RoadShapesTable.
If not already loaded, will read from shapes_file and return. If shapes_file is None, will return an empty dataframe with the right schema. If shapes_df is already set, will return that.
network_wrangler.roadway.network.RoadwayNetwork.summary
property
¶
Quick summary dictionary of number of links, nodes.
network_wrangler.roadway.network.RoadwayNetwork.add_links ¶
Validate combined links_df with LinksSchema before adding to self.links_df.
Parameters:
-
add_links_df
(DataFrame
) –Dataframe of additional links to add.
-
in_crs
(int
, default:LAT_LON_CRS
) –crs of input data. Defaults to LAT_LON_CRS.
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.add_nodes ¶
Validate combined nodes_df with NodesSchema before adding to self.nodes_df.
Parameters:
-
add_nodes_df
(DataFrame
) –Dataframe of additional nodes to add.
-
in_crs
(int
, default:LAT_LON_CRS
) –crs of input data. Defaults to LAT_LON_CRS.
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.add_shapes ¶
Validate combined shapes_df with RoadShapesTable efore adding to self.shapes_df.
Parameters:
-
add_shapes_df
(DataFrame
) –Dataframe of additional shapes to add.
-
in_crs
(int
, default:LAT_LON_CRS
) –crs of input data. Defaults to LAT_LON_CRS.
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.apply ¶
Wrapper method to apply a roadway project, returning a new RoadwayNetwork instance.
Parameters:
-
project_card
(Union[ProjectCard, dict]
) –either a dictionary of the project card object or ProjectCard instance
-
transit_net
(Optional[TransitNetwork]
, default:None
) –optional transit network which will be used to if project requires as noted in
SECONDARY_TRANSIT_CARD_TYPES
. If no transit network is provided, will skip anything related to transit network. -
**kwargs
–keyword arguments to pass to project application
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.clean_unused_nodes ¶
Removes any unused nodes from network that aren’t referenced by links_df.
NOTE: does not check if these nodes are used by transit, so use with caution.
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.clean_unused_shapes ¶
Removes any unused shapes from network that aren’t referenced by links_df.
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.coerce_crs ¶
Coerce crs of nodes_df and links_df to LAT_LON_CRS.
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.delete_links ¶
Deletes links based on selection dictionary and optionally associated nodes and shapes.
Parameters:
-
selection_dict
(SelectLinks
) –Dictionary describing link selections as follows:
all
: Optional[bool] = False. If true, will select all.name
: Optional[list[str]]ref
: Optional[list[str]]osm_link_id
:Optional[list[str]]model_link_id
: Optional[list[int]]modes
: Optional[list[str]]. Defaults to “any”ignore_missing
: if true, will not error when defaults to True. …plus any other link property to select on top of these. -
clean_nodes
(bool
, default:False
) –If True, will clean nodes uniquely associated with deleted links. Defaults to False.
-
clean_shapes
(bool
, default:False
) –If True, will clean nodes uniquely associated with deleted links. Defaults to False.
-
transit_net
(TransitNetwork
, default:None
) –If provided, will check TransitNetwork and warn if deletion breaks transit shapes. Defaults to None.
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.delete_nodes ¶
Deletes nodes from roadway network. Wont delete nodes used by links in network.
Parameters:
-
selection_dict
(Union[dict, SelectNodesDict]
) –dictionary of node selection criteria in the form of a SelectNodesDict.
-
remove_links
(bool
, default:False
) –if True, will remove any links that are associated with the nodes. If False, will only remove nodes if they are not associated with any links. Defaults to False.
Raises:
-
NodeDeletionError
–If not ignore_missing and selected nodes to delete aren’t in network
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.get_modal_graph ¶
Return a networkx graph of the network for a specific mode.
Parameters:
-
mode
–mode of the network, one of
drive
,transit
,walk
,bike
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.get_property_by_timespan_and_group ¶
get_property_by_timespan_and_group(link_property, category=DEFAULT_CATEGORY, timespan=DEFAULT_TIMESPAN, strict_timespan_match=False, min_overlap_minutes=60)
Returns a new dataframe with model_link_id and link property by category and timespan.
Convenience method for backward compatability.
Parameters:
-
link_property
(str
) –link property to query
-
category
(Optional[Union[str, int]]
, default:DEFAULT_CATEGORY
) –category to query or a list of categories. Defaults to DEFAULT_CATEGORY.
-
timespan
(Optional[TimespanString]
, default:DEFAULT_TIMESPAN
) –timespan to query in the form of [“HH:MM”,”HH:MM”]. Defaults to DEFAULT_TIMESPAN.
-
strict_timespan_match
(bool
, default:False
) –If True, will only return links that match the timespan exactly. Defaults to False.
-
min_overlap_minutes
(int
, default:60
) –If strict_timespan_match is False, will return links that overlap with the timespan by at least this many minutes. Defaults to 60.
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.get_selection ¶
Return selection if it already exists, otherwise performs selection.
Parameters:
-
selection_dict
(dict
) –SelectFacility dictionary.
-
overwrite
(bool
, default:False
) –if True, will overwrite any previously cached searches. Defaults to False.
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.has_link ¶
Returns true if network has links with AB values.
Parameters:
-
ab
(tuple
) –Tuple of values corresponding with A and B.
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.has_node ¶
Queries if network has node based on model_node_id.
Parameters:
-
model_node_id
(int
) –model_node_id to check for.
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.is_connected ¶
Determines if the network graph is “strongly” connected.
A graph is strongly connected if each vertex is reachable from every other vertex.
Parameters:
-
mode
(str
) –mode of the network, one of
drive
,transit
,walk
,bike
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.links_with_link_ids ¶
network_wrangler.roadway.network.RoadwayNetwork.links_with_nodes ¶
network_wrangler.roadway.network.RoadwayNetwork.modal_graph_hash ¶
Hash of the links in order to detect a network change from when graph created.
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.move_nodes ¶
Moves nodes based on updated geometry along with associated links and shape geometry.
Parameters:
-
node_geometry_change_table
(DataFrame
) –a table with model_node_id, X, Y, and CRS.
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.node_coords ¶
Return coordinates (x, y) of a node based on model_node_id.
Source code in network_wrangler/roadway/network.py
network_wrangler.roadway.network.RoadwayNetwork.nodes_in_links ¶
network_wrangler.roadway.network.add_incident_link_data_to_nodes ¶
Add data from links going to/from nodes to node.
Parameters:
-
links_df
(DataFrame
) –Will assess connectivity of this links list
-
nodes_df
(DataFrame
) –Will assess connectivity of this nodes list
-
link_variables
(Optional[list]
, default:None
) –list of columns in links dataframe to add to incident nodes
Returns:
-
DataFrame
–nodes DataFrame with link data where length is N*number of links going in/out
Source code in network_wrangler/roadway/network.py
TransitNetwork class for representing a transit network.
Transit Networks are represented as a Wrangler-flavored GTFS Feed and optionally mapped to a RoadwayNetwork object. The TransitNetwork object is the primary object for managing transit networks in Wrangler.
Usage:
1 2 3 4 5 6 7 8 |
|
network_wrangler.transit.network.TransitNetwork ¶
Representation of a Transit Network.
Typical usage example:
Attributes:
-
feed
–gtfs feed object with interlinked tables.
-
road_net
(RoadwayNetwork
) –Associated roadway network object.
-
graph
(MultiDiGraph
) –Graph for associated roadway network object.
-
config
(WranglerConfig
) –Configuration object for the transit network.
-
feed_path
(str
) –Where the feed was read in from.
-
validated_frequencies
(bool
) –The frequencies have been validated.
-
validated_road_network_consistency
–The network has been validated against the road network.
Source code in network_wrangler/transit/network.py
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 |
|
network_wrangler.transit.network.TransitNetwork.applied_projects
property
¶
List of projects applied to the network.
Note: This may or may not return a full accurate account of all the applied projects. For better project accounting, please leverage the scenario object.
network_wrangler.transit.network.TransitNetwork.consistent_with_road_net
property
¶
Indicate if road_net is consistent with transit network.
Will return True if road_net is None, but provide a warning.
Checks the network hash of when consistency was last evaluated. If transit network or roadway network has changed, will re-evaluate consistency and return the updated value and update self._stored_road_net_hash.
Returns:
-
bool
–Boolean indicating if road_net is consistent with transit network.
network_wrangler.transit.network.TransitNetwork.feed
property
writable
¶
Feed associated with the transit network.
network_wrangler.transit.network.TransitNetwork.feed_hash
property
¶
Return the hash of the feed.
network_wrangler.transit.network.TransitNetwork.feed_path
property
¶
Pass through property from Feed.
network_wrangler.transit.network.TransitNetwork.road_net
property
writable
¶
Roadway network associated with the transit network.
network_wrangler.transit.network.TransitNetwork.shape_links_gdf
property
¶
Return shape-links as a GeoDataFrame using set roadway geometry.
network_wrangler.transit.network.TransitNetwork.shapes_gdf
property
¶
Return aggregated shapes as a GeoDataFrame using set roadway geometry.
network_wrangler.transit.network.TransitNetwork.stop_time_links_gdf
property
¶
Return stop-time-links as a GeoDataFrame using set roadway geometry.
network_wrangler.transit.network.TransitNetwork.stop_times_points_gdf
property
¶
Return stop-time-points as a GeoDataFrame using set roadway geometry.
network_wrangler.transit.network.TransitNetwork.stops_gdf
property
¶
Return stops as a GeoDataFrame using set roadway geometry.
network_wrangler.transit.network.TransitNetwork.__deepcopy__ ¶
Returns copied TransitNetwork instance with deep copy of Feed but not roadway net.
Source code in network_wrangler/transit/network.py
network_wrangler.transit.network.TransitNetwork.__init__ ¶
Constructor for TransitNetwork.
Parameters:
-
feed
(Feed
) –Feed object representing the transit network gtfs tables
-
config
(WranglerConfig
, default:DefaultConfig
) –WranglerConfig object. Defaults to DefaultConfig.
Source code in network_wrangler/transit/network.py
network_wrangler.transit.network.TransitNetwork.apply ¶
Wrapper method to apply a roadway project, returning a new TransitNetwork instance.
Parameters:
-
project_card
(Union[ProjectCard, dict]
) –either a dictionary of the project card object or ProjectCard instance
-
**kwargs
–keyword arguments to pass to project application
Source code in network_wrangler/transit/network.py
network_wrangler.transit.network.TransitNetwork.deepcopy ¶
network_wrangler.transit.network.TransitNetwork.get_selection ¶
Return selection if it already exists, otherwise performs selection.
Will raise an error if no trips found.
Parameters:
-
selection_dict
(dict
) –description
-
overwrite
(bool
, default:False
) –if True, will overwrite any previously cached searches. Defaults to False.
Returns:
-
Selection
(TransitSelection
) –Selection object
Source code in network_wrangler/transit/network.py
network_wrangler.models._base.db.DbForeignKeys
module-attribute
¶
DbForeignKeys = dict[str, TableForeignKeys]
Mapping of tables that have fields that other tables use as fks.
{ <table>:{<field>:[(<table using FK>,<field using fk>)]} }
Example
{“stops”: {“stop_id”: [ (“stops”, “parent_station”), (“stop_times”, “stop_id”) ]} }
network_wrangler.models._base.db.TableForeignKeys
module-attribute
¶
Dict of each table’s foreign keys.
{ <table>:{<field>:[<fk_table>,<fk_field>]} }
Example
{“stops”: {“parent_station”: (“stops”, “stop_id”)} “stop_times”: {“stop_id”: (“stops”, “stop_id”)} {“trip_id”: (“trips”, “trip_id”)} }
network_wrangler.models._base.db.TablePrimaryKeys
module-attribute
¶
TableForeignKeys is a dictionary of foreign keys for a single table.
Uses the form
{
Example
{“parent_station”: (“stops”, “stop_id”)}
network_wrangler.models._base.db.DBModelMixin ¶
An mixin class for interrelated pandera DataFrameModel tables.
Contains a bunch of convenience methods and overrides the dunder methods deepcopy and eq.
Methods:
-
hash
–hash of tables
-
deepcopy
–deepcopy of tables which references a custom deepcopy
-
get_table
–retrieve table by name
-
table_names_with_field
–returns tables in
table_names
with field name
Attr
Where metadata variable _fk = {
e.g.: _fk = {"parent_station": ["stops", "stop_id"]}
Source code in network_wrangler/models/_base/db.py
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 |
|
network_wrangler.models._base.db.DBModelMixin.hash
property
¶
A hash representing the contents of the tables in self.table_names.
network_wrangler.models._base.db.DBModelMixin.__deepcopy__ ¶
Custom implementation of deepcopy method.
This method is called by copy.deepcopy() to create a deep copy of the object.
Parameters:
-
memo
(dict
) –Dictionary to track objects already copied during deepcopy.
Returns:
-
Feed
–A deep copy of the db object.
Source code in network_wrangler/models/_base/db.py
network_wrangler.models._base.db.DBModelMixin.__eq__ ¶
network_wrangler.models._base.db.DBModelMixin.__hash__ ¶
network_wrangler.models._base.db.DBModelMixin.__setattr__ ¶
Override the default setattr behavior to handle DataFrame validation.
Note: this is NOT called when a dataframe is mutated in place!
Parameters:
-
key
(str
) –The attribute name.
-
value
–The value to be assigned to the attribute.
Raises:
-
SchemaErrors
–If the DataFrame does not conform to the schema.
-
ForeignKeyError
–If doesn’t validate to foreign key.
Source code in network_wrangler/models/_base/db.py
network_wrangler.models._base.db.DBModelMixin.check_fks ¶
Check all FKs in set of tables.
Source code in network_wrangler/models/_base/db.py
network_wrangler.models._base.db.DBModelMixin.check_referenced_fk ¶
True if table.field has the values referenced in any table referencing fields as fk.
For example. If routes.route_id is referenced in trips table, we need to check that if a route_id is deleted, it isn’t referenced in trips.route_id.
Source code in network_wrangler/models/_base/db.py
network_wrangler.models._base.db.DBModelMixin.check_referenced_fks ¶
True if this table has the values referenced in any table referencing fields as fk.
For example. If routes.route_id is referenced in trips table, we need to check that if a route_id is deleted, it isn’t referenced in trips.route_id.
Source code in network_wrangler/models/_base/db.py
network_wrangler.models._base.db.DBModelMixin.check_table_fks ¶
Return True if the foreign key fields in table have valid references.
Note: will return true and give a warning if the specified foreign key table doesn’t exist.
Source code in network_wrangler/models/_base/db.py
network_wrangler.models._base.db.DBModelMixin.deepcopy ¶
network_wrangler.models._base.db.DBModelMixin.fields_as_fks
classmethod
¶
Returns mapping of tables that have fields that other tables use as fks.
{ <table>:{<field>:[(<table using FK>,<field using fk>)]} }
Useful for knowing if you should check FK validation when changing a field value.
Source code in network_wrangler/models/_base/db.py
network_wrangler.models._base.db.DBModelMixin.fks
classmethod
¶
Return the fk field constraints as { <table>:{<field>:[<fk_table>,<fk_field>]} }
.
Source code in network_wrangler/models/_base/db.py
network_wrangler.models._base.db.DBModelMixin.get_table ¶
Get table by name.
Source code in network_wrangler/models/_base/db.py
network_wrangler.models._base.db.DBModelMixin.initialize_tables ¶
Initializes the tables for the database.
Parameters:
-
**kwargs
–Keyword arguments representing the tables to be initialized.
Raises:
-
RequiredTableError
–If any required tables are missing in the initialization.
Source code in network_wrangler/models/_base/db.py
network_wrangler.models._base.db.DBModelMixin.table_names_with_field ¶
Returns tables in the class instance which contain the field.
Configuration ¶
Classes and utilities for configuring Network Wrangler behavior:
Configuration for parameters for Network Wrangler.
Users can change a handful of parameters which control the way Wrangler runs. These parameters can be saved as a wrangler config file which can be read in repeatedly to make sure the same parameters are used each time.
Usage
At runtime, you can specify configurable parameters at the scenario level which will then also be assigned and accessible to the roadway and transit networks.
Or if you are not using Scenario functionality, you can specify the config when you read in a RoadwayNetwork.
my_config
can be a:
- Path to a config file in yaml/toml/json (recommended),
- List of paths to config files (in case you want to split up various sub-configurations)
- Dictionary which is in the same structure of a config file, or
- A
WranglerConfig()
instance.
If not provided, Wrangler will use reasonable defaults.
Default Wrangler Configuration Values
If not explicitly provided, the following default values are used:
IDS:
TRANSIT_SHAPE_ID_METHOD: scalar
TRANSIT_SHAPE_ID_SCALAR: 1000000
ROAD_SHAPE_ID_METHOD: scalar
ROAD_SHAPE_ID_SCALAR: 1000
ML_LINK_ID_METHOD: range
ML_LINK_ID_RANGE: (950000, 999999)
ML_LINK_ID_SCALAR: 15000
ML_NODE_ID_METHOD: range
ML_NODE_ID_RANGE: (950000, 999999)
ML_NODE_ID_SCALAR: 15000
EDITS:
EXISTING_VALUE_CONFLIC: warn
OVERWRITE_SCOPED: conflicting
MODEL_ROADWAY:
ML_OFFSET_METERS: int = -10
ADDITIONAL_COPY_FROM_GP_TO_ML: []
ADDITIONAL_COPY_TO_ACCESS_EGRESS: []
CPU:
EST_PD_READ_SPEED:
csv: 0.03
parquet: 0.005
geojson: 0.03
json: 0.15
txt: 0.04
Extended usage
Load the default configuration:
Access the configuration:
from network_wrangler.configs import DefaultConfig
DefaultConfig.MODEL_ROADWAY.ML_OFFSET_METERS
>> -10
Modify the default configuration in-line:
from network_wrangler.configs import DefaultConfig
DefaultConfig.MODEL_ROADWAY.ML_OFFSET_METERS = 20
Load a configuration from a file:
from network_wrangler.configs import load_wrangler_config
config = load_wrangler_config("path/to/config.yaml")
Set a configuration value:
network_wrangler.configs.wrangler.CpuConfig ¶
Bases: ConfigItem
CPU Configuration - Will not change any outcomes.
Attributes:
-
EST_PD_READ_SPEED
(dict[str, float]
) –Read sec / MB - WILL DEPEND ON SPECIFIC COMPUTER
Source code in network_wrangler/configs/wrangler.py
network_wrangler.configs.wrangler.EditsConfig ¶
Bases: ConfigItem
Configuration for Edits.
Attributes:
-
EXISTING_VALUE_CONFLICT
(Literal['warn', 'error', 'skip']
) –Only used if ‘existing’ provided in project card and
existing
doesn’t match the existing network value. One oferror
,warn
, orskip
.error
will raise an error,warn
will warn the user, andskip
will skip the change for that specific property (note it will still apply any remaining property changes). Defaults towarn
. Can be overridden by settingexisting_value_conflict
in aroadway_property_change
project card. -
OVERWRITE_SCOPED
(Literal['conflicting', 'all', 'error']
) –How to handle conflicts with existing values. Should be one of “conflicting”, “all”, or False. “conflicting” will only overwrite values where the scope only partially overlaps with the existing value. “all” will overwrite all the scoped values. “error” will error if there is any overlap. Default is “conflicting”. Can be changed at the project-level by setting
overwrite_scoped
in aroadway_property_change
project card.
Source code in network_wrangler/configs/wrangler.py
network_wrangler.configs.wrangler.IdGenerationConfig ¶
Bases: ConfigItem
Model Roadway Configuration.
Attributes:
-
TRANSIT_SHAPE_ID_METHOD
(Literal['scalar']
) –method for creating a shape_id for a transit shape. Should be “scalar”.
-
TRANSIT_SHAPE_ID_SCALAR
(int
) –scalar value to add to general purpose lane to create a shape_id for a transit shape.
-
ROAD_SHAPE_ID_METHOD
(Literal['scalar']
) –method for creating a shape_id for a roadway shape. Should be “scalar”.
-
ROAD_SHAPE_ID_SCALAR
(int
) –scalar value to add to general purpose lane to create a shape_id for a roadway shape.
-
ML_LINK_ID_METHOD
(Literal['range', 'scalar']
) –method for creating a model_link_id for an associated link for a parallel managed lane.
-
ML_LINK_ID_RANGE
(tuple[int, int]
) –range of model_link_ids to use when creating an associated link for a parallel managed lane.
-
ML_LINK_ID_SCALAR
(int
) –scalar value to add to general purpose lane to create a model_link_id when creating an associated link for a parallel managed lane.
-
ML_NODE_ID_METHOD
(Literal['range', 'scalar']
) –method for creating a model_node_id for an associated node for a parallel managed lane.
-
ML_NODE_ID_RANGE
(tuple[int, int]
) –range of model_node_ids to use when creating an associated node for a parallel managed lane.
-
ML_NODE_ID_SCALAR
(int
) –scalar value to add to general purpose lane node ides create a model_node_id when creating an associated nodes for parallel managed lane.
Source code in network_wrangler/configs/wrangler.py
network_wrangler.configs.wrangler.ModelRoadwayConfig ¶
Bases: ConfigItem
Model Roadway Configuration.
Attributes:
-
ML_OFFSET_METERS
(int
) –Offset in meters for managed lanes.
-
ADDITIONAL_COPY_FROM_GP_TO_ML
(list[str]
) –Additional fields to copy from general purpose to managed lanes.
-
ADDITIONAL_COPY_TO_ACCESS_EGRESS
(list[str]
) –Additional fields to copy to access and egress links.
Source code in network_wrangler/configs/wrangler.py
network_wrangler.configs.wrangler.WranglerConfig ¶
Bases: ConfigItem
Configuration for Network Wrangler.
Attributes:
-
IDS
(IdGenerationConfig
) –Parameteters governing how new ids are generated.
-
MODEL_ROADWAY
(ModelRoadwayConfig
) –Parameters governing how the model roadway is created.
-
CPU
(CpuConfig
) –Parameters for accessing CPU information. Will not change any outcomes.
-
EDITS
(EditsConfig
) –Parameters governing how edits are handled.
Source code in network_wrangler/configs/wrangler.py
Scenario configuration for Network Wrangler.
You can build a scenario and write out the output from a scenario configuration file using the code below. This is very useful when you are running a specific scenario with minor variations over again because you can enter your config file into version control. In addition to the completed roadway and transit files, the output will provide a record of how the scenario was run.
Usage
from scenario import build_scenario_from_config
my_scenario = build_scenario_from_config(my_scenario_config)
Where my_scenario_config
can be a:
- Path to a scenario config file in yaml/toml/json (recommended),
- Dictionary which is in the same structure of a scenario config file, or
- A
ScenarioConfig()
instance.
Notes on relative paths in scenario configs
- Relative paths are recognized by a preceeding “.”.
- Relative paths within
output_scenario
forroadway
,transit
, andproject_cards
are interpreted to be relative tooutput_scenario.path
. - All other relative paths are interpreted to be relative to directory of the scenario config file. (Or if scenario config is provided as a dictionary, relative paths will be interpreted as relative to the current working directory.)
Example Scenario Config
name: "my_scenario"
base_scenario:
roadway:
dir: "path/to/roadway_network"
file_format: "geojson"
read_in_shapes: True
transit:
dir: "path/to/transit_network"
file_format: "txt"
applied_projects:
- "project1"
- "project2"
conflicts:
"project3": ["project1", "project2"]
"project4": ["project1"]
projects:
project_card_filepath:
- "path/to/projectA.yaml"
- "path/to/projectB.yaml"
filter_tags:
- "tag1"
output_scenario:
overwrite: True
roadway:
out_dir: "path/to/output/roadway"
prefix: "my_scenario"
file_format: "geojson"
true_shape: False
transit:
out_dir: "path/to/output/transit"
prefix: "my_scenario"
file_format: "txt"
project_cards:
out_dir: "path/to/output/project_cards"
wrangler_config: "path/to/wrangler_config.yaml"
Extended Usage
Load a configuration from a file:
from network_wrangler.configs import load_scenario_config
my_scenario_config = load_scenario_config("path/to/config.yaml")
Access the configuration:
network_wrangler.configs.scenario.ProjectCardOutputConfig ¶
Bases: ConfigItem
Configuration for outputing project cards in a scenario.
Attributes:
-
out_dir
–Path to write the project card files to if you don’t want to use the default.
-
write
–If True, will write the project cards. Defaults to True.
Source code in network_wrangler/configs/scenario.py
network_wrangler.configs.scenario.ProjectsConfig ¶
Bases: ConfigItem
Configuration for projects in a scenario.
Attributes:
-
project_card_filepath
–where the project card is. A single path, list of paths, a directory, or a glob pattern. Defaults to None.
-
filter_tags
–List of tags to filter the project cards by.
Source code in network_wrangler/configs/scenario.py
network_wrangler.configs.scenario.RoadwayNetworkInputConfig ¶
Bases: ConfigItem
Configuration for the road network in a scenario.
Attributes:
-
dir
–Path to directory with roadway network files.
-
file_format
–File format for the roadway network files. Should be one of RoadwayFileTypes. Defaults to “geojson”.
-
read_in_shapes
–If True, will read in the shapes of the roadway network. Defaults to False.
-
boundary_geocode
–Geocode of the boundary. Will use this to filter the roadway network.
-
boundary_file
–Path to the boundary file. If provided and both boundary_gdf and boundary_geocode are not provided, will use this to filter the roadway network.
Source code in network_wrangler/configs/scenario.py
network_wrangler.configs.scenario.RoadwayNetworkOutputConfig ¶
Bases: ConfigItem
Configuration for writing out the resulting roadway network for a scenario.
Attributes:
-
out_dir
–Path to write the roadway network files to if you don’t want to use the default.
-
prefix
–Prefix to add to the file name. If not provided will use the scenario name.
-
file_format
–File format to write the roadway network to. Should be one of RoadwayFileTypes. Defaults to “geojson”.
-
true_shape
–If True, will write the true shape of the roadway network. Defaults to False.
-
write
–If True, will write the roadway network. Defaults to True.
Source code in network_wrangler/configs/scenario.py
network_wrangler.configs.scenario.ScenarioConfig ¶
Bases: ConfigItem
Scenario configuration for Network Wrangler.
Attributes:
-
base_path
–base path of the scenario. Defaults to cwd.
-
name
–Name of the scenario.
-
base_scenario
–information about the base scenario
-
projects
–information about the projects to apply on top of the base scenario
-
output_scenario
–information about how to output the scenario
-
wrangler_config
–wrangler configuration to use
Source code in network_wrangler/configs/scenario.py
network_wrangler.configs.scenario.ScenarioInputConfig ¶
Bases: ConfigItem
Configuration for the writing the output of a scenario.
Attributes:
-
roadway
(Optional[RoadwayNetworkInputConfig]
) –Configuration for writing out the roadway network.
-
transit
(Optional[TransitNetworkInputConfig]
) –Configuration for writing out the transit network.
-
applied_projects
–List of projects to apply to the base scenario.
-
conflicts
–Dict of projects that conflict with the applied_projects.
Source code in network_wrangler/configs/scenario.py
network_wrangler.configs.scenario.ScenarioOutputConfig ¶
Bases: ConfigItem
Configuration for the writing the output of a scenario.
Attributes:
-
roadway
–Configuration for writing out the roadway network.
-
transit
–Configuration for writing out the transit network.
-
project_cards
(Optional[ProjectCardOutputConfig]
) –Configuration for writing out the project cards.
-
overwrite
–If True, will overwrite the files if they already exist. Defaults to True
Source code in network_wrangler/configs/scenario.py
network_wrangler.configs.scenario.TransitNetworkInputConfig ¶
Bases: ConfigItem
Configuration for the transit network in a scenario.
Attributes:
-
dir
–Path to the transit network files. Defaults to “.”.
-
file_format
–File format for the transit network files. Should be one of TransitFileTypes. Defaults to “txt”.
Source code in network_wrangler/configs/scenario.py
network_wrangler.configs.scenario.TransitNetworkOutputConfig ¶
Bases: ConfigItem
Configuration for the transit network in a scenario.
Attributes:
-
out_dir
–Path to write the transit network files to if you don’t want to use the default.
-
prefix
–Prefix to add to the file name. If not provided will use the scenario name.
-
file_format
–File format to write the transit network to. Should be one of TransitFileTypes. Defaults to “txt”.
-
write
–If True, will write the transit network. Defaults to True.
Source code in network_wrangler/configs/scenario.py
Configuration utilities.
network_wrangler.configs.utils.ConfigItem ¶
Base class to add partial dict-like interface to configuration.
Allow use of .items() [“X”] and .get(“X”) .to_dict() from configuration.
Not to be constructed directly. To be used a mixin for dataclasses representing config schema. Do not use “get” “to_dict”, or “items” for key names.
Source code in network_wrangler/configs/utils.py
network_wrangler.configs.utils.ConfigItem.__getitem__ ¶
network_wrangler.configs.utils.ConfigItem.get ¶
network_wrangler.configs.utils.ConfigItem.items ¶
network_wrangler.configs.utils.ConfigItem.resolve_paths ¶
Resolve relative paths in the configuration.
Source code in network_wrangler/configs/utils.py
network_wrangler.configs.utils.ConfigItem.to_dict ¶
Convert the configuration to a dictionary.
network_wrangler.configs.utils.ConfigItem.update ¶
Update the configuration with a dictionary of new values.
Source code in network_wrangler/configs/utils.py
network_wrangler.configs.utils.find_configs_in_dir ¶
Find configuration files in the directory that match *config<ext>
.