Example #1
0
def network():
    n = Network('epsg:27700')
    n.add_nodes({
        '5221390309039202089': {
            'x': 528344.70518,
            'y': 181583.80217
        },
        '5221390307703020221': {
            'x': 528328.94676,
            'y': 181736.07904
        },
        '5221390306965404303': {
            'x': 528320.26640,
            'y': 181814.06237
        },
    })
    n.add_links({
        'link_1': {
            'from':
            '5221390309039202089',
            'to':
            '5221390307703020221',
            'modes': ['car', 'walk'],
            'length':
            153.0294,
            'geometry':
            LineString([(528344.70518, 181583.80217),
                        (528342.99487, 181598.89393),
                        (528337.75892, 181652.61953),
                        (528333.77989, 181689.01855),
                        (528330.46435, 181722.27602),
                        (528328.94676, 181736.07904)])
        },
        'link_2': {
            'from':
            '5221390307703020221',
            'to':
            '5221390306965404303',
            'modes': ['car'],
            'length':
            78.443,
            'geometry':
            LineString([(528328.94676, 181736.07904),
                        (528327.95867, 181743.58574),
                        (528320.87099, 181810.80295),
                        (528320.2664, 181814.06237)])
        },
        'link_3': {
            'from':
            '5221390307703020221',
            'to':
            '5221390306965404303',
            'modes': ['walk'],
            'length':
            78.443,
            'geometry':
            LineString([(528328.94676, 181736.07904),
                        (528327.95867, 181743.58574),
                        (528320.87099, 181810.80295),
                        (528320.2664, 181814.06237)])
        },
        'link_4': {
            'from':
            '5221390306965404303',
            'to':
            '5221390307703020221',
            'modes': ['car', 'walk'],
            'length':
            78.443,
            'geometry':
            LineString([(528320.2664, 181814.06237),
                        (528320.87099, 181810.80295),
                        (528327.95867, 181743.58574),
                        (528328.94676, 181736.07904)])
        },
    })
    return n
def test_sanitising_geodataframes_with_ids_list(tmpdir):
    n = Network('epsg:27700')
    n.add_node('0',
               attribs={
                   'x': 528704.1425925883,
                   'y': 182068.78193707118,
                   's2_id': 7860190995130875979
               })
    n.add_node('1',
               attribs={
                   'x': 528804.1425925883,
                   'y': 182168.78193707118,
                   's2_id': 12118290696817869383
               })
    n.add_link('link_0',
               '0',
               '1',
               attribs={
                   'length': 123,
                   'modes': ['car', 'walk'],
                   'ids': ['1', '2']
               })

    correct_nodes = {
        'x': {
            '0': 528704.1425925883,
            '1': 528804.1425925883
        },
        'y': {
            '0': 182068.78193707118,
            '1': 182168.78193707118
        },
        's2_id': {
            '0': '7860190995130875979',
            '1': '12118290696817869383'
        }
    }
    correct_links = {
        'length': {
            'link_0': 123
        },
        'from': {
            'link_0': '0'
        },
        'to': {
            'link_0': '1'
        },
        'id': {
            'link_0': 'link_0'
        },
        'ids': {
            'link_0': '1,2'
        },
        'u': {
            'link_0': '0'
        },
        'v': {
            'link_0': '1'
        },
        'modes': {
            'link_0': 'car,walk'
        }
    }

    gdfs = gngeojson.generate_geodataframes(n.graph)
    nodes, links = gdfs['nodes'], gdfs['links']
    nodes = sanitiser.sanitise_geodataframe(nodes)
    links = sanitiser.sanitise_geodataframe(links)

    assert_semantically_equal(nodes[['x', 'y', 's2_id']].to_dict(),
                              correct_nodes)
    assert_semantically_equal(
        links[['length', 'from', 'to', 'id', 'ids', 'u', 'v',
               'modes']].to_dict(), correct_links)
Example #3
0
            raise Exception('Found more than one scenario with given name!')
        else:
            raise Exception('Scenario ' + scenario_name + ' not found in ' +
                            str(data_path) + ' !')

    return scenario_path


if __name__ == "__main__":

    data_path = sys.argv[1]
    scenario_name = sys.argv[2]

    scenario_path = get_scenario_path(data_path, scenario_name)

    n = Network('epsg:2177')
    with gzip.open(scenario_path + '/output/output_network.xml.gz', 'rb') as f:
        n.read_matsim_network(f)
    with gzip.open(scenario_path + '/output/output_transitSchedule.xml.gz',
                   'rb') as f:
        n.read_matsim_schedule(f)
    n.print()

    df = n.schedule.route_trips_to_dataframe()
    df.to_csv(scenario_path + '/vehicles.csv', index=None)

    df['id'] = df['vehicle_id']
    df['category'] = df.apply(lambda row: 'bus'
                              if 'bus' in row['vehicle_id'] else 'tram',
                              axis=1)
    df['tag'] = df['service_id']
Example #4
0
def network(correct_schedule):
    n = Network('epsg:27700')
    n.add_node('0', attribs={'x': 528704.1425925883, 'y': 182068.78193707118})
    n.add_node('1', attribs={'x': 528804.1425925883, 'y': 182168.78193707118})
    n.add_link('link_0',
               '0',
               '1',
               attribs={
                   'length': 123,
                   'modes': ['car', 'walk'],
                   'freespeed': 10,
                   'capacity': 5
               })
    n.add_link('link_1',
               '0',
               '1',
               attribs={
                   'length': 123,
                   'modes': ['bike'],
                   'attributes': {
                       'osm:way:highway': {
                           'name': 'osm:way:highway',
                           'class': 'java.lang.String',
                           'text': 'unclassified'
                       }
                   }
               })
    n.add_link('link_2', '1', '0', attribs={'length': 123, 'modes': ['rail']})

    n.schedule = correct_schedule
    return n