def test_time_space_diagram_merge(self): dir_path = os.path.dirname(os.path.realpath(__file__)) emission_data = tsd.import_data_from_emission( os.path.join(dir_path, 'test_files/merge_emission.csv')) flow_params = tsd.get_flow_params( os.path.join(dir_path, 'test_files/merge.json')) pos, speed, _ = tsd.get_time_space_data(emission_data, flow_params) expected_pos = np.array( [[4.86, 180.32, 361.32, 547.77, 0], [4.88, 180.36, 361.36, 547.8, 0], [4.95, 180.43, 361.44, 547.87, 0], [5.06, 180.54, 361.56, 547.98, 0], [5.21, 180.68, 361.72, 548.12, 0], [5.4, 180.86, 0, 0, 0]] ) expected_speed = np.array( [[0, 0, 0, 0, 0], [0.15, 0.17, 0.19, 0.14, 0], [0.35, 0.37, 0.39, 0.34, 0], [0.54, 0.57, 0.59, 0.54, 0], [0.74, 0.7, 0.79, 0.71, 0], [0.94, 0.9, 0, 0, 0]] ) np.testing.assert_array_almost_equal(pos, expected_pos) np.testing.assert_array_almost_equal(speed, expected_speed)
def test_time_space_diagram_I210(self): dir_path = os.path.dirname(os.path.realpath(__file__)) module = __import__("examples.exp_configs.non_rl", fromlist=["i210_subnetwork"]) flow_params = getattr(module, "i210_subnetwork").flow_params emission_data = tsd.import_data_from_trajectory( os.path.join(dir_path, 'test_files/i210_emission.csv'), flow_params) segs, _ = tsd.get_time_space_data(emission_data, flow_params) expected_segs = { 1: np.array([[[0.8, 5.1], [1.6, 23.37]], [[1.6, 23.37], [2.4, 42.02]], [[2.4, 42.02], [3.2, 61.21]], [[3.2, 61.21], [4., 18.87]], [[4., 18.87], [4.8, 39.93]], [[2.4, 5.1], [3.2, 22.97]], [[3.2, 22.97], [4., 40.73]]]), 2: np.array([[[2.4, 5.1], [3.2, 23.98]], [[3.2, 23.98], [4., 43.18]]]), 3: np.array([[[0.8, 5.1], [1.6, 23.72]], [[1.6, 23.72], [2.4, 43.06]], [[2.4, 43.06], [3.2, 1.33]], [[3.2, 1.33], [4., 21.65]], [[4., 21.65], [4.8, 43.46]], [[2.4, 5.1], [3.2, 23.74]], [[3.2, 23.74], [4., 42.38]]]), 4: np.array([[[2.4, 5.1], [3.2, 23.6]], [[3.2, 23.6], [4., 42.46]]]) } for lane, expected_seg in expected_segs.items(): np.testing.assert_array_almost_equal(segs[lane], expected_seg)
def test_time_space_diagram_ring_road(self): dir_path = os.path.dirname(os.path.realpath(__file__)) emission_data = tsd.import_data_from_emission( os.path.join(dir_path, 'test_files/loop_230_emission.csv')) flow_params = tsd.get_flow_params( os.path.join(dir_path, 'test_files/loop_230.json')) pos, speed, _ = tsd.get_time_space_data(emission_data, flow_params) expected_pos = np.array( [[0.0000e+00, 9.5500e+00, 9.5550e+01, 1.0510e+02, 1.1465e+02, 1.2429e+02, 1.3384e+02, 1.4338e+02, 1.5293e+02, 1.6247e+02, 1.7202e+02, 1.8166e+02, 1.9090e+01, 1.9121e+02, 2.0075e+02, 2.8640e+01, 3.8180e+01, 4.7730e+01, 5.7270e+01, 6.6920e+01, 7.6460e+01, 8.6010e+01], [1.0000e-02, 9.5500e+00, 9.5560e+01, 1.0511e+02, 1.1465e+02, 1.2430e+02, 1.3384e+02, 1.4339e+02, 1.5294e+02, 1.6248e+02, 1.7203e+02, 1.8167e+02, 1.9100e+01, 1.9122e+02, 2.0076e+02, 2.8640e+01, 3.8190e+01, 4.7740e+01, 5.7280e+01, 6.6930e+01, 7.6470e+01, 8.6020e+01], [2.0000e-02, 9.5700e+00, 9.5580e+01, 1.0512e+02, 1.1467e+02, 1.2431e+02, 1.3386e+02, 1.4341e+02, 1.5295e+02, 1.6250e+02, 1.7204e+02, 1.8169e+02, 1.9110e+01, 1.9123e+02, 2.0078e+02, 2.8660e+01, 3.8210e+01, 4.7750e+01, 5.7300e+01, 6.6940e+01, 7.6490e+01, 8.6030e+01], [5.0000e-02, 9.5900e+00, 9.5600e+01, 1.0515e+02, 1.1469e+02, 1.2434e+02, 1.3388e+02, 1.4343e+02, 1.5297e+02, 1.6252e+02, 1.7207e+02, 1.8171e+02, 1.9140e+01, 1.9126e+02, 2.0081e+02, 2.8680e+01, 3.8230e+01, 4.7770e+01, 5.7320e+01, 6.6970e+01, 7.6510e+01, 8.6060e+01], [8.0000e-02, 9.6200e+00, 9.5630e+01, 1.0518e+02, 1.1472e+02, 1.2437e+02, 1.3391e+02, 1.4346e+02, 1.5301e+02, 1.6255e+02, 1.7210e+02, 1.8174e+02, 1.9170e+01, 1.9129e+02, 2.0085e+02, 2.8710e+01, 3.8260e+01, 4.7810e+01, 5.7350e+01, 6.7000e+01, 7.6540e+01, 8.6090e+01], [1.2000e-01, 9.6600e+00, 9.5670e+01, 1.0522e+02, 1.1476e+02, 1.2441e+02, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00]] ) expected_speed = np.array([ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.1, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08], [0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.2, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16], [0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.29, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23], [0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.39, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31], [0.41, 0.41, 0.41, 0.41, 0.41, 0.41, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ]) np.testing.assert_array_almost_equal(pos, expected_pos) np.testing.assert_array_almost_equal(speed, expected_speed)
def test_time_space_diagram_figure_eight(self): dir_path = os.path.dirname(os.path.realpath(__file__)) flow_params = tsd.get_flow_params( os.path.join(dir_path, 'test_files/fig8.json')) emission_data = tsd.import_data_from_trajectory( os.path.join(dir_path, 'test_files/fig8_emission.csv'), flow_params) segs, _ = tsd.get_time_space_data(emission_data, flow_params) expected_segs = np.array([[[1., 60.], [2., 59.]], [[2., 59.], [3., 57.02]], [[3., 57.02], [4., 54.05]], [[1., 23.8], [2., 22.81]], [[2., 22.81], [3., 20.83]], [[3., 20.83], [4., 17.89]], [[1., 182.84166941], [2., 181.85166941]], [[2., 181.85166941], [3., 179.87166941]], [[3., 179.87166941], [4., 176.92166941]], [[1., 154.07166941], [2., 153.08166941]], [[2., 153.08166941], [3., 151.10166941]], [[3., 151.10166941], [4., 148.16166941]], [[1., 125.30166941], [2., 124.31166941]], [[2., 124.31166941], [3., 122.34166941]], [[3., 122.34166941], [4., 119.39166941]], [[1., 96.54166941], [2., 95.54166941]], [[2., 95.54166941], [3., 93.56166941]], [[3., 93.56166941], [4., 90.59166941]], [[1., -203.16166941], [2., -202.17166941]], [[2., -202.17166941], [3., -200.02166941]], [[3., -200.02166941], [4., -197.07166941]], [[1., -174.40166941], [2., -173.40166941]], [[2., -173.40166941], [3., -171.43166941]], [[3., -171.43166941], [4., -168.48166941]], [[1., -145.63166941], [2., -144.64166941]], [[2., -144.64166941], [3., -142.66166941]], [[3., -142.66166941], [4., -139.72166941]], [[1., -116.86166941], [2., -115.87166941]], [[2., -115.87166941], [3., -113.89166941]], [[3., -113.89166941], [4., -110.95166941]], [[1., -88.09166941], [2., -87.10166941]], [[2., -87.10166941], [3., -85.13166941]], [[3., -85.13166941], [4., -82.18166941]], [[1., -59.33], [2., -58.34]], [[2., -58.34], [3., -56.36]], [[3., -56.36], [4., -53.42]], [[1., -30.56], [2., -29.72]], [[2., -29.72], [3., -27.97]], [[3., -27.97], [4., -25.22]], [[1., -1.79], [2., -0.8]], [[2., -0.8], [3., 208.64166941]], [[3., 208.64166941], [4., 205.69166941]]]) np.testing.assert_array_almost_equal(segs, expected_segs)
def test_time_space_diagram_I210(self): dir_path = os.path.dirname(os.path.realpath(__file__)) emission_data = tsd.import_data_from_emission( os.path.join(dir_path, 'test_files/i210_emission.csv')) module = __import__("examples.exp_configs.non_rl", fromlist=["i210_subnetwork"]) flow_params = getattr(module, "i210_subnetwork").flow_params pos, speed, _ = tsd.get_time_space_data(emission_data, flow_params) expected_pos = np.array([[5.1, 0., 0.], [23.37, 0., 0.], [42.02, 5.1, 0.], [61.21, 22.97, 0.], [80.45, 40.73, 5.1], [101.51, 0., 0.]]) expected_speed = np.array([[23., 0., 0.], [22.84, 0., 0.], [23.31, 23., 0.], [23.98, 22.33, 0.], [24.25, 22.21, 23.], [26.33, 0., 0.]]) np.testing.assert_array_almost_equal(pos, expected_pos) np.testing.assert_array_almost_equal(speed, expected_speed)
def test_time_space_diagram_merge(self): dir_path = os.path.dirname(os.path.realpath(__file__)) flow_params = tsd.get_flow_params( os.path.join(dir_path, 'test_files/merge.json')) emission_data = tsd.import_data_from_trajectory( os.path.join(dir_path, 'test_files/merge_emission.csv'), flow_params) segs, _ = tsd.get_time_space_data(emission_data, flow_params) expected_segs = np.array([[[2.0000e-01, 7.2949e+02], [4.0000e-01, 7.2953e+02]], [[4.0000e-01, 7.2953e+02], [6.0000e-01, 7.2961e+02]], [[6.0000e-01, 7.2961e+02], [8.0000e-01, 7.2973e+02]], [[8.0000e-01, 7.2973e+02], [1.0000e+00, 7.2988e+02]]]) np.testing.assert_array_almost_equal(segs, expected_segs)
def test_time_space_diagram_ring_road(self): dir_path = os.path.dirname(os.path.realpath(__file__)) emission_data = tsd.import_data_from_emission( os.path.join(dir_path, 'test_files/loop_230_emission.csv')) flow_params = tsd.get_flow_params( os.path.join(dir_path, 'test_files/loop_230.json')) pos, speed, _ = tsd.get_time_space_data(emission_data, flow_params) expected_pos = np.array( [[ 0.0000e+00, 9.5500e+00, 9.5450e+01, 1.0500e+02, 1.1455e+02, 1.2409e+02, 1.3364e+02, 1.4318e+02, 1.5273e+02, 1.6227e+02, 1.7182e+02, 1.8136e+02, 1.9090e+01, 1.9091e+02, 2.0045e+02, 2.8640e+01, 3.8180e+01, 4.7730e+01, 5.7270e+01, 6.6820e+01, 7.6360e+01, 8.5910e+01 ], [ 1.0000e-02, 9.5500e+00, 9.5460e+01, 1.0501e+02, 1.1455e+02, 1.2410e+02, 1.3364e+02, 1.4319e+02, 1.5274e+02, 1.6228e+02, 1.7183e+02, 1.8137e+02, 1.9100e+01, 1.9092e+02, 2.0046e+02, 2.8640e+01, 3.8190e+01, 4.7740e+01, 5.7280e+01, 6.6830e+01, 7.6370e+01, 8.5920e+01 ], [ 2.0000e-02, 9.5700e+00, 9.5480e+01, 1.0502e+02, 1.1457e+02, 1.2411e+02, 1.3366e+02, 1.4321e+02, 1.5275e+02, 1.6230e+02, 1.7184e+02, 1.8139e+02, 1.9110e+01, 1.9093e+02, 2.0048e+02, 2.8660e+01, 3.8210e+01, 4.7750e+01, 5.7300e+01, 6.6840e+01, 7.6390e+01, 8.5930e+01 ], [ 5.0000e-02, 9.5900e+00, 9.5500e+01, 1.0505e+02, 1.1459e+02, 1.2414e+02, 1.3368e+02, 1.4323e+02, 1.5277e+02, 1.6232e+02, 1.7187e+02, 1.8141e+02, 1.9140e+01, 1.9096e+02, 2.0051e+02, 2.8680e+01, 3.8230e+01, 4.7770e+01, 5.7320e+01, 6.6870e+01, 7.6410e+01, 8.5960e+01 ], [ 8.0000e-02, 9.6200e+00, 9.5530e+01, 1.0508e+02, 1.1462e+02, 1.2417e+02, 1.3371e+02, 1.4326e+02, 1.5281e+02, 1.6235e+02, 1.7190e+02, 1.8144e+02, 1.9170e+01, 1.9099e+02, 2.0055e+02, 2.8710e+01, 3.8260e+01, 4.7810e+01, 5.7350e+01, 6.6900e+01, 7.6440e+01, 8.5990e+01 ], [ 1.2000e-01, 9.6600e+00, 9.5570e+01, 1.0512e+02, 1.1466e+02, 1.2421e+02, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00 ]]) expected_speed = np.array([ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.1, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08 ], [ 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.2, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16 ], [ 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.29, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23 ], [ 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.39, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31 ], [ 0.41, 0.41, 0.41, 0.41, 0.41, 0.41, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ]) np.testing.assert_array_almost_equal(pos, expected_pos) np.testing.assert_array_almost_equal(speed, expected_speed)
def test_time_space_diagram_figure_eight(self): # check that the exported data matches the expected emission file data fig8_emission_data = { 'idm_3': { 'pos': [27.25, 28.25, 30.22, 33.17], 'time': [1.0, 2.0, 3.0, 4.0], 'vel': [0.0, 0.99, 1.98, 2.95], 'edge': ['upper_ring', 'upper_ring', 'upper_ring', 'upper_ring'] }, 'idm_4': { 'pos': [56.02, 57.01, 58.99, 61.93], 'time': [1.0, 2.0, 3.0, 4.0], 'vel': [0.0, 0.99, 1.98, 2.95], 'edge': ['upper_ring', 'upper_ring', 'upper_ring', 'upper_ring'] }, 'idm_5': { 'pos': [84.79, 85.78, 87.76, 90.7], 'time': [1.0, 2.0, 3.0, 4.0], 'vel': [0.0, 0.99, 1.98, 2.95], 'edge': ['upper_ring', 'upper_ring', 'upper_ring', 'upper_ring'] }, 'idm_2': { 'pos': [28.77, 29.76, 1.63, 4.58], 'time': [1.0, 2.0, 3.0, 4.0], 'vel': [0.0, 0.99, 1.97, 2.95], 'edge': ['top', 'top', 'upper_ring', 'upper_ring'] }, 'idm_13': { 'pos': [106.79, 107.79, 109.77, 112.74], 'time': [1.0, 2.0, 3.0, 4.0], 'vel': [0.0, 0.99, 1.98, 2.96], 'edge': ['lower_ring', 'lower_ring', 'lower_ring', 'lower_ring'] }, 'idm_9': { 'pos': [22.01, 23.0, 24.97, 27.92], 'time': [1.0, 2.0, 3.0, 4.0], 'vel': [0.0, 0.99, 1.97, 2.95], 'edge': ['left', 'left', 'left', 'left'] }, 'idm_6': { 'pos': [113.56, 114.55, 116.52, 119.47], 'time': [1.0, 2.0, 3.0, 4.0], 'vel': [0.0, 0.99, 1.97, 2.95], 'edge': ['upper_ring', 'upper_ring', 'upper_ring', 'upper_ring'] }, 'idm_8': { 'pos': [29.44, 0.28, 2.03, 4.78], 'time': [1.0, 2.0, 3.0, 4.0], 'vel': [0.0, 0.84, 1.76, 2.75], 'edge': ['right', ':center_0', ':center_0', ':center_0'] }, 'idm_12': { 'pos': [78.03, 79.02, 80.99, 83.94], 'time': [1.0, 2.0, 3.0, 4.0], 'vel': [0.0, 0.99, 1.98, 2.95], 'edge': ['lower_ring', 'lower_ring', 'lower_ring', 'lower_ring'] }, 'idm_10': { 'pos': [20.49, 21.48, 23.46, 26.41], 'time': [1.0, 2.0, 3.0, 4.0], 'vel': [0.0, 0.99, 1.98, 2.95], 'edge': ['lower_ring', 'lower_ring', 'lower_ring', 'lower_ring'] }, 'idm_11': { 'pos': [49.26, 50.25, 52.23, 55.17], 'time': [1.0, 2.0, 3.0, 4.0], 'vel': [0.0, 0.99, 1.98, 2.95], 'edge': ['lower_ring', 'lower_ring', 'lower_ring', 'lower_ring'] }, 'idm_1': { 'pos': [0.0, 0.99, 2.97, 5.91], 'time': [1.0, 2.0, 3.0, 4.0], 'vel': [0.0, 0.99, 1.98, 2.95], 'edge': ['top', 'top', 'top', 'top'] }, 'idm_7': { 'pos': [0.67, 1.66, 3.64, 6.58], 'time': [1.0, 2.0, 3.0, 4.0], 'vel': [0.0, 0.99, 1.97, 2.94], 'edge': ['right', 'right', 'right', 'right'] }, 'idm_0': { 'pos': [0.0, 1.0, 2.98, 5.95], 'time': [1.0, 2.0, 3.0, 4.0], 'vel': [0.0, 1.0, 1.99, 2.97], 'edge': ['bottom', 'bottom', 'bottom', 'bottom'] } } dir_path = os.path.dirname(os.path.realpath(__file__)) actual_emission_data = tsd.import_data_from_emission( os.path.join(dir_path, 'test_files/fig8_emission.csv')) self.assertDictEqual(fig8_emission_data, actual_emission_data) # test get_time_space_data for figure eight networks flow_params = tsd.get_flow_params( os.path.join(dir_path, 'test_files/fig8.json')) pos, speed, _ = tsd.get_time_space_data(actual_emission_data, flow_params) expected_pos = np.array( [[ 60, 23.8, 182.84166941, 154.07166941, 125.30166941, 96.54166941, -203.16166941, -174.40166941, -145.63166941, -116.86166941, -88.09166941, -59.33, -30.56, -1.79 ], [ 59, 22.81, 181.85166941, 153.08166941, 124.31166941, 95.54166941, -202.17166941, -173.40166941, -144.64166941, -115.87166941, -87.10166941, -58.34, -29.72, -0.8 ], [ 57.02, 20.83, 179.87166941, 151.10166941, 122.34166941, 93.56166941, -200.02166941, -171.43166941, -142.66166941, -113.89166941, -85.13166941, -56.36, -27.97, 208.64166941 ]]) expected_speed = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 1, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.84, 0.99 ], [ 1.99, 1.98, 1.98, 1.98, 1.98, 1.98, 1.97, 1.98, 1.98, 1.98, 1.97, 1.97, 1.76, 1.97 ]]) np.testing.assert_array_almost_equal(pos[:-1, :], expected_pos) np.testing.assert_array_almost_equal(speed[:-1, :], expected_speed)