def test_reading_network_with_geometry_attributes(): correct_links = {'1': { 'id': "1", 'from': "25508485", 'to': "21667818", 'length': 52.765151087870265, 's2_from': 5221390301001263407, 's2_to': 5221390302696205321, 'freespeed': 4.166666666666667, 'capacity': 600.0, 'permlanes': 1.0, 'oneway': "1", 'geometry': LineString([(1, 2), (2, 3), (3, 4)]), 'modes': {'car'}, 'attributes': { 'osm:way:access': {'name': 'osm:way:access', 'class': 'java.lang.String', 'text': 'permissive'}, 'osm:way:highway': {'name': 'osm:way:highway', 'class': 'java.lang.String', 'text': 'unclassified'}, 'osm:way:id': {'name': 'osm:way:id', 'class': 'java.lang.Long', 'text': '26997928'}, 'osm:way:name': {'name': 'osm:way:name', 'class': 'java.lang.String', 'text': 'Brunswick Place'} }}, '2': { 'id': "2", 'from': "25508485", 'to': "21667818", 'length': 52.765151087870265, 's2_from': 5221390301001263407, 's2_to': 5221390302696205321, 'freespeed': 4.166666666666667, 'capacity': 600.0, 'permlanes': 1.0, 'oneway': "1", 'geometry': LineString([(1, 2), (2, 3), (3, 4)]), 'modes': {'car'}, 'attributes': { 'osm:way:access': {'name': 'osm:way:access', 'class': 'java.lang.String', 'text': 'permissive'}, 'osm:way:highway': {'name': 'osm:way:highway', 'class': 'java.lang.String', 'text': 'unclassified'}, 'osm:way:id': {'name': 'osm:way:id', 'class': 'java.lang.Long', 'text': '26997928'}, 'osm:way:name': {'name': 'osm:way:name', 'class': 'java.lang.String', 'text': 'Brunswick Place'} }} } n = read.read_matsim(path_to_network=pt2matsim_network_with_geometry_file, epsg='epsg:27700') assert_semantically_equal(dict(n.links()), correct_links)
def test_reading_NZ_network(): n = read.read_matsim(path_to_network=pt2matsim_NZ_network, epsg='epsg:2193') assert_semantically_equal(dict(n.nodes()), { '7872447671905026061': {'id': '7872447671905026061', 'x': 1789300.631705982, 'y': 5494320.626099871, 'lon': 175.23998223484716, 'lat': -40.68028521526985, 's2_id': 7872447671905026061}, '7858001326813216825': {'id': '7858001326813216825', 'x': 1756643.5667029365, 'y': 5937269.480530882, 'lon': 174.75350860744126, 'lat': -36.697337065329855, 's2_id': 7858001326813216825}}) assert_semantically_equal(dict(n.links()), { '1': {'id': '1', 'from': '7858001326813216825', 'to': '7872447671905026061', 'freespeed': 4.166666666666667, 'capacity': 600.0, 'permlanes': 1.0, 'oneway': '1', 'modes': {'car', 'walk'}, 's2_from': 7858001326813216825, 's2_to': 7872447671905026061, 'attributes': { 'osm:way:access': {'name': 'osm:way:access', 'class': 'java.lang.String', 'text': 'permissive'}}, 'length': 52.765151087870265}})
def test_reading_network_with_singular_geometry_attribute_cleans_up_empty_attributes_dict(): correct_links = { '1': { 'id': "1", 'from': "25508485", 'to': "21667818", 'length': 52.765151087870265, 's2_from': 5221390301001263407, 's2_to': 5221390302696205321, 'freespeed': 4.166666666666667, 'capacity': 600.0, 'permlanes': 1.0, 'oneway': "1", 'geometry': LineString([(1, 2), (2, 3), (3, 4)]), 'modes': {'car'} }, '2': { 'id': "2", 'from': "25508485", 'to': "21667818", 'length': 52.765151087870265, 's2_from': 5221390301001263407, 's2_to': 5221390302696205321, 'freespeed': 4.166666666666667, 'capacity': 600.0, 'permlanes': 1.0, 'oneway': "1", 'geometry': LineString([(1, 2), (2, 3), (3, 4)]), 'modes': {'car'} } } n = read.read_matsim(path_to_network=pt2matsim_network_with_singular_geometry_file, epsg='epsg:27700') assert_semantically_equal(dict(n.links()), correct_links)
def test_reading_matsim_output_network(): n = read.read_matsim(path_to_network=matsim_output_network, epsg='epsg:27700') correct_nodes = { '21667818': {'id': '21667818', 's2_id': 5221390302696205321, 'x': 528504.1342843144, 'y': 182155.7435136598, 'lon': -0.14910908709500162, 'lat': 51.52370573323939}, '25508485': {'id': '25508485', 's2_id': 5221390301001263407, 'x': 528489.467895946, 'y': 182206.20303669578, 'lon': -0.14930198709481451, 'lat': 51.524162533239284}} correct_edge = {'id': '1', 'from': '25508485', 'to': '21667818', 'freespeed': 4.166666666666667, 'capacity': 600.0, 'permlanes': 1.0, 'oneway': '1', 'modes': {'car', 'subway', 'metro', 'walk'}, 's2_from': 5221390301001263407, 's2_to': 5221390302696205321, 'length': 52.765151087870265, 'attributes': {'osm:way:access': {'name': 'osm:way:access', 'class': 'java.lang.String', 'text': 'permissive'}, 'osm:way:highway': {'name': 'osm:way:highway', 'class': 'java.lang.String', 'text': 'unclassified'}, 'osm:way:id': {'name': 'osm:way:id', 'class': 'java.lang.Long', 'text': '26997928'}, 'osm:way:name': {'name': 'osm:way:name', 'class': 'java.lang.String', 'text': 'Brunswick Place'}}} assert_semantically_equal(dict(n.graph.nodes(data=True)), correct_nodes) assert_semantically_equal(list(n.graph.edges(data=True))[0][2], correct_edge)
def test_nodes_with_elevation_written_correctly_to_xml_network( tmpdir, network_dtd): network = Network('epsg:27700') network.add_node('0', attribs={ 'id': '0', 'x': 1, 'y': 2, 'z': 3, 'lat': 1, 'lon': 2 }) network.add_node('1', attribs={ 'id': '1', 'x': 2, 'y': 2, 'z': 0, 'lat': 2, 'lon': 2 }) network.add_link('0', '0', '1', attribs={ 'id': '0', 'from': '0', 'to': '1', 'length': 1, 'freespeed': 1, 'capacity': 20, 'permlanes': 1, 'oneway': '1', 'modes': ['car'] }) network.write_to_matsim(tmpdir) generated_network_file_path = os.path.join(tmpdir, 'network.xml') _network_from_file = read.read_matsim( path_to_network=generated_network_file_path, epsg='epsg:27700') assert_semantically_equal( dict(_network_from_file.nodes()), { '0': { 'id': '0', 'x': 1.0, 'y': 2.0, 'z': 3.0, 'lon': -7.557148039524952, 'lat': 49.766825803756994, 's2_id': 5205973754090365183 }, '1': { 'id': '1', 'x': 2.0, 'y': 2.0, 'z': 0.0, 'lon': -7.557134218911724, 'lat': 49.766826468710484, 's2_id': 5205973754090480551 } })
def test_network_with_extra_attribs_produces_valid_matsim_network_xml_file( tmpdir, network_dtd): network = Network('epsg:27700') network.add_node('0', attribs={ 'id': '0', 'x': 1, 'y': 2, 'lat': 1, 'lon': 2 }) network.add_node('1', attribs={ 'id': '1', 'x': 2, 'y': 2, 'lat': 2, 'lon': 2 }) network.add_link('0', '0', '1', attribs={ 'id': '0', 'from': '0', 'to': '1', 'length': 1, 'freespeed': 1, 'capacity': 20, 'permlanes': 1, 'oneway': '1', 'modes': ['car'], 'extra_Special_attrib': 12 }) network.write_to_matsim(tmpdir) generated_network_file_path = os.path.join(tmpdir, 'network.xml') xml_obj = lxml.etree.parse(generated_network_file_path) assert network_dtd.validate(xml_obj), \ 'Doc generated at {} is not valid against DTD due to {}'.format(generated_network_file_path, network_dtd.error_log.filter_from_errors()) _network_from_file = read.read_matsim( path_to_network=generated_network_file_path, epsg='epsg:27700') assert_semantically_equal( dict(_network_from_file.nodes()), { '0': { 'id': '0', 'x': 1.0, 'y': 2.0, 'lon': -7.557148039524952, 'lat': 49.766825803756994, 's2_id': 5205973754090365183 }, '1': { 'id': '1', 'x': 2.0, 'y': 2.0, 'lon': -7.557134218911724, 'lat': 49.766826468710484, 's2_id': 5205973754090480551 } }) assert_semantically_equal( dict(_network_from_file.links()), { '0': { 'id': '0', 'from': '0', 'to': '1', 'freespeed': 1.0, 'capacity': 20.0, 'permlanes': 1.0, 'oneway': '1', 'modes': {'car'}, 's2_from': 5205973754090365183, 's2_to': 5205973754090480551, 'length': 1.0 } })
def network_object(): network_xml_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "test_data/road_pricing/network.xml")) yield read.read_matsim(path_to_network=network_xml_path, epsg='epsg:27700')
def network_object_from_test_data(): return read.read_matsim(path_to_network=pt2matsim_network_test_file, path_to_schedule=pt2matsim_schedule_file, path_to_vehicles=pt2matsim_vehicles_file, epsg='epsg:27700')
def test_uses_node_elevation_data_when_present_in_network_file(tmpdir): nodes_with_elevations = { '1': { 'id': '1', 'x': 114.161432, 'y': 22.279784, 'z': 25.0, 'lon': 114.161432, 'lat': 22.279784, 's2_id': 3748121220106005759 }, '2': { 'id': '2', 'x': 114.159648, 'y': 22.278037, 'z': 53.0, 'lon': 114.159648, 'lat': 22.278037, 's2_id': 3748121226099361651 } } links = { '0': { 'id': '0', 'from': '1', 'to': '2', 'freespeed': 4.166666666666667, 'capacity': 600.0, 'permlanes': 1.0, 'oneway': '1', 'modes': {'car'}, 's2_from': 3748121220106005759, 's2_to': 3748121226099361651, 'attributes': { 'osm:way:access': { 'name': 'osm:way:access', 'class': 'java.lang.String', 'text': 'permissive' }, 'osm:way:highway': { 'name': 'osm:way:highway', 'class': 'java.lang.String', 'text': 'unclassified' }, 'osm:way:id': { 'name': 'osm:way:id', 'class': 'java.lang.Long', 'text': '26997928564' }, 'osm:way:name': { 'name': 'osm:way:name', 'class': 'java.lang.String', 'text': 'Elevation Lane' } }, 'length': 52.765151087870265 } } network_file_path = make_network_with_elevations_xml_file(nodes_with_elevations, links, '{}/small-network-with-elevations.xml'.format(tmpdir)) n = read.read_matsim(path_to_network=network_file_path, epsg='epsg:4326') assert_semantically_equal(dict(n.nodes()), nodes_with_elevations) assert_semantically_equal(dict(n.links()), links)
def test_network(): return read.read_matsim(path_to_network=network_test_file, epsg='epsg:27700', path_to_schedule=schedule_test_file)