Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dhnx/input_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def download_footprints(self):

print('Downloading footprints...')

footprints = ox.geometries_from_point(
footprints = ox.features_from_point(
center_point=self.place,
dist=self.distance,
tags={'building': True},
Expand Down
94 changes: 69 additions & 25 deletions examples/optimisation/discrete_DN_numbers/discrete_DN_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,103 @@

For each of the DN numbers a separate row is given in the table.
"""

import os

import matplotlib.pyplot as plt
import dhnx


os.chdir(os.path.dirname(__file__))

# Initialize thermal network
network = dhnx.network.ThermalNetwork()
network = network.from_csv_folder('twn_data')
network = network.from_csv_folder("twn_data")

# Load investment parameter
invest_opt = dhnx.input_output.load_invest_options('invest_data')
invest_opt = dhnx.input_output.load_invest_options("invest_data")

# plot network
static_map = dhnx.plotting.StaticMap(network)
static_map.draw(background_map=False)
plt.title('Given network')
plt.scatter(network.components.consumers['lon'], network.components.consumers['lat'],
color='tab:green', label='consumers', zorder=2.5, s=50)
plt.scatter(network.components.producers['lon'], network.components.producers['lat'],
color='tab:red', label='producers', zorder=2.5, s=50)
plt.scatter(network.components.forks['lon'], network.components.forks['lat'],
color='tab:grey', label='forks', zorder=2.5, s=50)
plt.text(-2, 32, 'P0', fontsize=14)
plt.title("Given network")
plt.scatter(
network.components.consumers["lon"],
network.components.consumers["lat"],
color="tab:green",
label="consumers",
zorder=2.5,
s=50,
)
plt.scatter(
network.components.producers["lon"],
network.components.producers["lat"],
color="tab:red",
label="producers",
zorder=2.5,
s=50,
)
plt.scatter(
network.components.forks["lon"],
network.components.forks["lat"],
color="tab:grey",
label="forks",
zorder=2.5,
s=50,
)
plt.text(-2, 32, "P0", fontsize=14)
plt.legend()
plt.show()

# Execute investment optimization
network.optimize_investment(invest_options=invest_opt)

# ####### Postprocessing and Plotting ###########

# get results
results_edges = network.results.optimization['components']['pipes']
print(results_edges[['from_node', 'to_node', 'hp_type', 'capacity',
'direction', 'costs', 'losses']])
results_edges = network.results.optimization["components"]["pipes"]
print(
results_edges[
["from_node", "to_node", "hp_type", "capacity", "direction", "costs", "losses"]
]
)

# print(results_edges[['invest_costs[€]']].sum())
print('Objective value: ', network.results.optimization['oemof_meta']['objective'])
print("Objective value: ", network.results.optimization["oemof_meta"]["objective"])

# assign new ThermalNetwork with invested pipes
twn_results = network
twn_results.components['pipes'] = results_edges[results_edges['capacity'] > 0.001]
twn_results.components["pipes"] = results_edges[results_edges["capacity"] > 0.001]

# plot invested edges
static_map_2 = dhnx.plotting.StaticMap(twn_results)
static_map_2.draw(background_map=False)
plt.title('Result network')
plt.scatter(network.components.consumers['lon'], network.components.consumers['lat'],
color='tab:green', label='consumers', zorder=2.5, s=50)
plt.scatter(network.components.producers['lon'], network.components.producers['lat'],
color='tab:red', label='producers', zorder=2.5, s=50)
plt.scatter(network.components.forks['lon'], network.components.forks['lat'],
color='tab:grey', label='forks', zorder=2.5, s=50)
plt.text(-2, 32, 'P0', fontsize=14)
for r, c in twn_results.components['pipes'].iterrows():
plt.title("Result network")
plt.scatter(
network.components.consumers["lon"],
network.components.consumers["lat"],
color="tab:green",
label="consumers",
zorder=2.5,
s=50,
)
plt.scatter(
network.components.producers["lon"],
network.components.producers["lat"],
color="tab:red",
label="producers",
zorder=2.5,
s=50,
)
plt.scatter(
network.components.forks["lon"],
network.components.forks["lat"],
color="tab:grey",
label="forks",
zorder=2.5,
s=50,
)
plt.text(-2, 32, "P0", fontsize=14)
for r, c in twn_results.components["pipes"].iterrows():
size = c["hp_type"]
type = c["from_node"].split("-")[0]
id = c["from_node"].split("-")[1]
Expand Down
51 changes: 27 additions & 24 deletions examples/optimisation/invest_with_existing/invest_with_existing.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,63 @@
import matplotlib.pyplot as plt
import dhnx
import os

os.chdir(os.path.dirname(__file__))
# Initialize thermal network
network = dhnx.network.ThermalNetwork()
network = network.from_csv_folder('twn_data')
network = network.from_csv_folder("twn_data")

# general optimisation settings
set = {'num_ts': 3,
'time_res': 1,
'start_date': '1/1/2018',
'frequence': 'H',
'solver': 'cbc',
'solve_kw': {'tee': True},
'simultaneity': 0.8,
'bidirectional_pipes': True,
'print_logging_info': True,
'heat_demand': 'series',
}

invest_opt = dhnx.input_output.load_invest_options('invest_data')
set = {
"num_ts": 3,
"time_res": 1,
"start_date": "1/1/2018",
"frequence": "H",
"solver": "cbc",
"solve_kw": {"tee": True},
"simultaneity": 0.8,
"bidirectional_pipes": True,
"print_logging_info": True,
"heat_demand": "series",
}

invest_opt = dhnx.input_output.load_invest_options("invest_data")

network.optimize_investment(**set, invest_options=invest_opt)

# Draw network
static_map = dhnx.plotting.StaticMap(network)
static_map.draw(background_map=False)
plt.title('Given network')
plt.title("Given network")
plt.show()

# get results
results_edges = network.results.optimization['components']['pipes']
print('*Results*')
results_edges = network.results.optimization["components"]["pipes"]
print("*Results*")
print(results_edges)

# get indices which are existing or invested
ind = results_edges[results_edges['capacity'] > 0].index
ind = results_edges[results_edges["capacity"] > 0].index

edges = network.components['pipes']
ind_exist = list(edges[edges['existing'] == 1].index)
edges = network.components["pipes"]
ind_exist = list(edges[edges["existing"] == 1].index)

# plot existing network
network_exist = network
network_exist.components['pipes'] = edges.loc[ind_exist]
network_exist.components["pipes"] = edges.loc[ind_exist]

# plot existing network
static_map = dhnx.plotting.StaticMap(network_exist)
static_map.draw(background_map=False)
plt.title('Existing pipes')
plt.title("Existing pipes")
plt.show()

# select xisting or invested edges
network_result = network
network_result.components['pipes'] = results_edges.loc[ind]
network_result.components["pipes"] = results_edges.loc[ind]

# plot results network
static_map = dhnx.plotting.StaticMap(network_result)
static_map.draw(background_map=False)
plt.title('Investment result')
plt.title("Investment result")
plt.show()
31 changes: 17 additions & 14 deletions examples/optimisation/minimal_network/minimal_network.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,49 @@
import os

import matplotlib.pyplot as plt
import dhnx


os.chdir(os.path.dirname(__file__))


# Initialize thermal network
network = dhnx.network.ThermalNetwork()
network = network.from_csv_folder('twn_data')
network = network.from_csv_folder("twn_data")

# Load investment parameter
invest_opt = dhnx.input_output.load_invest_options('invest_data')
invest_opt = dhnx.input_output.load_invest_options("invest_data")

# Execute investment optimization
network.optimize_investment(invest_options=invest_opt,
write_lp_file=True)
network.optimize_investment(invest_options=invest_opt, write_lp_file=True)

# ####### Postprocessing and Plotting ###########
# Draw network
static_map = dhnx.plotting.StaticMap(network)
static_map.draw(background_map=False)
plt.title('Given network')
plt.title("Given network")
plt.show()

# get results
results_edges = network.results.optimization['components']['pipes']
print('*Results*')
results_edges = network.results.optimization["components"]["pipes"]
print("*Results*")
print(results_edges)
print('')
print('Objective Value: ',
network.results.optimization['oemof_meta']['objective'])
print("")
print("Objective Value: ", network.results.optimization["oemof_meta"]["objective"])

# manually recalculate total costs
total_costs = (33 * 3.162 + 15 * 1 + 18 * 1 + 18 * 0.5) * 0.5
print('Costs re-calculation: ', total_costs)
print("Costs re-calculation: ", total_costs)

# get indices which are existing or invested
ind = results_edges[results_edges['capacity'] > 0].index
ind = results_edges[results_edges["capacity"] > 0].index

# select invested edges
network_result = network
network_result.components['pipes'] = results_edges.loc[ind]
network_result.components["pipes"] = results_edges.loc[ind]

# plot results network
static_map = dhnx.plotting.StaticMap(network_result)
static_map.draw(background_map=False)
plt.title('Optimization result')
plt.title("Optimization result")
plt.show()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def read(fname):
extras_require={
'cartopy': ['cartopy'],
'geopandas': ['geopandas'],
'osmnx': ['osmnx >= 0.16.1'],
'osmnx': ['osmnx >= 2.0.0'],
"tests": [
"geopandas", "osmnx",
"CoolProp",
Expand Down