diff --git a/main/404.html b/main/404.html new file mode 100644 index 00000000..f252a540 --- /dev/null +++ b/main/404.html @@ -0,0 +1,574 @@ + + + +
+ + + + + + + + + + + + + + +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.
+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": {},
+}
+
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.
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()
+
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",
+)
+
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
+
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")
+
BASE_SCENARIO_SUGGESTED_PROPS: list[str] = ['road_net', 'transit_net', 'applied_projects', 'conflicts']
+
+
+ module-attribute
+
+
+ ¶List of card types that that will be applied to the transit network.
+ROADWAY_CARD_TYPES: list[str] = ['roadway_property_change', 'roadway_deletion', 'roadway_addition', 'pycode']
+
+
+ module-attribute
+
+
+ ¶List of card types that that will be applied to the transit network AFTER being applied to +the roadway network.
+TRANSIT_CARD_TYPES: list[str] = ['transit_property_change', 'transit_routing_change', 'transit_route_addition', 'transit_service_deletion']
+
+
+ module-attribute
+
+
+ ¶List of card types that that will be applied to the roadway network.
+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:
+Name | +Type | +Description | +
---|---|---|
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 |
+
corequisites |
+
+ dict[str, list[str]]
+ |
+
+
+
+ dictionary storing corequisite info as |
+
conflicts |
+
+ dict[str, list[str]]
+ |
+
+
+
+ dictionary storing conflict info as |
+
config |
+ + | +
+
+
+ WranglerConfig instance. + |
+
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 |
|
projects
+
+
+ property
+
+
+ ¶Returns a list of all projects in the scenario: applied and planned.
+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.
+summary: dict
+
+
+ property
+
+
+ ¶A high level summary of the created scenario and public attributes.
+__init__(base_scenario, project_card_list=None, config=None, name='')
+
+ ¶Constructor.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
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. |
+ + required + | +
project_card_list |
+
+ Optional[list[ProjectCard]]
+ |
+
+
+
+ Optional list of ProjectCard instances to add to planned projects. +Defaults to None. + |
+
+ None
+ |
+
config |
+
+ Optional[Union[WranglerConfig, dict, Path, list[Path]]]
+ |
+
+
+
+ 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
+ |
+
+ None
+ |
+
name |
+
+ str
+ |
+
+
+
+ Optional name for the scenario. + |
+
+ ''
+ |
+
network_wrangler/scenario.py
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 |
|
__str__()
+
+ ¶add_project_cards(project_card_list, validate=True, filter_tags=None)
+
+ ¶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:
+Name | +Type | +Description | +Default | +
---|---|---|---|
project_card_list |
+
+ list[ProjectCard]
+ |
+
+
+
+ List of ProjectCard instances to add to +scenario. + |
+ + required + | +
validate |
+
+ bool
+ |
+
+
+
+ If True, will require each ProjectCard is validated before +being added to scenario. Defaults to True. + |
+
+ True
+ |
+
filter_tags |
+
+ Optional[list[str]]
+ |
+
+
+
+ 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. + |
+
+ None
+ |
+
network_wrangler/scenario.py
apply_all_projects()
+
+ ¶Applies all planned projects in the queue.
+ +network_wrangler/scenario.py
apply_projects(project_list)
+
+ ¶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:
+Name | +Type | +Description | +Default | +
---|---|---|---|
project_list |
+
+ list[str]
+ |
+
+
+
+ List of projects to be applied. All need to be in the planned project +queue. + |
+ + required + | +
network_wrangler/scenario.py
order_projects(project_list)
+
+ ¶Orders a list of projects based on moving up pre-requisites into a deque.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
project_list |
+
+ list[str]
+ |
+
+
+
+ list of projects to order + |
+ + required + | +
network_wrangler/scenario.py
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:
+Name | +Type | +Description | +Default | +
---|---|---|---|
path |
+
+ Path
+ |
+
+
+
+ Path to write scenario networks and scenario summary to. + |
+ + required + | +
name |
+
+ str
+ |
+
+
+
+ Name to use. + |
+ + required + | +
overwrite |
+
+ bool
+ |
+
+
+
+ If True, will overwrite the files if they already exist. + |
+
+ True
+ |
+
roadway_write |
+
+ bool
+ |
+
+
+
+ If True, will write out the roadway network. + |
+
+ True
+ |
+
transit_write |
+
+ bool
+ |
+
+
+
+ If True, will write out the transit network. + |
+
+ True
+ |
+
projects_write |
+
+ bool
+ |
+
+
+
+ If True, will write out the project cards. + |
+
+ True
+ |
+
roadway_convert_complex_link_properties_to_single_field |
+
+ bool
+ |
+
+
+
+ If True, will convert complex +link properties to a single field. + |
+
+ False
+ |
+
roadway_out_dir |
+
+ Optional[Path]
+ |
+
+
+
+ Path to write the roadway network files to. + |
+
+ None
+ |
+
roadway_prefix |
+
+ Optional[str]
+ |
+
+
+
+ Prefix to add to the file name. + |
+
+ None
+ |
+
roadway_file_format |
+
+ RoadwayFileTypes
+ |
+
+
+
+ File format to write the roadway network to + |
+
+ 'parquet'
+ |
+
roadway_true_shape |
+
+ bool
+ |
+
+
+
+ If True, will write the true shape of the roadway network + |
+
+ False
+ |
+
transit_out_dir |
+
+ Optional[Path]
+ |
+
+
+
+ Path to write the transit network files to. + |
+
+ None
+ |
+
transit_prefix |
+
+ Optional[str]
+ |
+
+
+
+ Prefix to add to the file name. + |
+
+ None
+ |
+
transit_file_format |
+
+ TransitFileTypes
+ |
+
+
+
+ File format to write the transit network to + |
+
+ 'txt'
+ |
+
projects_out_dir |
+
+ Optional[Path]
+ |
+
+
+
+ Path to write the project cards to. + |
+
+ None
+ |
+
network_wrangler/scenario.py
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 |
|
build_scenario_from_config(scenario_config)
+
+ ¶Builds a scenario from a dictionary configuration.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
scenario_config |
+
+ Union[Path, list[Path], ScenarioConfig, dict]
+ |
+
+
+
+ Path to a configuration file, list of paths, or a dictionary of +configuration. + |
+ + required + | +
network_wrangler/scenario.py
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:
+Name | +Type | +Description | +Default | +
---|---|---|---|
roadway |
+
+ Optional[dict]
+ |
+
+
+
+ kwargs for load_roadway_from_dir + |
+
+ None
+ |
+
transit |
+
+ Optional[dict]
+ |
+
+
+
+ kwargs for load_transit from dir + |
+
+ None
+ |
+
applied_projects |
+
+ Optional[list]
+ |
+
+
+
+ list of projects that have been applied to the base scenario. + |
+
+ None
+ |
+
conflicts |
+
+ Optional[dict]
+ |
+
+
+
+ dictionary of conflicts that have been identified in the base scenario.
+Takes the format of |
+
+ None
+ |
+
config |
+
+ WranglerConfig
+ |
+
+
+
+ WranglerConfig instance. + |
+
+ DefaultConfig
+ |
+
network_wrangler/scenario.py
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:
+Name | +Type | +Description | +Default | +
---|---|---|---|
base_scenario |
+
+ Optional[Union[Scenario, dict]]
+ |
+
+
+
+ base Scenario scenario instances of dictionary of attributes. + |
+
+ None
+ |
+
name |
+
+ str
+ |
+
+
+
+ Optional name for the scenario. Defaults to current datetime. + |
+
+ strftime('%Y%m%d%H%M%S')
+ |
+
project_card_list |
+ + | +
+
+
+ List of ProjectCard instances to create Scenario from. Defaults +to []. + |
+
+ None
+ |
+
project_card_filepath |
+
+ Optional[Union[list[Path], Path]]
+ |
+
+
+
+ where the project card is. A single path, list of paths, + |
+
+ None
+ |
+
filter_tags |
+
+ Optional[list[str]]
+ |
+
+
+
+ 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. + |
+
+ None
+ |
+
config |
+
+ Optional[Union[dict, Path, list[Path], WranglerConfig]]
+ |
+
+
+
+ Optional wrangler configuration file or dictionary or instance. Defaults to +default config. + |
+
+ None
+ |
+
network_wrangler/scenario.py
extract_base_scenario_metadata(base_scenario)
+
+ ¶Extract metadata from base scenario rather than keeping all of big files.
+Useful for summarizing a scenario.
+ +network_wrangler/scenario.py
load_scenario(scenario_data, name=datetime.now().strftime('%Y%m%d%H%M%S'))
+
+ ¶Loads a scenario from a file written by Scenario.write() as the base scenario.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
scenario_data |
+
+ Union[dict, Path]
+ |
+
+
+
+ Scenario data as a dict or path to scenario data file + |
+ + required + | +
name |
+
+ str
+ |
+
+
+
+ Optional name for the scenario. Defaults to current datetime. + |
+
+ strftime('%Y%m%d%H%M%S')
+ |
+
network_wrangler/scenario.py
write_applied_projects(scenario, out_dir, overwrite=True)
+
+ ¶Summarizes all projects in a scenario to folder.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
scenario |
+
+ Scenario
+ |
+
+
+
+ Scenario instance to summarize. + |
+ + required + | +
out_dir |
+
+ Path
+ |
+
+
+
+ Path to write the project cards. + |
+ + required + | +
overwrite |
+
+ bool
+ |
+
+
+
+ If True, will overwrite the files if they already exist. + |
+
+ True
+ |
+
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")
+
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:
+Name | +Type | +Description | +
---|---|---|
nodes_df |
+
+ RoadNodesTable
+ |
+
+
+
+ dataframe of of node records. + |
+
links_df |
+
+ RoadLinksTable
+ |
+
+
+
+ dataframe of link records and associated properties. + |
+
shapes_df |
+
+ RoadShapestable
+ |
+
+
+
+ data from 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
+ |
+
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 |
+
config |
+
+ WranglerConfig
+ |
+
+
+
+ wrangler configuration object + |
+
network_wrangler/roadway/network.py
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 |
|
link_shapes_df: gpd.GeoDataFrame
+
+
+ property
+
+
+ ¶Add shape geometry to links if available.
+returns: shapes merged to links dataframe
+model_net: ModelRoadwayNetwork
+
+
+ property
+
+
+ ¶Return a ModelRoadwayNetwork object for this network.
+network_hash: str
+
+
+ property
+
+
+ ¶Hash of the links and nodes dataframes.
+shapes_df: DataFrame[RoadShapesTable]
+
+
+ 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.
+summary: dict
+
+
+ property
+
+
+ ¶Quick summary dictionary of number of links, nodes.
+add_links(add_links_df, in_crs=LAT_LON_CRS)
+
+ ¶Validate combined links_df with LinksSchema before adding to self.links_df.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
add_links_df |
+
+ Union[DataFrame, DataFrame[RoadLinksTable]]
+ |
+
+
+
+ Dataframe of additional links to add. + |
+ + required + | +
in_crs |
+
+ int
+ |
+
+
+
+ crs of input data. Defaults to LAT_LON_CRS. + |
+
+ LAT_LON_CRS
+ |
+
network_wrangler/roadway/network.py
add_nodes(add_nodes_df, in_crs=LAT_LON_CRS)
+
+ ¶Validate combined nodes_df with NodesSchema before adding to self.nodes_df.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
add_nodes_df |
+
+ Union[DataFrame, DataFrame[RoadNodesTable]]
+ |
+
+
+
+ Dataframe of additional nodes to add. + |
+ + required + | +
in_crs |
+
+ int
+ |
+
+
+
+ crs of input data. Defaults to LAT_LON_CRS. + |
+
+ LAT_LON_CRS
+ |
+
network_wrangler/roadway/network.py
add_shapes(add_shapes_df, in_crs=LAT_LON_CRS)
+
+ ¶Validate combined shapes_df with RoadShapesTable efore adding to self.shapes_df.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
add_shapes_df |
+
+ Union[DataFrame, DataFrame[RoadShapesTable]]
+ |
+
+
+
+ Dataframe of additional shapes to add. + |
+ + required + | +
in_crs |
+
+ int
+ |
+
+
+
+ crs of input data. Defaults to LAT_LON_CRS. + |
+
+ LAT_LON_CRS
+ |
+
network_wrangler/roadway/network.py
apply(project_card, transit_net=None, **kwargs)
+
+ ¶Wrapper method to apply a roadway project, returning a new RoadwayNetwork instance.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
project_card |
+
+ Union[ProjectCard, dict]
+ |
+
+
+
+ either a dictionary of the project card object or ProjectCard instance + |
+ + required + | +
transit_net |
+
+ Optional[TransitNetwork]
+ |
+
+
+
+ optional transit network which will be used to if project requires as
+noted in |
+
+ None
+ |
+
**kwargs |
+ + | +
+
+
+ keyword arguments to pass to project application + |
+
+ {}
+ |
+
network_wrangler/roadway/network.py
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.
+ +network_wrangler/roadway/network.py
clean_unused_shapes()
+
+ ¶Removes any unused shapes from network that aren’t referenced by links_df.
+ +network_wrangler/roadway/network.py
coerce_crs(v)
+
+ ¶Coerce crs of nodes_df and links_df to LAT_LON_CRS.
+ +network_wrangler/roadway/network.py
delete_links(selection_dict, clean_nodes=False, clean_shapes=False, transit_net=None)
+
+ ¶Deletes links based on selection dictionary and optionally associated nodes and shapes.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
selection_dict |
+
+ SelectLinks
+ |
+
+
+
+ Dictionary describing link selections as follows:
+ |
+ + required + | +
clean_nodes |
+
+ bool
+ |
+
+
+
+ If True, will clean nodes uniquely associated with +deleted links. Defaults to False. + |
+
+ False
+ |
+
clean_shapes |
+
+ bool
+ |
+
+
+
+ If True, will clean nodes uniquely associated with +deleted links. Defaults to False. + |
+
+ False
+ |
+
transit_net |
+
+ TransitNetwork
+ |
+
+
+
+ If provided, will check TransitNetwork and +warn if deletion breaks transit shapes. Defaults to None. + |
+
+ None
+ |
+
network_wrangler/roadway/network.py
delete_nodes(selection_dict, remove_links=False)
+
+ ¶Deletes nodes from roadway network. Wont delete nodes used by links in network.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
selection_dict |
+
+ Union[dict, SelectNodesDict]
+ |
+
+
+
+ dictionary of node selection criteria in the form of a SelectNodesDict. + |
+ + required + | +
remove_links |
+
+ bool
+ |
+
+
+
+ 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. + |
+
+ False
+ |
+
Raises:
+Type | +Description | +
---|---|
+ NodeDeletionError
+ |
+
+
+
+ If not ignore_missing and selected nodes to delete aren’t in network + |
+
network_wrangler/roadway/network.py
get_modal_graph(mode)
+
+ ¶Return a networkx graph of the network for a specific mode.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
mode |
+ + | +
+
+
+ mode of the network, one of |
+ + required + | +
network_wrangler/roadway/network.py
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:
+Name | +Type | +Description | +Default | +
---|---|---|---|
link_property |
+
+ str
+ |
+
+
+
+ link property to query + |
+ + required + | +
category |
+
+ Optional[Union[str, int]]
+ |
+
+
+
+ category to query or a list of categories. Defaults to DEFAULT_CATEGORY. + |
+
+ DEFAULT_CATEGORY
+ |
+
timespan |
+
+ Optional[TimespanString]
+ |
+
+
+
+ timespan to query in the form of [“HH:MM”,”HH:MM”]. +Defaults to DEFAULT_TIMESPAN. + |
+
+ DEFAULT_TIMESPAN
+ |
+
strict_timespan_match |
+
+ bool
+ |
+
+
+
+ If True, will only return links that match the timespan exactly. +Defaults to False. + |
+
+ False
+ |
+
min_overlap_minutes |
+
+ int
+ |
+
+
+
+ If strict_timespan_match is False, will return links that overlap +with the timespan by at least this many minutes. Defaults to 60. + |
+
+ 60
+ |
+
network_wrangler/roadway/network.py
get_selection(selection_dict, overwrite=False)
+
+ ¶Return selection if it already exists, otherwise performs selection.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
selection_dict |
+
+ dict
+ |
+
+
+
+ SelectFacility dictionary. + |
+ + required + | +
overwrite |
+
+ bool
+ |
+
+
+
+ if True, will overwrite any previously cached searches. Defaults to False. + |
+
+ False
+ |
+
network_wrangler/roadway/network.py
has_link(ab)
+
+ ¶Returns true if network has links with AB values.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
ab |
+
+ tuple
+ |
+
+
+
+ Tuple of values corresponding with A and B. + |
+ + required + | +
network_wrangler/roadway/network.py
has_node(model_node_id)
+
+ ¶Queries if network has node based on model_node_id.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
model_node_id |
+
+ int
+ |
+
+
+
+ model_node_id to check for. + |
+ + required + | +
network_wrangler/roadway/network.py
is_connected(mode)
+
+ ¶Determines if the network graph is “strongly” connected.
+A graph is strongly connected if each vertex is reachable from every other vertex.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
mode |
+
+ str
+ |
+
+
+
+ mode of the network, one of |
+ + required + | +
network_wrangler/roadway/network.py
links_with_link_ids(link_ids)
+
+ ¶Return subset of links_df based on link_ids list.
+ + +links_with_nodes(node_ids)
+
+ ¶Return subset of links_df based on node_ids list.
+ + +modal_graph_hash(mode)
+
+ ¶Hash of the links in order to detect a network change from when graph created.
+ +network_wrangler/roadway/network.py
move_nodes(node_geometry_change_table)
+
+ ¶Moves nodes based on updated geometry along with associated links and shape geometry.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
node_geometry_change_table |
+
+ DataFrame[NodeGeometryChangeTable]
+ |
+
+
+
+ a table with model_node_id, X, Y, and CRS. + |
+ + required + | +
network_wrangler/roadway/network.py
node_coords(model_node_id)
+
+ ¶Return coordinates (x, y) of a node based on model_node_id.
+ +network_wrangler/roadway/network.py
nodes_in_links()
+
+ ¶Returns subset of self.nodes_df that are in self.links_df.
+ + +add_incident_link_data_to_nodes(links_df, nodes_df, link_variables=None)
+
+ ¶Add data from links going to/from nodes to node.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
links_df |
+
+ DataFrame[RoadLinksTable]
+ |
+
+
+
+ Will assess connectivity of this links list + |
+ + required + | +
nodes_df |
+
+ DataFrame[RoadNodesTable]
+ |
+
+
+
+ Will assess connectivity of this nodes list + |
+ + required + | +
link_variables |
+
+ Optional[list]
+ |
+
+
+
+ list of columns in links dataframe to add to incident nodes + |
+
+ None
+ |
+
Returns:
+Type | +Description | +
---|---|
+ DataFrame[RoadNodesTable]
+ |
+
+
+
+ nodes DataFrame with link data where length is N*number of links going in/out + |
+
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 |
|
TransitNetwork
+
+
+ ¶Representation of a Transit Network.
+Typical usage example: +
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
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. + |
+
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 |
|
applied_projects: list[str]
+
+
+ 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.
+consistent_with_road_net: bool
+
+
+ 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:
+Type | +Description | +
---|---|
+ bool
+ |
+
+
+
+ Boolean indicating if road_net is consistent with transit network. + |
+
feed
+
+
+ property
+ writable
+
+
+ ¶Feed associated with the transit network.
+feed_hash
+
+
+ property
+
+
+ ¶Return the hash of the feed.
+feed_path
+
+
+ property
+
+
+ ¶Pass through property from Feed.
+road_net: Union[None, RoadwayNetwork]
+
+
+ property
+ writable
+
+
+ ¶Roadway network associated with the transit network.
+shape_links_gdf: gpd.GeoDataFrame
+
+
+ property
+
+
+ ¶Return shape-links as a GeoDataFrame using set roadway geometry.
+shapes_gdf: gpd.GeoDataFrame
+
+
+ property
+
+
+ ¶Return aggregated shapes as a GeoDataFrame using set roadway geometry.
+stop_time_links_gdf: gpd.GeoDataFrame
+
+
+ property
+
+
+ ¶Return stop-time-links as a GeoDataFrame using set roadway geometry.
+stop_times_points_gdf: gpd.GeoDataFrame
+
+
+ property
+
+
+ ¶Return stop-time-points as a GeoDataFrame using set roadway geometry.
+stops_gdf: gpd.GeoDataFrame
+
+
+ property
+
+
+ ¶Return stops as a GeoDataFrame using set roadway geometry.
+__deepcopy__(memo)
+
+ ¶Returns copied TransitNetwork instance with deep copy of Feed but not roadway net.
+ +network_wrangler/transit/network.py
__init__(feed, config=DefaultConfig)
+
+ ¶Constructor for TransitNetwork.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
feed |
+
+ Feed
+ |
+
+
+
+ Feed object representing the transit network gtfs tables + |
+ + required + | +
config |
+
+ WranglerConfig
+ |
+
+
+
+ WranglerConfig object. Defaults to DefaultConfig. + |
+
+ DefaultConfig
+ |
+
network_wrangler/transit/network.py
apply(project_card, **kwargs)
+
+ ¶Wrapper method to apply a roadway project, returning a new TransitNetwork instance.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
project_card |
+
+ Union[ProjectCard, dict]
+ |
+
+
+
+ either a dictionary of the project card object or ProjectCard instance + |
+ + required + | +
**kwargs |
+ + | +
+
+
+ keyword arguments to pass to project application + |
+
+ {}
+ |
+
network_wrangler/transit/network.py
deepcopy()
+
+ ¶Returns copied TransitNetwork instance with deep copy of Feed but not roadway net.
+ + +get_selection(selection_dict, overwrite=False)
+
+ ¶Return selection if it already exists, otherwise performs selection.
+Will raise an error if no trips found.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
selection_dict |
+
+ dict
+ |
+
+
+
+ description + |
+ + required + | +
overwrite |
+
+ bool
+ |
+
+
+
+ if True, will overwrite any previously cached searches. Defaults to False. + |
+
+ False
+ |
+
Returns:
+Name | Type | +Description | +
---|---|---|
Selection |
+ TransitSelection
+ |
+
+
+
+ Selection object + |
+
network_wrangler/transit/network.py
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.
+ + +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:
WranglerConfig()
instance.If not provided, Wrangler will use reasonable defaults.
+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
+
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:
+ +CpuConfig
+
+
+ ¶
+ Bases: ConfigItem
CPU Configuration - Will not change any outcomes.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
EST_PD_READ_SPEED |
+
+ dict[str, float]
+ |
+
+
+
+ Read sec / MB - WILL DEPEND ON SPECIFIC COMPUTER + |
+
network_wrangler/configs/wrangler.py
EditsConfig
+
+
+ ¶
+ Bases: ConfigItem
Configuration for Edits.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
EXISTING_VALUE_CONFLICT |
+
+ Literal['warn', 'error', 'skip']
+ |
+
+
+
+ Only used if ‘existing’ provided in project card and
+ |
+
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 |
+
network_wrangler/configs/wrangler.py
IdGenerationConfig
+
+
+ ¶
+ Bases: ConfigItem
Model Roadway Configuration.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
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. + |
+
network_wrangler/configs/wrangler.py
ModelRoadwayConfig
+
+
+ ¶
+ Bases: ConfigItem
Model Roadway Configuration.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
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. + |
+
network_wrangler/configs/wrangler.py
WranglerConfig
+
+
+ ¶
+ Bases: ConfigItem
Configuration for Network Wrangler.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
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. + |
+
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.
+ + + from scenario import build_scenario_from_config
+ my_scenario = build_scenario_from_config(my_scenario_config)
+
Where my_scenario_config
can be a:
ScenarioConfig()
instance.Notes on relative paths in scenario configs
+output_scenario
for roadway
, transit
, and project_cards
are interpreted to be relative to output_scenario.path
.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"
+
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:
+ +ProjectCardOutputConfig
+
+
+ ¶
+ Bases: ConfigItem
Configuration for outputing project cards in a scenario.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
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. + |
+
network_wrangler/configs/scenario.py
__init__(base_path=DEFAULT_BASE_DIR, out_dir=DEFAULT_PROJECT_OUT_DIR, write=DEFAULT_PROJECT_WRITE)
+
+ ¶Constructor for ProjectCardOutputConfig.
+ +network_wrangler/configs/scenario.py
ProjectsConfig
+
+
+ ¶
+ Bases: ConfigItem
Configuration for projects in a scenario.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
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. + |
+
network_wrangler/configs/scenario.py
__init__(base_path=DEFAULT_BASE_DIR, project_card_filepath=DEFAULT_PROJECT_IN_PATHS, filter_tags=DEFAULT_PROJECT_TAGS)
+
+ ¶Constructor for ProjectsConfig.
+ +network_wrangler/configs/scenario.py
RoadwayNetworkInputConfig
+
+
+ ¶
+ Bases: ConfigItem
Configuration for the road network in a scenario.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
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. + |
+
network_wrangler/configs/scenario.py
__init__(base_path=DEFAULT_BASE_DIR, dir=DEFAULT_ROADWAY_IN_DIR, file_format=DEFAULT_ROADWAY_IN_FORMAT, read_in_shapes=DEFAULT_ROADWAY_SHAPE_READ, boundary_geocode=None, boundary_file=None)
+
+ ¶Constructor for RoadwayNetworkInputConfig.
+ +network_wrangler/configs/scenario.py
RoadwayNetworkOutputConfig
+
+
+ ¶
+ Bases: ConfigItem
Configuration for writing out the resulting roadway network for a scenario.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
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. + |
+
network_wrangler/configs/scenario.py
__init__(out_dir=DEFAULT_ROADWAY_OUT_DIR, base_path=DEFAULT_BASE_DIR, convert_complex_link_properties_to_single_field=False, prefix=None, file_format=DEFAULT_ROADWAY_OUT_FORMAT, true_shape=False, write=DEFAULT_ROADWAY_WRITE)
+
+ ¶Constructor for RoadwayNetworkOutputConfig.
+ +network_wrangler/configs/scenario.py
ScenarioConfig
+
+
+ ¶
+ Bases: ConfigItem
Scenario configuration for Network Wrangler.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
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 + |
+
network_wrangler/configs/scenario.py
__init__(base_scenario, projects, output_scenario, base_path=DEFAULT_BASE_DIR, name=DEFAULT_SCENARIO_NAME, wrangler_config=DefaultConfig)
+
+ ¶Constructor for ScenarioConfig.
+ +network_wrangler/configs/scenario.py
ScenarioInputConfig
+
+
+ ¶
+ Bases: ConfigItem
Configuration for the writing the output of a scenario.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
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. + |
+
network_wrangler/configs/scenario.py
__init__(base_path=DEFAULT_BASE_DIR, roadway=None, transit=None, applied_projects=None, conflicts=None)
+
+ ¶Constructor for ScenarioInputConfig.
+ +network_wrangler/configs/scenario.py
ScenarioOutputConfig
+
+
+ ¶
+ Bases: ConfigItem
Configuration for the writing the output of a scenario.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
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 + |
+
network_wrangler/configs/scenario.py
__init__(path=DEFAULT_OUTPUT_DIR, base_path=DEFAULT_BASE_DIR, roadway=None, transit=None, project_cards=None, overwrite=True)
+
+ ¶Constructor for ScenarioOutputConfig.
+ +network_wrangler/configs/scenario.py
TransitNetworkInputConfig
+
+
+ ¶
+ Bases: ConfigItem
Configuration for the transit network in a scenario.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
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”. + |
+
network_wrangler/configs/scenario.py
__init__(base_path=DEFAULT_BASE_DIR, dir=DEFAULT_TRANSIT_IN_DIR, file_format=DEFAULT_TRANSIT_IN_FORMAT)
+
+ ¶Constructor for TransitNetworkInputConfig.
+ +network_wrangler/configs/scenario.py
TransitNetworkOutputConfig
+
+
+ ¶
+ Bases: ConfigItem
Configuration for the transit network in a scenario.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
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. + |
+
network_wrangler/configs/scenario.py
__init__(base_path=DEFAULT_BASE_DIR, out_dir=DEFAULT_TRANSIT_OUT_DIR, prefix=None, file_format=DEFAULT_TRANSIT_OUT_FORMAT, write=DEFAULT_TRANSIT_WRITE)
+
+ ¶Constructor for TransitNetworkOutputCOnfig.
+ +network_wrangler/configs/scenario.py
Projects are how you manipulate the networks. Each project type is defined in a module in the projects
folder and accepts a RoadwayNetwork and or TransitNetwork as an input and returns the same objects (manipulated) as an output.
The roadway module contains submodules which define and extend the links, nodes, and shapes dataframe objects which within a RoadwayNetwork object as well as other classes and methods which support and extend the RoadwayNetwork class.
+Submodules which define and extend the links, nodes, and shapes dataframe objects which within a RoadwayNetwork object. Includes classes which define:
+pandera
:: network_wrangler.roadway.links.io + options: + heading_level: 5 +:: network_wrangler.roadway.links.create + options: + heading_level: 5 +:: network_wrangler.roadway.links.delete + options: + heading_level: 5 +:: network_wrangler.roadway.links.edit + options: + heading_level: 5 +:: network_wrangler.roadway.links.filters + options: + heading_level: 5 +:: network_wrangler.roadway.links.geo + options: + heading_level: 5 +:: network_wrangler.roadway.links.scopes + options: + heading_level: 5 +:: network_wrangler.roadway.links.summary + options: + heading_level: 5 +:: network_wrangler.roadway.links.validate + options: + heading_level: 5 +:: network_wrangler.roadway.links.df_accessors + options: + heading_level: 5
+:: network_wrangler.roadway.nodes.io + options: + heading_level: 5 +:: network_wrangler.roadway.nodes.create + options: + heading_level: 5 +:: network_wrangler.roadway.nodes.delete + options: + heading_level: 5 +:: network_wrangler.roadway.nodes.edit + options: + heading_level: 5 +:: network_wrangler.roadway.nodes.filters + options: + heading_level: 5 +:: network_wrangler.roadway.nodes + options: + heading_level: 5
+:: network_wrangler.roadway.shapes.io + options: + heading_level: 5 +:: network_wrangler.roadway.shapes.create + options: + heading_level: 5 +:: network_wrangler.roadway.shapes.edit + options: + heading_level: 5 +:: network_wrangler.roadway.shapes.delete + options: + heading_level: 5 +:: network_wrangler.roadway.shapes.filters + options: + heading_level: 5 +:: network_wrangler.roadway.shapes.shapes + options: + heading_level: 5
+:: network_wrangler.roadway.projects.add + options: + heading_level: 4 +:: network_wrangler.roadway.projects.calculate + options: + heading_level: 4 +:: network_wrangler.roadway.projects.delete + options: + heading_level: 4 +:: network_wrangler.roadway.projects.edit_property + options: + heading_level: 4
+:: network_wrangler.roadway.io + options: + heading_level: 4 +:: network_wrangler.roadway.clip + options: + heading_level: 4 +:: network_wrangler.roadway.model_roadway + options: + heading_level: 4 +:: network_wrangler.roadway.utils + options: + heading_level: 4 +:: network_wrangler.roadway.validate + options: + heading_level: 4 +:: network_wrangler.roadway.segment + options: + heading_level: 4 +:: network_wrangler.roadway.subnet + options: + heading_level: 4 +:: network_wrangler.roadway.graph + options: + heading_level: 4
+Main functionality for GTFS tables including Feed object.
+ + + +Feed
+
+
+ ¶
+ Bases: DBModelMixin
Wrapper class around Wrangler flavored GTFS feed.
+Most functionality derives from mixin class DBModelMixin which provides:
+Attributes:
+Name | +Type | +Description | +
---|---|---|
table_names |
+
+ list[str]
+ |
+
+
+
+ list of table names in GTFS feed. + |
+
tables |
+
+ list[DataFrame]
+ |
+
+
+
+ : list tables as dataframes. + |
+
stop_times |
+
+ DataFrame[WranglerStopTimesTable]
+ |
+
+
+
+ : stop_times dataframe with roadway node_ids + |
+
stops |
+
+ DataFrame[WranglerStopsTable]
+ |
+
+
+
+ stops dataframe + |
+
shapes(DataFrame[WranglerShapesTable]) |
+
+ DataFrame[WranglerStopsTable]
+ |
+
+
+
+ shapes dataframe + |
+
trips |
+
+ DataFrame[WranglerTripsTable]
+ |
+
+
+
+ trips dataframe + |
+
frequencies |
+
+ DataFrame[WranglerFrequenciesTable]
+ |
+
+
+
+ frequencies dataframe + |
+
routes |
+
+ DataFrame[RoutesTable]
+ |
+
+
+
+ route dataframe + |
+
agencies |
+
+ Optional[DataFrame[AgenciesTable]]
+ |
+
+
+
+ agencies dataframe + |
+
net |
+
+ Optional[TransitNetwork]
+ |
+
+
+
+ TransitNetwork object + |
+
network_wrangler/transit/feed/feed.py
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 |
|
__init__(**kwargs)
+
+ ¶Create a Feed object from a dictionary of DataFrames representing a GTFS feed.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
kwargs |
+ + | +
+
+
+ A dictionary containing DataFrames representing the tables of a GTFS feed. + |
+
+ {}
+ |
+
network_wrangler/transit/feed/feed.py
set_by_id(table_name, set_df, id_property='index', properties=None)
+
+ ¶Set one or more property values based on an ID property for a given table.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
table_name |
+
+ str
+ |
+
+
+
+ Name of the table to modify. + |
+ + required + | +
set_df |
+
+ DataFrame
+ |
+
+
+
+ DataFrame with columns |
+ + required + | +
id_property |
+
+ str
+ |
+
+
+
+ Property to use as ID to set by. Defaults to “index”. + |
+
+ 'index'
+ |
+
properties |
+
+ Optional[list[str]]
+ |
+
+
+
+ List of properties to set which are in set_df. If not specified, will set +all properties. + |
+
+ None
+ |
+
network_wrangler/transit/feed/feed.py
merge_shapes_to_stop_times(stop_times, shapes, trips)
+
+ ¶Add shape_id and shape_pt_sequence to stop_times dataframe.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
stop_times |
+
+ DataFrame[WranglerStopTimesTable]
+ |
+
+
+
+ stop_times dataframe to add shape_id and shape_pt_sequence to. + |
+ + required + | +
shapes |
+
+ DataFrame[WranglerShapesTable]
+ |
+
+
+
+ shapes dataframe to add to stop_times. + |
+ + required + | +
trips |
+
+ DataFrame[WranglerTripsTable]
+ |
+
+
+
+ trips dataframe to link stop_times to shapes + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ DataFrame[WranglerStopTimesTable]
+ |
+
+
+
+ stop_times dataframe with shape_id and shape_pt_sequence added. + |
+
network_wrangler/transit/feed/feed.py
stop_count_by_trip(stop_times)
+
+ ¶Returns dataframe with trip_id and stop_count from stop_times.
+ +network_wrangler/transit/feed/feed.py
Filters and queries of a gtfs frequencies table.
+ + + +frequencies_for_trips(frequencies, trips)
+
+ ¶Filter frequenceis dataframe to records associated with trips table.
+ +network_wrangler/transit/feed/frequencies.py
Filters and queries of a gtfs routes table and route_ids.
+ + + +route_ids_for_trip_ids(trips, trip_ids)
+
+ ¶Returns route ids for given list of trip_ids.
+ +network_wrangler/transit/feed/routes.py
routes_for_trip_ids(routes, trips, trip_ids)
+
+ ¶Returns route records for given list of trip_ids.
+ +network_wrangler/transit/feed/routes.py
routes_for_trips(routes, trips)
+
+ ¶Filter routes dataframe to records associated with trip records.
+ +network_wrangler/transit/feed/routes.py
Filters, queries of a gtfs shapes table and node patterns.
+ + + +find_nearest_stops(shapes, trips, stop_times, trip_id, node_id, pickup_dropoff='either')
+
+ ¶Returns node_ids (before and after) of nearest node_ids that are stops for a given trip_id.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
shapes |
+
+ WranglerShapesTable
+ |
+
+
+
+ WranglerShapesTable + |
+ + required + | +
trips |
+
+ WranglerTripsTable
+ |
+
+
+
+ WranglerTripsTable + |
+ + required + | +
stop_times |
+
+ WranglerStopTimesTable
+ |
+
+
+
+ WranglerStopTimesTable + |
+ + required + | +
trip_id |
+
+ str
+ |
+
+
+
+ trip id to find nearest stops for + |
+ + required + | +
node_id |
+
+ int
+ |
+
+
+
+ node_id to find nearest stops for + |
+ + required + | +
pickup_dropoff |
+
+ PickupDropoffAvailability
+ |
+
+
+
+ str indicating logic for selecting stops based on piackup and dropoff +availability at stop. Defaults to “either”. +“either”: either pickup_type or dropoff_type > 0 +“both”: both pickup_type or dropoff_type > 0 +“pickup_only”: only pickup > 0 +“dropoff_only”: only dropoff > 0 + |
+
+ 'either'
+ |
+
Returns:
+Name | Type | +Description | +
---|---|---|
tuple |
+ tuple[int, int]
+ |
+
+
+
+ node_ids for stop before and stop after + |
+
network_wrangler/transit/feed/shapes.py
node_pattern_for_shape_id(shapes, shape_id)
+
+ ¶Returns node pattern of a shape.
+ +network_wrangler/transit/feed/shapes.py
shape_id_for_trip_id(trips, trip_id)
+
+ ¶Returns a shape_id for a given trip_id.
+ + +shape_ids_for_trip_ids(trips, trip_ids)
+
+ ¶Returns a list of shape_ids for a given list of trip_ids.
+ +network_wrangler/transit/feed/shapes.py
shapes_for_road_links(shapes, links_df)
+
+ ¶Filter shapes dataframe to records associated with links dataframe.
+EX:
+++shapes = pd.DataFrame({ + “shape_id”: [“1”, “1”, “1”, “1”, “2”, “2”, “2”, “2”, “2”], + “shape_pt_sequence”: [1, 2, 3, 4, 1, 2, 3, 4, 5], + “shape_model_node_id”: [1, 2, 3, 4, 2, 3, 1, 5, 4] +})
+links_df = pd.DataFrame({ + “A”: [1, 2, 3], + “B”: [2, 3, 4] +})
+shapes
+
shape_id shape_pt_sequence shape_model_node_id should retain +1 1 1 TRUE +1 2 2 TRUE +1 3 3 TRUE +1 4 4 TRUE +1 5 5 FALSE +2 1 1 TRUE +2 2 2 TRUE +2 3 3 TRUE +2 4 1 FALSE +2 5 5 FALSE +2 6 4 FALSE +2 7 1 FALSE - not largest segment +2 8 2 FALSE - not largest segment
+++links_df
+
A B +1 2 +2 3 +3 4
+ +network_wrangler/transit/feed/shapes.py
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 |
|
shapes_for_shape_id(shapes, shape_id)
+
+ ¶Returns shape records for a given shape_id.
+ +network_wrangler/transit/feed/shapes.py
shapes_for_trip_id(shapes, trips, trip_id)
+
+ ¶Returns shape records for a single given trip_id.
+ +network_wrangler/transit/feed/shapes.py
shapes_for_trip_ids(shapes, trips, trip_ids)
+
+ ¶Returns shape records for list of trip_ids.
+ +network_wrangler/transit/feed/shapes.py
shapes_for_trips(shapes, trips)
+
+ ¶Filter shapes dataframe to records associated with trips table.
+ +network_wrangler/transit/feed/shapes.py
shapes_with_stop_id_for_trip_id(shapes, trips, stop_times, trip_id, pickup_dropoff='either')
+
+ ¶Returns shapes.txt for a given trip_id with the stop_id added based on pickup_type.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
shapes |
+
+ DataFrame[WranglerShapesTable]
+ |
+
+
+
+ WranglerShapesTable + |
+ + required + | +
trips |
+
+ DataFrame[WranglerTripsTable]
+ |
+
+
+
+ WranglerTripsTable + |
+ + required + | +
stop_times |
+
+ DataFrame[WranglerStopTimesTable]
+ |
+
+
+
+ WranglerStopTimesTable + |
+ + required + | +
trip_id |
+
+ str
+ |
+
+
+
+ trip id to select + |
+ + required + | +
pickup_dropoff |
+
+ PickupDropoffAvailability
+ |
+
+
+
+ str indicating logic for selecting stops based on piackup and dropoff +availability at stop. Defaults to “either”. +“either”: either pickup_type or dropoff_type > 0 +“both”: both pickup_type or dropoff_type > 0 +“pickup_only”: only pickup > 0 +“dropoff_only”: only dropoff > 0 + |
+
+ 'either'
+ |
+
network_wrangler/transit/feed/shapes.py
shapes_with_stops_for_shape_id(shapes, trips, stop_times, shape_id)
+
+ ¶Returns a DataFrame containing shapes with associated stops for a given shape_id.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
shapes |
+
+ DataFrame[WranglerShapesTable]
+ |
+
+
+
+ DataFrame containing shape data. + |
+ + required + | +
trips |
+
+ DataFrame[WranglerTripsTable]
+ |
+
+
+
+ DataFrame containing trip data. + |
+ + required + | +
stop_times |
+
+ DataFrame[WranglerStopTimesTable]
+ |
+
+
+
+ DataFrame containing stop times data. + |
+ + required + | +
shape_id |
+
+ str
+ |
+
+
+
+ The shape_id for which to retrieve shapes with stops. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ DataFrame[WranglerShapesTable]
+ |
+
+
+
+ DataFrame[WranglerShapesTable]: DataFrame containing shapes with associated stops. + |
+
network_wrangler/transit/feed/shapes.py
Filters and queries of a gtfs stop_times table.
+ + + +stop_times_for_longest_segments(stop_times)
+
+ ¶Find the longest segment of each trip_id that is in the stop_times.
+Segment ends defined based on interruptions in stop_sequence
.
network_wrangler/transit/feed/stop_times.py
stop_times_for_min_stops(stop_times, min_stops)
+
+ ¶Filter stop_times dataframe to only the records which have >= min_stops for the trip.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
stop_times |
+
+ DataFrame[WranglerStopTimesTable]
+ |
+
+
+
+ stoptimestable to filter + |
+ + required + | +
min_stops |
+
+ int
+ |
+
+
+
+ minimum stops to require to keep trip in stoptimes + |
+ + required + | +
network_wrangler/transit/feed/stop_times.py
stop_times_for_pickup_dropoff_trip_id(stop_times, trip_id, pickup_dropoff='either')
+
+ ¶Filters stop_times for a given trip_id based on pickup type.
+GTFS values for pickup_type and drop_off_type” + 0 or empty - Regularly scheduled pickup/dropoff. + 1 - No pickup/dropoff available. + 2 - Must phone agency to arrange pickup/dropoff. + 3 - Must coordinate with driver to arrange pickup/dropoff.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
stop_times |
+
+ DataFrame[WranglerStopTimesTable]
+ |
+
+
+
+ A WranglerStopTimesTable to query. + |
+ + required + | +
trip_id |
+
+ str
+ |
+
+
+
+ trip_id to get stop pattern for + |
+ + required + | +
pickup_dropoff |
+
+ PickupDropoffAvailability
+ |
+
+
+
+ str indicating logic for selecting stops based on pickup and dropoff +availability at stop. Defaults to “either”. +“any”: all stoptime records +“either”: either pickup_type or dropoff_type != 1 +“both”: both pickup_type and dropoff_type != 1 +“pickup_only”: dropoff = 1; pickup != 1 +“dropoff_only”: pickup = 1; dropoff != 1 + |
+
+ 'either'
+ |
+
network_wrangler/transit/feed/stop_times.py
stop_times_for_route_ids(stop_times, trips, route_ids)
+
+ ¶Returns a stop_time records for a list of route_ids.
+ +network_wrangler/transit/feed/stop_times.py
stop_times_for_shapes(stop_times, shapes, trips)
+
+ ¶Filter stop_times dataframe to records associated with shapes dataframe.
+Where multiple segments of stop_times are found to match shapes, retain only the longest.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
stop_times |
+
+ DataFrame[WranglerStopTimesTable]
+ |
+
+
+
+ stop_times dataframe to filter + |
+ + required + | +
shapes |
+
+ DataFrame[WranglerShapesTable]
+ |
+
+
+
+ shapes dataframe to stop_times to. + |
+ + required + | +
trips |
+
+ DataFrame[WranglerTripsTable]
+ |
+
+
+
+ trips to link stop_times to shapess + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ DataFrame[WranglerStopTimesTable]
+ |
+
+
+
+ filtered stop_times dataframe + |
+
++stop_times
+
trip_id stop_sequence stop_id +t1 1 1 +t1 2 2 +t1 3 3 +t1 4 5 +t2 1 1 +*t2 2 3 +t2 3 7
+++shapes
+
shape_id shape_pt_sequence shape_model_node_id +s1 1 1 +s1 2 2 +s1 3 3 +s1 4 4 +s2 1 1 +s2 2 2 +s2 3 3
+++trips
+
trip_id shape_id +t1 s1 +t2 s2
+ +network_wrangler/transit/feed/stop_times.py
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 |
|
stop_times_for_stops(stop_times, stops)
+
+ ¶Filter stop_times dataframe to only have stop_times associated with stops records.
+ +network_wrangler/transit/feed/stop_times.py
stop_times_for_trip_id(stop_times, trip_id)
+
+ ¶Returns a stop_time records for a given trip_id.
+ +network_wrangler/transit/feed/stop_times.py
stop_times_for_trip_ids(stop_times, trip_ids)
+
+ ¶Returns a stop_time records for a given list of trip_ids.
+ +network_wrangler/transit/feed/stop_times.py
stop_times_for_trip_node_segment(stop_times, trip_id, node_id_start, node_id_end, include_start=True, include_end=True)
+
+ ¶Returns stop_times for a given trip_id between two nodes or with those nodes included.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
stop_times |
+
+ DataFrame[WranglerStopTimesTable]
+ |
+
+
+
+ WranglerStopTimesTable + |
+ + required + | +
trip_id |
+
+ str
+ |
+
+
+
+ trip id to select + |
+ + required + | +
node_id_start |
+
+ int
+ |
+
+
+
+ int of the starting node + |
+ + required + | +
node_id_end |
+
+ int
+ |
+
+
+
+ int of the ending node + |
+ + required + | +
include_start |
+
+ bool
+ |
+
+
+
+ bool indicating if the start node should be included in the segment. +Defaults to True. + |
+
+ True
+ |
+
include_end |
+
+ bool
+ |
+
+
+
+ bool indicating if the end node should be included in the segment. +Defaults to True. + |
+
+ True
+ |
+
network_wrangler/transit/feed/stop_times.py
Filters and queries of a gtfs stops table and stop_ids.
+ + + +node_is_stop(stops, stop_times, node_id, trip_id, pickup_dropoff='either')
+
+ ¶Returns boolean indicating if a (or list of) node(s)) is (are) stops for a given trip_id.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
stops |
+
+ DataFrame[WranglerStopsTable]
+ |
+
+
+
+ WranglerStopsTable + |
+ + required + | +
stop_times |
+
+ DataFrame[WranglerStopTimesTable]
+ |
+
+
+
+ WranglerStopTimesTable + |
+ + required + | +
node_id |
+
+ Union[int, list[int]]
+ |
+
+
+
+ node ID for roadway + |
+ + required + | +
trip_id |
+
+ str
+ |
+
+
+
+ trip_id to get stop pattern for + |
+ + required + | +
pickup_dropoff |
+
+ PickupDropoffAvailability
+ |
+
+
+
+ str indicating logic for selecting stops based on piackup and dropoff +availability at stop. Defaults to “either”. +“either”: either pickup_type or dropoff_type > 0 +“both”: both pickup_type or dropoff_type > 0 +“pickup_only”: only pickup > 0 +“dropoff_only”: only dropoff > 0 + |
+
+ 'either'
+ |
+
network_wrangler/transit/feed/stops.py
stop_id_pattern_for_trip(stop_times, trip_id, pickup_dropoff='either')
+
+ ¶Returns a stop pattern for a given trip_id given by a list of stop_ids.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
stop_times |
+
+ DataFrame[WranglerStopTimesTable]
+ |
+
+
+
+ WranglerStopTimesTable + |
+ + required + | +
trip_id |
+
+ str
+ |
+
+
+
+ trip_id to get stop pattern for + |
+ + required + | +
pickup_dropoff |
+
+ PickupDropoffAvailability
+ |
+
+
+
+ str indicating logic for selecting stops based on piackup and dropoff +availability at stop. Defaults to “either”. +“either”: either pickup_type or dropoff_type > 0 +“both”: both pickup_type or dropoff_type > 0 +“pickup_only”: only pickup > 0 +“dropoff_only”: only dropoff > 0 + |
+
+ 'either'
+ |
+
network_wrangler/transit/feed/stops.py
stops_for_stop_times(stops, stop_times)
+
+ ¶Filter stops dataframe to only have stops associated with stop_times records.
+ +network_wrangler/transit/feed/stops.py
stops_for_trip_id(stops, stop_times, trip_id, pickup_dropoff='any')
+
+ ¶Returns stops.txt which are used for a given trip_id.
+ +network_wrangler/transit/feed/stops.py
Filters and queries of a gtfs trips table and trip_ids.
+ + + +trip_ids_for_shape_id(trips, shape_id)
+
+ ¶Returns a list of trip_ids for a given shape_id.
+ + +trips_for_shape_id(trips, shape_id)
+
+ ¶Returns a trips records for a given shape_id.
+ + +trips_for_stop_times(trips, stop_times)
+
+ ¶Filter trips dataframe to records associated with stop_time records.
+ +network_wrangler/transit/feed/trips.py
Functions for translating transit tables into visualizable links relatable to roadway network.
+ + + +shapes_to_shape_links(shapes)
+
+ ¶Converts shapes DataFrame to shape links DataFrame.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
shapes |
+
+ DataFrame[WranglerShapesTable]
+ |
+
+
+
+ The input shapes DataFrame. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ DataFrame
+ |
+
+
+
+ pd.DataFrame: The resulting shape links DataFrame. + |
+
network_wrangler/transit/feed/transit_links.py
stop_times_to_stop_times_links(stop_times, from_field='A', to_field='B')
+
+ ¶Converts stop times to stop times links.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
stop_times |
+
+ DataFrame[WranglerStopTimesTable]
+ |
+
+
+
+ The stop times data. + |
+ + required + | +
from_field |
+
+ str
+ |
+
+
+
+ The name of the field representing the ‘from’ stop. +Defaults to “A”. + |
+
+ 'A'
+ |
+
to_field |
+
+ str
+ |
+
+
+
+ The name of the field representing the ‘to’ stop. +Defaults to “B”. + |
+
+ 'B'
+ |
+
Returns:
+Type | +Description | +
---|---|
+ DataFrame
+ |
+
+
+
+ pd.DataFrame: The resulting stop times links. + |
+
network_wrangler/transit/feed/transit_links.py
unique_shape_links(shapes, from_field='A', to_field='B')
+
+ ¶Returns a DataFrame containing unique shape links based on the provided shapes DataFrame.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
shapes |
+
+ DataFrame[WranglerShapesTable]
+ |
+
+
+
+ The input DataFrame containing shape information. + |
+ + required + | +
from_field |
+
+ str
+ |
+
+
+
+ The name of the column representing the ‘from’ field. +Defaults to “A”. + |
+
+ 'A'
+ |
+
to_field |
+
+ str
+ |
+
+
+
+ The name of the column representing the ‘to’ field. +Defaults to “B”. + |
+
+ 'B'
+ |
+
Returns:
+Type | +Description | +
---|---|
+ DataFrame
+ |
+
+
+
+ pd.DataFrame: DataFrame containing unique shape links based on the provided shapes df. + |
+
network_wrangler/transit/feed/transit_links.py
unique_stop_time_links(stop_times, from_field='A', to_field='B')
+
+ ¶Returns a DataFrame containing unique stop time links based on the given stop times DataFrame.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
stop_times |
+
+ DataFrame[WranglerStopTimesTable]
+ |
+
+
+
+ The DataFrame containing stop times data. + |
+ + required + | +
from_field |
+
+ str
+ |
+
+
+
+ The name of the column representing the ‘from’ field in the +stop times DataFrame. Defaults to “A”. + |
+
+ 'A'
+ |
+
to_field |
+
+ str
+ |
+
+
+
+ The name of the column representing the ‘to’ field in the stop +times DataFrame. Defaults to “B”. + |
+
+ 'B'
+ |
+
Returns:
+Type | +Description | +
---|---|
+ DataFrame
+ |
+
+
+
+ pd.DataFrame: A DataFrame containing unique stop time links with columns ‘from_field’, +‘to_field’, and ‘trip_id’. + |
+
network_wrangler/transit/feed/transit_links.py
Functions to create segments from shapes and shape_links.
+ + + +filter_shapes_to_segments(shapes, segments)
+
+ ¶Filter shapes dataframe to records associated with segments dataframe.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
shapes |
+
+ DataFrame[WranglerShapesTable]
+ |
+
+
+
+ shapes dataframe to filter + |
+ + required + | +
segments |
+
+ DataFrame
+ |
+
+
+
+ segments dataframe to filter by with shape_id, segment_start_shape_pt_seq, +segment_end_shape_pt_seq . Should have one record per shape_id. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ DataFrame[WranglerShapesTable]
+ |
+
+
+
+ filtered shapes dataframe + |
+
network_wrangler/transit/feed/transit_segments.py
shape_links_to_longest_shape_segments(shape_links)
+
+ ¶Find the longest segment of each shape_id that is in the links.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
shape_links |
+ + | +
+
+
+ DataFrame with shape_id, shape_pt_sequence_A, shape_pt_sequence_B + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ DataFrame
+ |
+
+
+
+ DataFrame with shape_id, segment_id, segment_start_shape_pt_seq, segment_end_shape_pt_seq + |
+
network_wrangler/transit/feed/transit_segments.py
shape_links_to_segments(shape_links)
+
+ ¶Convert shape_links to segments by shape_id with segments of continuous shape_pt_sequence.
+ + +DataFrame with shape_id, segment_id, segment_start_shape_pt_seq,
+Type | +Description | +
---|---|
+ DataFrame
+ |
+
+
+
+ segment_end_shape_pt_seq + |
+
network_wrangler/transit/feed/transit_segments.py
Functions for adding a transit route to a TransitNetwork.
+ + + +apply_transit_route_addition(net, transit_route_addition, reference_road_net=None)
+
+ ¶Add transit route to TransitNetwork.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
net |
+
+ TransitNetwork
+ |
+
+
+
+ Network to modify. + |
+ + required + | +
transit_route_addition |
+
+ dict
+ |
+
+
+
+ route dictionary to add to the feed. + |
+ + required + | +
reference_road_net |
+
+ Optional[RoadwayNetwork]
+ |
+
+
+
+ (RoadwayNetwork, optional): Reference roadway network to use for adding shapes and stops. Defaults to None. + |
+
+ None
+ |
+
Returns:
+Name | Type | +Description | +
---|---|---|
TransitNetwork |
+ TransitNetwork
+ |
+
+
+
+ Modified network. + |
+
network_wrangler/transit/projects/add_route.py
Module for applying calculated transit projects to a transit network object.
+These projects are stored in project card pycode
property as python code strings which are
+executed to change the transit network object.
apply_calculated_transit(net, pycode)
+
+ ¶Changes transit network object by executing pycode.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
net |
+
+ TransitNetwork
+ |
+
+
+
+ transit network to manipulate + |
+ + required + | +
pycode |
+
+ str
+ |
+
+
+
+ python code which changes values in the transit network object + |
+ + required + | +
network_wrangler/transit/projects/calculate.py
Functions for adding a transit route to a TransitNetwork.
+ + + +apply_transit_service_deletion(net, selection, clean_shapes=False, clean_routes=False)
+
+ ¶Delete transit service to TransitNetwork.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
net |
+
+ TransitNetwork
+ |
+
+
+
+ Network to modify. + |
+ + required + | +
selection |
+
+ TransitSelection
+ |
+
+
+
+ TransitSelection object, created from a selection dictionary. + |
+ + required + | +
clean_shapes |
+
+ bool
+ |
+
+
+
+ If True, remove shapes not used by any trips. +Defaults to False. + |
+
+ False
+ |
+
clean_routes |
+
+ bool
+ |
+
+
+
+ If True, remove routes not used by any trips. +Defaults to False. + |
+
+ False
+ |
+
Returns:
+Name | Type | +Description | +
---|---|---|
TransitNetwork |
+ TransitNetwork
+ |
+
+
+
+ Modified network. + |
+
network_wrangler/transit/projects/delete_service.py
Functions for editing transit properties in a TransitNetwork.
+ + + +apply_transit_property_change(net, selection, property_changes, project_name=None)
+
+ ¶Apply changes to transit properties.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
net |
+
+ TransitNetwork
+ |
+
+
+
+ Network to modify. + |
+ + required + | +
selection |
+
+ TransitSelection
+ |
+
+
+
+ Selection of trips to modify. + |
+ + required + | +
property_changes |
+
+ dict
+ |
+
+
+
+ Dictionary of properties to change. + |
+ + required + | +
project_name |
+
+ str
+ |
+
+
+
+ Name of the project. Defaults to None. + |
+
+ None
+ |
+
Returns:
+Name | Type | +Description | +
---|---|---|
TransitNetwork |
+ TransitNetwork
+ |
+
+
+
+ Modified network. + |
+
network_wrangler/transit/projects/edit_property.py
Functions for editing the transit route shapes and stop patterns.
+ + + +apply_transit_routing_change(net, selection, routing_change, reference_road_net=None, project_name=None)
+
+ ¶Apply a routing change to the transit network, including stop updates.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
net |
+
+ TransitNetwork
+ |
+
+
+
+ TransitNetwork object to apply routing change to. + |
+ + required + | +
selection |
+
+ Selection
+ |
+
+
+
+ TransitSelection object, created from a selection dictionary. + |
+ + required + | +
routing_change |
+
+ dict
+ |
+ + + | ++ required + | +
shape_id_scalar |
+
+ int
+ |
+
+
+
+ Initial scalar value to add to duplicated shape_ids to +create a new shape_id. Defaults to SHAPE_ID_SCALAR. + |
+ + required + | +
reference_road_net |
+
+ RoadwayNetwork
+ |
+
+
+
+ Reference roadway network to use for +updating shapes and stops. Defaults to None. + |
+
+ None
+ |
+
project_name |
+
+ str
+ |
+
+
+
+ Name of the project. Defaults to None. + |
+
+ None
+ |
+
network_wrangler/transit/projects/edit_routing.py
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 |
|
Functions to clip a TransitNetwork object to a boundary.
+Clipped transit is an independent transit network that is a subset of the original transit network.
+Example usage:
+from network_wrangler.transit load_transit, write_transit
+from network_wrangler.transit.clip import clip_transit
+
+stpaul_transit = load_transit(example_dir / "stpaul")
+boundary_file = test_dir / "data" / "ecolab.geojson"
+clipped_network = clip_transit(stpaul_transit, boundary_file=boundary_file)
+write_transit(clipped_network, out_dir, prefix="ecolab", format="geojson", true_shape=True)
+
clip_feed_to_boundary(feed, ref_nodes_df, boundary_gdf=None, boundary_geocode=None, boundary_file=None, min_stops=DEFAULT_MIN_STOPS)
+
+ ¶Clips a transit Feed object to a boundary and returns the resulting GeoDataFrames.
+Retains only the stops within the boundary and trips that traverse them subject to a minimum
+number of stops per trip as defined by min_stops
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
feed |
+
+ Feed
+ |
+
+
+
+ Feed object to be clipped. + |
+ + required + | +
ref_nodes_df |
+
+ GeoDataFrame
+ |
+
+
+
+ geodataframe with node geometry to reference + |
+ + required + | +
boundary_geocode |
+
+ Union[str, dict]
+ |
+
+
+
+ A geocode string or dictionary +representing the boundary. Defaults to None. + |
+
+ None
+ |
+
boundary_file |
+
+ Union[str, Path]
+ |
+
+
+
+ A path to the boundary file. Only used if +boundary_geocode is None. Defaults to None. + |
+
+ None
+ |
+
boundary_gdf |
+
+ GeoDataFrame
+ |
+
+
+
+ A GeoDataFrame representing the boundary. +Only used if boundary_geocode and boundary_file are None. Defaults to None. + |
+
+ None
+ |
+
min_stops |
+
+ int
+ |
+
+
+
+ minimum number of stops needed to retain a transit trip within clipped area. +Defaults to DEFAULT_MIN_STOPS which is set to 2. + |
+
+ DEFAULT_MIN_STOPS
+ |
+
network_wrangler/transit/clip.py
clip_feed_to_roadway(feed, roadway_net, min_stops=DEFAULT_MIN_STOPS)
+
+ ¶Returns a copy of transit feed clipped to the roadway network.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
feed |
+
+ Feed
+ |
+
+
+
+ Transit Feed to clip. + |
+ + required + | +
roadway_net |
+
+ RoadwayNetwork
+ |
+
+
+
+ Roadway network to clip to. + |
+ + required + | +
min_stops |
+
+ int
+ |
+
+
+
+ minimum number of stops needed to retain a transit trip within clipped area. +Defaults to DEFAULT_MIN_STOPS which is set to 2. + |
+
+ DEFAULT_MIN_STOPS
+ |
+
Raises:
+Type | +Description | +
---|---|
+ ValueError
+ |
+
+
+
+ If no stops found within the roadway network. + |
+
Returns:
+Name | Type | +Description | +
---|---|---|
Feed |
+ Feed
+ |
+
+
+
+ Clipped deep copy of feed limited to the roadway network. + |
+
network_wrangler/transit/clip.py
clip_transit(network, node_ids=None, boundary_geocode=None, boundary_file=None, boundary_gdf=None, ref_nodes_df=None, roadway_net=None, min_stops=DEFAULT_MIN_STOPS)
+
+ ¶Returns a new TransitNetwork clipped to a boundary as determined by arguments.
+Will clip based on which arguments are provided as prioritized below:
+node_ids
provided, will clip based on node_ids
boundary_geocode
provided, will clip based on on search in OSM for that jurisdiction
+ boundary using reference geometry from ref_nodes_df
, roadway_net
, or roadway_path
boundary_file
provided, will clip based on that polygon using reference geometry
+ from ref_nodes_df
, roadway_net
, or roadway_path
boundary_gdf
provided, will clip based on that geodataframe using reference geometry
+ from ref_nodes_df
, roadway_net
, or roadway_path
roadway_net
provided, will clip based on that roadway networkParameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
network |
+
+ TransitNetwork
+ |
+
+
+
+ TransitNetwork to clip. + |
+ + required + | +
node_ids |
+
+ list[str]
+ |
+
+
+
+ A list of node_ids to clip to. Defaults to None. + |
+
+ None
+ |
+
boundary_geocode |
+
+ Union[str, dict]
+ |
+
+
+
+ A geocode string or dictionary +representing the boundary. Only used if node_ids are None. Defaults to None. + |
+
+ None
+ |
+
boundary_file |
+
+ Union[str, Path]
+ |
+
+
+
+ A path to the boundary file. Only used if +node_ids and boundary_geocode are None. Defaults to None. + |
+
+ None
+ |
+
boundary_gdf |
+
+ GeoDataFrame
+ |
+
+
+
+ A GeoDataFrame representing the boundary. +Only used if node_ids, boundary_geocode and boundary_file are None. Defaults to None. + |
+
+ None
+ |
+
ref_nodes_df |
+
+ Optional[Union[None, GeoDataFrame]]
+ |
+
+
+
+ GeoDataFrame of geographic references for node_ids. Only used if +node_ids is None and one of boundary_* is not None. + |
+
+ None
+ |
+
roadway_net |
+
+ Optional[Union[None, RoadwayNetwork]]
+ |
+
+
+
+ Roadway Network instance to clip transit network to. Only used if +node_ids is None and allof boundary_* are None + |
+
+ None
+ |
+
min_stops |
+
+ int
+ |
+
+
+
+ minimum number of stops needed to retain a transit trip within clipped area. +Defaults to DEFAULT_MIN_STOPS which is set to 2. + |
+
+ DEFAULT_MIN_STOPS
+ |
+
network_wrangler/transit/clip.py
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 |
|
Utilities for working with transit geodataframes.
+ + + +shapes_to_shape_links_gdf(shapes, ref_nodes_df=None, from_field='A', to_field='B', crs=LAT_LON_CRS)
+
+ ¶Translates shapes to shape links geodataframe using geometry from ref_nodes_df if provided.
+TODO: Add join to links and then shapes to get true geometry.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
shapes |
+
+ DataFrame[WranglerShapesTable]
+ |
+
+
+
+ Feed shapes table + |
+ + required + | +
ref_nodes_df |
+
+ Optional[DataFrame[RoadNodesTable]]
+ |
+
+
+
+ If specified, will use geometry from these nodes. Otherwise, will use +geometry in shapes file. Defaults to None. + |
+
+ None
+ |
+
from_field |
+
+ str
+ |
+
+
+
+ Field used for the link’s from node |
+
+ 'A'
+ |
+
to_field |
+
+ str
+ |
+
+
+
+ Field used for the link’s to node |
+
+ 'B'
+ |
+
crs |
+
+ int
+ |
+
+
+
+ Coordinate reference system. SHouldn’t be changed unless you know +what you are doing. Defaults to LAT_LON_CRS which is WGS84 lat/long. + |
+
+ LAT_LON_CRS
+ |
+
Returns:
+Type | +Description | +
---|---|
+ GeoDataFrame
+ |
+
+
+
+ gpd.GeoDataFrame: description + |
+
network_wrangler/transit/geo.py
shapes_to_trip_shapes_gdf(shapes, ref_nodes_df=None, crs=LAT_LON_CRS)
+
+ ¶Geodataframe with one polyline shape per shape_id.
+TODO: add information about the route and trips.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
shapes |
+
+ DataFrame[WranglerShapesTable]
+ |
+
+
+
+ WranglerShapesTable + |
+ + required + | +
trips |
+ + | +
+
+
+ WranglerTripsTable + |
+ + required + | +
ref_nodes_df |
+
+ Optional[DataFrame[RoadNodesTable]]
+ |
+
+
+
+ If specified, will use geometry from these nodes. Otherwise, will use +geometry in shapes file. Defaults to None. + |
+
+ None
+ |
+
crs |
+
+ int
+ |
+
+
+
+ int, optional, default 4326 + |
+
+ LAT_LON_CRS
+ |
+
network_wrangler/transit/geo.py
stop_times_to_stop_time_links_gdf(stop_times, stops, ref_nodes_df=None, from_field='A', to_field='B')
+
+ ¶Stop times geodataframe as links using geometry from stops.txt or optionally another df.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
stop_times |
+
+ WranglerStopTimesTable
+ |
+
+
+
+ Feed stop times table. + |
+ + required + | +
stops |
+
+ WranglerStopsTable
+ |
+
+
+
+ Feed stops table. + |
+ + required + | +
ref_nodes_df |
+
+ DataFrame
+ |
+
+
+
+ If specified, will use geometry from these nodes. +Otherwise, will use geometry in shapes file. Defaults to None. + |
+
+ None
+ |
+
from_field |
+
+ str
+ |
+
+
+
+ Field used for the link’s from node |
+
+ 'A'
+ |
+
to_field |
+
+ str
+ |
+
+
+
+ Field used for the link’s to node |
+
+ 'B'
+ |
+
network_wrangler/transit/geo.py
stop_times_to_stop_time_points_gdf(stop_times, stops, ref_nodes_df=None)
+
+ ¶Stoptimes geodataframe as points using geometry from stops.txt or optionally another df.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
stop_times |
+
+ WranglerStopTimesTable
+ |
+
+
+
+ Feed stop times table. + |
+ + required + | +
stops |
+
+ WranglerStopsTable
+ |
+
+
+
+ Feed stops table. + |
+ + required + | +
ref_nodes_df |
+
+ DataFrame
+ |
+
+
+
+ If specified, will use geometry from these nodes. +Otherwise, will use geometry in shapes file. Defaults to None. + |
+
+ None
+ |
+
network_wrangler/transit/geo.py
update_shapes_geometry(shapes, ref_nodes_df)
+
+ ¶Returns shapes table with geometry updated from ref_nodes_df.
+NOTE: does not update “geometry” field if it exists.
+ +network_wrangler/transit/geo.py
update_stops_geometry(stops, ref_nodes_df)
+
+ ¶Returns stops table with geometry updated from ref_nodes_df.
+NOTE: does not update “geometry” field if it exists.
+ +network_wrangler/transit/geo.py
Functions for reading and writing transit feeds and networks.
+ + + +convert_transit_serialization(input_path, output_format, out_dir='.', input_file_format='csv', out_prefix='', overwrite=True)
+
+ ¶Converts a transit network from one serialization to another.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
input_path |
+
+ Union[str, Path]
+ |
+
+
+
+ path to the input network + |
+ + required + | +
output_format |
+
+ TransitFileTypes
+ |
+
+
+
+ the format of the output files. Should be txt, csv, or parquet. + |
+ + required + | +
out_dir |
+
+ Union[Path, str]
+ |
+
+
+
+ directory to write the network to. Defaults to current directory. + |
+
+ '.'
+ |
+
input_file_format |
+
+ TransitFileTypes
+ |
+
+
+
+ the file_format of the files to read. Should be txt, csv, or parquet. +Defaults to “txt” + |
+
+ 'csv'
+ |
+
out_prefix |
+
+ str
+ |
+
+
+
+ prefix to add to the file name. Defaults to “” + |
+
+ ''
+ |
+
overwrite |
+
+ bool
+ |
+
+
+
+ if True, will overwrite the files if they already exist. Defaults to True + |
+
+ True
+ |
+
network_wrangler/transit/io.py
load_feed_from_dfs(feed_dfs)
+
+ ¶Create a TransitNetwork object from a dictionary of DataFrames representing a GTFS feed.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
feed_dfs |
+
+ dict
+ |
+
+
+
+ A dictionary containing DataFrames representing the tables of a GTFS feed. + |
+ + required + | +
Returns:
+Name | Type | +Description | +
---|---|---|
Feed |
+ Feed
+ |
+
+
+
+ A Feed object representing the transit network. + |
+
Raises:
+Type | +Description | +
---|---|
+ ValueError
+ |
+
+
+
+ If the feed_dfs dictionary does not contain all the required tables. + |
+
++++++feed_dfs = { +… “agency”: agency_df, +… “routes”: routes_df, +… “stops”: stops_df, +… “trips”: trips_df, +… “stop_times”: stop_times_df, +… } +feed = load_feed_from_dfs(feed_dfs)
+
network_wrangler/transit/io.py
load_feed_from_path(feed_path, file_format='txt')
+
+ ¶Create a Feed object from the path to a GTFS transit feed.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
feed_path |
+
+ Union[Path, str]
+ |
+
+
+
+ The path to the GTFS transit feed. + |
+ + required + | +
file_format |
+
+ TransitFileTypes
+ |
+
+
+
+ the format of the files to read. Defaults to “txt” + |
+
+ 'txt'
+ |
+
Returns:
+Name | Type | +Description | +
---|---|---|
Feed |
+ Feed
+ |
+
+
+
+ The TransitNetwork object created from the GTFS transit feed. + |
+
network_wrangler/transit/io.py
load_transit(feed, file_format='txt', config=DefaultConfig)
+
+ ¶Create a TransitNetwork object.
+This function takes in a feed
parameter, which can be one of the following types:
+- Feed
: A Feed object representing a transit feed.
+- dict[str, pd.DataFrame]
: A dictionary of DataFrames representing transit data.
+- str
or Path
: A string or a Path object representing the path to a transit feed file.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
feed |
+
+ Union[Feed, GtfsModel, dict[str, DataFrame], str, Path]
+ |
+
+
+
+ Feed boject, dict of transit data frames, or path to transit feed data + |
+ + required + | +
file_format |
+
+ TransitFileTypes
+ |
+
+
+
+ the format of the files to read. Defaults to “txt” + |
+
+ 'txt'
+ |
+
config |
+
+ WranglerConfig
+ |
+
+
+
+ WranglerConfig object. Defaults to DefaultConfig. + |
+
+ DefaultConfig
+ |
+
A TransitNetwork object representing the loaded transit network.
+Raises:
+ValueError: If the feed
parameter is not one of the supported types.
Example usage: +
transit_network_from_zip = load_transit("path/to/gtfs.zip")
+
+transit_network_from_unzipped_dir = load_transit("path/to/files")
+
+transit_network_from_parquet = load_transit("path/to/files", file_format="parquet")
+
+dfs_of_transit_data = {"routes": routes_df, "stops": stops_df, "trips": trips_df...}
+transit_network_from_dfs = load_transit(dfs_of_transit_data)
+
network_wrangler/transit/io.py
write_feed_geo(feed, ref_nodes_df, out_dir, file_format='geojson', out_prefix=None, overwrite=True)
+
+ ¶Write a Feed object to a directory in a geospatial format.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
feed |
+
+ Feed
+ |
+
+
+
+ Feed object to write + |
+ + required + | +
ref_nodes_df |
+
+ GeoDataFrame
+ |
+
+
+
+ Reference nodes dataframe to use for geometry + |
+ + required + | +
out_dir |
+
+ Union[str, Path]
+ |
+
+
+
+ directory to write the network to + |
+ + required + | +
file_format |
+
+ Literal['geojson', 'shp', 'parquet']
+ |
+
+
+
+ the format of the output files. Defaults to “geojson” + |
+
+ 'geojson'
+ |
+
out_prefix |
+ + | +
+
+
+ prefix to add to the file name + |
+
+ None
+ |
+
overwrite |
+
+ bool
+ |
+
+
+
+ if True, will overwrite the files if they already exist. Defaults to True + |
+
+ True
+ |
+
network_wrangler/transit/io.py
write_transit(transit_net, out_dir='.', prefix=None, file_format='txt', overwrite=True)
+
+ ¶Writes a network in the transit network standard.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
transit_net |
+ + | +
+
+
+ a TransitNetwork instance + |
+ + required + | +
out_dir |
+
+ Union[Path, str]
+ |
+
+
+
+ directory to write the network to + |
+
+ '.'
+ |
+
file_format |
+
+ Literal['txt', 'csv', 'parquet']
+ |
+
+
+
+ the format of the output files. Defaults to “txt” which is csv with txt +file format. + |
+
+ 'txt'
+ |
+
prefix |
+
+ Optional[Union[Path, str]]
+ |
+
+
+
+ prefix to add to the file name + |
+
+ None
+ |
+
overwrite |
+
+ bool
+ |
+
+
+
+ if True, will overwrite the files if they already exist. Defaults to True + |
+
+ True
+ |
+
network_wrangler/transit/io.py
ModelTransit class and functions for managing consistency between roadway and transit networks.
+NOTE: this is not thoroughly tested and may not be fully functional.
+ + + +ModelTransit
+
+
+ ¶ModelTransit class for managing consistency between roadway and transit networks.
+ +network_wrangler/transit/model_transit.py
consistent_nets: bool
+
+
+ property
+
+
+ ¶Indicate if roadway and transit networks have changed since self.m_feed updated.
+m_feed
+
+
+ property
+
+
+ ¶TransitNetwork.feed with updates for consistency with associated ModelRoadwayNetwork.
+model_roadway_net
+
+
+ property
+
+
+ ¶ModelRoadwayNetwork associated with this ModelTransit.
+__init__(transit_net, roadway_net, shift_transit_to_managed_lanes=True)
+
+ ¶ModelTransit class for managing consistency between roadway and transit networks.
+ +network_wrangler/transit/model_transit.py
Classes and functions for selecting transit trips from a transit network.
+Usage:
+Create a TransitSelection object by providing a TransitNetwork object and a selection dictionary:
+1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 |
|
Access the selected trip ids or dataframe as follows:
+1 +2 +3 +4 |
|
Note: The selection dictionary should conform to the SelectTransitTrips model defined in +the models.projects.transit_selection module.
+ + + +TransitSelection
+
+
+ ¶Object to perform and store information about a selection from a project card “facility”.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
selection_dict |
+ + | +
+
+
+
+ |
+
selected_trips |
+
+ list
+ |
+
+
+
+
+ |
+
selected_trips_df |
+
+ DataFrame[WranglerTripsTable]
+ |
+
+
+
+ pd.DataFrame: DataFrame of selected trips + |
+
sel_key |
+ + | +
+
+
+
+ |
+
net |
+ + | +
+
+
+
+ |
+
network_wrangler/transit/selection.py
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 |
|
selected_frequencies_df: DataFrame[WranglerFrequenciesTable]
+
+
+ property
+
+
+ ¶DataFrame of selected frequencies.
+selected_shapes_df: DataFrame[WranglerShapesTable]
+
+
+ property
+
+
+ ¶selected_trips: list
+
+
+ property
+
+
+ ¶List of selected trip_ids.
+selected_trips_df: DataFrame[WranglerTripsTable]
+
+
+ property
+
+
+ ¶Lazily evaluates selection for trips or returns stored value in self._selected_trips_df.
+Will re-evaluate if the current network hash is different than the stored one from the +last selection.
+ + +Returns:
+Type | +Description | +
---|---|
+ DataFrame[WranglerTripsTable]
+ |
+
+
+
+ DataFrame[WranglerTripsTable] of selected trips + |
+
selection_dict
+
+
+ property
+ writable
+
+
+ ¶Getter for selection_dict.
+__init__(net, selection_dict)
+
+ ¶Constructor for TransitSelection object.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
net |
+
+ TransitNetwork
+ |
+
+
+
+ Transit network object to select from. + |
+ + required + | +
selection_dict |
+
+ Union[dict, SelectTransitTrips]
+ |
+
+
+
+ Selection dictionary conforming to SelectTransitTrips + |
+ + required + | +
network_wrangler/transit/selection.py
__nonzero__()
+
+ ¶validate_selection_dict(selection_dict)
+
+ ¶Check that selection dictionary has valid and used properties consistent with network.
+ + +Raises:
+Type | +Description | +
---|---|
+ TransitSelectionNetworkConsistencyError
+ |
+
+
+
+ If not consistent with transit network + |
+
+ ValidationError
+ |
+
+
+
+ if format not consistent with SelectTransitTrips + |
+
network_wrangler/transit/selection.py
Functions to check for transit network validity and consistency with roadway network.
+ + + +shape_links_without_road_links(tr_shapes, rd_links_df)
+
+ ¶Validate that links in transit shapes exist in referenced roadway links.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
tr_shapes |
+
+ DataFrame[WranglerShapesTable]
+ |
+
+
+
+ transit shapes from shapes.txt to validate foreign key to. + |
+ + required + | +
rd_links_df |
+
+ DataFrame[RoadLinksTable]
+ |
+
+
+
+ Links dataframe from roadway network to validate + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ DataFrame
+ |
+
+
+
+ df with shape_id and A, B + |
+
network_wrangler/transit/validate.py
stop_times_without_road_links(tr_stop_times, rd_links_df)
+
+ ¶Validate that links in transit shapes exist in referenced roadway links.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
tr_stop_times |
+
+ DataFrame[WranglerStopTimesTable]
+ |
+
+
+
+ transit stop_times from stop_times.txt to validate foreign key to. + |
+ + required + | +
rd_links_df |
+
+ DataFrame[RoadLinksTable]
+ |
+
+
+
+ Links dataframe from roadway network to validate + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ DataFrame
+ |
+
+
+
+ df with shape_id and A, B + |
+
network_wrangler/transit/validate.py
transit_nodes_without_road_nodes(feed, nodes_df, rd_field='model_node_id')
+
+ ¶Validate all of a transit feeds node foreign keys exist in referenced roadway nodes.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
feed |
+
+ Feed
+ |
+
+
+
+ Transit Feed to query. + |
+ + required + | +
nodes_df |
+
+ DataFrame
+ |
+
+
+
+ Nodes dataframe from roadway network to validate +foreign key to. Defaults to self.roadway_net.nodes_df + |
+ + required + | +
rd_field |
+
+ str
+ |
+
+
+
+ field in roadway nodes to check against. Defaults to “model_node_id” + |
+
+ 'model_node_id'
+ |
+
Returns:
+Type | +Description | +
---|---|
+ list[int]
+ |
+
+
+
+ boolean indicating if relationships are all valid + |
+
network_wrangler/transit/validate.py
transit_road_net_consistency(feed, road_net)
+
+ ¶Checks foreign key and network link relationships between transit feed and a road_net.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
feed |
+
+ Feed
+ |
+
+
+
+ Transit Feed. + |
+ + required + | +
road_net |
+
+ RoadwayNetwork
+ |
+
+
+
+ Roadway network to check relationship with. + |
+ + required + | +
Returns:
+Name | Type | +Description | +
---|---|---|
bool |
+ bool
+ |
+
+
+
+ boolean indicating if road_net is consistent with transit network. + |
+
network_wrangler/transit/validate.py
validate_transit_in_dir(dir, file_format='txt', road_dir=None, road_file_format='geojson')
+
+ ¶Validates a roadway network in a directory to the wrangler data model specifications.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
dir |
+
+ Path
+ |
+
+
+
+ The transit network file directory. + |
+ + required + | +
file_format |
+
+ str
+ |
+
+
+
+ The format of roadway network file name. Defaults to “txt”. + |
+
+ 'txt'
+ |
+
road_dir |
+
+ Path
+ |
+
+
+
+ The roadway network file directory. Defaults to None. + |
+
+ None
+ |
+
road_file_format |
+
+ str
+ |
+
+
+
+ The format of roadway network file name. Defaults to “geojson”. + |
+
+ 'geojson'
+ |
+
output_dir |
+
+ str
+ |
+
+
+
+ The output directory for the validation report. Defaults to “.”. + |
+ + required + | +
network_wrangler/transit/validate.py
General utility functions used throughout package.
+ + + +DictionaryMergeError
+
+
+ ¶check_one_or_one_superset_present(mixed_list, all_fields_present)
+
+ ¶Checks that exactly one of the fields in mixed_list is in fields_present or one superset.
+ +network_wrangler/utils/utils.py
combine_unique_unhashable_list(list1, list2)
+
+ ¶Combines lists preserving order of first and removing duplicates.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
list1 |
+
+ list
+ |
+
+
+
+ The first list. + |
+ + required + | +
list2 |
+
+ list
+ |
+
+
+
+ The second list. + |
+ + required + | +
Returns:
+Name | Type | +Description | +
---|---|---|
list | + | +
+
+
+ A new list containing the elements from list1 followed by the + |
+
+ | +
+
+
+ unique elements from list2. + |
+
++++++list1 = [1, 2, 3] +list2 = [2, 3, 4, 5] +combine_unique_unhashable_list(list1, list2) +[1, 2, 3, 4, 5]
+
network_wrangler/utils/utils.py
delete_keys_from_dict(dictionary, keys)
+
+ ¶Removes list of keys from potentially nested dictionary.
+SOURCE: https://stackoverflow.com/questions/3405715/ +User: @mseifert
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
dictionary |
+
+ dict
+ |
+
+
+
+ dictionary to remove keys from + |
+ + required + | +
keys |
+
+ list
+ |
+
+
+
+ list of keys to remove + |
+ + required + | +
network_wrangler/utils/utils.py
dict_to_hexkey(d)
+
+ ¶Converts a dictionary to a hexdigest of the sha1 hash of the dictionary.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
d |
+
+ dict
+ |
+
+
+
+ dictionary to convert to string + |
+ + required + | +
Returns:
+Name | Type | +Description | +
---|---|---|
str |
+ str
+ |
+
+
+
+ hexdigest of the sha1 hash of dictionary + |
+
network_wrangler/utils/utils.py
findkeys(node, kv)
+
+ ¶Returns values of all keys in various objects.
+Adapted from arainchi on Stack Overflow: +https://stackoverflow.com/questions/9807634/find-all-occurrences-of-a-key-in-nested-dictionaries-and-lists
+ +network_wrangler/utils/utils.py
get_overlapping_range(ranges)
+
+ ¶Returns the overlapping range for a list of ranges or tuples defining ranges.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
ranges |
+
+ list[Union[tuple[int], range]]
+ |
+
+
+
+ A list of ranges or tuples defining ranges. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Union[None, range]
+ |
+
+
+
+ Union[None, range]: The overlapping range if found, otherwise None. + |
+
++++++ranges = [(1, 5), (3, 7), (6, 10)] +get_overlapping_range(ranges) +range(3, 5)
+
network_wrangler/utils/utils.py
list_elements_subset_of_single_element(mixed_list)
+
+ ¶Find the first list in the mixed_list.
+ +network_wrangler/utils/utils.py
make_slug(text, delimiter='_')
+
+ ¶merge_dicts(right, left, path=None)
+
+ ¶Merges the contents of nested dict left into nested dict right.
+Raises errors in case of namespace conflicts.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
right |
+ + | +
+
+
+ dict, modified in place + |
+ + required + | +
left |
+ + | +
+
+
+ dict to be merged into right + |
+ + required + | +
path |
+ + | +
+
+
+ default None, sequence of keys to be reported in case of +error in merging nested dictionaries + |
+
+ None
+ |
+
network_wrangler/utils/utils.py
normalize_to_lists(mixed_list)
+
+ ¶Turn a mixed list of scalars and lists into a list of lists.
+ +network_wrangler/utils/utils.py
split_string_prefix_suffix_from_num(input_string)
+
+ ¶Split a string prefix and suffix from last number.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
input_string |
+
+ str
+ |
+
+
+
+ The input string to be processed. + |
+ + required + | +
Returns:
+Name | Type | +Description | +
---|---|---|
tuple | + | +
+
+
+ A tuple containing the prefix (including preceding numbers), + the last numeric part as an integer, and the suffix. + |
+
This function uses regular expressions to split a string into three parts: +the prefix, the last numeric part, and the suffix. The prefix includes any +preceding numbers, the last numeric part is converted to an integer, and +the suffix includes any non-digit characters after the last numeric part.
+Examples:
+ + + + +network_wrangler/utils/utils.py
topological_sort(adjacency_list, visited_list)
+
+ ¶Topological sorting for Acyclic Directed Graph.
+Parameters: +- adjacency_list (dict): A dictionary representing the adjacency list of the graph. +- visited_list (list): A list representing the visited status of each vertex in the graph.
+Returns: +- output_stack (list): A list containing the vertices in topological order.
+This function performs a topological sort on an acyclic directed graph. It takes an adjacency +list and a visited list as input. The adjacency list represents the connections between +vertices in the graph, and the visited list keeps track of the visited status of each vertex.
+The function uses a recursive helper function to perform the topological sort. It starts by +iterating over each vertex in the visited list. For each unvisited vertex, it calls the helper +function, which recursively visits all the neighbors of the vertex and adds them to the output +stack in reverse order. Finally, it returns the output stack, which contains the vertices in +topological order.
+ +network_wrangler/utils/utils.py
Helper functions for reading and writing files to reduce boilerplate.
+ + + +FileReadError
+
+
+ ¶FileWriteError
+
+
+ ¶convert_file_serialization(input_file, output_file, overwrite=True, boundary_gdf=None, boundary_geocode=None, boundary_file=None, node_filter_s=None, chunk_size=None)
+
+ ¶Convert a file serialization format to another and optionally filter to a boundary.
+If the input file is a JSON file that is larger than a reasonable portion of available +memory, and the output file is a Parquet file the JSON file will be read in chunks.
+If the input file is a Geographic data type (shp, geojon, geoparquet) and a boundary is +provided, the data will be filtered to the boundary.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
input_file |
+
+ Path
+ |
+
+
+
+ Path to the input JSON or GEOJSON file. + |
+ + required + | +
output_file |
+
+ Path
+ |
+
+
+
+ Path to the output Parquet file. + |
+ + required + | +
overwrite |
+
+ bool
+ |
+
+
+
+ If True, overwrite the output file if it exists. + |
+
+ True
+ |
+
boundary_gdf |
+
+ Optional[GeoDataFrame]
+ |
+
+
+
+ GeoDataFrame to filter the input data to. Only used for geographic data. +Defaults to None. + |
+
+ None
+ |
+
boundary_geocode |
+
+ Optional[str]
+ |
+
+
+
+ Geocode to filter the input data to. Only used for geographic data. +Defaults to None. + |
+
+ None
+ |
+
boundary_file |
+
+ Optional[Path]
+ |
+
+
+
+ File to load as a boundary to filter the input data to. Only used for +geographic data. Defaults to None. + |
+
+ None
+ |
+
node_filter_s |
+
+ Optional[Series]
+ |
+
+
+
+ If provided, will filter links in .json file to only those that connect to +nodes. Defaults to None. + |
+
+ None
+ |
+
chunk_size |
+
+ Optional[int]
+ |
+
+
+
+ Number of JSON objects to process in each chunk. Only works for +JSON to Parquet. If None, will determine if chunking needed and what size. + |
+
+ None
+ |
+
network_wrangler/utils/io_table.py
prep_dir(outdir, overwrite=True)
+
+ ¶Prepare a directory for writing files.
+ +network_wrangler/utils/io_table.py
read_table(filename, sub_filename=None, boundary_gdf=None, boundary_geocode=None, boundary_file=None, read_speed=DefaultConfig.CPU.EST_PD_READ_SPEED)
+
+ ¶Read file and return a dataframe or geodataframe.
+If filename is a zip file, will unzip to a temporary directory.
+If filename is a geojson or shapefile, will filter the data +to the boundary_gdf, boundary_geocode, or boundary_file if provided. Note that you can only +provide one of these boundary filters.
+If filename is a geoparquet file, will filter the data to the bounding box of the +boundary_gdf, boundary_geocode, or boundary_file if provided. Note that you can only +provide one of these boundary filters.
+NOTE: if you are accessing multiple files from this zip file you will want to unzip it first +and THEN access the table files so you don’t create multiple duplicate unzipped tmp dirs.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
filename |
+
+ Path
+ |
+
+
+
+ filename to load. + |
+ + required + | +
sub_filename |
+
+ Optional[str]
+ |
+
+
+
+ if the file is a zip, the sub_filename to load. + |
+
+ None
+ |
+
boundary_gdf |
+
+ Optional[GeoDataFrame]
+ |
+
+
+
+ GeoDataFrame to filter the input data to. Only used for geographic data. +Defaults to None. + |
+
+ None
+ |
+
boundary_geocode |
+
+ Optional[str]
+ |
+
+
+
+ Geocode to filter the input data to. Only used for geographic data. +Defaults to None. + |
+
+ None
+ |
+
boundary_file |
+
+ Optional[Path]
+ |
+
+
+
+ File to load as a boundary to filter the input data to. Only used for +geographic data. Defaults to None. + |
+
+ None
+ |
+
read_speed |
+
+ dict
+ |
+
+
+
+ dictionary of read speeds for different file types. Defaults to +DefaultConfig.CPU.EST_PD_READ_SPEED. + |
+
+ EST_PD_READ_SPEED
+ |
+
network_wrangler/utils/io_table.py
109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 |
|
unzip_file(path)
+
+ ¶Unzips a file to a temporary directory and returns the directory path.
+ +network_wrangler/utils/io_table.py
write_table(df, filename, overwrite=False, **kwargs)
+
+ ¶Write a dataframe or geodataframe to a file.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
df |
+
+ DataFrame
+ |
+
+
+
+ dataframe to write. + |
+ + required + | +
filename |
+
+ Path
+ |
+
+
+
+ filename to write to. + |
+ + required + | +
overwrite |
+
+ bool
+ |
+
+
+
+ whether to overwrite the file if it exists. Defaults to False. + |
+
+ False
+ |
+
kwargs |
+ + | +
+
+
+ additional arguments to pass to the writer. + |
+
+ {}
+ |
+
network_wrangler/utils/io_table.py
Utility functions for loading dictionaries from files.
+ + + +load_dict(path)
+
+ ¶Load a dictionary from a file.
+ +network_wrangler/utils/io_dict.py
load_merge_dict(path)
+
+ ¶Load and merge multiple dictionaries from files.
+ +network_wrangler/utils/io_dict.py
Helper functions for data models.
+ + + +DatamodelDataframeIncompatableError
+
+
+ ¶TableValidationError
+
+
+ ¶coerce_extra_fields_to_type_in_df(data, model, df)
+
+ ¶Coerce extra fields in data that aren’t specified in Pydantic model to the type in the df.
+Note: will not coerce lists of submodels, etc.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
data |
+
+ dict
+ |
+
+
+
+ The data to coerce. + |
+ + required + | +
model |
+
+ BaseModel
+ |
+
+
+
+ The Pydantic model to validate the data against. + |
+ + required + | +
df |
+
+ DataFrame
+ |
+
+
+
+ The DataFrame to coerce the data to. + |
+ + required + | +
network_wrangler/utils/models.py
default_from_datamodel(data_model, field)
+
+ ¶Returns default value from pandera data model for a given field name.
+ +network_wrangler/utils/models.py
empty_df_from_datamodel(model, crs=LAT_LON_CRS)
+
+ ¶Create an empty DataFrame or GeoDataFrame with the specified columns.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
model |
+
+ BaseModel
+ |
+
+
+
+ A pandera data model to create empty [Geo]DataFrame from. + |
+ + required + | +
crs |
+
+ int
+ |
+
+
+
+ if schema has geometry, will use this as the geometry’s crs. Defaults to LAT_LONG_CRS + |
+
+ LAT_LON_CRS
+ |
+
network_wrangler/utils/models.py
extra_attributes_undefined_in_model(instance, model)
+
+ ¶Find the extra attributes in a pydantic model that are not defined in the model.
+ +network_wrangler/utils/models.py
fill_df_with_defaults_from_model(df, model)
+
+ ¶Fill a DataFrame with default values from a Pandera DataFrameModel.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
df |
+ + | +
+
+
+ DataFrame to fill with default values. + |
+ + required + | +
model |
+ + | +
+
+
+ Pandera DataFrameModel to get default values from. + |
+ + required + | +
network_wrangler/utils/models.py
identify_model(data, models)
+
+ ¶Identify the model that the input data conforms to.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
data |
+
+ Union[DataFrame, dict]
+ |
+
+
+
+ The input data to identify. + |
+ + required + | +
models |
+
+ list[DataFrameModel, BaseModel]
+ |
+
+
+
+ A list of models to validate the input +data against. + |
+ + required + | +
network_wrangler/utils/models.py
order_fields_from_data_model(df, model)
+
+ ¶Order the fields in a DataFrame to match the order in a Pandera DataFrameModel.
+Will add any fields that are not in the model to the end of the DataFrame. +Will not add any fields that are in the model but not in the DataFrame.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
df |
+
+ DataFrame
+ |
+
+
+
+ DataFrame to order. + |
+ + required + | +
model |
+
+ DataFrameModel
+ |
+
+
+
+ Pandera DataFrameModel to order the DataFrame to. + |
+ + required + | +
network_wrangler/utils/models.py
submodel_fields_in_model(model, instance=None)
+
+ ¶Find the fields in a pydantic model that are submodels.
+ +network_wrangler/utils/models.py
validate_call_pyd(func)
+
+ ¶Decorator to validate the function i/o using Pydantic models without Pandera.
+ +network_wrangler/utils/models.py
validate_df_to_model(df, model, output_file=Path('validation_failure_cases.csv'))
+
+ ¶Wrapper to validate a DataFrame against a Pandera DataFrameModel with better logging.
+Also copies the attrs from the input DataFrame to the validated DataFrame.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
df |
+
+ DataFrame
+ |
+
+
+
+ DataFrame to validate. + |
+ + required + | +
model |
+
+ type
+ |
+
+
+
+ Pandera DataFrameModel to validate against. + |
+ + required + | +
output_file |
+
+ Path
+ |
+
+
+
+ Optional file to write validation errors to. Defaults to +validation_failure_cases.csv. + |
+
+ Path('validation_failure_cases.csv')
+ |
+
network_wrangler/utils/models.py
Functions to help with network manipulations in dataframes.
+ + + +point_seq_to_links(point_seq_df, id_field, seq_field, node_id_field, from_field='A', to_field='B')
+
+ ¶Translates a df with tidy data representing a sequence of points into links.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
point_seq_df |
+
+ DataFrame
+ |
+
+
+
+ Dataframe with source breadcrumbs + |
+ + required + | +
id_field |
+
+ str
+ |
+
+
+
+ Trace ID + |
+ + required + | +
seq_field |
+
+ str
+ |
+
+
+
+ Order of breadcrumbs within ID_field + |
+ + required + | +
node_id_field |
+
+ str
+ |
+
+
+
+ field denoting the node ID + |
+ + required + | +
from_field |
+
+ str
+ |
+
+
+
+ Field to export from_field to. Defaults to “A”. + |
+
+ 'A'
+ |
+
to_field |
+
+ str
+ |
+
+
+
+ Field to export to_field to. Defaults to “B”. + |
+
+ 'B'
+ |
+
Returns:
+Type | +Description | +
---|---|
+ DataFrame
+ |
+
+
+
+ pd.DataFrame: Link records with id_field, from_field, to_field + |
+
network_wrangler/utils/net.py
Functions related to parsing and comparing time objects and series.
+Internal function terminology for timespan scopes:
+matching
: a scope that could be applied for a given timespan combination.
+ This includes the default timespan as well as scopes wholely contained within.overlapping
: a timespan that fully or partially overlaps a given timespan.
+ This includes the default timespan, all matching
timespans and all timespans where
+ at least one minute overlap.conflicting
: a timespan that is overlapping but not matching. By definition default
+ scope values are not conflicting.independent
a timespan that is not overlapping.TimespanDfQueryError
+
+
+ ¶calc_overlap_duration_with_query(start_time_s, end_time_s, start_time_q, end_time_q)
+
+ ¶Calculate the overlap series of start and end times and a query start and end times.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
start_time_s |
+
+ Series[datetime]
+ |
+
+
+
+ Series of start times to calculate overlap with. + |
+ + required + | +
end_time_s |
+
+ Series[datetime]
+ |
+
+
+
+ Series of end times to calculate overlap with. + |
+ + required + | +
start_time_q |
+
+ datetime
+ |
+
+
+
+ Query start time to calculate overlap with. + |
+ + required + | +
end_time_q |
+
+ datetime
+ |
+
+
+
+ Query end time to calculate overlap with. + |
+ + required + | +
network_wrangler/utils/time.py
convert_timespan_to_start_end_dt(timespan_s)
+
+ ¶Convert a timespan string [‘12:00’,‘14:00] to start_time & end_time datetime cols in df.
+ +network_wrangler/utils/time.py
dt_contains(timespan1, timespan2)
+
+ ¶Check timespan1 inclusively contains timespan2.
+If the end time is less than the start time, it is assumed to be the next day.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
timespan1 |
+
+ list[time]
+ |
+
+
+
+ The first timespan represented as a list containing the start +time and end time. + |
+ + required + | +
timespan2 |
+
+ list[time]
+ |
+
+
+
+ The second timespan represented as a list containing the start +time and end time. + |
+ + required + | +
Returns:
+Name | Type | +Description | +
---|---|---|
bool |
+ bool
+ |
+
+
+
+ True if the first timespan contains the second timespan, False otherwise. + |
+
network_wrangler/utils/time.py
dt_list_overlaps(timespans)
+
+ ¶Check if any of the timespans overlap.
+overlapping
: a timespan that fully or partially overlaps a given timespan.
+This includes and all timespans where at least one minute overlap.
network_wrangler/utils/time.py
dt_overlap_duration(timedelta1, timedelta2)
+
+ ¶Check if two timespans overlap and return the amount of overlap.
+If the end time is less than the start time, it is assumed to be the next day.
+ +network_wrangler/utils/time.py
dt_overlaps(timespan1, timespan2)
+
+ ¶Check if two timespans overlap.
+If the end time is less than the start time, it is assumed to be the next day.
+overlapping
: a timespan that fully or partially overlaps a given timespan.
+This includes and all timespans where at least one minute overlap.
network_wrangler/utils/time.py
dt_to_seconds_from_midnight(dt)
+
+ ¶Convert a datetime object to the number of seconds since midnight.
+ +network_wrangler/utils/time.py
duration_dt(start_time_dt, end_time_dt)
+
+ ¶Returns a datetime.timedelta object representing the duration of the timespan.
+If end_time is less than start_time, the duration will assume that it crosses over +midnight.
+ +network_wrangler/utils/time.py
filter_df_to_max_overlapping_timespans(orig_df, query_timespan, strict_match=False, min_overlap_minutes=1, keep_max_of_cols=None)
+
+ ¶Filters dataframe for entries that have maximum overlap with the given query timespan.
+If the end time is less than the start time, it is assumed to be the next day.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
orig_df |
+
+ DataFrame
+ |
+
+
+
+ dataframe to query timespans for with |
+ + required + | +
query_timespan |
+
+ list[TimeString]
+ |
+
+
+
+ TimespanString of format [‘HH:MM’,’HH:MM’] to query orig_df for overlapping +records. + |
+ + required + | +
strict_match |
+
+ bool
+ |
+
+
+
+ boolean indicating if the returned df should only contain +records that fully contain the query timespan. If set to True, min_overlap_minutes +does not apply. Defaults to False. + |
+
+ False
+ |
+
min_overlap_minutes |
+
+ int
+ |
+
+
+
+ minimum number of minutes the timespans need to overlap to keep. +Defaults to 1. + |
+
+ 1
+ |
+
keep_max_of_cols |
+
+ Optional[list[str]]
+ |
+
+
+
+ list of fields to return the maximum value of overlap for. If None,
+will return all overlapping time periods. Defaults to |
+
+ None
+ |
+
network_wrangler/utils/time.py
filter_df_to_overlapping_timespans(orig_df, query_timespans)
+
+ ¶Filters dataframe for entries that have any overlap with ANY of the given query timespans.
+If the end time is less than the start time, it is assumed to be the next day.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
orig_df |
+
+ DataFrame
+ |
+
+
+
+ dataframe to query timespans for with |
+ + required + | +
query_timespans |
+
+ list[TimespanString]
+ |
+
+
+
+ List of a list of TimespanStr of format [‘HH:MM’,’HH:MM’] to query orig_df +for overlapping records. + |
+ + required + | +
network_wrangler/utils/time.py
filter_dt_list_to_overlaps(timespans)
+
+ ¶Filter a list of timespans to only include those that overlap.
+overlapping
: a timespan that fully or partially overlaps a given timespan.
+This includes and all timespans where at least one minute overlap.
network_wrangler/utils/time.py
format_seconds_to_legible_str(seconds)
+
+ ¶Formats seconds into a human-friendly string for log files.
+ +network_wrangler/utils/time.py
is_increasing(datetimes)
+
+ ¶Check if a list of datetime objects is increasing in time.
+ + +seconds_from_midnight_to_str(seconds)
+
+ ¶Convert the number of seconds since midnight to a TimeString (HH:MM).
+ +network_wrangler/utils/time.py
str_to_seconds_from_midnight(time_str)
+
+ ¶Convert a TimeString (HH:MM<:SS>) to the number of seconds since midnight.
+ +network_wrangler/utils/time.py
str_to_time(time_str, base_date=None)
+
+ ¶Convert TimeString (HH:MM<:SS>) to datetime object.
+If HH > 24, will subtract 24 to be within 24 hours. Timespans will be treated as the next day.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
time_str |
+
+ TimeString
+ |
+
+
+
+ TimeString in HH:MM:SS or HH:MM format. + |
+ + required + | +
base_date |
+
+ Optional[date]
+ |
+
+
+
+ optional date to base the datetime on. Defaults to None. +If not provided, will use today. + |
+
+ None
+ |
+
network_wrangler/utils/time.py
str_to_time_list(timespan)
+
+ ¶Convert list of TimeStrings (HH:MM<:SS>) to list of datetime.time objects.
+ +network_wrangler/utils/time.py
str_to_time_series(time_str_s, base_date=None)
+
+ ¶Convert mixed panda series datetime and TimeString (HH:MM<:SS>) to datetime object.
+If HH > 24, will subtract 24 to be within 24 hours. Timespans will be treated as the next day.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
time_str_s |
+
+ Series
+ |
+
+
+
+ Pandas Series of TimeStrings in HH:MM:SS or HH:MM format. + |
+ + required + | +
base_date |
+
+ Optional[Union[Series, date]]
+ |
+
+
+
+ optional date to base the datetime on. Defaults to None. +If not provided, will use today. Can be either a single instance or a series of +same length as time_str_s + |
+
+ None
+ |
+
network_wrangler/utils/time.py
timespan_str_list_to_dt(timespans)
+
+ ¶Convert list of TimespanStrings to list of datetime.time objects.
+ +network_wrangler/utils/time.py
timespans_overlap(timespan1, timespan2)
+
+ ¶Check if two timespan strings overlap.
+overlapping
: a timespan that fully or partially overlaps a given timespan.
+This includes and all timespans where at least one minute overlap.
network_wrangler/utils/time.py
Utility functions for pandas data manipulation.
+ + + +DataSegmentationError
+
+
+ ¶InvalidJoinFieldError
+
+
+ ¶MissingPropertiesError
+
+
+ ¶coerce_dict_to_df_types(d, df, skip_keys=None, return_skipped=False)
+
+ ¶Coerce dictionary values to match the type of a dataframe columns matching dict keys.
+Will also coerce a list of values.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
d |
+
+ dict
+ |
+
+
+
+ dictionary to coerce with singleton or list values + |
+ + required + | +
df |
+
+ DataFrame
+ |
+
+
+
+ dataframe to get types from + |
+ + required + | +
skip_keys |
+
+ Optional[list]
+ |
+
+
+
+ list of dict keys to skip. Defaults to []/ + |
+
+ None
+ |
+
return_skipped |
+
+ bool
+ |
+
+
+
+ keep the uncoerced, skipped keys/vals in the resulting dict. +Defaults to False. + |
+
+ False
+ |
+
Returns:
+Name | Type | +Description | +
---|---|---|
dict |
+ dict[str, CoerceTypes]
+ |
+
+
+
+ dict with coerced types + |
+
network_wrangler/utils/data.py
coerce_gdf(df, geometry=None, in_crs=LAT_LON_CRS)
+
+ ¶Coerce a DataFrame to a GeoDataFrame, optionally with a new geometry.
+ +network_wrangler/utils/data.py
coerce_val_to_df_types(field, val, df)
+
+ ¶Coerce field value to match the type of a matching dataframe columns.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
field |
+
+ str
+ |
+
+
+
+ field to lookup + |
+ + required + | +
val |
+
+ CoerceTypes
+ |
+
+
+
+ value or list of values to coerce + |
+ + required + | +
df |
+
+ DataFrame
+ |
+
+
+
+ dataframe to get types from + |
+ + required + | +
network_wrangler/utils/data.py
coerce_val_to_series_type(val, s)
+
+ ¶Coerces a value to match type of pandas series.
+Will try not to fail so if you give it a value that can’t convert to a number, it will +return a string.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
val |
+ + | +
+
+
+ Any type of singleton value + |
+ + required + | +
s |
+
+ Series
+ |
+
+
+
+ series to match the type to + |
+ + required + | +
network_wrangler/utils/data.py
compare_df_values(df1, df2, join_col=None, ignore=None, atol=1e-05)
+
+ ¶Compare overlapping part of dataframes and returns where there are differences.
+ +network_wrangler/utils/data.py
compare_lists(list1, list2)
+
+ ¶concat_with_attr(dfs, **kwargs)
+
+ ¶Concatenate a list of dataframes and retain the attributes of the first dataframe.
+ +network_wrangler/utils/data.py
convert_numpy_to_list(item)
+
+ ¶Function to recursively convert numpy arrays to lists.
+ +network_wrangler/utils/data.py
dict_fields_in_df(d, df)
+
+ ¶Check if all fields in dict are in dataframe.
+ +network_wrangler/utils/data.py
dict_to_query(selection_dict)
+
+ ¶Generates the query of from selection_dict.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
selection_dict |
+
+ Mapping[str, Any]
+ |
+
+
+
+ selection dictionary + |
+ + required + | +
Returns:
+Name | Type | +Description | +
---|---|---|
_type_ |
+ str
+ |
+
+
+
+ Query value + |
+
network_wrangler/utils/data.py
diff_dfs(df1, df2, ignore=None)
+
+ ¶Returns True if two dataframes are different and log differences.
+ +network_wrangler/utils/data.py
diff_list_like_series(s1, s2)
+
+ ¶Compare two series that contain list-like items as strings.
+ +network_wrangler/utils/data.py
fk_in_pk(pk, fk, ignore_nan=True)
+
+ ¶Check if all foreign keys are in the primary keys, optionally ignoring NaN.
+ +network_wrangler/utils/data.py
isin_dict(df, d, ignore_missing=True, strict_str=False)
+
+ ¶Filter the dataframe using a dictionary - faster than using isin.
+Uses merge to filter the dataframe by the dictionary keys and values.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
df |
+
+ DataFrame
+ |
+
+
+
+ dataframe to filter + |
+ + required + | +
d |
+
+ dict
+ |
+
+
+
+ dictionary with keys as column names and values as values to filter by + |
+ + required + | +
ignore_missing |
+
+ bool
+ |
+
+
+
+ if True, will ignore missing values in the selection dict. + |
+
+ True
+ |
+
strict_str |
+
+ bool
+ |
+
+
+
+ if True, will not allow partial string matches and will force case-matching. +Defaults to False. If False, will be overridden if key is in STRICT_MATCH_FIELDS or if +ignore_missing is False. + |
+
+ False
+ |
+
network_wrangler/utils/data.py
list_like_columns(df, item_type=None)
+
+ ¶Find columns in a dataframe that contain list-like items that can’t be json-serialized.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
df |
+ + | +
+
+
+ dataframe to check + |
+ + required + | +
item_type |
+
+ Optional[type]
+ |
+
+
+
+ if not None, will only return columns where all items are of this type by +checking only the first item in the column. Defaults to None. + |
+
+ None
+ |
+
network_wrangler/utils/data.py
segment_data_by_selection(item_list, data, field=None, end_val=0)
+
+ ¶Segment a dataframe or series into before, middle, and end segments based on item_list.
+selected segment = everything from the first to last item in item_list inclusive of the first + and last items. +Before segment = everything before +After segment = everything after
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
item_list |
+
+ list
+ |
+
+
+
+ List of items to segment data by. If longer than two, will only +use the first and last items. + |
+ + required + | +
data |
+
+ Union[Series, DataFrame]
+ |
+
+
+
+ Data to segment into before, middle, and after. + |
+ + required + | +
field |
+
+ str
+ |
+
+
+
+ If a dataframe, specifies which field to reference. +Defaults to None. + |
+
+ None
+ |
+
end_val |
+
+ int
+ |
+
+
+
+ Notation for util the end or from the begining. Defaults to 0. + |
+
+ 0
+ |
+
Raises:
+Type | +Description | +
---|---|
+ DataSegmentationError
+ |
+
+
+
+ If item list isn’t found in data in correct order. + |
+
Returns:
+Name | Type | +Description | +
---|---|---|
tuple |
+ tuple[Union[Series, list, DataFrame], Union[Series, list, DataFrame], Union[Series, list, DataFrame]]
+ |
+
+
+
+ data broken out by beofore, selected segment, and after. + |
+
network_wrangler/utils/data.py
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 |
|
segment_data_by_selection_min_overlap(selection_list, data, field, replacements_list, end_val=0)
+
+ ¶Segments data based on item_list reducing overlap with replacement list.
+selected segment: everything from the first to last item in item_list inclusive of the first + and last items but not if first and last items overlap with replacement list. +Before segment = everything before +After segment = everything after
+Example: +selection_list = [2,5] +data = pd.DataFrame({“i”:[1,2,3,4,5,6]}) +field = “i” +replacements_list = [2,22,33]
+ + +Returns:
+Type | +Description | +
---|---|
+ list
+ |
+
+
+
+ [22,33] + |
+
+ tuple[Union[Series, DataFrame], Union[Series, DataFrame], Union[Series, DataFrame]]
+ |
+
+
+
+ [1], [2,3,4,5], [6] + |
+
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
selection_list |
+
+ list
+ |
+
+
+
+ List of items to segment data by. If longer than two, will only +use the first and last items. + |
+ + required + | +
data |
+
+ Union[Series, DataFrame]
+ |
+
+
+
+ Data to segment into before, middle, and after. + |
+ + required + | +
field |
+
+ str
+ |
+
+
+
+ Specifies which field to reference. + |
+ + required + | +
replacements_list |
+
+ list
+ |
+
+
+
+ List of items to eventually replace the selected segment with. + |
+ + required + | +
end_val |
+
+ int
+ |
+
+
+
+ Notation for util the end or from the begining. Defaults to 0. + |
+
+ 0
+ |
+
tuple containing:
+Type | +Description | +
---|---|
+ list
+ |
+
+
+
+
|
+
+ tuple[Union[Series, DataFrame], Union[Series, DataFrame], Union[Series, DataFrame]]
+ |
+
+
+
+
|
+
network_wrangler/utils/data.py
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 |
|
update_df_by_col_value(destination_df, source_df, join_col, properties=None, fail_if_missing=True)
+
+ ¶Updates destination_df with ALL values in source_df for specified props with same join_col.
+Source_df can contain a subset of IDs of destination_df. +If fail_if_missing is true, destination_df must have all +the IDS in source DF - ensuring all source_df values are contained in resulting df.
+>> destination_df
+trip_id property1 property2
+1 10 100
+2 20 200
+3 30 300
+4 40 400
+
+>> source_df
+trip_id property1 property2
+2 25 250
+3 35 350
+
+>> updated_df
+trip_id property1 property2
+0 1 10 100
+1 2 25 250
+2 3 35 350
+3 4 40 400
+
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
destination_df |
+
+ DataFrame
+ |
+
+
+
+ Dataframe to modify. + |
+ + required + | +
source_df |
+
+ DataFrame
+ |
+
+
+
+ Dataframe with updated columns + |
+ + required + | +
join_col |
+
+ str
+ |
+
+
+
+ column to join on + |
+ + required + | +
properties |
+
+ list[str]
+ |
+
+
+
+ List of properties to use. If None, will default to all +in source_df. + |
+
+ None
+ |
+
fail_if_missing |
+
+ bool
+ |
+
+
+
+ If True, will raise an error if there are missing IDs in +destination_df that exist in source_df. + |
+
+ True
+ |
+
network_wrangler/utils/data.py
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 |
|
validate_existing_value_in_df(df, idx, field, expected_value)
+
+ ¶Validate if df[field]==expected_value for all indices in idx.
+ +network_wrangler/utils/data.py
Helper geographic manipulation functions.
+ + + +InvalidCRSError
+
+
+ ¶check_point_valid_for_crs(point, crs)
+
+ ¶Check if a point is valid for a given coordinate reference system.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
point |
+
+ Point
+ |
+
+
+
+ Shapely Point + |
+ + required + | +
crs |
+
+ int
+ |
+
+
+
+ coordinate reference system in ESPG code + |
+ + required + | +
network_wrangler/utils/geo.py
get_bearing(lat1, lon1, lat2, lon2)
+
+ ¶Calculate the bearing (forward azimuth) b/w the two points.
+returns: bearing in radians
+ +network_wrangler/utils/geo.py
get_bounding_polygon(boundary_geocode=None, boundary_file=None, boundary_gdf=None, crs=LAT_LON_CRS)
+
+ ¶Get the bounding polygon for a given boundary.
+Will return None if no arguments given. Will raise a ValueError if more than one given.
+This function retrieves the bounding polygon for a given boundary. The boundary can be provided +as a GeoDataFrame, a geocode string or dictionary, or a boundary file. The resulting polygon +geometry is returned as a GeoSeries.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
boundary_geocode |
+
+ Union[str, dict]
+ |
+
+
+
+ A geocode string or dictionary +representing the boundary. Defaults to None. + |
+
+ None
+ |
+
boundary_file |
+
+ Union[str, Path]
+ |
+
+
+
+ A path to the boundary file. Only used if +boundary_geocode is None. Defaults to None. + |
+
+ None
+ |
+
boundary_gdf |
+
+ GeoDataFrame
+ |
+
+
+
+ A GeoDataFrame representing the boundary. +Only used if boundary_geocode and boundary_file are None. Defaults to None. + |
+
+ None
+ |
+
crs |
+
+ int
+ |
+
+
+
+ The coordinate reference system (CRS) code. Defaults to 4326 (WGS84). + |
+
+ LAT_LON_CRS
+ |
+
Returns:
+Type | +Description | +
---|---|
+ GeoSeries
+ |
+
+
+
+ gpd.GeoSeries: The polygon geometry representing the bounding polygon. + |
+
network_wrangler/utils/geo.py
379 +380 +381 +382 +383 +384 +385 +386 +387 +388 +389 +390 +391 +392 +393 +394 +395 +396 +397 +398 +399 +400 +401 +402 +403 +404 +405 +406 +407 +408 +409 +410 +411 +412 +413 +414 +415 +416 +417 +418 +419 +420 +421 +422 +423 +424 +425 +426 +427 +428 +429 +430 +431 +432 +433 +434 +435 +436 +437 +438 +439 +440 +441 +442 +443 +444 +445 +446 |
|
get_point_geometry_from_linestring(polyline_geometry, pos=0)
+
+ ¶Get a point geometry from a linestring geometry.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
polyline_geometry |
+ + | +
+
+
+ shapely LineString instance + |
+ + required + | +
pos |
+
+ int
+ |
+
+
+
+ position in the linestring to get the point from. Defaults to 0. + |
+
+ 0
+ |
+
network_wrangler/utils/geo.py
length_of_linestring_miles(gdf)
+
+ ¶Returns a Series with the linestring length in miles.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
gdf |
+
+ Union[GeoSeries, GeoDataFrame]
+ |
+
+
+
+ GeoDataFrame with linestring geometry. If given a GeoSeries will attempt to convert +to a GeoDataFrame. + |
+ + required + | +
network_wrangler/utils/geo.py
linestring_from_lats_lons(df, lat_fields, lon_fields)
+
+ ¶Create a LineString geometry from a DataFrame with lon/lat fields.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
df |
+ + | +
+
+
+ DataFrame with columns for lon/lat fields. + |
+ + required + | +
lat_fields |
+ + | +
+
+
+ list of column names for the lat fields. + |
+ + required + | +
lon_fields |
+ + | +
+
+
+ list of column names for the lon fields. + |
+ + required + | +
network_wrangler/utils/geo.py
linestring_from_nodes(links_df, nodes_df, from_node='A', to_node='B', node_pk='model_node_id')
+
+ ¶Creates a LineString geometry GeoSeries from a DataFrame of links and a DataFrame of nodes.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
links_df |
+
+ DataFrame
+ |
+
+
+
+ DataFrame with columns for from_node and to_node. + |
+ + required + | +
nodes_df |
+
+ GeoDataFrame
+ |
+
+
+
+ GeoDataFrame with geometry column. + |
+ + required + | +
from_node |
+
+ str
+ |
+
+
+
+ column name in links_df for the from node. Defaults to “A”. + |
+
+ 'A'
+ |
+
to_node |
+
+ str
+ |
+
+
+
+ column name in links_df for the to node. Defaults to “B”. + |
+
+ 'B'
+ |
+
node_pk |
+
+ str
+ |
+
+
+
+ primary key column name in nodes_df. Defaults to “model_node_id”. + |
+
+ 'model_node_id'
+ |
+
network_wrangler/utils/geo.py
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 |
|
location_ref_from_point(geometry, sequence=1, bearing=None, distance_to_next_ref=None)
+
+ ¶Generates a shared street point location reference.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
geometry |
+
+ Point
+ |
+
+
+
+ Point shapely geometry + |
+ + required + | +
sequence |
+
+ int
+ |
+
+
+
+ Sequence if part of polyline. Defaults to None. + |
+
+ 1
+ |
+
bearing |
+
+ float
+ |
+
+
+
+ Direction of line if part of polyline. Defaults to None. + |
+
+ None
+ |
+
distance_to_next_ref |
+
+ float
+ |
+
+
+
+ Distnce to next point if part of polyline. +Defaults to None. + |
+
+ None
+ |
+
Returns:
+Name | Type | +Description | +
---|---|---|
LocationReference |
+ LocationReference
+ |
+
+
+
+ As defined by sharedStreets.io schema + |
+
network_wrangler/utils/geo.py
location_refs_from_linestring(geometry)
+
+ ¶Generates a shared street location reference from linestring.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
geometry |
+
+ LineString
+ |
+
+
+
+ Shapely LineString instance + |
+ + required + | +
Returns:
+Name | Type | +Description | +
---|---|---|
LocationReferences |
+ list[LocationReference]
+ |
+
+
+
+ As defined by sharedStreets.io schema + |
+
network_wrangler/utils/geo.py
offset_geometry_meters(geo_s, offset_distance_meters)
+
+ ¶Offset a GeoSeries of LineStrings by a given distance in meters.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
geo_s |
+
+ GeoSeries
+ |
+
+
+
+ GeoSeries of LineStrings to offset. + |
+ + required + | +
offset_distance_meters |
+
+ float
+ |
+
+
+
+ distance in meters to offset the LineStrings. + |
+ + required + | +
network_wrangler/utils/geo.py
offset_point_with_distance_and_bearing(lon, lat, distance, bearing)
+
+ ¶Get the new lon-lat (in degrees) given current point (lon-lat), distance and bearing.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
lon |
+
+ float
+ |
+
+
+
+ longitude of original point + |
+ + required + | +
lat |
+
+ float
+ |
+
+
+
+ latitude of original point + |
+ + required + | +
distance |
+
+ float
+ |
+
+
+
+ distance in meters to offset point by + |
+ + required + | +
bearing |
+
+ float
+ |
+
+
+
+ direction to offset point to in radians + |
+ + required + | +
network_wrangler/utils/geo.py
point_from_xy(x, y, xy_crs=LAT_LON_CRS, point_crs=LAT_LON_CRS)
+
+ ¶Creates point geometry from x and y coordinates.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
x |
+ + | +
+
+
+ x coordinate, in xy_crs + |
+ + required + | +
y |
+ + | +
+
+
+ y coordinate, in xy_crs + |
+ + required + | +
xy_crs |
+
+ int
+ |
+
+
+
+ coordinate reference system in ESPG code for x/y inputs. Defaults to 4326 (WGS84) + |
+
+ LAT_LON_CRS
+ |
+
point_crs |
+
+ int
+ |
+
+
+
+ coordinate reference system in ESPG code for point output. +Defaults to 4326 (WGS84) + |
+
+ LAT_LON_CRS
+ |
+
network_wrangler/utils/geo.py
to_points_gdf(table, ref_nodes_df=None, ref_road_net=None)
+
+ ¶Convert a table to a GeoDataFrame.
+If the table is already a GeoDataFrame, return it as is. Otherwise, attempt to convert the +table to a GeoDataFrame using the following methods: +1. If the table has a ‘geometry’ column, return a GeoDataFrame using that column. +2. If the table has ‘lat’ and ‘lon’ columns, return a GeoDataFrame using those columns. +3. If the table has a ‘*model_node_id’ or ‘stop_id’ column, return a GeoDataFrame using that column and the + nodes_df provided. +If none of the above, raise a ValueError.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
table |
+
+ DataFrame
+ |
+
+
+
+ DataFrame to convert to GeoDataFrame. + |
+ + required + | +
ref_nodes_df |
+
+ Optional[GeoDataFrame]
+ |
+
+
+
+ GeoDataFrame of nodes to use to convert model_node_id to geometry. + |
+
+ None
+ |
+
ref_road_net |
+
+ Optional[RoadwayNetwork]
+ |
+
+
+
+ RoadwayNetwork object to use to convert model_node_id to geometry. + |
+
+ None
+ |
+
Returns:
+Name | Type | +Description | +
---|---|---|
GeoDataFrame |
+ GeoDataFrame
+ |
+
+
+
+ GeoDataFrame representation of the table. + |
+
network_wrangler/utils/geo.py
484 +485 +486 +487 +488 +489 +490 +491 +492 +493 +494 +495 +496 +497 +498 +499 +500 +501 +502 +503 +504 +505 +506 +507 +508 +509 +510 +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 |
|
update_nodes_in_linestring_geometry(original_df, updated_nodes_df, position)
+
+ ¶Updates the nodes in a linestring geometry and returns updated geometry.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
original_df |
+
+ GeoDataFrame
+ |
+
+
+
+ GeoDataFrame with the |
+ + required + | +
updated_nodes_df |
+
+ GeoDataFrame
+ |
+
+
+
+ GeoDataFrame with updated node geometries. + |
+ + required + | +
position |
+
+ int
+ |
+
+
+
+ position in the linestring to update with the node. + |
+ + required + | +
network_wrangler/utils/geo.py
update_point_geometry(df, ref_point_df, lon_field='X', lat_field='Y', id_field='model_node_id', ref_lon_field='X', ref_lat_field='Y', ref_id_field='model_node_id')
+
+ ¶Returns copy of df with lat and long fields updated with geometry from ref_point_df.
+NOTE: does not update “geometry” field if it exists.
+ +network_wrangler/utils/geo.py
update_points_in_linestring(linestring, updated_coords, position)
+
+ ¶Replaces a point in a linestring with a new point.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
linestring |
+
+ LineString
+ |
+
+
+
+ original_linestring + |
+ + required + | +
updated_coords |
+
+ List[float]
+ |
+
+
+
+ updated poimt coordinates + |
+ + required + | +
position |
+
+ int
+ |
+
+
+
+ position in the linestring to update + |
+ + required + | +
network_wrangler/utils/geo.py
Dataframe accessors that allow functions to be called directly on the dataframe.
+ + + +DictQueryAccessor
+
+
+ ¶Query link, node and shape dataframes using project selection dictionary.
+Will overlook any keys which are not columns in the dataframe.
+Usage:
+selection_dict = {
+ "lanes": [1, 2, 3],
+ "name": ["6th", "Sixth", "sixth"],
+ "drive_access": 1,
+}
+selected_links_df = links_df.dict_query(selection_dict)
+
network_wrangler/utils/df_accessors.py
__call__(selection_dict, return_all_if_none=False)
+
+ ¶Queries the dataframe using the selection dictionary.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
selection_dict |
+
+ dict
+ |
+
+
+
+ description + |
+ + required + | +
return_all_if_none |
+
+ bool
+ |
+
+
+
+ If True, will return entire df if dict has + no values. Defaults to False. + |
+
+ False
+ |
+
network_wrangler/utils/df_accessors.py
__init__(pandas_obj)
+
+ ¶Isin_dict
+
+
+ ¶Faster implimentation of isin for querying dataframes with dictionary.
+ +network_wrangler/utils/df_accessors.py
__call__(d, **kwargs)
+
+ ¶dfHash
+
+
+ ¶Creates a dataframe hash that is compatable with geopandas and various metadata.
+Definitely not the fastest, but she seems to work where others have failed.
+ +network_wrangler/utils/df_accessors.py
__call__()
+
+ ¶Logging utilities for Network Wrangler.
+ + + +setup_logging(info_log_filename=None, debug_log_filename=None, std_out_level='info')
+
+ ¶Sets up the WranglerLogger w.r.t. the debug file location and if logging to console.
+Called by the test_logging fixture in conftest.py and can be called by the user to setup +logging for their session. If called multiple times, the logger will be reset.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
info_log_filename |
+
+ Optional[Path]
+ |
+
+
+
+ the location of the log file that will get created to add the INFO log.
+The INFO Log is terse, just gives the bare minimum of details.
+Defaults to file in cwd() |
+
+ None
+ |
+
debug_log_filename |
+
+ Optional[Path]
+ |
+
+
+
+ the location of the log file that will get created to add the DEBUG log
+The DEBUG log is very noisy, for debugging. Defaults to file in cwd()
+ |
+
+ None
+ |
+
std_out_level |
+
+ str
+ |
+
+
+
+ the level of logging to the console. One of “info”, “warning”, “debug”. +Defaults to “info” but will be set to ERROR if nothing provided matches. + |
+
+ 'info'
+ |
+
network_wrangler/logger.py
Configuration utilities.
+ + + +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.
+ +network_wrangler/configs/utils.py
__getitem__(key)
+
+ ¶get(key, default=None)
+
+ ¶items()
+
+ ¶resolve_paths(base_path)
+
+ ¶Resolve relative paths in the configuration.
+ +network_wrangler/configs/utils.py
to_dict()
+
+ ¶Convert the configuration to a dictionary.
+ +network_wrangler/configs/utils.py
update(data)
+
+ ¶Update the configuration with a dictionary of new values.
+ +network_wrangler/configs/utils.py
find_configs_in_dir(dir, config_type)
+
+ ¶Find configuration files in the directory that match *config<ext>
.
network_wrangler/configs/utils.py
Module for time and timespan objects.
+ + + +Time
+
+
+ ¶Represents a time object.
+This class provides methods to initialize and manipulate time objects.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
datetime |
+
+ datetime
+ |
+
+
+
+ The underlying datetime object representing the time. + |
+
time_str |
+
+ str
+ |
+
+
+
+ The time string representation in HH:MM:SS format. + |
+
time_sec |
+
+ int
+ |
+
+
+
+ The time in seconds since midnight. + |
+
_raw_time_in |
+
+ TimeType
+ |
+
+
+
+ The raw input value used to initialize the Time object. + |
+
network_wrangler/time.py
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 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 |
|
time_sec
+
+
+ property
+
+
+ ¶Get the time in seconds since midnight.
+ + +Returns:
+Name | Type | +Description | +
---|---|---|
int | + | +
+
+
+ The time in seconds since midnight. + |
+
time_str
+
+
+ property
+
+
+ ¶Get the time string representation.
+ + +Returns:
+Name | Type | +Description | +
---|---|---|
str | + | +
+
+
+ The time string representation in HH:MM:SS format. + |
+
__getitem__(item)
+
+ ¶Get the time string representation.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
item |
+
+ Any
+ |
+
+
+
+ Not used. + |
+ + required + | +
Returns:
+Name | Type | +Description | +
---|---|---|
str |
+ str
+ |
+
+
+
+ The time string representation in HH:MM:SS format. + |
+
network_wrangler/time.py
__hash__()
+
+ ¶Get the hash value of the Time object.
+ + +Returns:
+Name | Type | +Description | +
---|---|---|
int |
+ int
+ |
+
+
+
+ The hash value of the Time object. + |
+
__init__(value)
+
+ ¶Initializes a Time object.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
value |
+
+ TimeType
+ |
+
+
+
+ A time object, string in HH:MM[:SS] format, or seconds since +midnight. + |
+ + required + | +
Raises:
+Type | +Description | +
---|---|
+ TimeFormatError
+ |
+
+
+
+ If the value is not a valid time format. + |
+
network_wrangler/time.py
__str__()
+
+ ¶Get the string representation of the Time object.
+ + +Returns:
+Name | Type | +Description | +
---|---|---|
str |
+ str
+ |
+
+
+
+ The time string representation in HH:MM:SS format. + |
+
Timespan
+
+
+ ¶Timespan object.
+This class provides methods to initialize and manipulate time objects.
+If the end_time is less than the start_time, the duration will assume that it crosses + over midnight.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
start_time |
+
+ time
+ |
+
+
+
+ The start time of the timespan. + |
+
end_time |
+
+ time
+ |
+
+
+
+ The end time of the timespan. + |
+
timespan_str_list |
+
+ str
+ |
+
+
+
+ A list of start time and end time in HH:MM:SS format. + |
+
start_time_sec |
+
+ int
+ |
+
+
+
+ The start time in seconds since midnight. + |
+
end_time_sec |
+
+ int
+ |
+
+
+
+ The end time in seconds since midnight. + |
+
duration |
+
+ timedelta
+ |
+
+
+
+ The duration of the timespan. + |
+
duration_sec |
+
+ int
+ |
+
+
+
+ The duration of the timespan in seconds. + |
+
_raw_timespan_in |
+
+ Any
+ |
+
+
+
+ The raw input value used to initialize the Timespan object. + |
+
network_wrangler/time.py
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 |
|
duration
+
+
+ property
+
+
+ ¶Duration of timespan as a timedelta object.
+duration_sec
+
+
+ property
+
+
+ ¶Duration of timespan in seconds.
+If end_time is less than start_time, the duration will assume that it crosses over +midnight.
+end_time_sec
+
+
+ property
+
+
+ ¶End time in seconds since midnight.
+start_time_sec
+
+
+ property
+
+
+ ¶Start time in seconds since midnight.
+timespan_str_list
+
+
+ property
+
+
+ ¶Get the timespan string representation.
+__hash__()
+
+ ¶__init__(value)
+
+ ¶Constructor for the Timespan object.
+If the value is a list of two time strings, datetime objects, Time, or seconds from +midnight, the start_time and end_time attributes will be set accordingly.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
value |
+
+ time
+ |
+
+
+
+ a list of two time strings, datetime objects, Time, or seconds from +midnight. + |
+ + required + | +
network_wrangler/time.py
__str__()
+
+ ¶overlaps(other)
+
+ ¶Check if two timespans overlap.
+If the start time is greater than the end time, the timespan is assumed to cross over +midnight.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
other |
+
+ Timespan
+ |
+
+
+
+ The other timespan to compare. + |
+ + required + | +
Returns:
+Name | Type | +Description | +
---|---|---|
bool |
+ bool
+ |
+
+
+
+ True if the two timespans overlap, False otherwise. + |
+
network_wrangler/time.py
Module for visualizing roadway and transit networks using Mapbox tiles.
+This module provides a function net_to_mapbox
that creates and serves Mapbox tiles on a local web server based on roadway and transit networks.
net_to_mapbox(roadway, transit)
+MissingMapboxTokenError
+
+
+ ¶net_to_mapbox(roadway=None, transit=None, roadway_geojson_out=Path('roadway_shapes.geojson'), transit_geojson_out=Path('transit_shapes.geojson'), mbtiles_out=Path('network.mbtiles'), overwrite=True, port='9000')
+
+ ¶Creates and serves mapbox tiles on local web server based on roadway and transit networks.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
roadway |
+
+ Optional[Union[RoadwayNetwork, GeoDataFrame, str, Path]]
+ |
+
+
+
+ a RoadwayNetwork instance, geodataframe with roadway linetrings, or path to a +geojson file. Defaults to empty GeoDataFrame. + |
+
+ None
+ |
+
transit |
+
+ Optional[Union[TransitNetwork, GeoDataFrame]]
+ |
+
+
+
+ a TransitNetwork instance or a geodataframe with roadway linetrings, or path to a +geojson file. Defaults to empty GeoDataFrame. + |
+
+ None
+ |
+
roadway_geojson_out |
+
+ Path
+ |
+
+
+
+ file path for roadway geojson which gets created if roadway is not +a path to a geojson file. Defaults to roadway_shapes.geojson. + |
+
+ Path('roadway_shapes.geojson')
+ |
+
transit_geojson_out |
+
+ Path
+ |
+
+
+
+ file path for transit geojson which gets created if transit is not +a path to a geojson file. Defaults to transit_shapes.geojson. + |
+
+ Path('transit_shapes.geojson')
+ |
+
mbtiles_out |
+
+ Path
+ |
+
+
+
+ path to output mapbox tiles. Defaults to network.mbtiles + |
+
+ Path('network.mbtiles')
+ |
+
overwrite |
+
+ bool
+ |
+
+
+
+ boolean indicating if can overwrite mbtiles_out and roadway_geojson_out and +transit_geojson_out. Defaults to True. + |
+
+ True
+ |
+
port |
+
+ str
+ |
+
+
+
+ port to serve resulting tiles on. Defaults to 9000. + |
+
+ '9000'
+ |
+
network_wrangler/viz.py
24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + 39 + 40 + 41 + 42 + 43 + 44 + 45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 |
|
All network wrangler errors.
+ + + +DataframeSelectionError
+
+
+ ¶FeedReadError
+
+
+ ¶FeedValidationError
+
+
+ ¶InvalidScopedLinkValue
+
+
+ ¶LinkAddError
+
+
+ ¶LinkChangeError
+
+
+ ¶LinkCreationError
+
+
+ ¶LinkDeletionError
+
+
+ ¶LinkNotFoundError
+
+
+ ¶ManagedLaneAccessEgressError
+
+
+ ¶MissingNodesError
+
+
+ ¶NewRoadwayError
+
+
+ ¶NodeAddError
+
+
+ ¶NodeChangeError
+
+
+ ¶NodeDeletionError
+
+
+ ¶NodeNotFoundError
+
+
+ ¶NodesInLinksMissingError
+
+
+ ¶NotLinksError
+
+
+ ¶NotNodesError
+
+
+ ¶ProjectCardError
+
+
+ ¶RoadwayDeletionError
+
+
+ ¶RoadwayPropertyChangeError
+
+
+ ¶ScenarioConflictError
+
+
+ ¶ScenarioCorequisiteError
+
+
+ ¶ScenarioPrerequisiteError
+
+
+ ¶ScopeConflictError
+
+
+ ¶ScopeLinkValueError
+
+
+ ¶SegmentFormatError
+
+
+ ¶SegmentSelectionError
+
+
+ ¶SelectionError
+
+
+ ¶ShapeAddError
+
+
+ ¶ShapeDeletionError
+
+
+ ¶SubnetCreationError
+
+
+ ¶SubnetExpansionError
+
+
+ ¶TimeFormatError
+
+
+ ¶TimespanFormatError
+
+
+ ¶TransitPropertyChangeError
+
+
+ ¶TransitRoadwayConsistencyError
+
+
+ ¶TransitRouteAddError
+
+
+ ¶TransitRoutingChangeError
+
+
+ ¶TransitSelectionEmptyError
+
+
+ ¶TransitSelectionError
+
+
+ ¶TransitSelectionNetworkConsistencyError
+
+
+ ¶
+ Bases: TransitSelectionError
Error for when transit selection dictionary is not consistent with transit network.
+ + + +TransitValidationError
+
+
+ ¶