network_wrangler.Scenario

class network_wrangler.Scenario(base_scenario, project_cards=None)[source]

Bases: object

Holds information about a scenario.

Typical usage example:

my_base_scenario = {
    "road_net": RoadwayNetwork.read(
        link_filename=STPAUL_LINK_FILE,
        node_filename=STPAUL_NODE_FILE,
        shape_filename=STPAUL_SHAPE_FILE,
        fast=True,
    ),
    "transit_net": TransitNetwork.read(STPAUL_DIR),
}

card_filenames = [
    "3_multiple_roadway_attribute_change.yml",
    "multiple_changes.yml",
    "4_simple_managed_lane.yml",
]

project_card_directory = os.path.join(STPAUL_DIR, "project_cards")

project_cards_list = [
    ProjectCard.read(os.path.join(project_card_directory, filename), validate=False)
    for filename in card_filenames
]

my_scenario = Scenario.create_scenario(
  base_scenario=my_base_scenario,
  project_cards_list=project_cards_list,
)
my_scenario.check_scenario_requisites()

my_scenario.apply_all_projects()

my_scenario.scenario_summary()
base_scenario

dictionary representation of a scenario

project_cards

list of Project Card Instances

Type:

Optional

road_net

instance of RoadwayNetwork for the scenario

transit_net

instance of TransitNetwork for the scenario

applied_projects

list of project names that have been applied

project_cards

list of project card instances

ordered_project_cards
prerequisites

dictionary storing prerequiste information

corequisites

dictionary storing corequisite information

conflicts

dictionary storing conflict information

requisites_checked

boolean indicating if the co- and pre-requisites have been checked in the project cards

conflicts_checked

boolean indicating if the project conflicts have been checked

has_requisite_error

boolean indicating if there is a conflict in the pre- or co-requisites of project cards

has_conflict_error

boolean indicating if there is are conflicting project cards

prerequisites_sorted

boolean indicating if the project cards have been sorted to make sure cards that are pre-requisites are applied first

__init__(base_scenario, project_cards=None)[source]

Constructor

args: base_scenario: dict the base scenario project_cards: list this scenario’s project cards

Methods

__init__(base_scenario[, project_cards])

Constructor

add_project_card_from_file(project_card_filename)

add_project_cards_from_directory(folder[, ...])

Adds projects cards to the scenario.

add_project_cards_from_tags(folder[, tags, ...])

Adds projects cards to the scenario.

applied_project_card_summary(...)

Create a summary of applied project card and what they changed for the scenario.

apply_all_projects()

apply_project(p)

check_scenario_conflicts()

Checks if there are any conflicting projects in the scenario Fail if the project A specifies that project B is a conflict and project B is included in the scenario

check_scenario_requisites()

Checks if there are any missing pre- or co-requisite projects in the scenario Fail if the project A specifies that project B is a pre- or co-requisite and project B is not included in the scenario

create_base_scenario(base_shape_name, ...[, ...])

rtype:

Scenario

create_scenario([base_scenario, ...])

Validates project cards with a specific tag from the specified folder or list of user specified project cards and creates a scenario object with the valid project card.

get_project_names()

Returns a list of project names

order_project_cards()

create a list of project cards such that they are in order based on pre-requisites

remove_all_projects()

scenario_summary([project_detail, outfile, mode])

A high level summary of the created scenario.

add_project_card_from_file(project_card_filename, validate=True, tags=[])[source]
add_project_cards_from_directory(folder, glob_search='', validate=True)[source]

Adds projects cards to the scenario. A folder is provided to look for project cards and if applicable, a glob-style search.

i.e. glob_search = ‘road*.yml’

args: folder: the folder location where the project cards will be glob_search: https://docs.python.org/2/library/glob.html

add_project_cards_from_tags(folder, tags=[], glob_search='', validate=True)[source]

Adds projects cards to the scenario. A folder is provided to look for project cards that have a matching tag that is passed to the method.

args: folder: the folder location where the project cards will be tags: only project cards with these tags will be validated and added to the returning scenario

applied_project_card_summary(project_card_dictionary)[source]

Create a summary of applied project card and what they changed for the scenario.

Return type:

dict

Parameters:

project_card_dictionary – dictionary representation of the values of a project card (i.e. ProjectCard.__dict__ )

Returns:

A dict of project summary change dictionaries for each change

apply_all_projects()[source]
apply_project(p)[source]
check_scenario_conflicts()[source]

Checks if there are any conflicting projects in the scenario Fail if the project A specifies that project B is a conflict and project B is included in the scenario

Returns: boolean indicating if the check was successful or returned an error

Return type:

bool

check_scenario_requisites()[source]

Checks if there are any missing pre- or co-requisite projects in the scenario Fail if the project A specifies that project B is a pre- or co-requisite and project B is not included in the scenario

Returns: boolean indicating if the checks were successful or returned an error

Return type:

bool

static create_base_scenario(base_shape_name, base_link_name, base_node_name, roadway_dir='', transit_dir='', validate=True, **kwargs)[source]
Return type:

Scenario

Parameters:
  • roadway_dir (optional) – path to the base scenario roadway network files

  • base_shape_name – filename of the base network shape

  • base_link_name – filename of the base network link

  • base_node_name – filename of the base network node

  • transit_dir (optional) – path to base scenario transit files

  • validate – boolean indicating whether to validate the base network or not

static create_scenario(base_scenario={}, card_directory='', tags=None, project_cards_list=[], glob_search='', validate_project_cards=True)[source]

Validates project cards with a specific tag from the specified folder or list of user specified project cards and creates a scenario object with the valid project card.

Parameters:
  • base_scenario – object dictionary for the base scenario (i.e. my_base_scenario.__dict__)

  • tags – only project cards with these tags will be read/validated

  • folder – the folder location where the project cards will be

  • project_cards_list – list of project cards to be applied

  • glob_search

get_project_names()[source]

Returns a list of project names

Return type:

list

order_project_cards()[source]

create a list of project cards such that they are in order based on pre-requisites

Returns: ordered list of project cards to be applied to scenario

remove_all_projects()[source]
scenario_summary(project_detail=True, outfile='', mode='a')[source]

A high level summary of the created scenario.

Return type:

str

Parameters:
  • project_detail – If True (default), will write out project card summaries.

  • outfile – If specified, will write scenario summary to text file.

  • mode – Outfile open mode. ‘a’ to append ‘w’ to overwrite.

Returns:

string of summary