コード例 #1
0
def test_roadway_read_write(request):
    print("\n--Starting:",request.node.name)

    out_prefix = "t_readwrite"
    out_shape_file = os.path.join(SCRATCH_DIR,out_prefix+"_"+"shape.geojson")
    out_link_file  = os.path.join(SCRATCH_DIR,out_prefix+"_"+"link.json")
    out_node_file  = os.path.join(SCRATCH_DIR,out_prefix+"_"+"node.geojson")

    time0 = time.time()

    net = RoadwayNetwork.read(link_file= STPAUL_LINK_FILE, node_file=STPAUL_NODE_FILE, shape_file=STPAUL_SHAPE_FILE, fast=True)
    time1 = time.time()
    print("Writing to: {}".format(SCRATCH_DIR))
    net.write(filename=out_prefix,path=SCRATCH_DIR)
    time2 = time.time()
    net_2 = RoadwayNetwork.read(link_file= out_link_file, node_file=out_node_file, shape_file=out_shape_file)
    time3 = time.time()

    read_time1 = time1-time0
    read_time2 = time3-time2
    write_time = time2-time1

    print("TIME, read (w/out valdiation, with): {},{}".format(read_time1, read_time2))
    print("TIME, write:{}".format(write_time))
    '''
コード例 #2
0
def test_quick_roadway_read_write(request):
    print("\n--Starting:",request.node.name)

    out_prefix = "t_readwrite"
    out_shape_file = os.path.join(SCRATCH_DIR,out_prefix+"_"+"shape.geojson")
    out_link_file  = os.path.join(SCRATCH_DIR,out_prefix+"_"+"link.json")
    out_node_file  = os.path.join(SCRATCH_DIR,out_prefix+"_"+"node.geojson")
    net = RoadwayNetwork.read(link_file= SMALL_LINK_FILE, node_file=SMALL_NODE_FILE, shape_file=SMALL_SHAPE_FILE, fast=True)
    net.write(filename=out_prefix,path=SCRATCH_DIR)
    net_2 = RoadwayNetwork.read(link_file= out_link_file, node_file=out_node_file, shape_file=out_shape_file)
    print("--Finished:",request.node.name)
コード例 #3
0
def test_select_roadway_features_from_projectcard(request):
    print("\n--Starting:",request.node.name)

    print("Reading network ...")
    net = RoadwayNetwork.read(link_file= STPAUL_LINK_FILE, node_file=STPAUL_NODE_FILE, shape_file=STPAUL_SHAPE_FILE, fast=True)

    print("Reading project card ...")
    #project_card_name = '1_simple_roadway_attribute_change.yml'
    #project_card_name = '2_multiple_roadway.yml'
    project_card_name = '3_multiple_roadway_attribute_change.yml'

    project_card_path = os.path.join(os.getcwd(),'example','stpaul','project_cards',project_card_name)
    project_card = ProjectCard.read(project_card_path)

    print("Selecting roadway features ...")
    sel = project_card.facility
    print("Selection:\n",sel)
    selected_links = net.select_roadway_features(sel)

    if not type(selected_links) == GeoDataFrame:
        print("Couldn't find path from {} to {}".format(sel['A'],sel['B']))
    else:
        print("Features selected:",len(selected_links))

    print("--Finished:",request.node.name)
コード例 #4
0
def test_write_model_net(request):
    print("\n--Starting:", request.node.name)

    print("Reading network ...")

    net = RoadwayNetwork.read(
        link_file=STPAUL_LINK_FILE,
        node_file=STPAUL_NODE_FILE,
        shape_file=STPAUL_SHAPE_FILE,
        fast=True,
    )

    print("Reading project card ...")
    project_card_name = "5_managed_lane.yml"
    project_card_path = os.path.join(STPAUL_DIR, "project_cards", project_card_name)
    project_card = ProjectCard.read(project_card_path)

    net.apply(project_card.__dict__)
    net.links_df.to_csv(os.path.join(SCRATCH_DIR, "in_ml_links.csv"), index=False)
    net.nodes_df.to_csv(os.path.join(SCRATCH_DIR, "in_ml_nodes.csv"), index=False)
    net.shapes_df.to_csv(os.path.join(SCRATCH_DIR, "in_ml_shape.csv"), index=False)

    ml_net = net.create_managed_lane_network(in_place=False)
    ml_net.links_df.to_csv(os.path.join(SCRATCH_DIR, "out_ml_links.csv"), index=False)
    ml_net.nodes_df.to_csv(os.path.join(SCRATCH_DIR, "out_ml_nodes.csv"), index=False)
    ml_net.shapes_df.to_csv(os.path.join(SCRATCH_DIR, "out_ml_shape.csv"), index=False)

    print("--Finished:", request.node.name)
コード例 #5
0
def _read_stpaul_net():
    net = RoadwayNetwork.read(
        link_file=STPAUL_LINK_FILE,
        node_file=STPAUL_NODE_FILE,
        shape_file=STPAUL_SHAPE_FILE,
        fast=True,
    )
    return net
コード例 #6
0
def test_set_roadnet(request):
    print("\n--Starting:", request.node.name)

    road_net = RoadwayNetwork.read(
        link_file=os.path.join(STPAUL_DIR, "link.json"),
        node_file=os.path.join(STPAUL_DIR, "node.geojson"),
        shape_file=os.path.join(STPAUL_DIR, "shape.geojson"),
        fast=True
    )
    transit_net = TransitNetwork.read(STPAUL_DIR)
    transit_net.set_roadnet(road_net)

    print("--Finished:", request.node.name)
コード例 #7
0
def test_network_connectivity(request):
    print("\n--Starting:", request.node.name)

    print("Reading network ...")

    net = RoadwayNetwork.read(
        link_file=STPAUL_LINK_FILE,
        node_file=STPAUL_NODE_FILE,
        shape_file=STPAUL_SHAPE_FILE,
        fast=True,
    )
    print("Checking network connectivity ...")
    print("Drive Network Connected:", net.is_network_connected(mode="drive"))
    print("--Finished:", request.node.name)
コード例 #8
0
def test_network_connectivity_ignore_single_nodes(request):
    print("\n--Starting:", request.node.name)

    print("Reading network ...")

    net = RoadwayNetwork.read(
        link_file=STPAUL_LINK_FILE,
        node_file=STPAUL_NODE_FILE,
        shape_file=STPAUL_SHAPE_FILE,
        fast=True,
    )
    print("Assessing network connectivity for walk...")
    _, disconnected_nodes = net.assess_connectivity(mode="walk", ignore_end_nodes=True)
    print("{} Disconnected Subnetworks:".format(len(disconnected_nodes)))
    print("-->\n{}".format("\n".join(list(map(str,disconnected_nodes)))))
    print("--Finished:", request.node.name)
コード例 #9
0
def test_get_modal_network(request):
    print("\n--Starting:", request.node.name)

    mode = "transit"
    print("Reading network. Mode: {} ...".format(mode))

    net = RoadwayNetwork.read(
        link_file=STPAUL_LINK_FILE,
        node_file=STPAUL_NODE_FILE,
        shape_file=STPAUL_SHAPE_FILE,
        fast=True,
    )
    _links_df, _nodes_df = RoadwayNetwork.get_modal_links_nodes(
        net.links_df, net.nodes_df, mode=mode,
    )
    mode_variable = RoadwayNetwork.MODES_TO_NETWORK_LINK_VARIABLES[mode]
    non_transit_links =_links_df[_links_df[mode_variable] != 1]
    assert non_transit_links.shape[0] == 0
コード例 #10
0
ファイル: test_roadway.py プロジェクト: wsp-sag/Lasso
def test_calculate_area_type(request):
    """
    Tests that parameters are read
    """
    print("\n--Starting:", request.node.name)

    net = RoadwayNetwork.read(
        link_file=STPAUL_LINK_FILE,
        node_file=STPAUL_NODE_FILE,
        shape_file=STPAUL_SHAPE_FILE,
        fast=True,
    )

    model_road_net = ModelRoadwayNetwork.from_RoadwayNetwork(net)

    model_road_net.calculate_area_type()
    assert "area_type" in net.links_df.columns
    print("Area Type  Frequency")
    print(net.links_df.area_type.value_counts())
コード例 #11
0
def test_select_roadway_features(request):
    print("\n--Starting:",request.node.name)
    net = RoadwayNetwork.read(link_file= STPAUL_LINK_FILE, node_file=STPAUL_NODE_FILE, shape_file=STPAUL_SHAPE_FILE, fast=True)

    test_selections = { \
    "1. simple": {
     'link':{'name': ['6th','Sixth','sixth']},
     'A':{'osmNodeId': '187899923'},
     'B':{'osmNodeId': '187865924'},
     'answer': ['187899923', '187858777', '187923585', '187865924'],
    },
    "2. farther": {
     'link':{'name': ['6th','Sixth','sixth']},
     'A':{'osmNodeId': '187899923'}, # start searching for segments at A
     'B':{'osmNodeId': '187942339'}
    },
    "3. multi-criteria": {
     'link':{
        'name': ['6th','Sixth','sixth'],
        'LANES': [1,2],
        },
     'A':{'osmNodeId': '187899923'}, # start searching for segments at A
     'B':{'osmNodeId': '187942339'}
    }
    }

    for i,sel in test_selections.items():
        print("--->",i,"\n",sel)
        path_found = False
        selected_links = net.select_roadway_features(sel)
        if not type(selected_links) == GeoDataFrame:
            print("Couldn't find path from {} to {}".format(sel['A'],sel['B']))
        else:
            print("Features selected:",len(selected_links))
            selected_nodes = [str(sel['A']['osmNodeId'])]+selected_links['v'].tolist()
            #print("Nodes selected: ",selected_nodes)

            if 'answer' in sel.keys():
                print("Expected Answer: ",sel['answer'])
                assert(set(selected_nodes) == set(sel['answer']))

    print("--Finished:",request.node.name)
コード例 #12
0
def test_roadway_feature_change(request):
    print("\n--Starting:",request.node.name)

    print("Reading network ...")
    net = RoadwayNetwork.read(link_file= STPAUL_LINK_FILE, node_file=STPAUL_NODE_FILE, shape_file=STPAUL_SHAPE_FILE, fast=True)

    project_card_set = [
        (net, '1_simple_roadway_attribute_change.yml'),
        (net, '2_multiple_roadway.yml'),
        (net, '3_multiple_roadway_attribute_change.yml'),
    ]

    for my_net, project_card_name in project_card_set:
        project_card_path = os.path.join(os.getcwd(),'example','stpaul','project_cards',project_card_name)
        print("Reading project card from:\n {}".format(project_card_path))
        project_card = ProjectCard.read(project_card_path)

        roadway_feature_change(my_net, project_card)

    print("--Finished:",request.node.name)
コード例 #13
0
def test_transit_road_consistencies(request):
    print("\n--Starting:", request.node.name)
    net = TransitNetwork.read(STPAUL_DIR)

    STPAUL_SHAPE_FILE = os.path.join(STPAUL_DIR, "shape.geojson")
    STPAUL_LINK_FILE = os.path.join(STPAUL_DIR, "link.json")
    STPAUL_NODE_FILE = os.path.join(STPAUL_DIR, "node.geojson")

    road_net = RoadwayNetwork.read(
        link_file=STPAUL_LINK_FILE,
        node_file=STPAUL_NODE_FILE,
        shape_file=STPAUL_SHAPE_FILE,
        fast=True,
    )

    net.set_roadnet(road_net=road_net)

    net.validate_road_network_consistencies()
    print(net.validated_road_network_consistency)
    print("--Finished:", request.node.name)
コード例 #14
0
def test_existing_managed_lane_apply(request):
    print("\n--Starting:", request.node.name)

    print("Reading network ...")

    net = RoadwayNetwork.read(
        link_file=STPAUL_LINK_FILE,
        node_file=STPAUL_NODE_FILE,
        shape_file=STPAUL_SHAPE_FILE,
        fast=True,
    )

    print("Reading project card ...")
    project_card_name = "4_simple_managed_lane.yml"
    project_card_path = os.path.join(STPAUL_DIR, "project_cards",
                                     project_card_name)
    project_card = ProjectCard.read(project_card_path)

    print("Selecting roadway features ...")
    selected_link_indices = net.select_roadway_features(project_card.facility)

    if "managed" in net.links_df.columns:
        existing_ml_links = len(
            (net.links_df[net.links_df["managed"] == 1]).index)
    else:
        existing_ml_links = 0

    print("Existing # of ML links in the network:", existing_ml_links)

    net.apply_managed_lane_feature_change(
        net.select_roadway_features(project_card.facility),
        project_card.properties)

    new_ml_links = len((net.links_df[net.links_df["managed"] == 1]).index)
    print("New # of ML links in the network:", new_ml_links)

    assert new_ml_links == existing_ml_links + len(selected_link_indices)

    print("--Finished:", request.node.name)
コード例 #15
0
def test_apply_summary_wrappers(request):
    print("\n--Starting:", request.node.name)

    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
    ]

    base_scenario = {
        "road_net":
        RoadwayNetwork.read(
            link_file=STPAUL_LINK_FILE,
            node_file=STPAUL_NODE_FILE,
            shape_file=STPAUL_SHAPE_FILE,
            fast=True,
        ),
        "transit_net":
        TransitNetwork.read(STPAUL_DIR),
    }

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

    my_scenario.apply_all_projects()

    my_scenario.scenario_summary()

    print("--Finished:", request.node.name)
コード例 #16
0
def test_get_modal_network(request):
    print("\n--Starting:", request.node.name)

    mode = "transit"
    print("Reading network. Mode: {} ...".format(mode))

    net = RoadwayNetwork.read(
        link_file=STPAUL_LINK_FILE,
        node_file=STPAUL_NODE_FILE,
        shape_file=STPAUL_SHAPE_FILE,
        fast=True,
    )
    _links_df, _nodes_df = RoadwayNetwork.get_modal_links_nodes(
        net.links_df,
        net.nodes_df,
        modes=[mode],
    )

    test_links_of_selection = _links_df["model_link_id"].tolist()
    print("TEST - Number of selected links: {}".format(
        len(test_links_of_selection)))

    mode_variables = RoadwayNetwork.MODES_TO_NETWORK_LINK_VARIABLES[mode]

    control_links_of_selection = []
    for m in mode_variables:
        control_links_of_selection.extend(net.links_df.loc[net.links_df[m],
                                                           "model_link_id"])
    print("CONTROL - Number of selected links: {}".format(
        len(control_links_of_selection)))

    all_model_link_ids = _links_df["model_link_id"].tolist()
    print("CONTROL - Number of total links: {}".format(
        len(all_model_link_ids)))

    assert set(test_links_of_selection) == set(control_links_of_selection)