Skip to content

Commit

Permalink
Merge pull request #43 from oemof/features/update-naming
Browse files Browse the repository at this point in the history
Features/update naming
  • Loading branch information
jnnr committed Sep 8, 2020
2 parents 6971f83 + a6be895 commit 166a8e5
Show file tree
Hide file tree
Showing 35 changed files with 83 additions and 97 deletions.
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions dhnx/components.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ component_class,list_name,description
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"
4 changes: 3 additions & 1 deletion dhnx/dhn_from_osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def connect_points_to_network(points, nodes, edges):
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.
edges : geopandas.GeoDataFrame
Edges of the network.
Expand Down
6 changes: 4 additions & 2 deletions dhnx/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ 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)
edges = thermal_network.components['pipes'].copy()

edge_attr = list(edges.columns)

edge_attr.remove('from_node')

edge_attr.remove('to_node')

nx_graph = nx.from_pandas_edgelist(
thermal_network.components['edges'],
edges,
'from_node',
'to_node',
edge_attr=edge_attr,
Expand Down
24 changes: 12 additions & 12 deletions dhnx/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down Expand Up @@ -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',
Expand All @@ -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.")
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions dhnx/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ 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 = thermal_network.components.pipes
self.edge_data['value'] = 1
self.node_id = self.node_data.index
self.lat = self.node_data['lat']
Expand Down Expand Up @@ -220,7 +220,7 @@ def _get_extent(self):
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):
edgecolor='r', node_zorder=1):
"""
This function has been adapted from osmnx plots.plot_graph() function.
"""
Expand Down Expand Up @@ -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=edgecolor,
zorder=node_zorder)

if no_axis:
Expand Down
6 changes: 3 additions & 3 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ 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)
# returns
# 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
Expand Down
8 changes: 4 additions & 4 deletions docs/network.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ 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::
:header-rows: 1
: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
:file: ../dhnx/component_attrs/pipes.csv
28 changes: 16 additions & 12 deletions examples/import_osmnx/import_osmnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -63,25 +63,29 @@
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(
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'))
edges.to_file(os.path.join('data', f'{file_name}_potential_dhn', 'edges.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),
Expand All @@ -95,7 +99,7 @@
textcoords='offset points',
alpha=.3)

splits.plot(ax=ax)
edges.plot(ax=ax)
forks.plot(ax=ax)
pipes.plot(ax=ax)
footprints.plot(ax=ax, alpha=.3)
plt.show()
16 changes: 0 additions & 16 deletions examples/optimisation/investment_input/edges.csv

This file was deleted.

16 changes: 16 additions & 0 deletions examples/optimisation/investment_input/pipes.csv
Original file line number Diff line number Diff line change
@@ -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
7 changes: 0 additions & 7 deletions examples/optimisation/operation_input/edges.csv

This file was deleted.

7 changes: 7 additions & 0 deletions examples/optimisation/operation_input/pipes.csv
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 0 additions & 4 deletions examples/simulation/results/sequences/edges-mass_flow.csv

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 8 additions & 26 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,26 @@
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_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['id'] = np.float(thermal_network.pipes['id'])
#
#
# def test_required_param_nodes():
# with pytest.raises(ValueError):
# thermal_network.producers = thermal_network.producers.drop('lat', axis=1)
#
#
# def test_required_param_edges():
# with pytest.raises(ValueError):
# thermal_network.edges = thermal_network.edges.drop('from_node', axis=1)
#
#
# def test_is_consistent_nodes():
# with pytest.raises(ValueError):
# thermal_network.producers = thermal_network.producers
#
#
# def test_is_consistent_edges():
# with pytest.raises(ValueError):
# thermal_network.edges.loc[0] = thermal_network.edges
#
#
# def test_is_consistent_thermal_network():
# with pytest.raises(ValueError):
# thermal_network.edges
#
#
# def test_is_consistent_thermal_network_2():
# def test_required_param_pipes():
# with pytest.raises(ValueError):
# thermal_network.producers
# thermal_network.pipes = thermal_network.pipes.drop('from_node', axis=1)


def test_load_inconsistent_thermal_network():
Expand All @@ -74,4 +56,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)
2 changes: 1 addition & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 166a8e5

Please sign in to comment.