From 77398f1a62dd14c6da46175ceac2ab7b0f82faa9 Mon Sep 17 00:00:00 2001 From: Marie Gering Date: Mon, 10 Aug 2020 18:09:00 +0200 Subject: [PATCH 01/10] Rename edge to pipe in directory dhnx --- dhnx/component_attrs/{edges.csv => pipes.csv} | 6 +-- dhnx/components.csv | 5 +- dhnx/dhn_from_osm.py | 24 +++++----- dhnx/graph.py | 10 ++-- dhnx/network.py | 22 ++++----- dhnx/plotting.py | 48 +++++++++---------- 6 files changed, 57 insertions(+), 58 deletions(-) rename dhnx/component_attrs/{edges.csv => pipes.csv} (63%) diff --git a/dhnx/component_attrs/edges.csv b/dhnx/component_attrs/pipes.csv similarity index 63% rename from dhnx/component_attrs/edges.csv rename to dhnx/component_attrs/pipes.csv index da6602e9..8e11d8f6 100644 --- a/dhnx/component_attrs/edges.csv +++ b/dhnx/component_attrs/pipes.csv @@ -1,8 +1,8 @@ attribute,type,unit,default,description,status,requirement id,int,n/a,n/a,Unique id,Input,required -from_node,int,n/a,n/a,Node where Edge begins,Input,required -to_node,int,n/a,n/a,Node where Edge ends,Input,required -length,float,m,n/a,Length of the Edge,Input,optional +from_node,int,n/a,n/a,Node where Pipe begins,Input,required +to_node,int,n/a,n/a,Node where Pipe ends,Input,required +length,float,m,n/a,Length of the Pipe,Input,optional diameter,float,mm,n/a,Inner diameter of the pipes,Input,optional heat_transfer_coeff,float,W/(m*K),n/a,Heat transfer coefficient,Input,optional roughness,float,mm,n/a,Roughness of pipes,Input,optional diff --git a/dhnx/components.csv b/dhnx/components.csv index 71a34161..72f8ac75 100644 --- a/dhnx/components.csv +++ b/dhnx/components.csv @@ -1,9 +1,8 @@ component_class,list_name,description -ThermalNetwork,thermal_networks,"Container for all components belonging to one thermal network" ThermalSubNetwork,thermal_sub_networks,"Subsets of a thermal network" Producer,producers,"Heat producer" Consumer,consumers,"Heat consumer" -Fork,forks,"Node where several edges meet" +Fork,forks,"Node where several pipes meet" TransferStation,transfer_stations,"Transfer station" ThermalStorage,thermal_storages,"Thermal storage unit" -Edge,edges,"Edges representing double pipes (feed and return) that connect nodes" +Pipe,pipes,"Pipes representing double pipes (feed and return) that connect nodes" diff --git a/dhnx/dhn_from_osm.py b/dhnx/dhn_from_osm.py index c344302b..59addfce 100644 --- a/dhnx/dhn_from_osm.py +++ b/dhnx/dhn_from_osm.py @@ -18,7 +18,7 @@ from shapely.geometry import LineString -def connect_points_to_network(points, nodes, edges): +def connect_points_to_network(points, nodes, pipes): r""" Parameter @@ -29,8 +29,8 @@ def connect_points_to_network(points, nodes, edges): nodes : geopandas.GeoDataFrame Nodes of the network - edges : geopandas.GeoDataFrame - Edges of the network + pipes : geopandas.GeoDataFrame + Pipes of the network Returns ------- @@ -40,10 +40,10 @@ def connect_points_to_network(points, nodes, edges): nodes : geopandas.GeoDataFrame Nodes of the network - edges : geopandas.GeoDataFrame - Edges of the network. + Pipes : geopandas.GeoDataFrame + Pipes of the network. """ - edges_united = edges.unary_union + pipes_united = pipes.unary_union len_nodes = len(nodes) len_points = len(points) @@ -51,20 +51,20 @@ def connect_points_to_network(points, nodes, edges): # assign ids to new points n_points = [] n_nearest_points = [] - n_edges = [] + n_pipes = [] for i, point in enumerate(points.geometry): id_nearest_point = len_nodes + i id_point = len_nodes + len_points + i - nearest_point = nearest_points(edges_united, point)[0] + nearest_point = nearest_points(pipes_united, point)[0] n_points.append([id_point, point.x, point.y, point]) n_nearest_points.append([id_nearest_point, nearest_point.x, nearest_point.y, nearest_point]) - n_edges.append([id_point, id_nearest_point, LineString([point, nearest_point])]) + n_pipes.append([id_point, id_nearest_point, LineString([point, nearest_point])]) n_points = gpd.GeoDataFrame( n_points, @@ -74,9 +74,9 @@ def connect_points_to_network(points, nodes, edges): n_nearest_points, columns=['index', 'x', 'y', 'geometry']).set_index('index') - n_edges = gpd.GeoDataFrame(n_edges, columns=['u', 'v', 'geometry']) + n_pipes = gpd.GeoDataFrame(n_pipes, columns=['u', 'v', 'geometry']) joined_nodes = pd.concat([nodes, n_nearest_points], sort=True) - joined_edges = pd.concat([edges, n_edges], sort=True) + joined_pipes = pd.concat([pipes, n_pipes], sort=True) - return n_points, joined_nodes, joined_edges + return n_points, joined_nodes, joined_pipes diff --git a/dhnx/graph.py b/dhnx/graph.py index abc15175..47c3cd60 100644 --- a/dhnx/graph.py +++ b/dhnx/graph.py @@ -29,17 +29,17 @@ def thermal_network_to_nx_graph(thermal_network): """ nx_graph = nx.MultiDiGraph() # TODO: Check if this line can be removed. - edge_attr = list(thermal_network.components['edges'].columns) + pipe_attr = list(thermal_network.components['pipes'].columns) - edge_attr.remove('from_node') + pipe_attr.remove('from_node') - edge_attr.remove('to_node') + pipe_attr.remove('to_node') nx_graph = nx.from_pandas_edgelist( - thermal_network.components['edges'], + thermal_network.components['pipes'], 'from_node', 'to_node', - edge_attr=edge_attr, + edge_attr=pipe_attr, create_using=thermal_network.graph ) diff --git a/dhnx/network.py b/dhnx/network.py index d9cab672..77249425 100644 --- a/dhnx/network.py +++ b/dhnx/network.py @@ -172,9 +172,9 @@ def remove(self, class_name, id): def is_consistent(self): r""" Checks that - * edges connect to existing nodes, - * edges do not connect a node with itself, - * there are no duplicate edges between two nodes. + * pipes connect to existing nodes, + * pipes do not connect a node with itself, + * there are no duplicate pipes between two nodes. """ nodes = {list_name: self.components[list_name].copy() for list_name in [ 'consumers', @@ -189,7 +189,7 @@ def is_consistent(self): node_indices = nodes.index - for id, data in self.components.edges.iterrows(): + for id, data in self.components.pipes.iterrows(): if not data['from_node'] in node_indices: raise ValueError(f"Node {data['from_node']} not defined.") @@ -198,18 +198,18 @@ def is_consistent(self): raise ValueError(f"Node {data['to_node']} not defined.") assert data['from_node'] != data['to_node'], \ - f"Edge {id} connects {data['from_node']} to itself" + f"Pipe {id} connects {data['from_node']} to itself" - if not self.components.edges.empty: + if not self.components.pipes.empty: - duplicate_edges = [ - name for name, group in self.components.edges.groupby(['from_node', 'to_node']) + duplicate_pipes = [ + name for name, group in self.components.pipes.groupby(['from_node', 'to_node']) if len(group) > 1 ] - assert not duplicate_edges, ( - f"There is more than one edge that connects " - f"{[edge[0] + ' to ' + edge[1] for edge in duplicate_edges]}") + assert not duplicate_pipes, ( + f"There is more than one pipe that connects " + f"{[pipe[0] + ' to ' + pipe[1] for pipe in duplicate_pipes]}") return True diff --git a/dhnx/plotting.py b/dhnx/plotting.py index 16fe35a3..5b6c9197 100644 --- a/dhnx/plotting.py +++ b/dhnx/plotting.py @@ -40,8 +40,8 @@ class InteractiveMap(): """ def __init__(self, thermal_network): self.node_data = self.collect_node_data(thermal_network) - self.edge_data = thermal_network.components['edges'] - self.edge_data['value'] = 1 + self.pipe_data = thermal_network.components['pipes'] + self.pipe_data['value'] = 1 self.node_id = self.node_data.index self.lat = self.node_data['lat'] self.lon = self.node_data['lon'] @@ -168,23 +168,23 @@ def draw(self): ) ).add_to(m) - for i in range(0, len(self.edge_data)): + for i in range(0, len(self.pipe_data)): # linewidth settings - lw_avg = self.edge_data['value'].mean() - lw = self.edge_data['value'][i] / lw_avg + lw_avg = self.pipe_data['value'].mean() + lw = self.pipe_data['value'][i] / lw_avg - fol.PolyLine(locations=[[self.lat[self.edge_data['from_node'][i]], - self.lon[self.edge_data['from_node'][i]]], - [self.lat[self.edge_data['to_node'][i]], - self.lon[self.edge_data['to_node'][i]]]], + fol.PolyLine(locations=[[self.lat[self.pipe_data['from_node'][i]], + self.lon[self.pipe_data['from_node'][i]]], + [self.lat[self.pipe_data['to_node'][i]], + self.lon[self.pipe_data['to_node'][i]]]], color='orange', weight=lw * 3).add_to(m) arrows = self._get_arrows( - locations=[[self.lat[self.edge_data['from_node'][i]], - self.lon[self.edge_data['from_node'][i]]], - [self.lat[self.edge_data['to_node'][i]], - self.lon[self.edge_data['to_node'][i]]]], + locations=[[self.lat[self.pipe_data['from_node'][i]], + self.lon[self.pipe_data['from_node'][i]]], + [self.lat[self.pipe_data['to_node'][i]], + self.lon[self.pipe_data['to_node'][i]]]], color='orange', n_arrows=3) for arrow in arrows: @@ -198,13 +198,13 @@ class StaticMap(): A static map of a network.ThermalNetwork. """ def __init__(self, thermal_network, figsize=(5, 5), node_size=3, - edge_width=3, node_color='r', edge_color='g'): + pipe_width=3, node_color='r', pipe_color='g'): self.graph = thermal_network.to_nx_graph() self.figsize = figsize self.node_size = node_size - self.edge_width = edge_width + self.pipe_width = pipe_width self.node_color = node_color - self.edge_color = edge_color + self.pipe_color = pipe_color self.positions = {node_id: np.array([data['lon'], data['lat']]) for node_id, data in self.graph.nodes(data=True)} self.extent = self._get_extent() @@ -218,9 +218,9 @@ def _get_extent(self): return extent def draw(self, bgcolor='w', no_axis=False, background_map=False, - use_geom=False, edge_color='b', edge_linewidth=2, - edge_alpha=1, node_size=40, node_color='r', node_alpha=1, - node_edgecolor='r', node_zorder=1): + use_geom=False, pipe_color='b', pipe_linewidth=2, + pipe_alpha=1, node_size=40, node_color='r', node_alpha=1, + node_pipecolor='r', node_zorder=1): """ This function has been adapted from osmnx plots.plot_graph() function. """ @@ -250,7 +250,7 @@ def draw(self, bgcolor='w', no_axis=False, background_map=False, xs, ys = data['geometry'].xy lines.append(list(zip(xs, ys))) else: - # if it doesn't have a geometry attribute, the edge is a straight + # if it doesn't have a geometry attribute, the pipe is a straight # line from node to node x1 = self.graph.nodes[u]['lon'] y1 = self.graph.nodes[u]['lat'] @@ -261,9 +261,9 @@ def draw(self, bgcolor='w', no_axis=False, background_map=False, # add the lines to the axis as a linecollection lc = collections.LineCollection(lines, - colors=edge_color, - linewidths=edge_linewidth, - alpha=edge_alpha, + colors=pipe_color, + linewidths=pipe_linewidth, + alpha=pipe_alpha, zorder=2) ax.add_collection(lc) @@ -275,7 +275,7 @@ def draw(self, bgcolor='w', no_axis=False, background_map=False, s=node_size, c=node_color, alpha=node_alpha, - edgecolor=node_edgecolor, + edgecolor=node_pipecolor, zorder=node_zorder) if no_axis: From fd8f07f40ed2963397710c26a40f8ac1ec81f0b5 Mon Sep 17 00:00:00 2001 From: Marie Gering Date: Mon, 10 Aug 2020 18:09:36 +0200 Subject: [PATCH 02/10] Rename edge to pipe in directory docs --- docs/examples.rst | 6 +++--- docs/network.rst | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/examples.rst b/docs/examples.rst index 2c596827..1d645f85 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -17,7 +17,7 @@ Create a thermal network thermal_network.add('Consumer', id=0, lat=50, lon=10) - thermal_network.add('Edge', id=0, from_node='producer-0', to_node='consumer-0') + thermal_network.add('Pipe', id=0, from_node='producer-0', to_node='consumer-0') print(thermal_network) @@ -25,9 +25,9 @@ Create a thermal network # dhnx.network.ThermalNetwork object with these components # * 1 producers # * 1 consumers - # * 1 edges + # * 1 pipes - print(thermal_network.components.edges) + print(thermal_network.components.pipes) # returns # from_node to_node diff --git a/docs/network.rst b/docs/network.rst index cd70b7b2..26b21edc 100644 --- a/docs/network.rst +++ b/docs/network.rst @@ -46,7 +46,7 @@ Producers are described with the following attributes: Fork ==== -Forks are the nodes where several edges of the network meet. +Forks are the nodes where several pipes of the network meet. Forks have the attributes described in the following table: .. csv-table:: @@ -54,12 +54,12 @@ Forks have the attributes described in the following table: :file: ../dhnx/component_attrs/forks.csv -Edge +Pipe ==== -Edges represent the feed and return pipes connecting the different nodes of the network. +Pipes imply the feed and return pipes connecting the different nodes of the network. They are characterized by these attributes: .. csv-table:: :header-rows: 1 - :file: ../dhnx/component_attrs/edges.csv \ No newline at end of file + :file: ../dhnx/component_attrs/pipes.csv \ No newline at end of file From 18c264121d6e85753a85b0a210960bad603f9a90 Mon Sep 17 00:00:00 2001 From: Marie Gering Date: Mon, 10 Aug 2020 19:01:46 +0200 Subject: [PATCH 03/10] Rename edge to pipe in directory examples --- .../data_csv_input/{edges.csv => pipes.csv} | 0 examples/import_osmnx/import_osmnx.py | 16 ++++++++-------- examples/optimisation/investment_input/edges.csv | 16 ---------------- examples/optimisation/investment_input/pipes.csv | 16 ++++++++++++++++ ...ure_inlet.csv => pipes-temperature_inlet.csv} | 0 ...e_return.csv => pipes-temperature_return.csv} | 0 examples/optimisation/operation_input/edges.csv | 7 ------- examples/optimisation/operation_input/pipes.csv | 7 +++++++ ...ure_inlet.csv => pipes-temperature_inlet.csv} | 0 ...e_return.csv => pipes-temperature_return.csv} | 0 .../results_investment/{edges.csv => pipes.csv} | 2 +- .../{edges-heat_flow.csv => pipes-heat_flow.csv} | 0 ...ges-heat_losses.csv => pipes-heat_losses.csv} | 0 .../{edges-mass_flow.csv => pipes-mass_flow.csv} | 0 .../results_operation/{edges.csv => pipes.csv} | 0 .../{edges-heat_flow.csv => pipes-heat_flow.csv} | 0 ...ges-heat_losses.csv => pipes-heat_losses.csv} | 0 .../{edges-mass_flow.csv => pipes-mass_flow.csv} | 0 .../results/sequences/edges-mass_flow.csv | 4 ---- .../single_loop/{edges.csv => pipes.csv} | 0 .../simulation/tree/{edges.csv => pipes.csv} | 0 21 files changed, 32 insertions(+), 36 deletions(-) rename examples/import_export_plot/data_csv_input/{edges.csv => pipes.csv} (100%) delete mode 100644 examples/optimisation/investment_input/edges.csv create mode 100644 examples/optimisation/investment_input/pipes.csv rename examples/optimisation/investment_input/sequences/{edges-temperature_inlet.csv => pipes-temperature_inlet.csv} (100%) rename examples/optimisation/investment_input/sequences/{edges-temperature_return.csv => pipes-temperature_return.csv} (100%) delete mode 100644 examples/optimisation/operation_input/edges.csv create mode 100644 examples/optimisation/operation_input/pipes.csv rename examples/optimisation/operation_input/sequences/{edges-temperature_inlet.csv => pipes-temperature_inlet.csv} (100%) rename examples/optimisation/operation_input/sequences/{edges-temperature_return.csv => pipes-temperature_return.csv} (100%) rename examples/optimisation/results_investment/{edges.csv => pipes.csv} (84%) rename examples/optimisation/results_investment/sequences/{edges-heat_flow.csv => pipes-heat_flow.csv} (100%) rename examples/optimisation/results_investment/sequences/{edges-heat_losses.csv => pipes-heat_losses.csv} (100%) rename examples/optimisation/results_investment/sequences/{edges-mass_flow.csv => pipes-mass_flow.csv} (100%) rename examples/optimisation/results_operation/{edges.csv => pipes.csv} (100%) rename examples/optimisation/results_operation/sequences/{edges-heat_flow.csv => pipes-heat_flow.csv} (100%) rename examples/optimisation/results_operation/sequences/{edges-heat_losses.csv => pipes-heat_losses.csv} (100%) rename examples/optimisation/results_operation/sequences/{edges-mass_flow.csv => pipes-mass_flow.csv} (100%) delete mode 100644 examples/simulation/results/sequences/edges-mass_flow.csv rename examples/simulation/single_loop/{edges.csv => pipes.csv} (100%) rename examples/simulation/tree/{edges.csv => pipes.csv} (100%) diff --git a/examples/import_export_plot/data_csv_input/edges.csv b/examples/import_export_plot/data_csv_input/pipes.csv similarity index 100% rename from examples/import_export_plot/data_csv_input/edges.csv rename to examples/import_export_plot/data_csv_input/pipes.csv diff --git a/examples/import_osmnx/import_osmnx.py b/examples/import_osmnx/import_osmnx.py index 2de9384a..d346980d 100644 --- a/examples/import_osmnx/import_osmnx.py +++ b/examples/import_osmnx/import_osmnx.py @@ -48,23 +48,23 @@ # get building data areas = footprints.area -# get nodes and edges from graph -nodes, edges = ox.save_load.graph_to_gdfs(graph) +# get nodes and pipes from graph +nodes, pipes = ox.save_load.graph_to_gdfs(graph) nodes = nodes.loc[:, ['x', 'y', 'geometry']].reset_index() replace_ids = {v: k for k, v in dict(nodes.loc[:, 'index']).items()} nodes = nodes.drop('index', 1) -edges = edges.loc[:, ['u', 'v', 'geometry']] -edges.loc[:, ['u', 'v']] = edges.loc[:, ['u', 'v']].replace(replace_ids) +pipes = pipes.loc[:, ['u', 'v', 'geometry']] +pipes.loc[:, ['u', 'v']] = pipes.loc[:, ['u', 'v']].replace(replace_ids) building_midpoints = gpd.GeoDataFrame(footprints.geometry.centroid, columns=['geometry']) building_midpoints['x'] = building_midpoints.apply(lambda x: x.geometry.x, 1) building_midpoints['y'] = building_midpoints.apply(lambda x: x.geometry.y, 1) building_midpoints = building_midpoints[['x', 'y', 'geometry']] -points, splits, edges = dhnx.dhn_from_osm.connect_points_to_network( - building_midpoints, nodes, edges) +points, splits, pipes = dhnx.dhn_from_osm.connect_points_to_network( + building_midpoints, nodes, pipes) producer = points.loc[[323], :] consumer = points.drop(323) @@ -76,7 +76,7 @@ producer.to_file(os.path.join('data', f'{file_name}_potential_dhn', 'producer.shp')) consumer.to_file(os.path.join('data', f'{file_name}_potential_dhn', 'consumer.shp')) splits.to_file(os.path.join('data', f'{file_name}_potential_dhn', 'splits.shp')) -edges.to_file(os.path.join('data', f'{file_name}_potential_dhn', 'edges.shp')) +pipes.to_file(os.path.join('data', f'{file_name}_potential_dhn', 'pipes.shp')) # plot fig, ax = plt.subplots() @@ -96,6 +96,6 @@ alpha=.3) splits.plot(ax=ax) -edges.plot(ax=ax) +pipes.plot(ax=ax) footprints.plot(ax=ax, alpha=.3) plt.show() diff --git a/examples/optimisation/investment_input/edges.csv b/examples/optimisation/investment_input/edges.csv deleted file mode 100644 index c5969800..00000000 --- a/examples/optimisation/investment_input/edges.csv +++ /dev/null @@ -1,16 +0,0 @@ -id,from_node,to_node,length[m],heat_flow_max,investment_cost[Eur/m],temperature_inlet,temperature_return -0,producers-0,forks-0,200,forks-2,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -1,producers-0,forks-1,200,forks-2,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -2,producers-0,forks-2,200,forks-2,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -3,producers-0,consumers-0,200,forks-2,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -4,producers-0,consumers-1,200,forks-2,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -5,forks-0,forks-1,100,forks-2,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -6,forks-0,forks-2,100,forks-2,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -7,forks-0,consumers-0,100,forks-2,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -8,forks-0,consumers-1,100,forks-2,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -9,forks-1,forks-2,100,forks-2,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -10,forks-1,consumers-0,100,forks-2,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -11,forks-1,consumers-1,100,forks-2,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -12,forks-2,consumers-0,100,forks-2,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -13,forks-2,consumers-1,100,forks-2,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -14,consumers-0,consumers-1,100,forks-2,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return diff --git a/examples/optimisation/investment_input/pipes.csv b/examples/optimisation/investment_input/pipes.csv new file mode 100644 index 00000000..af7c17b4 --- /dev/null +++ b/examples/optimisation/investment_input/pipes.csv @@ -0,0 +1,16 @@ +id,from_node,to_node,length[m],heat_flow_max,investment_cost[Eur/m],temperature_inlet,temperature_return +0,producers-0,forks-0,200,forks-2,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +1,producers-0,forks-1,200,forks-2,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +2,producers-0,forks-2,200,forks-2,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +3,producers-0,consumers-0,200,forks-2,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +4,producers-0,consumers-1,200,forks-2,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +5,forks-0,forks-1,100,forks-2,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +6,forks-0,forks-2,100,forks-2,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +7,forks-0,consumers-0,100,forks-2,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +8,forks-0,consumers-1,100,forks-2,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +9,forks-1,forks-2,100,forks-2,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +10,forks-1,consumers-0,100,forks-2,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +11,forks-1,consumers-1,100,forks-2,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +12,forks-2,consumers-0,100,forks-2,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +13,forks-2,consumers-1,100,forks-2,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +14,consumers-0,consumers-1,100,forks-2,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return diff --git a/examples/optimisation/investment_input/sequences/edges-temperature_inlet.csv b/examples/optimisation/investment_input/sequences/pipes-temperature_inlet.csv similarity index 100% rename from examples/optimisation/investment_input/sequences/edges-temperature_inlet.csv rename to examples/optimisation/investment_input/sequences/pipes-temperature_inlet.csv diff --git a/examples/optimisation/investment_input/sequences/edges-temperature_return.csv b/examples/optimisation/investment_input/sequences/pipes-temperature_return.csv similarity index 100% rename from examples/optimisation/investment_input/sequences/edges-temperature_return.csv rename to examples/optimisation/investment_input/sequences/pipes-temperature_return.csv diff --git a/examples/optimisation/operation_input/edges.csv b/examples/optimisation/operation_input/edges.csv deleted file mode 100644 index a29890ff..00000000 --- a/examples/optimisation/operation_input/edges.csv +++ /dev/null @@ -1,7 +0,0 @@ -id,from_node,to_node,length[m],heat_flow_max,investment_cost[Eur/m],temperature_inlet,temperature_return -0,producers-0,forks-0,200,3,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -5,forks-0,forks-1,100,3,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -6,forks-0,forks-2,100,3,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -9,forks-1,forks-2,100,3,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -10,forks-1,consumers-0,100,3,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return -13,forks-2,consumers-1,100,3,2000,sequences/edges/temperature_inlet,sequences/edges/temperature_return diff --git a/examples/optimisation/operation_input/pipes.csv b/examples/optimisation/operation_input/pipes.csv new file mode 100644 index 00000000..56fb4b05 --- /dev/null +++ b/examples/optimisation/operation_input/pipes.csv @@ -0,0 +1,7 @@ +id,from_node,to_node,length[m],heat_flow_max,investment_cost[Eur/m],temperature_inlet,temperature_return +0,producers-0,forks-0,200,3,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +5,forks-0,forks-1,100,3,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +6,forks-0,forks-2,100,3,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +9,forks-1,forks-2,100,3,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +10,forks-1,consumers-0,100,3,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return +13,forks-2,consumers-1,100,3,2000,sequences/pipes/temperature_inlet,sequences/pipes/temperature_return diff --git a/examples/optimisation/operation_input/sequences/edges-temperature_inlet.csv b/examples/optimisation/operation_input/sequences/pipes-temperature_inlet.csv similarity index 100% rename from examples/optimisation/operation_input/sequences/edges-temperature_inlet.csv rename to examples/optimisation/operation_input/sequences/pipes-temperature_inlet.csv diff --git a/examples/optimisation/operation_input/sequences/edges-temperature_return.csv b/examples/optimisation/operation_input/sequences/pipes-temperature_return.csv similarity index 100% rename from examples/optimisation/operation_input/sequences/edges-temperature_return.csv rename to examples/optimisation/operation_input/sequences/pipes-temperature_return.csv diff --git a/examples/optimisation/results_investment/edges.csv b/examples/optimisation/results_investment/pipes.csv similarity index 84% rename from examples/optimisation/results_investment/edges.csv rename to examples/optimisation/results_investment/pipes.csv index e6e615ae..28cfdd8b 100644 --- a/examples/optimisation/results_investment/edges.csv +++ b/examples/optimisation/results_investment/pipes.csv @@ -1,4 +1,4 @@ -edge_id,from_node,to_node,built +pipe_id,from_node,to_node,built 0,0,1,True 1,0,2,True 2,0,3,True diff --git a/examples/optimisation/results_investment/sequences/edges-heat_flow.csv b/examples/optimisation/results_investment/sequences/pipes-heat_flow.csv similarity index 100% rename from examples/optimisation/results_investment/sequences/edges-heat_flow.csv rename to examples/optimisation/results_investment/sequences/pipes-heat_flow.csv diff --git a/examples/optimisation/results_investment/sequences/edges-heat_losses.csv b/examples/optimisation/results_investment/sequences/pipes-heat_losses.csv similarity index 100% rename from examples/optimisation/results_investment/sequences/edges-heat_losses.csv rename to examples/optimisation/results_investment/sequences/pipes-heat_losses.csv diff --git a/examples/optimisation/results_investment/sequences/edges-mass_flow.csv b/examples/optimisation/results_investment/sequences/pipes-mass_flow.csv similarity index 100% rename from examples/optimisation/results_investment/sequences/edges-mass_flow.csv rename to examples/optimisation/results_investment/sequences/pipes-mass_flow.csv diff --git a/examples/optimisation/results_operation/edges.csv b/examples/optimisation/results_operation/pipes.csv similarity index 100% rename from examples/optimisation/results_operation/edges.csv rename to examples/optimisation/results_operation/pipes.csv diff --git a/examples/optimisation/results_operation/sequences/edges-heat_flow.csv b/examples/optimisation/results_operation/sequences/pipes-heat_flow.csv similarity index 100% rename from examples/optimisation/results_operation/sequences/edges-heat_flow.csv rename to examples/optimisation/results_operation/sequences/pipes-heat_flow.csv diff --git a/examples/optimisation/results_operation/sequences/edges-heat_losses.csv b/examples/optimisation/results_operation/sequences/pipes-heat_losses.csv similarity index 100% rename from examples/optimisation/results_operation/sequences/edges-heat_losses.csv rename to examples/optimisation/results_operation/sequences/pipes-heat_losses.csv diff --git a/examples/optimisation/results_operation/sequences/edges-mass_flow.csv b/examples/optimisation/results_operation/sequences/pipes-mass_flow.csv similarity index 100% rename from examples/optimisation/results_operation/sequences/edges-mass_flow.csv rename to examples/optimisation/results_operation/sequences/pipes-mass_flow.csv diff --git a/examples/simulation/results/sequences/edges-mass_flow.csv b/examples/simulation/results/sequences/edges-mass_flow.csv deleted file mode 100644 index 19020346..00000000 --- a/examples/simulation/results/sequences/edges-mass_flow.csv +++ /dev/null @@ -1,4 +0,0 @@ -snapshots,0,1,2 -0,0.6799999999999999,0.3400000000000004,0.3400000000000001 -1,0.7999999999999999,0.40000000000000036,0.4000000000000001 -2,0.6,0.3000000000000003,0.30000000000000016 diff --git a/examples/simulation/single_loop/edges.csv b/examples/simulation/single_loop/pipes.csv similarity index 100% rename from examples/simulation/single_loop/edges.csv rename to examples/simulation/single_loop/pipes.csv diff --git a/examples/simulation/tree/edges.csv b/examples/simulation/tree/pipes.csv similarity index 100% rename from examples/simulation/tree/edges.csv rename to examples/simulation/tree/pipes.csv From ec85f402e005c26c8705edc69015e980478170c7 Mon Sep 17 00:00:00 2001 From: Marie Gering Date: Mon, 10 Aug 2020 19:02:05 +0200 Subject: [PATCH 04/10] Rename edge to pipe in directory tests --- .../{edges.csv => pipes.csv} | 0 .../network_import/{edges.csv => pipes.csv} | 0 ...ure_inlet.csv => pipes-temperature_inlet.csv} | 0 ...e_return.csv => pipes-temperature_return.csv} | 0 tests/test_errors.py | 16 ++++++++-------- tests/test_integration.py | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) rename tests/_files/inconsistent_network_import/{edges.csv => pipes.csv} (100%) rename tests/_files/network_import/{edges.csv => pipes.csv} (100%) rename tests/_files/network_import/sequences/{edges-temperature_inlet.csv => pipes-temperature_inlet.csv} (100%) rename tests/_files/network_import/sequences/{edges-temperature_return.csv => pipes-temperature_return.csv} (100%) diff --git a/tests/_files/inconsistent_network_import/edges.csv b/tests/_files/inconsistent_network_import/pipes.csv similarity index 100% rename from tests/_files/inconsistent_network_import/edges.csv rename to tests/_files/inconsistent_network_import/pipes.csv diff --git a/tests/_files/network_import/edges.csv b/tests/_files/network_import/pipes.csv similarity index 100% rename from tests/_files/network_import/edges.csv rename to tests/_files/network_import/pipes.csv diff --git a/tests/_files/network_import/sequences/edges-temperature_inlet.csv b/tests/_files/network_import/sequences/pipes-temperature_inlet.csv similarity index 100% rename from tests/_files/network_import/sequences/edges-temperature_inlet.csv rename to tests/_files/network_import/sequences/pipes-temperature_inlet.csv diff --git a/tests/_files/network_import/sequences/edges-temperature_return.csv b/tests/_files/network_import/sequences/pipes-temperature_return.csv similarity index 100% rename from tests/_files/network_import/sequences/edges-temperature_return.csv rename to tests/_files/network_import/sequences/pipes-temperature_return.csv diff --git a/tests/test_errors.py b/tests/test_errors.py index 563ff6fa..2b230a2a 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -31,9 +31,9 @@ # thermal_network.producers['node_id'] = np.float(thermal_network.producers['node_id']) # # -# def test_datatype_param_edges(): +# def test_datatype_param_pipes(): # with pytest.raises(TypeError): -# thermal_network.edges['edge_id'] = np.float(thermal_network.edges['edge_id']) +# thermal_network.pipes['pipe_id'] = np.float(thermal_network.pipes['pipe_id']) # # # def test_required_param_nodes(): @@ -41,9 +41,9 @@ # thermal_network.producers = thermal_network.producers.drop('lat', axis=1) # # -# def test_required_param_edges(): +# def test_required_param_pipes(): # with pytest.raises(ValueError): -# thermal_network.edges = thermal_network.edges.drop('from_node', axis=1) +# thermal_network.pipes = thermal_network.pipes.drop('from_node', axis=1) # # # def test_is_consistent_nodes(): @@ -51,14 +51,14 @@ # thermal_network.producers = thermal_network.producers # # -# def test_is_consistent_edges(): +# def test_is_consistent_pipes(): # with pytest.raises(ValueError): -# thermal_network.edges.loc[0] = thermal_network.edges +# thermal_network.pipes.loc[0] = thermal_network.pipes # # # def test_is_consistent_thermal_network(): # with pytest.raises(ValueError): -# thermal_network.edges +# thermal_network.pipes # # # def test_is_consistent_thermal_network_2(): @@ -74,4 +74,4 @@ def test_load_inconsistent_thermal_network(): def test_add(): # missing required attributes with pytest.raises(ValueError): - thermal_network.add('Edge', 10) + thermal_network.add('Pipe', 10) diff --git a/tests/test_integration.py b/tests/test_integration.py index 9f5c45ed..ceca4b3e 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -48,7 +48,7 @@ def test_access_attributes(): assert isinstance(network.components.consumers, pd.DataFrame) - assert isinstance(network.sequences.edges.temperature_return, pd.DataFrame) + assert isinstance(network.sequences.pipes.temperature_return, pd.DataFrame) def test_get_nx_graph(): From 9242581481a6da0ae27e0c13475b81339c9250e4 Mon Sep 17 00:00:00 2001 From: jnnr Date: Mon, 7 Sep 2020 11:34:09 +0200 Subject: [PATCH 05/10] Revert renaming in function for connecting nodes to network --- dhnx/dhn_from_osm.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/dhnx/dhn_from_osm.py b/dhnx/dhn_from_osm.py index 59addfce..6dfd97e1 100644 --- a/dhnx/dhn_from_osm.py +++ b/dhnx/dhn_from_osm.py @@ -18,7 +18,7 @@ from shapely.geometry import LineString -def connect_points_to_network(points, nodes, pipes): +def connect_points_to_network(points, nodes, edges): r""" Parameter @@ -29,8 +29,8 @@ def connect_points_to_network(points, nodes, pipes): nodes : geopandas.GeoDataFrame Nodes of the network - pipes : geopandas.GeoDataFrame - Pipes of the network + edges : geopandas.GeoDataFrame + Edges of the network Returns ------- @@ -38,12 +38,14 @@ def connect_points_to_network(points, nodes, pipes): Points connected to the network nodes : geopandas.GeoDataFrame - Nodes of the network + Original nodes of the network and + nearest connecting points on the + network's edges. - Pipes : geopandas.GeoDataFrame - Pipes of the network. + edges : geopandas.GeoDataFrame + Edges of the network. """ - pipes_united = pipes.unary_union + edges_united = edges.unary_union len_nodes = len(nodes) len_points = len(points) @@ -51,20 +53,20 @@ def connect_points_to_network(points, nodes, pipes): # assign ids to new points n_points = [] n_nearest_points = [] - n_pipes = [] + n_edges = [] for i, point in enumerate(points.geometry): id_nearest_point = len_nodes + i id_point = len_nodes + len_points + i - nearest_point = nearest_points(pipes_united, point)[0] + nearest_point = nearest_points(edges_united, point)[0] n_points.append([id_point, point.x, point.y, point]) n_nearest_points.append([id_nearest_point, nearest_point.x, nearest_point.y, nearest_point]) - n_pipes.append([id_point, id_nearest_point, LineString([point, nearest_point])]) + n_edges.append([id_point, id_nearest_point, LineString([point, nearest_point])]) n_points = gpd.GeoDataFrame( n_points, @@ -74,9 +76,9 @@ def connect_points_to_network(points, nodes, pipes): n_nearest_points, columns=['index', 'x', 'y', 'geometry']).set_index('index') - n_pipes = gpd.GeoDataFrame(n_pipes, columns=['u', 'v', 'geometry']) + n_edges = gpd.GeoDataFrame(n_edges, columns=['u', 'v', 'geometry']) joined_nodes = pd.concat([nodes, n_nearest_points], sort=True) - joined_pipes = pd.concat([pipes, n_pipes], sort=True) + joined_edges = pd.concat([edges, n_edges], sort=True) - return n_points, joined_nodes, joined_pipes + return n_points, joined_nodes, joined_edges From 356d31f9b4fb1411834ca3ba2120ccb6591f7bca Mon Sep 17 00:00:00 2001 From: jnnr Date: Mon, 7 Sep 2020 11:39:27 +0200 Subject: [PATCH 06/10] Revert renaming in graph function --- dhnx/graph.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dhnx/graph.py b/dhnx/graph.py index 47c3cd60..6bb8eb71 100644 --- a/dhnx/graph.py +++ b/dhnx/graph.py @@ -29,17 +29,19 @@ def thermal_network_to_nx_graph(thermal_network): """ nx_graph = nx.MultiDiGraph() # TODO: Check if this line can be removed. - pipe_attr = list(thermal_network.components['pipes'].columns) + edges = thermal_network.components['pipes'].copy() - pipe_attr.remove('from_node') + edge_attr = list(edges.columns) - pipe_attr.remove('to_node') + edge_attr.remove('from_node') + + edge_attr.remove('to_node') nx_graph = nx.from_pandas_edgelist( - thermal_network.components['pipes'], + edges, 'from_node', 'to_node', - edge_attr=pipe_attr, + edge_attr=edge_attr, create_using=thermal_network.graph ) From 92bcab1df09e2c02f3311e7d22a4553956d28a1a Mon Sep 17 00:00:00 2001 From: jnnr Date: Mon, 7 Sep 2020 11:42:57 +0200 Subject: [PATCH 07/10] Revert renaming in plotting function --- dhnx/plotting.py | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/dhnx/plotting.py b/dhnx/plotting.py index 5b6c9197..a1766118 100644 --- a/dhnx/plotting.py +++ b/dhnx/plotting.py @@ -40,8 +40,8 @@ class InteractiveMap(): """ def __init__(self, thermal_network): self.node_data = self.collect_node_data(thermal_network) - self.pipe_data = thermal_network.components['pipes'] - self.pipe_data['value'] = 1 + self.edge_data = thermal_network.components.pipes + self.edge_data['value'] = 1 self.node_id = self.node_data.index self.lat = self.node_data['lat'] self.lon = self.node_data['lon'] @@ -168,23 +168,23 @@ def draw(self): ) ).add_to(m) - for i in range(0, len(self.pipe_data)): + for i in range(0, len(self.edge_data)): # linewidth settings - lw_avg = self.pipe_data['value'].mean() - lw = self.pipe_data['value'][i] / lw_avg + lw_avg = self.edge_data['value'].mean() + lw = self.edge_data['value'][i] / lw_avg - fol.PolyLine(locations=[[self.lat[self.pipe_data['from_node'][i]], - self.lon[self.pipe_data['from_node'][i]]], - [self.lat[self.pipe_data['to_node'][i]], - self.lon[self.pipe_data['to_node'][i]]]], + fol.PolyLine(locations=[[self.lat[self.edge_data['from_node'][i]], + self.lon[self.edge_data['from_node'][i]]], + [self.lat[self.edge_data['to_node'][i]], + self.lon[self.edge_data['to_node'][i]]]], color='orange', weight=lw * 3).add_to(m) arrows = self._get_arrows( - locations=[[self.lat[self.pipe_data['from_node'][i]], - self.lon[self.pipe_data['from_node'][i]]], - [self.lat[self.pipe_data['to_node'][i]], - self.lon[self.pipe_data['to_node'][i]]]], + locations=[[self.lat[self.edge_data['from_node'][i]], + self.lon[self.edge_data['from_node'][i]]], + [self.lat[self.edge_data['to_node'][i]], + self.lon[self.edge_data['to_node'][i]]]], color='orange', n_arrows=3) for arrow in arrows: @@ -198,13 +198,13 @@ class StaticMap(): A static map of a network.ThermalNetwork. """ def __init__(self, thermal_network, figsize=(5, 5), node_size=3, - pipe_width=3, node_color='r', pipe_color='g'): + edge_width=3, node_color='r', edge_color='g'): self.graph = thermal_network.to_nx_graph() self.figsize = figsize self.node_size = node_size - self.pipe_width = pipe_width + self.edge_width = edge_width self.node_color = node_color - self.pipe_color = pipe_color + self.edge_color = edge_color self.positions = {node_id: np.array([data['lon'], data['lat']]) for node_id, data in self.graph.nodes(data=True)} self.extent = self._get_extent() @@ -218,9 +218,9 @@ def _get_extent(self): return extent def draw(self, bgcolor='w', no_axis=False, background_map=False, - use_geom=False, pipe_color='b', pipe_linewidth=2, - pipe_alpha=1, node_size=40, node_color='r', node_alpha=1, - node_pipecolor='r', node_zorder=1): + use_geom=False, edge_color='b', edge_linewidth=2, + edge_alpha=1, node_size=40, node_color='r', node_alpha=1, + edgecolor='r', node_zorder=1): """ This function has been adapted from osmnx plots.plot_graph() function. """ @@ -250,7 +250,7 @@ def draw(self, bgcolor='w', no_axis=False, background_map=False, xs, ys = data['geometry'].xy lines.append(list(zip(xs, ys))) else: - # if it doesn't have a geometry attribute, the pipe is a straight + # if it doesn't have a geometry attribute, the edge is a straight # line from node to node x1 = self.graph.nodes[u]['lon'] y1 = self.graph.nodes[u]['lat'] @@ -261,9 +261,9 @@ def draw(self, bgcolor='w', no_axis=False, background_map=False, # add the lines to the axis as a linecollection lc = collections.LineCollection(lines, - colors=pipe_color, - linewidths=pipe_linewidth, - alpha=pipe_alpha, + colors=edge_color, + linewidths=edge_linewidth, + alpha=edge_alpha, zorder=2) ax.add_collection(lc) @@ -275,7 +275,7 @@ def draw(self, bgcolor='w', no_axis=False, background_map=False, s=node_size, c=node_color, alpha=node_alpha, - edgecolor=node_pipecolor, + edgecolor=edgecolor, zorder=node_zorder) if no_axis: From 9b2ef20b945dd25bae367d46290fb6ee0be5bcb5 Mon Sep 17 00:00:00 2001 From: jnnr Date: Mon, 7 Sep 2020 11:50:48 +0200 Subject: [PATCH 08/10] Update and comment deactivated tests --- tests/test_errors.py | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/tests/test_errors.py b/tests/test_errors.py index 2b230a2a..a9444243 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -26,14 +26,16 @@ thermal_network = dhnx.network.ThermalNetwork(dir_import) +# TODO: The assertions that let these tests fail have yet to be implemented. +# # def test_datatype_param_nodes(): # with pytest.raises(TypeError): -# thermal_network.producers['node_id'] = np.float(thermal_network.producers['node_id']) +# thermal_network.producers['id'] = np.float(thermal_network.producers['node_id']) # # # def test_datatype_param_pipes(): # with pytest.raises(TypeError): -# thermal_network.pipes['pipe_id'] = np.float(thermal_network.pipes['pipe_id']) +# thermal_network.pipes['id'] = np.float(thermal_network.pipes['id']) # # # def test_required_param_nodes(): @@ -44,26 +46,6 @@ # def test_required_param_pipes(): # with pytest.raises(ValueError): # thermal_network.pipes = thermal_network.pipes.drop('from_node', axis=1) -# -# -# def test_is_consistent_nodes(): -# with pytest.raises(ValueError): -# thermal_network.producers = thermal_network.producers -# -# -# def test_is_consistent_pipes(): -# with pytest.raises(ValueError): -# thermal_network.pipes.loc[0] = thermal_network.pipes -# -# -# def test_is_consistent_thermal_network(): -# with pytest.raises(ValueError): -# thermal_network.pipes -# -# -# def test_is_consistent_thermal_network_2(): -# with pytest.raises(ValueError): -# thermal_network.producers def test_load_inconsistent_thermal_network(): From ad3db5c40a5cadc704a87e2bbec09cc1500b26f3 Mon Sep 17 00:00:00 2001 From: jnnr Date: Mon, 7 Sep 2020 13:35:12 +0200 Subject: [PATCH 09/10] Revert renaming for osmnx part of the example --- examples/import_osmnx/import_osmnx.py | 34 +++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/examples/import_osmnx/import_osmnx.py b/examples/import_osmnx/import_osmnx.py index d346980d..3a0d7cd7 100644 --- a/examples/import_osmnx/import_osmnx.py +++ b/examples/import_osmnx/import_osmnx.py @@ -8,7 +8,7 @@ except ImportError: print("Need to install osmnx to run this example") -import dhnx +from dhnx.dhn_from_osm import connect_points_to_network # load street network and footprints from osm @@ -48,40 +48,44 @@ # get building data areas = footprints.area -# get nodes and pipes from graph -nodes, pipes = ox.save_load.graph_to_gdfs(graph) +# get nodes and edges from graph +nodes, edges = ox.save_load.graph_to_gdfs(graph) nodes = nodes.loc[:, ['x', 'y', 'geometry']].reset_index() replace_ids = {v: k for k, v in dict(nodes.loc[:, 'index']).items()} nodes = nodes.drop('index', 1) -pipes = pipes.loc[:, ['u', 'v', 'geometry']] -pipes.loc[:, ['u', 'v']] = pipes.loc[:, ['u', 'v']].replace(replace_ids) +edges = edges.loc[:, ['u', 'v', 'geometry']] +edges.loc[:, ['u', 'v']] = edges.loc[:, ['u', 'v']].replace(replace_ids) building_midpoints = gpd.GeoDataFrame(footprints.geometry.centroid, columns=['geometry']) building_midpoints['x'] = building_midpoints.apply(lambda x: x.geometry.x, 1) building_midpoints['y'] = building_midpoints.apply(lambda x: x.geometry.y, 1) building_midpoints = building_midpoints[['x', 'y', 'geometry']] -points, splits, pipes = dhnx.dhn_from_osm.connect_points_to_network( - building_midpoints, nodes, pipes) +points, forks, pipes = connect_points_to_network( + building_midpoints, nodes, edges) -producer = points.loc[[323], :] -consumer = points.drop(323) +# choose one of the points to be a producer +producer_id = 469 + +producers = points.loc[[producer_id], :] + +consumers = points.drop(producer_id) # save files if not os.path.isdir(os.path.join('data', f'{file_name}_potential_dhn')): os.makedirs(os.path.join('data', f'{file_name}_potential_dhn')) -producer.to_file(os.path.join('data', f'{file_name}_potential_dhn', 'producer.shp')) -consumer.to_file(os.path.join('data', f'{file_name}_potential_dhn', 'consumer.shp')) -splits.to_file(os.path.join('data', f'{file_name}_potential_dhn', 'splits.shp')) +producers.to_file(os.path.join('data', f'{file_name}_potential_dhn', 'producer.shp')) +consumers.to_file(os.path.join('data', f'{file_name}_potential_dhn', 'consumer.shp')) +forks.to_file(os.path.join('data', f'{file_name}_potential_dhn', 'forks.shp')) pipes.to_file(os.path.join('data', f'{file_name}_potential_dhn', 'pipes.shp')) # plot fig, ax = plt.subplots() -producer.plot(ax=ax, color='r') -consumer.plot(ax=ax, color='g') +producers.plot(ax=ax, color='r') +consumers.plot(ax=ax, color='g') for x, y, label in zip(points.geometry.x, points.geometry.y, points.index): ax.annotate(label, xy=(x, y), @@ -95,7 +99,7 @@ textcoords='offset points', alpha=.3) -splits.plot(ax=ax) +forks.plot(ax=ax) pipes.plot(ax=ax) footprints.plot(ax=ax, alpha=.3) plt.show() From a6be89578e5ca1c0bf1634c83f9658e12e50dc64 Mon Sep 17 00:00:00 2001 From: jnnr Date: Tue, 8 Sep 2020 11:01:04 +0200 Subject: [PATCH 10/10] Remove obsolete f-string --- dhnx/network.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhnx/network.py b/dhnx/network.py index 77249425..07dba6c0 100644 --- a/dhnx/network.py +++ b/dhnx/network.py @@ -91,7 +91,7 @@ def __repr__(self): summary += ' * ' + str(count) + ' ' + component + '\n' if summary == '': - return f"empty dhnx.network.ThermalNetwork object containing no components" + return "Empty dhnx.network.ThermalNetwork object containing no components." return f"dhnx.network.ThermalNetwork object with these components\n{summary}"