diff --git a/src/topupopt/data/gis/calculate.py b/src/topupopt/data/gis/calculate.py index 8b99ec7997dd82095ea836c0d79726251b2a68cc..901ee9bed23b056c90353d6b96c3997284a9943a 100644 --- a/src/topupopt/data/gis/calculate.py +++ b/src/topupopt/data/gis/calculate.py @@ -10,7 +10,7 @@ from geopandas import GeoDataFrame from pandas import isna from shapely.geometry import LineString, Point from shapely import length -from osmnx.distance import great_circle_vec +from osmnx.distance import great_circle from osmnx.stats import count_streets_per_node from osmnx.projection import is_projected @@ -103,11 +103,11 @@ def arc_lengths(network: MultiDiGraph, # use (unprojected) coordinates - length_dict[arc_key] = great_circle_vec( + length_dict[arc_key] = great_circle( lat1=network.nodes[arc_key[0]][osm.KEY_OSMNX_Y], - lng1=network.nodes[arc_key[0]][osm.KEY_OSMNX_X], + lon1=network.nodes[arc_key[0]][osm.KEY_OSMNX_X], lat2=network.nodes[arc_key[1]][osm.KEY_OSMNX_Y], - lng2=network.nodes[arc_key[1]][osm.KEY_OSMNX_X] + lon2=network.nodes[arc_key[1]][osm.KEY_OSMNX_X] ) return length_dict @@ -136,18 +136,18 @@ def great_circle_distance_along_path(path: LineString) -> float: # get coordinates - lng = tuple(path.coords.xy[0]) + lon = tuple(path.coords.xy[0]) lat = tuple(path.coords.xy[1]) # sum individual distances and return return sum( - great_circle_vec( + great_circle( lat[:-1], # latitudes of starting points - lng[:-1], # longitudes of starting points + lon[:-1], # longitudes of starting points lat[1:], # latitudes of ending points - lng[1:] # longitudes of ending points + lon[1:] # longitudes of ending points ) ) diff --git a/src/topupopt/data/gis/modify.py b/src/topupopt/data/gis/modify.py index e8c3856990a55c438970835d8f3cb46107248b91..d041e92f0c649ba15757f644421fc4ad58d12567 100644 --- a/src/topupopt/data/gis/modify.py +++ b/src/topupopt/data/gis/modify.py @@ -12,7 +12,7 @@ import networkx as nx from shapely.geometry import Point, LineString from shapely.ops import nearest_points, linemerge, snap from shapely import length -from osmnx.distance import great_circle_vec, add_edge_lengths +from osmnx.distance import great_circle, add_edge_lengths from osmnx.projection import is_projected # from pyproj import CRS @@ -213,11 +213,11 @@ def transform_roundabouts_into_crossroads( arc_keys=[edge_key])[edge_key] # # calculate it - # old_length = great_circle_vec( + # old_length = great_circle( # lat1=network.nodes[edge_key[0]][osm.KEY_OSMNX_Y], - # lng1=network.nodes[edge_key[0]][osm.KEY_OSMNX_X], + # lon1=network.nodes[edge_key[0]][osm.KEY_OSMNX_X], # lat2=network.nodes[edge_key[1]][osm.KEY_OSMNX_Y], - # lng2=network.nodes[edge_key[1]][osm.KEY_OSMNX_X] + # lon2=network.nodes[edge_key[1]][osm.KEY_OSMNX_X] # ) #****************************************************************** @@ -249,13 +249,13 @@ def transform_roundabouts_into_crossroads( else: - extra_length = great_circle_vec( + extra_length = great_circle( lat1=network.nodes[ roundabout_centroid_key][osm.KEY_OSMNX_Y], - lng1=network.nodes[ + lon1=network.nodes[ roundabout_centroid_key][osm.KEY_OSMNX_X], lat2=network.nodes[edge_key[0]][osm.KEY_OSMNX_Y], - lng2=network.nodes[edge_key[0]][osm.KEY_OSMNX_X] + lon2=network.nodes[edge_key[0]][osm.KEY_OSMNX_X] ) elif edge_key[1] in roundabout: @@ -282,13 +282,13 @@ def transform_roundabouts_into_crossroads( else: - extra_length = great_circle_vec( + extra_length = great_circle( lat1=network.nodes[ roundabout_centroid_key][osm.KEY_OSMNX_Y], - lng1=network.nodes[ + lon1=network.nodes[ roundabout_centroid_key][osm.KEY_OSMNX_X], lat2=network.nodes[edge_key[1]][osm.KEY_OSMNX_Y], - lng2=network.nodes[edge_key[1]][osm.KEY_OSMNX_X] + lon2=network.nodes[edge_key[1]][osm.KEY_OSMNX_X] ) #****************************************************************** diff --git a/src/topupopt/data/misc/utils.py b/src/topupopt/data/misc/utils.py index 8d56254be6c200a7b4f2fc6f69979f5fb07fc7c8..9a70e635c34b05c2a2b5d90a309c7508b2de54c3 100644 --- a/src/topupopt/data/misc/utils.py +++ b/src/topupopt/data/misc/utils.py @@ -44,7 +44,7 @@ def generate_pseudo_unique_key(key_list: tuple, def discrete_sinusoid_matching_integral( integration_result: float, time_interval_durations: list, - ratio_min_avg: float, + min_to_max_ratio: float, phase_shift_radians: float = None) -> list: """ Returns a profile that approximates a sinusoidal function in discrete time. @@ -52,7 +52,7 @@ def discrete_sinusoid_matching_integral( The profile is obtained by integrating the sinusoidal function between spe- cific time intervals. The sum of the samples adds up to a specified result. Additional parameters include the function\'s phase and the ratio between - the function\'s minimum and average values. + the function\'s minimum (b-a) and maximum (b+a) values. The sinusoidal function is as follows: @@ -60,7 +60,7 @@ def discrete_sinusoid_matching_integral( where: - a = (1-ratio_min_avg)*b + a = b*(1-min_to_max_ratio)/(1+min_to_max_ratio) b = integration_result/integration_period @@ -74,9 +74,8 @@ def discrete_sinusoid_matching_integral( The result of integrating the sinusoidal function for one period. time_interval_durations : list The time interval durations for each sample. - ratio_min_avg : float - The ratio between integration of the b-a constant function equal to the - base level and the integration of the function for one period. + min_to_max_ratio : float + The ratio between the minimum and maximum values of the function. phase_shift_radians : float, optional The phase shift for the sinusoidal function. The default is None, which indicates phase zero. @@ -94,7 +93,7 @@ def discrete_sinusoid_matching_integral( b = integration_result/integration_period - a = (1-ratio_min_avg)*b + a = b*(1-min_to_max_ratio)/(1+min_to_max_ratio) alpha = 2*math.pi/integration_period @@ -107,7 +106,7 @@ def discrete_sinusoid_matching_integral( beta = phase_shift_radians t = [sum(time_interval_durations[0:i]) - for i in range(len(time_interval_durations)+1)] + for i in range(len(time_interval_durations)+1)] def _integral(a, b, alpha, beta, t, t0): @@ -207,7 +206,7 @@ def create_profile_using_time_weighted_state( integration_result: float, avg_state: list, time_interval_durations: list, - ratio_min_avg: float, + min_to_max_ratio: float, state_correlates_with_output: bool = True) -> list: """ Returns a profile that approximates a sinusoidal function in discrete time. @@ -226,7 +225,7 @@ def create_profile_using_time_weighted_state( where: - a = (1-ratio_min_avg)*b + a = b*(1-min_to_max_ratio)/(1+min_to_max_ratio) b = integration_result/integration_period @@ -242,9 +241,8 @@ def create_profile_using_time_weighted_state( The average state during each time interval. time_interval_durations : list The time interval durations for each sample. - ratio_min_avg : float - The ratio between integration of the b-a constant function equal to the - base level and the integration of the function for one period. + min_to_max_ratio : float + The ratio between the minimum and maximum values of the function. state_correlates_with_output : bool, optional If True, the peak should happen when the state is at its highest point. If False, the peak should happen when the state is at its lowest point. @@ -297,7 +295,7 @@ def create_profile_using_time_weighted_state( new_profile = discrete_sinusoid_matching_integral( integration_result=integration_result, time_interval_durations=swapped_time_durations, - ratio_min_avg=ratio_min_avg, + min_to_max_ratio=min_to_max_ratio, phase_shift_radians=( math.pi/2 - @@ -316,7 +314,7 @@ def max_min_sinusoidal_profile( integration_result: float or int, period: float or int, time_interval_duration: float or int, - ratio_min_avg: float) -> tuple: + min_to_max_ratio: float) -> tuple: """ Returns the maximum and minimum amount for a given time interval, according to a sinusoidal function of time. @@ -332,7 +330,7 @@ def max_min_sinusoidal_profile( where: - a = (1-ratio_min_avg)*b + a = b*(1-min_to_max_ratio)/(1+min_to_max_ratio) b = integration_result/integration_period @@ -346,9 +344,8 @@ def max_min_sinusoidal_profile( The result of integrating the sinusoidal function for one period. time_interval_durations : list The time interval durations for each sample. - ratio_min_avg : float - The ratio between integration of the b-a constant function equal to the - base level and the integration of the function for one period. + min_to_max_ratio : float + The ratio between the minimum and maximum values of the function. phase_shift_radians : float, optional The phase shift for the sinusoidal function. The default is None, which indicates phase zero. @@ -361,7 +358,7 @@ def max_min_sinusoidal_profile( """ b = integration_result/period - a = (1-ratio_min_avg)*b + a = b*(1-min_to_max_ratio)/(1+min_to_max_ratio) alpha = 2*math.pi/period amplitude = a*(2/alpha)*math.sin(alpha*time_interval_duration/2) diff --git a/tests/examples_gis.py b/tests/examples_gis.py index abbabd49123253c44ebba7c415ab16a2d75cd821..c90190e2f5fb5891a9642a39e1a0b334b76b8241 100644 --- a/tests/examples_gis.py +++ b/tests/examples_gis.py @@ -14,7 +14,7 @@ from shapely.geometry import Point, LineString from numpy.testing import assert_allclose from osmnx.stats import count_streets_per_node # from osmnx.projection import project_graph -from osmnx.distance import k_shortest_paths +from osmnx.routing import k_shortest_paths # local, internal diff --git a/tests/examples_gis_utils.py b/tests/examples_gis_utils.py index b0f498e0c2d0f7ca231f23101cf36b67004577c5..c628dcd9da81f17dd23bab77387a3617efdfa6d9 100644 --- a/tests/examples_gis_utils.py +++ b/tests/examples_gis_utils.py @@ -1889,8 +1889,7 @@ def example_discrete_plot_gdf(): (55.71654,9.11728), network_type='drive', custom_filter='["highway"~"residential|tertiary|unclassified|service"]', - truncate_by_edge=True, - clean_periphery=True + truncate_by_edge=True ) #************************************************************************** diff --git a/tests/test_all.py b/tests/test_all.py index ea178110ce9615989855516a67c76def56dcaa24..7e75605bed5750cc796793ee7402c3b70c6163fe 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -22,29 +22,29 @@ from examples_signal import examples as examples_signal def test_suite(): - # test_examples_converter = True - test_examples_converter = False + test_examples_converter = True + # test_examples_converter = False - # test_examples_dynsys = True - test_examples_dynsys = False + test_examples_dynsys = True + # test_examples_dynsys = False - # test_examples_esipp_network = True - test_examples_esipp_network = False + test_examples_esipp_network = True + # test_examples_esipp_network = False - # test_examples_esipp_problem = True - test_examples_esipp_problem = False + test_examples_esipp_problem = True + # test_examples_esipp_problem = False - # test_examples_esipp_resource = True - test_examples_esipp_resource = False + test_examples_esipp_resource = True + # test_examples_esipp_resource = False - # test_examples_esipp = True - test_examples_esipp = False + test_examples_esipp = True + # test_examples_esipp = False - test_examples_gis = True - # test_examples_gis = False + # test_examples_gis = True + test_examples_gis = False - # test_examples_signal = True - test_examples_signal = False + test_examples_signal = True + # test_examples_signal = False # test_examples_converter = True # test_examples_dynsys = True diff --git a/tests/test_data_utils.py b/tests/test_data_utils.py index e710387b3658ed913b6ec884a40c43686ee553ac..4ba332a8b14f496b5457690fbbe8f80ce5d77291 100644 --- a/tests/test_data_utils.py +++ b/tests/test_data_utils.py @@ -24,6 +24,7 @@ class TestDataUtils: integration_result = 10446 ratio_min_avg = 0.2 + min_to_max_ratio = ratio_min_avg/(2-ratio_min_avg) avg_state = [ 2.66, @@ -63,7 +64,7 @@ class TestDataUtils: integration_result=integration_result, avg_state=avg_state, time_interval_durations=time_interval_durations, - ratio_min_avg=ratio_min_avg, + min_to_max_ratio=min_to_max_ratio, state_correlates_with_output=False ) @@ -109,7 +110,7 @@ class TestDataUtils: integration_result=integration_result, avg_state=avg_state, time_interval_durations=time_interval_durations, - ratio_min_avg=ratio_min_avg, + min_to_max_ratio=min_to_max_ratio, state_correlates_with_output=True ) @@ -153,7 +154,7 @@ class TestDataUtils: integration_result=integration_result, period=sum(time_interval_durations), time_interval_duration=mean(time_interval_durations), - ratio_min_avg=ratio_min_avg + min_to_max_ratio=min_to_max_ratio ) expected_pmax, expected_pmin = 1558.972133279683, 182.02786672031687 @@ -182,7 +183,7 @@ class TestDataUtils: integration_result=integration_result, avg_state=avg_state, time_interval_durations=time_interval_durations, - ratio_min_avg=ratio_min_avg, + min_to_max_ratio=min_to_max_ratio, state_correlates_with_output=True ) except ValueError: @@ -248,12 +249,12 @@ class TestDataUtils: integration_result = 100 - ratio_min_avg = 0.2 + min_to_max_ratio = 0.2 profile = utils.discrete_sinusoid_matching_integral( integration_result, time_interval_durations, - ratio_min_avg, + min_to_max_ratio, phase_shift_radians=phase_shift_radians) assert math.isclose( @@ -301,12 +302,12 @@ class TestDataUtils: integration_result = 100 - ratio_min_avg = 0.2 + min_to_max_ratio = 0.2 profile = utils.discrete_sinusoid_matching_integral( integration_result, time_interval_durations, - ratio_min_avg, + min_to_max_ratio, phase_shift_radians=phase_shift_radians) assert math.isclose( @@ -352,12 +353,12 @@ class TestDataUtils: integration_result = 100 - ratio_min_avg = 0.2 + min_to_max_ratio = 0.2 profile = utils.discrete_sinusoid_matching_integral( integration_result, time_interval_durations, - ratio_min_avg) + min_to_max_ratio) assert math.isclose( sum(profile), diff --git a/tests/test_dhn_utils.py b/tests/test_dhn_utils.py index 2cc6e8b750da0f34969b2a60bb1073f5e548c1a5..b2e513910757f54aef551b1a9f639cecc71387d1 100644 --- a/tests/test_dhn_utils.py +++ b/tests/test_dhn_utils.py @@ -289,8 +289,7 @@ class TestDistrictHeatingNetworkUtils: custom_filter=( '["highway"~"residential|tertiary|unclassified|service"]' ), - truncate_by_edge=True, - clean_periphery=True + truncate_by_edge=True ) # create a network object diff --git a/tests/test_gis_calculate.py b/tests/test_gis_calculate.py index d59537c0abc1f7f665820496dcbe379a180aea68..7ad2d3994fabe835b594bc54ffbdbb686e445d28 100644 --- a/tests/test_gis_calculate.py +++ b/tests/test_gis_calculate.py @@ -58,8 +58,7 @@ class TestGisCalculate: (55.71654,9.11728), network_type='drive', custom_filter='["highway"~"residential|tertiary|unclassified|service"]', - truncate_by_edge=True, - clean_periphery=True + truncate_by_edge=True ) # count occurrences diff --git a/tests/test_gis_identify.py b/tests/test_gis_identify.py index 1148071de4945fce3b1ee0a17fe2ce504e951016..7377f038a036cdcce9996bf8da9e509377faee67 100644 --- a/tests/test_gis_identify.py +++ b/tests/test_gis_identify.py @@ -1432,8 +1432,7 @@ class TestGisIdentify: (55.71654,9.11728), network_type='drive', custom_filter='["highway"~"residential|tertiary|unclassified|service"]', - truncate_by_edge=True, - clean_periphery=True + truncate_by_edge=True ) # pick a certain number of nodes randomly @@ -2226,8 +2225,7 @@ class TestGisIdentify: custom_filter=( '["highway"~"residential|tertiary|unclassified|service"]' ), - truncate_by_edge=True, - clean_periphery=True + truncate_by_edge=True ) for edge_key in network.edges(keys=True): @@ -2328,8 +2326,7 @@ class TestGisIdentify: custom_filter=( '["highway"~"residential|tertiary|unclassified|service"]' ), - truncate_by_edge=True, - clean_periphery=True + truncate_by_edge=True ) # create arc to trigger the negative case with a different length @@ -2554,8 +2551,7 @@ class TestGisIdentify: custom_filter=( '["highway"~"residential|tertiary|unclassified|service"]' ), - truncate_by_edge=True, - clean_periphery=True + truncate_by_edge=True ) for edge_key in network.edges(keys=True): diff --git a/tests/test_gis_modify.py b/tests/test_gis_modify.py index 9558b92aa26c175c17b0b3d2741686bd2190cd65..96c21ba8694fe4c60edf75c0b5de20a18a756bb8 100644 --- a/tests/test_gis_modify.py +++ b/tests/test_gis_modify.py @@ -149,8 +149,7 @@ class TestGisModify: (55.71654,9.11728), network_type='drive', custom_filter='["highway"~"residential|tertiary|unclassified|service"]', - truncate_by_edge=True, - clean_periphery=True + truncate_by_edge=True ) # find non-overlapping paths @@ -735,8 +734,7 @@ class TestGisModify: (55.71654,9.11728), network_type='drive', custom_filter='["highway"~"residential|tertiary|unclassified|service"]', - truncate_by_edge=True, - clean_periphery=True + truncate_by_edge=True ) _net = network.copy() @@ -1101,8 +1099,7 @@ class TestGisModify: (55.71654,9.11728), network_type='drive', custom_filter='["highway"~"residential|tertiary|unclassified|service"]', - truncate_by_edge=True, - clean_periphery=True + truncate_by_edge=True ) _net = network.copy() @@ -1228,8 +1225,7 @@ class TestGisModify: custom_filter=( '["highway"~"residential|tertiary|unclassified|service"]' ), - truncate_by_edge=True, - clean_periphery=True + truncate_by_edge=True ) self.example_connect_points_to_arcs_osmnx( @@ -1251,8 +1247,7 @@ class TestGisModify: custom_filter=( '["highway"~"residential|tertiary|unclassified|service"]' ), - truncate_by_edge=True, - clean_periphery=True + truncate_by_edge=True ) self.example_connect_points_to_arcs_osmnx( @@ -1274,8 +1269,7 @@ class TestGisModify: custom_filter=( '["highway"~"residential|tertiary|unclassified|service"]' ), - truncate_by_edge=True, - clean_periphery=True + truncate_by_edge=True ) self.example_connect_points_to_arcs_osmnx( @@ -1297,8 +1291,7 @@ class TestGisModify: custom_filter=( '["highway"~"residential|tertiary|unclassified|service"]' ), - truncate_by_edge=True, - clean_periphery=True + truncate_by_edge=True ) self.example_connect_points_to_arcs_osmnx( diff --git a/tests/test_gis_utils.py b/tests/test_gis_utils.py index 5a1a1a3ed8748376ca8dcb2ed61bc6e8842a173e..05697d809d3800b87bba1fb5bfffba47fc6ef6fa 100644 --- a/tests/test_gis_utils.py +++ b/tests/test_gis_utils.py @@ -1900,8 +1900,7 @@ class TestGisUtils: (55.71654,9.11728), network_type='drive', custom_filter='["highway"~"residential|tertiary|unclassified|service"]', - truncate_by_edge=True, - clean_periphery=True + truncate_by_edge=True ) #************************************************************************** @@ -2016,8 +2015,7 @@ class TestGisUtils: (55.71654,9.11728), network_type='drive', custom_filter='["highway"~"residential|tertiary|unclassified|service"]', - truncate_by_edge=True, - clean_periphery=True + truncate_by_edge=True ) # convert to undirected