Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/costs calculation #396

Draft
wants to merge 53 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
34c30b4
Add new reinforce measure in case of voltage issues
birgits Oct 26, 2023
b9d27d8
Add function to get standard line from config
birgits Oct 27, 2023
f82804b
Move splitting of feeder to separate function
birgits Oct 27, 2023
8bc8bea
Minor doc change
birgits Oct 27, 2023
67d2cb3
Add option to keep line_type and number of parallel lines when splitt…
birgits Oct 27, 2023
ebd8172
Change parameter name
birgits Oct 27, 2023
56dddb9
Fix adding parameter to function
birgits Oct 27, 2023
8924e2d
Add function to obtain transformer costs
birgits Oct 28, 2023
8f55efb
Add type_info to new transformers when grid is split
birgits Oct 28, 2023
6b6b75b
Use minimum of quantity added and parallel lines because sometimes li…
birgits Oct 28, 2023
1a2aed1
Bug fix not all transformer changes have station in name
birgits Oct 28, 2023
aba6897
Bug fix
birgits Oct 30, 2023
25c5df5
Bug fix add missing parameter
birgits Oct 30, 2023
3fed9d1
Merge branch 'features/home_storage_operation' into wp_flex_changed_r…
birgits Oct 30, 2023
c0837d5
Merge branch 'features/home_storage_operation' into wp_flex_changed_r…
birgits Oct 31, 2023
7ea7eb8
Bug fix convert to float64 so that round() does not fail
birgits Oct 31, 2023
097f965
Bug fix create directory for logging
birgits Nov 15, 2023
4dfc1d0
Bug fix create directories recursively
birgits Nov 15, 2023
2973cba
Enable getting electricity time series for status quo for households …
birgits Nov 18, 2023
f3eab58
Add todo
birgits Dec 6, 2023
762dce3
Merge branch 'dev' into wp_flex_changed_reinforcement_2
birgits Dec 20, 2023
5288c7d
Merge branch 'dev' into wp_flex_changed_reinforcement_2
birgits Jan 18, 2024
dc5a3ae
Merge branch 'wp_flex_changed_reinforcement' into wp_flex_changed_rei…
birgits Feb 1, 2024
c31aa38
Revert changes to reinforcement
birgits Feb 1, 2024
9e2f7f5
Revert changes in grid reinforcement
birgits Feb 1, 2024
6a6feb0
Fix voltage level for HV/MV transformers
birgits Feb 1, 2024
39565ce
Fix test as costs calculation changed
birgits Feb 1, 2024
65b82a5
Add test for transformer_expansion_costs
birgits Feb 1, 2024
b674573
Remove adding split lines to equipment changes as there are no additi…
birgits Feb 1, 2024
fb4e655
Use number of parallel lines from line information in lines_df
birgits Feb 1, 2024
5d1c5bd
Bug fix use mvlv_trafos dataframe
birgits Feb 1, 2024
2fde162
Adapt setup_logger tests
birgits Feb 2, 2024
120da33
Fix test - transformer costs were previously not included as transfor…
birgits Feb 2, 2024
d5d4000
Fix tests due to changes costs calculation
birgits Feb 2, 2024
d361a18
Make different runs for linux and windows tests to include runonlinux…
birgits Feb 3, 2024
2b2f143
Make separate test for when logging file is written to user dir as th…
birgits Feb 3, 2024
dd2099d
Add abstract Topology class to allow for a new Topology class contain…
birgits Feb 3, 2024
a3d75e4
Only remove logging file if permission allows it
birgits Feb 3, 2024
56c201f
Bug fix - set up julia whenever linux tests are run
birgits Feb 3, 2024
82019fd
Implement to_csv and from_csv for TopologyBase class
birgits Feb 3, 2024
c7f6d1c
Add runonlinux again as test fails under Windows on github
birgits Feb 3, 2024
2be4d1e
Try running OPF test on Windows
birgits Feb 7, 2024
9edf382
Revert "Try running OPF test on Windows"
birgits Feb 7, 2024
2b1b944
Merge branch 'dev' into features/costs_calculation
birgits Apr 24, 2024
b38a753
Revert changes in topology
birgits Jun 10, 2024
d0cac72
Add to ding0 import and to_csv
birgits Jun 10, 2024
e1fa657
Merge branch 'features/costs_calculation' of github.com:openego/eDisG…
birgits Jun 10, 2024
c17015b
Minor changes
birgits Jun 10, 2024
cc25888
Add charging points getter again
birgits Jun 11, 2024
4f47fbd
Bug fix in case original grid topology is set to None
birgits Jun 12, 2024
0baf18e
Implement getting original grid topology from csv or zip
birgits Jun 12, 2024
c72bc91
Adapt to new matplotlib version
birgits Jun 12, 2024
19b1de4
Add costs function
birgits Sep 18, 2024
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
200 changes: 200 additions & 0 deletions edisgo/flex_opt/costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,203 @@ def transformer_expansion_costs(edisgo_obj, transformer_names=None):
]
)
return costs_df


def grid_expansion_costs_from_diff(edisgo_obj):
"""
Returns grid expansion costs based on a comparison of the original grid topology
and the current grid topology.

The original grid topology is stored in :class:`~.EDisGo`

Parameters
----------

Returns
--------
`pandas.DataFrame<DataFrame>`

"""
edisgo_grid_orig = edisgo_obj.topology.original_grid_topology

buses_orig = edisgo_grid_orig.topology.buses_df.copy()
lines_orig = edisgo_grid_orig.topology.lines_df.copy()

buses = edisgo_obj.topology.buses_df.copy()
lines = edisgo_obj.topology.lines_df.copy()

# get lines that are in grid now but not in original grid - these were either
# added or changed
new_or_changed_or_split_lines = [_ for _ in lines.index if
_ not in lines_orig.index]
# get lines that were in original grid but not in grid now - these were split or
# connected to other bus (when splitting LV grid lines where feeder is split are
# renamed) or removed when component was deleted, e.g. generator decommissioned
removed_lines = [_ for _ in lines_orig.index if _ not in lines.index]
# get lines that are in both grids to check, whether they changed
lines_in_both_grids = [_ for _ in lines_orig.index if _ in lines.index]

# get new buses
new_buses = [_ for _ in buses.index if _ not in buses_orig.index]
# get removed buses - exist when generators were decommisioned or lines aggregated
removed_buses = [_ for _ in buses_orig.index if _ not in buses.index]

# track lines changes
lines_changed = pd.DataFrame()

# check lines in both grids whether they changed - check line type and length and
# add to lines_changed if either changed
lines_tmp = lines.loc[lines_in_both_grids, :]
lines_changed_length = lines_tmp[
lines_orig.loc[lines_in_both_grids, "length"] != lines.loc[
lines_in_both_grids, "length"]]
if not lines_changed_length.empty:
lines_changed = pd.concat([lines_changed, lines_changed_length], axis=0)
lines_changed_type = lines_tmp[
lines_orig.loc[lines_in_both_grids, "type_info"] != lines.loc[
lines_in_both_grids, "type_info"]]
if not lines_changed_type.empty:
lines_changed = pd.concat([lines_changed, lines_changed_type], axis=0)

# check removed lines
for removed_line in removed_lines.copy():
# check whether any of its buses were also removed
if (lines_orig.at[removed_line, "bus0"] in removed_buses) or (
lines_orig.at[removed_line, "bus1"] in removed_buses):
# drop from removed lines
removed_lines.remove(removed_line)

# remaining lines in removed_lines list should be lines that were split
# match each line in removed_lines with lines in new_or_changed_or_split_lines -
# important because these may not lead to additional costs
for removed_line in removed_lines:
# find path between original buses in new grid - all lines on that path
line_bus0 = lines_orig.at[removed_line, "bus0"]
line_bus1 = lines_orig.at[removed_line, "bus1"]
if buses.at[line_bus0, "v_nom"] > 1.0:
graph = edisgo_obj.topology.mv_grid.graph
else:
# check if buses are in same LV grid or not (could happen when grid is
# split)
if int(buses.at[line_bus0, "lv_grid_id"]) == int(
buses.at[line_bus1, "lv_grid_id"]):
graph = edisgo_obj.topology.get_lv_grid(
int(buses.at[line_bus0, "lv_grid_id"])).graph
else:
graph = edisgo_obj.topology.to_graph()
path = nx.shortest_path(graph, line_bus0, line_bus1)
# get lines in path
lines_in_path = lines[lines.bus0.isin(path) & lines.bus1.isin(path)]
# drop these lines from new_or_changed_or_split_lines
for l in lines_in_path.index:
try:
new_or_changed_or_split_lines.remove(l)
except:
logger.debug(f"Line {l} is in path but could not be removed.")
# check whether line type changed or number of parallel lines and add
# to lines_changed
lines_changed_type = lines_in_path[
lines_in_path.type_info != lines_orig.at[removed_line, "type_info"]]
if not lines_changed_type.empty:
# add to lines_changed dataframe
lines_changed = pd.concat([lines_changed, lines_changed_type], axis=0)
# drop from lines_in_path
lines_in_path.drop(index=lines_changed_type.index, inplace=True)
# for num parallel changes only consider additional line in costs
lines_changed_num_parallel = lines_in_path[
lines_in_path.num_parallel != lines_orig.at[removed_line, "num_parallel"]]
if not lines_changed_num_parallel.empty:
# reduce num_parallel by number of parallel lines in original grid
lines_changed_num_parallel["num_parallel"] = lines_changed_num_parallel[
"num_parallel"] - lines_orig.at[
removed_line, "num_parallel"]
lines_changed = pd.concat(
[lines_changed, lines_changed_num_parallel], axis=0
)

# get new buses where new component is directly connected - these are most likely
# not new branch tees where line was split
buses_components_orig = pd.concat(
[edisgo_grid_orig.topology.loads_df.loc[:, ["bus"]],
edisgo_grid_orig.topology.generators_df.loc[:, ["bus"]],
edisgo_grid_orig.topology.storage_units_df.loc[:, ["bus"]]]
)
buses_components = pd.concat(
[edisgo_obj.topology.loads_df.loc[:, ["bus"]],
edisgo_obj.topology.generators_df.loc[:, ["bus"]],
edisgo_obj.topology.storage_units_df.loc[:, ["bus"]]]
)
buses_components_new = list(set([_ for _ in buses_components.bus if
_ not in buses_components_orig.bus and _ in
new_buses]))
new_or_changed_or_split_lines_df = lines.loc[new_or_changed_or_split_lines, :]
added_lines = new_or_changed_or_split_lines_df[
(new_or_changed_or_split_lines_df.bus0.isin(buses_components_new)) | (
new_or_changed_or_split_lines_df.bus1.isin(buses_components_new))]
lines_changed = pd.concat([lines_changed, added_lines], axis=0)

# remove from new_or_changed_or_split_lines
for l in new_or_changed_or_split_lines_df.index:
new_or_changed_or_split_lines.remove(l)

if not len(new_or_changed_or_split_lines) == 0:
logger.warning(
f"new_or_changed_or_split_lines is not empty: "
f"{new_or_changed_or_split_lines}"
)

# determine line costs
lines_changed.drop_duplicates(keep="last", inplace=True, subset=["bus0", "bus1"])
line_costs = line_expansion_costs(edisgo_obj, lines_names=lines_changed.index)
costs_df = pd.DataFrame(
{
"type": lines_changed.type_info,
"total_costs": (line_costs.costs_earthworks +
line_costs.costs_cable * lines_changed.num_parallel),
"length": lines_changed.num_parallel * lines_changed.length,
"quantity": lines_changed.num_parallel,
"voltage_level": line_costs.voltage_level,
},
index=lines_changed.index
)

# add costs for transformers
transformers_orig = pd.concat(
[edisgo_grid_orig.topology.transformers_df.copy(),
edisgo_grid_orig.topology.transformers_hvmv_df.copy()]
)
transformers = pd.concat(
[edisgo_obj.topology.transformers_df.copy(),
edisgo_obj.topology.transformers_hvmv_df.copy()]
)
new_transformers = [_ for _ in transformers.index if
_ not in transformers_orig.index]
transformers_in_both_grids = [_ for _ in transformers_orig.index if
_ in transformers.index]
transformers_changed = transformers.loc[new_transformers, :]
# check transformers in both grids whether they changed - check type_info
# and add to transformers_changed if type changed
transformers_tmp = transformers.loc[transformers_in_both_grids, :]
transformers_changed_type = transformers_tmp[
transformers_orig.loc[transformers_in_both_grids, "type_info"] !=
transformers.loc[
transformers_in_both_grids, "type_info"]]
if not transformers_changed_type.empty:
transformers_changed = pd.concat(
[transformers_changed, transformers_changed_type], axis=0)
transformer_costs = transformer_expansion_costs(
edisgo_obj, transformers_changed.index
)
transformer_costs_df = pd.DataFrame(
{
"type": transformers_changed.type_info,
"total_costs": transformer_costs.costs,
"length": 0.0,
"quantity": 1,
"voltage_level": transformer_costs.voltage_level,
},
index=transformers_changed.index
)
costs_df = pd.concat([costs_df, transformer_costs_df])

return lines_changed, transformers_changed, costs_df
3 changes: 3 additions & 0 deletions edisgo/io/ding0_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,6 @@ def sort_hvmv_transformer_buses(transformers_df):

# check data integrity
edisgo_obj.topology.check_integrity()

# write topology to Topology.original_grid_topology to save original grid topology
edisgo_obj.topology.original_grid_topology = edisgo_obj.topology
Loading
Loading