diff --git a/update_gtfs_data_model/404.html b/update_gtfs_data_model/404.html deleted file mode 100644 index a9b404fd..00000000 --- a/update_gtfs_data_model/404.html +++ /dev/null @@ -1,553 +0,0 @@ - - - -
- - - - - - - - - - - - - - -Scenario class and related functions for managing a scenario.
-Usage:
-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 = os.path.join(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.summarize(outfile = "baseline2050summary.txt")
-
-# 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.summarize(outfile = "build2050summary.txt")
-
ProjectCardError
-
-
- ¶
- Bases: Exception
Raised when a project card is not valid.
- -network_wrangler/scenario.py
92 -93 -94 -95 |
|
Scenario
-
-
- ¶
- Bases: object
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 = os.path.join(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.summarize(outfile = "baseline2050summary.txt")
-
-# 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.summarize(outfile = "build2050summary.txt")
-
Attributes:
-Name | -Type | -Description | -
---|---|---|
base_scenario |
- - | -
-
-
- 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 of project names that have been applied - |
-
projects |
- - | -
-
-
- list of all projects either planned, queued, or applied - |
-
prerequisites |
- - | -
-
-
- dictionary storing prerequiste information - |
-
corequisites |
- - | -
-
-
- dictionary storing corequisite information - |
-
conflicts |
- - | -
-
-
- dictionary storing conflict information - |
-
network_wrangler/scenario.py
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 |
|
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.
-__init__(base_scenario, project_card_list=[], name='')
-
- ¶Constructor.
- - -network_wrangler/scenario.py
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 |
|
__str__()
-
- ¶String representation of the Scenario object.
- -network_wrangler/scenario.py
221 -222 -223 -224 |
|
add_project_cards(project_card_list, validate=True, filter_tags=[])
-
- ¶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 |
-
- Collection[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 |
-
- Collection[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. - |
-
- []
- |
-
network_wrangler/scenario.py
290 -291 -292 -293 -294 -295 -296 -297 -298 -299 -300 -301 -302 -303 -304 -305 -306 -307 -308 -309 -310 -311 -312 |
|
apply_all_projects()
-
- ¶Applies all planned projects in the queue.
- -network_wrangler/scenario.py
447 -448 -449 -450 -451 -452 -453 -454 -455 -456 -457 |
|
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 sin
- - -Parameters:
-Name | -Type | -Description | -Default | -
---|---|---|---|
project_list |
-
- Collection[str]
- |
-
-
-
- List of projects to be applied. All need to be in the planned project -queue. - |
- - required - | -
network_wrangler/scenario.py
512 -513 -514 -515 -516 -517 -518 -519 -520 -521 -522 -523 -524 -525 -526 -527 -528 -529 -530 -531 -532 |
|
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 |
-
- Collection[str]
- |
-
-
-
- list of projects to order - |
- - required - | -
network_wrangler/scenario.py
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 |
|
summarize(project_detail=True, outfile='', mode='a')
-
- ¶A high level summary of the created scenario.
- - -Parameters:
-Name | -Type | -Description | -Default | -
---|---|---|---|
project_detail |
-
- bool
- |
-
-
-
- If True (default), will write out project card summaries. - |
-
- True
- |
-
outfile |
-
- str
- |
-
-
-
- If specified, will write scenario summary to text file. - |
-
- ''
- |
-
mode |
-
- str
- |
-
-
-
- Outfile open mode. ‘a’ to append ‘w’ to overwrite. - |
-
- 'a'
- |
-
Returns:
-Type | -Description | -
---|---|
- str
- |
-
-
-
- string of summary - |
-
network_wrangler/scenario.py
547 -548 -549 -550 -551 -552 -553 -554 -555 -556 -557 -558 -559 |
|
write(path, name)
-
- ¶summary.
- - -Parameters:
-Name | -Type | -Description | -Default | -
---|---|---|---|
path |
-
- Union[Path, str]
- |
-
-
-
- Path to write scenario networks and scenario summary to. - |
- - required - | -
name |
-
- str
- |
-
-
-
- Name to use. - |
- - required - | -
network_wrangler/scenario.py
534 -535 -536 -537 -538 -539 -540 -541 -542 -543 -544 -545 |
|
ScenarioConflictError
-
-
- ¶
- Bases: Exception
Raised when a conflict is detected.
- -network_wrangler/scenario.py
74 -75 -76 -77 |
|
ScenarioCorequisiteError
-
-
- ¶
- Bases: Exception
Raised when a co-requisite is not satisfied.
- -network_wrangler/scenario.py
80 -81 -82 -83 |
|
ScenarioPrerequisiteError
-
-
- ¶
- Bases: Exception
Raised when a pre-requisite is not satisfied.
- -network_wrangler/scenario.py
86 -87 -88 -89 |
|
create_base_scenario(base_shape_name, base_link_name, base_node_name, roadway_dir='', transit_dir='')
-
- ¶Creates a base scenario dictionary from roadway and transit network files.
- - -Parameters:
-Name | -Type | -Description | -Default | -
---|---|---|---|
base_shape_name |
-
- str
- |
-
-
-
- filename of the base network shape - |
- - required - | -
base_link_name |
-
- str
- |
-
-
-
- filename of the base network link - |
- - required - | -
base_node_name |
-
- str
- |
-
-
-
- filename of the base network node - |
- - required - | -
roadway_dir |
-
- str
- |
-
-
-
- optional path to the base scenario roadway network files - |
-
- ''
- |
-
transit_dir |
-
- str
- |
-
-
-
- optional path to base scenario transit files - |
-
- ''
- |
-
network_wrangler/scenario.py
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 |
|
create_scenario(base_scenario={}, project_card_list=[], project_card_filepath=None, filter_tags=[], validate=True)
-
- ¶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 |
-
- Union[Scenario, dict]
- |
-
-
-
- base Scenario scenario instances of dictionary of attributes. - |
-
- {}
- |
-
project_card_list |
- - | -
-
-
- List of ProjectCard instances to create Scenario from. Defaults -to []. - |
-
- []
- |
-
project_card_filepath |
-
- Optional[Union[Collection[str], str]]
- |
-
-
-
- where the project card is. A single path, list of paths, - |
-
- None
- |
-
filter_tags |
-
- Collection[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. - |
-
- []
- |
-
validate |
-
- bool
- |
-
-
-
- If True, will validate the projectcard before -being adding it to the scenario. Defaults to True. - |
-
- True
- |
-
network_wrangler/scenario.py
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 |
|
scenario_summary(scenario, project_detail=True, outfile='', mode='a')
-
- ¶A high level summary of the created scenario.
- - -Parameters:
-Name | -Type | -Description | -Default | -
---|---|---|---|
scenario |
-
- Scenario
- |
-
-
-
- Scenario instance to summarize. - |
- - required - | -
project_detail |
-
- bool
- |
-
-
-
- If True (default), will write out project card summaries. - |
-
- True
- |
-
outfile |
-
- str
- |
-
-
-
- If specified, will write scenario summary to text file. - |
-
- ''
- |
-
mode |
-
- str
- |
-
-
-
- Outfile open mode. ‘a’ to append ‘w’ to overwrite. - |
-
- 'a'
- |
-
Returns:
-Type | -Description | -
---|---|
- str
- |
-
-
-
- string of summary - |
-
network_wrangler/scenario.py
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 |
|
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
- |
-
crs |
-
- str
- |
-
-
-
- coordinate reference system in ESPG number format. Defaults to DEFAULT_CRS -which is set to 4326, WGS 84 Lat/Long - |
-
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 |
-
network_wrangler/roadway/network.py
79 - 80 - 81 - 82 - 83 - 84 - 85 - 86 - 87 - 88 - 89 - 90 - 91 - 92 - 93 - 94 - 95 - 96 - 97 - 98 - 99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 -172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 -189 -190 -191 -192 -193 -194 -195 -196 -197 -198 -199 -200 -201 -202 -203 -204 -205 -206 -207 -208 -209 -210 -211 -212 -213 -214 -215 -216 -217 -218 -219 -220 -221 -222 -223 -224 -225 -226 -227 -228 -229 -230 -231 -232 -233 -234 -235 -236 -237 -238 -239 -240 -241 -242 -243 -244 -245 -246 -247 -248 -249 -250 -251 -252 -253 -254 -255 -256 -257 -258 -259 -260 -261 -262 -263 -264 -265 -266 -267 -268 -269 -270 -271 -272 -273 -274 -275 -276 -277 -278 -279 -280 -281 -282 -283 -284 -285 -286 -287 -288 -289 -290 -291 -292 -293 -294 -295 -296 -297 -298 -299 -300 -301 -302 -303 -304 -305 -306 -307 -308 -309 -310 -311 -312 -313 -314 -315 -316 -317 -318 -319 -320 -321 -322 -323 -324 -325 -326 -327 -328 -329 -330 -331 -332 -333 -334 -335 -336 -337 -338 -339 -340 -341 -342 -343 -344 -345 -346 -347 -348 -349 -350 -351 -352 -353 -354 -355 -356 -357 -358 -359 -360 -361 -362 -363 -364 -365 -366 -367 -368 -369 -370 -371 -372 -373 -374 -375 -376 -377 -378 -379 -380 -381 -382 -383 -384 -385 -386 -387 -388 -389 -390 -391 -392 -393 -394 -395 -396 -397 -398 -399 -400 -401 -402 -403 -404 -405 -406 -407 -408 -409 -410 -411 -412 -413 -414 -415 -416 -417 -418 -419 -420 -421 -422 -423 -424 -425 -426 -427 -428 -429 -430 -431 -432 -433 -434 -435 -436 -437 -438 -439 -440 -441 -442 -443 -444 -445 -446 -447 -448 -449 -450 -451 -452 -453 -454 -455 -456 -457 -458 -459 -460 -461 -462 -463 -464 -465 -466 -467 -468 -469 -470 -471 -472 -473 -474 -475 -476 -477 -478 -479 -480 -481 -482 -483 -484 -485 -486 -487 -488 -489 -490 -491 -492 -493 -494 -495 -496 -497 -498 -499 -500 -501 -502 -503 -504 -505 -506 -507 -508 -509 -510 -511 -512 -513 -514 -515 -516 -517 -518 -519 -520 -521 -522 -523 -524 -525 -526 -527 -528 -529 -530 -531 -532 -533 -534 -535 -536 -537 -538 -539 -540 -541 -542 -543 -544 -545 -546 -547 -548 -549 -550 -551 -552 -553 -554 -555 -556 -557 -558 -559 -560 -561 -562 -563 -564 -565 -566 -567 -568 -569 -570 -571 -572 -573 -574 -575 -576 -577 -578 -579 -580 -581 -582 -583 -584 -585 -586 -587 -588 -589 -590 -591 -592 -593 -594 -595 -596 -597 -598 -599 -600 -601 -602 -603 -604 -605 -606 -607 -608 -609 -610 -611 -612 -613 -614 -615 -616 -617 |
|
link_shapes_df: gpd.GeoDataFrame
-
-
- property
-
-
- ¶Add shape geometry to links if available.
-returns: shapes merged to nodes 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_incident_link_data_to_nodes(links_df=None, nodes_df=None, link_variables=[])
-
-
- staticmethod
-
-
- ¶Add data from links going to/from nodes to node.
- - -Parameters:
-Name | -Type | -Description | -Default | -
---|---|---|---|
links_df |
-
- Optional[DataFrame[RoadLinksTable]]
- |
-
-
-
- if specified, will assess connectivity of this -links list rather than self.links_df - |
-
- None
- |
-
nodes_df |
-
- Optional[DataFrame[RoadNodesTable]]
- |
-
-
-
- if specified, will assess connectivity of this -nodes list rather than self.nodes_df - |
-
- None
- |
-
link_variables |
-
- list
- |
-
-
-
- list of columns in links dataframe to add to incident nodes - |
-
- []
- |
-
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
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 |
|
add_links(add_links_df)
-
- ¶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 - | -
network_wrangler/roadway/network.py
385 -386 -387 -388 -389 -390 -391 -392 -393 |
|
add_nodes(add_nodes_df)
-
- ¶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 - | -
network_wrangler/roadway/network.py
395 -396 -397 -398 -399 -400 -401 -402 -403 |
|
add_shapes(add_shapes_df)
-
- ¶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 - | -
network_wrangler/roadway/network.py
405 -406 -407 -408 -409 -410 -411 -412 -413 -414 -415 -416 -417 |
|
apply(project_card)
-
- ¶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 - | -
network_wrangler/roadway/network.py
324 -325 -326 -327 -328 -329 -330 -331 -332 -333 -334 -335 -336 -337 -338 -339 -340 -341 |
|
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
515 -516 -517 -518 -519 -520 -521 -522 -523 |
|
clean_unused_shapes()
-
- ¶Removes any unused shapes from network that aren’t referenced by links_df.
- -network_wrangler/roadway/network.py
508 -509 -510 -511 -512 -513 |
|
coerce_crs(v, info)
-
- ¶Coerce crs of nodes_df and links_df to network crs.
- -network_wrangler/roadway/network.py
156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 |
|
delete_links(selection_dict, clean_nodes=False, clean_shapes=False)
-
- ¶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
- |
-
network_wrangler/roadway/network.py
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 |
|
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
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 |
|
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
311 -312 -313 -314 -315 -316 -317 -318 -319 -320 -321 -322 |
|
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 |
-
- Union[str, int]
- |
-
-
-
- category to query or a list of categories. Defaults to DEFAULT_CATEGORY. - |
-
- DEFAULT_CATEGORY
- |
-
timespan |
-
- 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
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 |
|
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
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 |
|
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
553 -554 -555 -556 -557 -558 -559 -560 -561 |
|
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
543 -544 -545 -546 -547 -548 -549 -550 -551 |
|
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
563 -564 -565 -566 -567 -568 -569 -570 -571 -572 -573 |
|
links_with_link_ids(link_ids)
-
- ¶Return subset of links_df based on link_ids list.
- -network_wrangler/roadway/network.py
373 -374 -375 |
|
links_with_nodes(node_ids)
-
- ¶Return subset of links_df based on node_ids list.
- -network_wrangler/roadway/network.py
377 -378 -379 |
|
modal_graph_hash(mode)
-
- ¶Hash of the links in order to detect a network change from when graph created.
- -network_wrangler/roadway/network.py
304 -305 -306 -307 -308 -309 |
|
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
525 -526 -527 -528 -529 -530 -531 -532 -533 -534 -535 -536 -537 -538 -539 -540 -541 |
|
nodes_in_links()
-
- ¶Returns subset of self.nodes_df that are in self.links_df.
- -network_wrangler/roadway/network.py
381 -382 -383 |
|
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 |
|
TransitNetwork
-
-
- ¶
- Bases: object
Representation of a Transit Network.
-Typical usage example: -
import network_wrangler as wr
-tc=wr.load_transit(stpaul_gtfs)
-
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. - |
-
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
57 - 58 - 59 - 60 - 61 - 62 - 63 - 64 - 65 - 66 - 67 - 68 - 69 - 70 - 71 - 72 - 73 - 74 - 75 - 76 - 77 - 78 - 79 - 80 - 81 - 82 - 83 - 84 - 85 - 86 - 87 - 88 - 89 - 90 - 91 - 92 - 93 - 94 - 95 - 96 - 97 - 98 - 99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 -172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 -189 -190 -191 -192 -193 -194 -195 -196 -197 -198 -199 -200 -201 -202 -203 -204 -205 -206 -207 -208 -209 -210 -211 -212 -213 -214 -215 -216 -217 -218 -219 -220 -221 -222 -223 -224 -225 -226 -227 -228 -229 -230 -231 -232 -233 -234 -235 -236 -237 -238 -239 -240 -241 -242 -243 -244 -245 -246 -247 -248 -249 -250 -251 -252 -253 -254 -255 -256 -257 -258 -259 -260 -261 -262 -263 -264 -265 -266 -267 -268 -269 -270 -271 -272 -273 -274 -275 -276 -277 -278 -279 -280 -281 -282 -283 -284 -285 -286 -287 -288 -289 -290 -291 -292 -293 -294 -295 -296 -297 -298 -299 -300 -301 -302 -303 -304 -305 -306 -307 -308 -309 -310 -311 -312 -313 -314 -315 -316 -317 -318 -319 -320 -321 -322 -323 -324 -325 -326 -327 -328 -329 -330 -331 -332 -333 -334 -335 -336 -337 -338 -339 -340 |
|
config
-
-
- property
-
-
- ¶Pass through property from Feed.
-consistent_with_road_net: bool
-
-
- property
-
-
- ¶Indicate if road_net is consistent with transit network.
-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: 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
175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 -189 -190 -191 -192 -193 -194 |
|
__init__(feed)
-
- ¶Constructor for TransitNetwork.
- - -Parameters:
-Name | -Type | -Description | -Default | -
---|---|---|---|
feed |
-
- Feed
- |
-
-
-
- Feed object representing the transit network gtfs tables - |
- - required - | -
network_wrangler/transit/network.py
78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 |
|
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
281 -282 -283 -284 -285 -286 -287 -288 -289 -290 -291 -292 -293 -294 -295 -296 -297 -298 -299 -300 -301 |
|
deepcopy()
-
- ¶Returns copied TransitNetwork instance with deep copy of Feed but not roadway net.
- -network_wrangler/transit/network.py
196 -197 -198 |
|
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
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 |
|
TransitRoadwayConsistencyError
-
-
- ¶
- Bases: Exception
Error raised when transit network is inconsistent with roadway network.
- -network_wrangler/transit/network.py
51 -52 -53 -54 |
|
Parameters for Network Wrangler.
- - - -COPY_FROM_GP_TO_ML = ['ref', 'roadway', 'access', 'distance', 'bike_access', 'drive_access', 'walk_access', 'bus_only', 'rail_only']
-
-
- module-attribute
-
-
- ¶(list(str)): list of attributes copied from GP lanes to access and egress dummy links.
-COPY_TO_ACCESS_EGRESS = ['ref', 'ML_access', 'ML_drive_access', 'ML_bus_only', 'ML_rail_only']
-
-
- module-attribute
-
-
- ¶(list(str)): list of attributes -that must be provided in managed lanes
-DEFAULT_CATEGORY = 'any'
-
-
- module-attribute
-
-
- ¶Read sec / MB - WILL DEPEND ON SPECIFIC COMPUTER
-DEFAULT_DELETE_MODES = ['any']
-
-
- module-attribute
-
-
- ¶(int): default for initial number of links from name-based - selection that are traveresed before trying another shortest - path when searching for paths between A and B node
-DEFAULT_MAX_SEARCH_BREADTH = 10
-
-
- module-attribute
-
-
- ¶Union(int, float)): default penalty assigned for each - degree of distance between a link and a link with the searched-for - name when searching for paths between A and B node
-DEFAULT_SEARCH_BREADTH = 5
-
-
- module-attribute
-
-
- ¶(int): default for maximum number of links traversed between - links that match the searched name when searching for paths - between A and B node
-DEFAULT_SEARCH_MODES = ['drive']
-
-
- module-attribute
-
-
- ¶(list(str)): default for searching for links to delete when no modes are specified.
-DEFAULT_SP_WEIGHT_COL = 'i'
-
-
- module-attribute
-
-
- ¶Default timespan for scoped values.
-DEFAULT_SP_WEIGHT_FACTOR = 100
-
-
- module-attribute
-
-
- ¶(str): default column to use as weights in the shortest path calculations.
-DEFAULT_TIMESPAN = ['00:00', '24:00']
-
-
- module-attribute
-
-
- ¶Default category for scoped values.
-EST_PD_READ_SPEED = {'csv': 0.03, 'parquet': 0.005, 'geojson': 0.03, 'json': 0.15, 'txt': 0.04}
-
-
- module-attribute
-
-
- ¶(float): offset in meters for managed lanes centerlines
-MANAGED_LANES_LINK_ID_RANGE = (950000, 999999)
-
-
- module-attribute
-
-
- ¶Range of model_node_ids to use when creating an associated node for a parallel managed lane.
-MANAGED_LANES_REQUIRED_ATTRIBUTES = ['A', 'B', 'model_link_id']
-
-
- module-attribute
-
-
- ¶Range of model_link_ids to use when creating an associated link for a parallel managed lane.
-ML_OFFSET_METERS = -5
-
-
- module-attribute
-
-
- ¶(list(str)): list of attributes
-to copy from a general purpose lane to managed lane so long as a ML_
SECONDARY_TRANSIT_CARD_TYPES = ['roadway_deletion']
-
-
- module-attribute
-
-
- ¶(list(str)): default for search modes when searching for paths between A and B node - when no modes are specified.
-LinksParams
-
-
-
- dataclass
-
-
- ¶Parameters for RoadLinksTable.
- -network_wrangler/params.py
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 |
|
display_cols: List[str]
-
-
- property
-
-
- ¶List of columns to display in the table.
-explicit_ids: List[str]
-
-
- property
-
-
- ¶List of columns that can be used to easily find specific row sin the table.
-fks_to_nodes
-
-
- property
-
-
- ¶Foreign keys to nodes in the network.
-idx_col
-
-
- property
-
-
- ¶Column to make the index of the table.
-unique_ids: List[str]
-
-
- property
-
-
- ¶List of unique ids for the table.
-NodesParams
-
-
-
- dataclass
-
-
- ¶Parameters for RoadNodesTable.
- -network_wrangler/params.py
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 |
|
display_cols: List[str]
-
-
- property
-
-
- ¶Columns to display in the table.
-explicit_ids: List[str]
-
-
- property
-
-
- ¶List of columns that can be used to easily find specific records the table.
-geometry_props: List[str]
-
-
- property
-
-
- ¶List of geometry properties.
-idx_col: str
-
-
- property
-
-
- ¶Column to make the index of the table.
-unique_ids: List[str]
-
-
- property
-
-
- ¶List of unique ids for the table.
-ShapesParams
-
-
-
- dataclass
-
-
- ¶Parameters for RoadShapesTable.
- -network_wrangler/params.py
117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 |
|
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 -:: network_wrangler.roadway.links.create -:: network_wrangler.roadway.links.delete -:: network_wrangler.roadway.links.edit -:: network_wrangler.roadway.links.filters -:: network_wrangler.roadway.links.geo -:: network_wrangler.roadway.links.scopes -:: network_wrangler.roadway.links.summary -:: network_wrangler.roadway.links.validate -:: network_wrangler.roadway.links.df_accessors
-:: network_wrangler.roadway.nodes.io -:: network_wrangler.roadway.nodes.create -:: network_wrangler.roadway.nodes.delete -:: network_wrangler.roadway.nodes.edit -:: network_wrangler.roadway.nodes.filters -:: network_wrangler.roadway.nodes
-:: network_wrangler.roadway.shapes.io -:: network_wrangler.roadway.shapes.create -:: network_wrangler.roadway.shapes.edit -:: network_wrangler.roadway.shapes.delete -:: network_wrangler.roadway.shapes.filters -:: network_wrangler.roadway.shapes.shapes
-:: network_wrangler.roadway.segment -:: network_wrangler.roadway.subnet -:: network_wrangler.roadway.graph
-General utility functions used throughout package.
- - - -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
294 -295 -296 -297 -298 -299 -300 -301 -302 -303 -304 -305 |
|
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
242 -243 -244 -245 -246 -247 -248 -249 -250 -251 -252 -253 -254 -255 -256 -257 -258 -259 |
|
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
54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 |
|
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
230 -231 -232 -233 -234 -235 -236 -237 -238 -239 |
|
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
105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 |
|
generate_list_of_new_ids(input_ids, existing_ids, id_scalar, iter_val=10, max_iter=1000)
-
- ¶Generates a list of new IDs based on the input IDs, existing IDs, and other parameters.
- - -Parameters:
-Name | -Type | -Description | -Default | -
---|---|---|---|
input_ids |
-
- list[str]
- |
-
-
-
- The input IDs for which new IDs need to be generated. - |
- - required - | -
existing_ids |
-
- Series
- |
-
-
-
- The existing IDs that should be avoided when generating new IDs. - |
- - required - | -
id_scalar |
-
- int
- |
-
-
-
- The scalar value used to generate new IDs. - |
- - required - | -
iter_val |
-
- int
- |
-
-
-
- The iteration value used in the generation process. -Defaults to 10. - |
-
- 10
- |
-
max_iter |
-
- int
- |
-
-
-
- The maximum number of iterations allowed in the generation -process. Defaults to 1000. - |
-
- 1000
- |
-
Returns:
-Type | -Description | -
---|---|
- list[str]
- |
-
-
-
- list[str]: A list of new IDs generated based on the input IDs and other parameters. - |
-
network_wrangler/utils/utils.py
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 |
|
generate_new_id(input_id, existing_ids, id_scalar, iter_val=10, max_iter=1000)
-
- ¶Generate a new ID that isn’t in existing_ids.
-TODO: check a registry rather than existing IDs
- - -Parameters:
-Name | -Type | -Description | -Default | -
---|---|---|---|
input_id |
-
- str
- |
-
-
-
- id to use to generate new id. - |
- - required - | -
existing_ids |
-
- Series
- |
-
-
-
- series that has existing IDs that should be unique - |
- - required - | -
id_scalar |
-
- int
- |
-
-
-
- scalar value to initially use to create the new id. - |
- - required - | -
iter_val |
-
- int
- |
-
-
-
- iteration value to use in the generation process. - |
-
- 10
- |
-
max_iter |
-
- int
- |
-
-
-
- maximum number of iterations allowed in the generation process. - |
-
- 1000
- |
-
network_wrangler/utils/utils.py
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 |
|
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
79 - 80 - 81 - 82 - 83 - 84 - 85 - 86 - 87 - 88 - 89 - 90 - 91 - 92 - 93 - 94 - 95 - 96 - 97 - 98 - 99 -100 -101 -102 |
|
list_elements_subset_of_single_element(mixed_list)
-
- ¶Find the first list in the mixed_list.
- -network_wrangler/utils/utils.py
273 -274 -275 -276 -277 -278 -279 -280 -281 -282 -283 -284 -285 -286 -287 -288 -289 -290 -291 |
|
make_slug(text, delimiter='_')
-
- ¶Makes a slug from text.
- -network_wrangler/utils/utils.py
48 -49 -50 -51 |
|
normalize_to_lists(mixed_list)
-
- ¶Turn a mixed list of scalars and lists into a list of lists.
- -network_wrangler/utils/utils.py
262 -263 -264 -265 -266 -267 -268 -269 -270 |
|
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:
->>> split_string_prefix_suffix_from_num("abc123def456")
-('abc', 123, 'def456')
-
>>> split_string_prefix_suffix_from_num("hello")
-('hello', 0, '')
-
>>> split_string_prefix_suffix_from_num("123")
-('', 123, '')
-
network_wrangler/utils/utils.py
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 |
|
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
13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 |
|
Helper functions for reading and writing files to reduce boilerplate.
- - - -FileReadError
-
-
- ¶
- Bases: Exception
Raised when there is an error reading a file.
- -network_wrangler/utils/io.py
39 -40 -41 -42 |
|
FileWriteError
-
-
- ¶
- Bases: Exception
Raised when there is an error writing a file.
- -network_wrangler/utils/io.py
45 -46 -47 -48 |
|
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.py
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 |
|
read_table(filename, sub_filename=None, boundary_gdf=None, boundary_geocode=None, boundary_file=None)
-
- ¶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 |
-
- 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
- |
-
network_wrangler/utils/io.py
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 |
|
unzip_file(path)
-
- ¶Unzips a file to a temporary directory and returns the directory path.
- -network_wrangler/utils/io.py
403 -404 -405 -406 -407 -408 -409 -410 -411 -412 -413 -414 |
|
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.py
51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 |
|
Helper functions for data models.
- - - -DatamodelDataframeIncompatableError
-
-
- ¶
- Bases: Exception
Raised when a data model and a dataframe are not compatable.
- -network_wrangler/utils/models.py
126 -127 -128 -129 |
|
TableValidationError
-
-
- ¶
- Bases: Exception
Raised when a table validation fails.
- -network_wrangler/utils/models.py
49 -50 -51 -52 |
|
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
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 |
|
default_from_datamodel(data_model, field)
-
- ¶Returns default value from pandera data model for a given field name.
- -network_wrangler/utils/models.py
41 -42 -43 -44 -45 -46 |
|
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
21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 |
|
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
132 -133 -134 -135 -136 -137 |
|
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
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 |
|
submodel_fields_in_model(model, instance=None)
-
- ¶Find the fields in a pydantic model that are submodels.
- -network_wrangler/utils/models.py
140 -141 -142 -143 -144 -145 -146 -147 -148 |
|
validate_df_to_model(df, model)
-
- ¶Wrapper to validate a DataFrame against a Pandera DataFrameModel with better logging.
- - -Parameters:
-Name | -Type | -Description | -Default | -
---|---|---|---|
df |
-
- DataFrame
- |
-
-
-
- DataFrame to validate. - |
- - required - | -
model |
-
- DataFrameModel
- |
-
-
-
- Pandera DataFrameModel to validate against. - |
- - required - | -
network_wrangler/utils/models.py
55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 |
|
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
6 - 7 - 8 - 9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 |
|
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.convert_timespan_to_start_end_dt(timespan_s)
-
- ¶Covert a timespan string [‘12:00’,‘14:00] to start_time and end_time datetime cols in df.
- -network_wrangler/utils/time.py
152 -153 -154 -155 -156 |
|
dt_contains(timespan1, timespan2)
-
- ¶Check if one timespan inclusively contains another.
- - -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
168 -169 -170 -171 -172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 |
|
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
227 -228 -229 -230 -231 -232 -233 -234 -235 -236 |
|
dt_overlap_duration(timedelta1, timedelta2)
-
- ¶Check if two timespans overlap and return the amount of overlap.
- -network_wrangler/utils/time.py
159 -160 -161 -162 -163 -164 -165 |
|
dt_overlaps(timespan1, timespan2)
-
- ¶Check if two 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
186 -187 -188 -189 -190 -191 -192 -193 -194 -195 |
|
dt_to_seconds_from_midnight(dt)
-
- ¶Convert a datetime object to the number of seconds since midnight.
- -network_wrangler/utils/time.py
71 -72 -73 |
|
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
239 -240 -241 -242 -243 -244 -245 -246 -247 -248 -249 -250 -251 -252 |
|
filter_df_to_max_overlapping_timespans(orig_df, query_timespan, strict_match=False, min_overlap_minutes=0, keep_max_of_cols=['model_link_id'])
-
- ¶Filters dataframe for entries that have maximum overlap with the given query timespan.
- - -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 0. - |
-
- 0
- |
-
keep_max_of_cols |
-
- list[str]
- |
-
-
-
- list of fields to return the maximum value of overlap for. If None,
-will return all overlapping time periods. Defaults to |
-
- ['model_link_id']
- |
-
network_wrangler/utils/time.py
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 |
|
filter_df_to_overlapping_timespans(orig_df, query_timespan)
-
- ¶Filters dataframe for entries that have any overlap with the given query timespan.
- - -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 - | -
network_wrangler/utils/time.py
87 - 88 - 89 - 90 - 91 - 92 - 93 - 94 - 95 - 96 - 97 - 98 - 99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 |
|
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
209 -210 -211 -212 -213 -214 -215 -216 -217 -218 -219 -220 -221 -222 -223 -224 |
|
format_time(seconds)
-
- ¶Formats seconds into a human-friendly string for log files.
- -network_wrangler/utils/time.py
255 -256 -257 -258 -259 -260 -261 -262 -263 -264 |
|
seconds_from_midnight_to_str(seconds)
-
- ¶Convert the number of seconds since midnight to a TimeString (HH:MM).
- -network_wrangler/utils/time.py
82 -83 -84 |
|
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
76 -77 -78 -79 |
|
str_to_time(time_str, base_date=None)
-
- ¶Convert TimeString (HH:MM<:SS>) to datetime object.
-If HH > 24, will add a day to the base_date.
- - -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
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 |
|
str_to_time_list(timespan)
-
- ¶Convert list of TimeStrings (HH:MM<:SS>) to list of datetime.time objects.
- -network_wrangler/utils/time.py
61 -62 -63 |
|
timespan_str_list_to_dt(timespans)
-
- ¶Convert list of TimespanStrings to list of datetime.time objects.
- -network_wrangler/utils/time.py
66 -67 -68 |
|
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
198 -199 -200 -201 -202 -203 -204 -205 -206 |
|
Utility functions for pandas data manipulation.
- - - -InvalidJoinFieldError
-
-
- ¶
- Bases: Exception
Raised when the join field is not unique.
- -network_wrangler/utils/data.py
64 -65 -66 -67 |
|
MissingPropertiesError
-
-
- ¶
- Bases: Exception
Raised when properties are missing from the dataframe.
- -network_wrangler/utils/data.py
58 -59 -60 -61 |
|
attach_parameters_to_df(df, params)
-
- ¶Attatch params as a dataframe attribute which will be copied with dataframe.
- -network_wrangler/utils/data.py
518 -519 -520 -521 -522 -523 -524 -525 -526 |
|
coerce_dict_to_df_types(d, df, skip_keys=[], 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 |
-
- list
- |
-
-
-
- list of dict keys to skip. Defaults to []/ - |
-
- []
- |
-
return_skipped |
-
- bool
- |
-
-
-
- keep the uncoerced, skipped keys/vals in the resulting dict. -Defaults to False. - |
-
- False
- |
-
Returns:
-Name | Type | -Description | -
---|---|---|
dict |
- dict
- |
-
-
-
- dict with coerced types - |
-
network_wrangler/utils/data.py
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 |
|
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
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 |
|
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 |
-
- Union[str, int, float, bool, list[Union[str, int, float, bool]]]
- |
-
-
-
- value or list of values to coerce - |
- - required - | -
df |
-
- DataFrame
- |
-
-
-
- dataframe to get types from - |
- - required - | -
network_wrangler/utils/data.py
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 |
|
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
628 -629 -630 -631 -632 -633 -634 -635 -636 -637 -638 -639 -640 -641 -642 -643 -644 -645 -646 -647 -648 -649 -650 |
|
compare_df_values(df1, df2, join_col=None, ignore=[], atol=1e-05)
-
- ¶Compare overlapping part of dataframes and returns where there are differences.
- -network_wrangler/utils/data.py
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 |
|
compare_lists(list1, list2)
-
- ¶Compare two lists.
- -network_wrangler/utils/data.py
326 -327 -328 -329 -330 |
|
convert_numpy_to_list(item)
-
- ¶Function to recursively convert numpy arrays to lists.
- -network_wrangler/utils/data.py
315 -316 -317 -318 -319 -320 -321 -322 -323 |
|
dict_fields_in_df(d, df)
-
- ¶Check if all fields in dict are in dataframe.
- -network_wrangler/utils/data.py
675 -676 -677 -678 -679 -680 -681 |
|
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
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 |
|
diff_dfs(df1, df2, ignore=[])
-
- ¶Returns True if two dataframes are different and log differences.
- -network_wrangler/utils/data.py
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 |
|
diff_list_like_series(s1, s2)
-
- ¶Compare two series that contain list-like items as strings.
- -network_wrangler/utils/data.py
333 -334 -335 -336 -337 -338 -339 -340 -341 -342 |
|
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
653 -654 -655 -656 -657 -658 -659 -660 -661 -662 -663 -664 -665 -666 -667 -668 -669 -670 -671 -672 |
|
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 |
-
- 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
213 -214 -215 -216 -217 -218 -219 -220 -221 -222 -223 -224 -225 -226 -227 -228 -229 |
|
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 | -
---|---|
- ValueError
- |
-
-
-
- If item list isn’t found in data in correct order. - |
-
Returns:
-Name | Type | -Description | -
---|---|---|
tuple |
- tuple[Union[Series, list, DataFrame]]
- |
-
-
-
- data broken out by beofore, selected segment, and after. - |
-
network_wrangler/utils/data.py
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 |
|
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, list, 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, list, DataFrame]]
- |
-
-
-
-
|
-
network_wrangler/utils/data.py
431 -432 -433 -434 -435 -436 -437 -438 -439 -440 -441 -442 -443 -444 -445 -446 -447 -448 -449 -450 -451 -452 -453 -454 -455 -456 -457 -458 -459 -460 -461 -462 -463 -464 -465 -466 -467 -468 -469 -470 -471 -472 -473 -474 -475 -476 -477 -478 -479 -480 -481 -482 -483 -484 -485 -486 |
|
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
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 |
|
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
529 -530 -531 -532 -533 -534 -535 -536 -537 -538 -539 -540 -541 -542 |
|
Helper geographic manipulation functions.
- - - -InvalidCRSError
-
-
- ¶
- Bases: Exception
Raised when a point is not valid for a given coordinate reference system.
- -network_wrangler/utils/geo.py
212 -213 -214 -215 |
|
MissingNodesError
-
-
- ¶
- Bases: Exception
Raised when referenced nodes are missing from the network.
- -network_wrangler/utils/geo.py
103 -104 -105 -106 |
|
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
218 -219 -220 -221 -222 -223 -224 -225 -226 -227 -228 -229 -230 -231 -232 -233 -234 -235 -236 -237 -238 |
|
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
32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 |
|
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 | -
---|---|
- Union[None, GeoSeries]
- |
-
-
-
- gpd.GeoSeries: The polygon geometry representing the bounding polygon. - |
-
network_wrangler/utils/geo.py
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 |
|
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
320 -321 -322 -323 -324 -325 -326 -327 -328 -329 -330 -331 -332 -333 -334 |
|
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
83 - 84 - 85 - 86 - 87 - 88 - 89 - 90 - 91 - 92 - 93 - 94 - 95 - 96 - 97 - 98 - 99 -100 |
|
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
191 -192 -193 -194 -195 -196 -197 -198 -199 -200 -201 -202 -203 -204 -205 -206 -207 -208 -209 |
|
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
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 |
|
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
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 |
|
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
366 -367 -368 -369 -370 -371 -372 -373 -374 -375 -376 -377 -378 -379 -380 -381 -382 -383 |
|
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
459 -460 -461 -462 -463 -464 -465 -466 -467 -468 -469 |
|
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
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 |
|
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
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 |
|
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 |
-
- GeoDataFrame
- |
-
-
-
- GeoDataFrame of nodes to use to convert model_node_id to geometry. - |
-
- None
- |
-
ref_road_net |
-
- '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
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 |
|
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
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 |
|
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
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 |
|
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
270 -271 -272 -273 -274 -275 -276 -277 -278 -279 -280 -281 -282 |
|
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
11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 |
|
__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
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 |
|
__init__(pandas_obj)
-
- ¶Initialization function for the dictionary query accessor.
- -network_wrangler/utils/df_accessors.py
30 -31 -32 |
|
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
63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 |
|
__call__()
-
- ¶Function to hash the dataframe.
- -network_wrangler/utils/df_accessors.py
74 -75 -76 -77 -78 |
|
__init__(pandas_obj)
-
- ¶Initialization function for the dataframe hash.
- -network_wrangler/utils/df_accessors.py
70 -71 -72 |
|
Logging utilities for Network Wrangler.
- - - -setup_logging(info_log_filename=None, debug_log_filename='wrangler_{}.debug.log'.format(datetime.now().strftime('%Y_%m_%d__%H_%M_%S')), 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 |
-
- str
- |
-
-
-
- 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 |
-
- str
- |
-
-
-
- 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()
- |
-
- format(strftime('%Y_%m_%d__%H_%M_%S'))
- |
-
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
13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 |
|