Skip to content

Commit

Permalink
Merge branch 'dev' into features/update-module-structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaraBuettner committed Jan 30, 2024
2 parents 586afdc + bcc3f84 commit ab79776
Show file tree
Hide file tree
Showing 16 changed files with 1,005 additions and 202 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
with:
python-version: |
3
3.8
3.9
3.10
3.11
Expand Down
51 changes: 48 additions & 3 deletions etrago/analyze/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import logging
import os

from etrago.execute import import_gen_from_links
from matplotlib import pyplot as plt
from matplotlib.legend_handler import HandlerPatch
from matplotlib.patches import Circle, Ellipse
Expand Down Expand Up @@ -196,6 +197,14 @@ def coloring():
"BEV charger": "indigo",
"BEV_charger": "indigo",
"others": "dimgrey",
"central_coal_CHP": "darkorange",
"central_lignite_CHP": "darkorange",
"central_oil_CHP": "darkorange",
"central_others_CHP": "darkorange",
"industrial_coal_CHP": "darkorange",
"industrial_lignite_CHP": "darkorange",
"industrial_oil_CHP": "darkorange",
"industrial_others_CHP": "darkorange",
}

return colors
Expand Down Expand Up @@ -764,7 +773,7 @@ def curtailment(network, carrier="solar", filename=None):
plt.close()


def calc_dispatch_per_carrier(network, timesteps):
def calc_dispatch_per_carrier(network, timesteps, dispatch_type="total"):
"""Function that calculates dispatch per carrier in given timesteps
Parameters
Expand All @@ -773,13 +782,45 @@ def calc_dispatch_per_carrier(network, timesteps):
Holds topology of grid including results from powerflow analysis
timesteps : array
Timesteps considered in dispatch calculation
dispatch_type: str
This parameter can receive 3 different options: total, ramp_up and
ramp_down. The default is total, which plots the total energy supplied
by carrier by the given timesteps.
Returns
-------
dist : pandas.Series
dispatch per carrier
"""
# up_time_before and down_time_before are irrelevant for this plot but
# create problems when grouping, therefore they are set to 0.
if ("up_time_before" in (network.generators.columns)) | (
"down_time_before" in (network.generators.columns)
):
network.generators["up_time_before"] = 0
network.generators["down_time_before"] = 0

# If ramp_up or ramp_down are passed to the argument dispath_type, all the
# not relevant generators and their time series are discarted.
if dispatch_type in ("ramp_up", "ramp_down"):
if dispatch_type == "ramp_up":
discard_gen = network.generators[
~network.generators.index.str.contains("ramp_up")
].index
discard_gen_l = network.links[
~network.links.index.str.contains("ramp_up")
].index
if dispatch_type == "ramp_down":
discard_gen = network.generators[
~network.generators.index.str.contains("ramp_down")
].index
discard_gen_l = network.links[
~network.links.index.str.contains("ramp_down")
].index
network.mremove("Generator", discard_gen)
network.mremove("Link", discard_gen_l)
network.generators_t.p = network.generators_t.p * -1

import_gen_from_links(network)

Expand Down Expand Up @@ -2334,6 +2375,8 @@ def plot_grid(
* 'h2_battery_storage_expansion': storage expansion per bus and
technology for underground and overground H2 and batteries.
* 'gen_dist': dispatch per carrier in selected timesteps
* 'ramp_up': re-dispatch up per carrier in selected timesteps
* 'ramp_down': re-dispatch down per carrier in selected timesteps
* 'PowerToH2': location and sizes of electrolizers
* 'flexibility_usage': use of DSM and BEV charger
Expand Down Expand Up @@ -2620,9 +2663,11 @@ def plot_grid(
)
bus_legend = "Storage distribution"
bus_unit = "TW"
elif bus_colors == "gen_dist":
elif bus_colors in ("gen_dist", "ramp_up", "ramp_down"):
bus_scaling = bus_sizes
bus_sizes = bus_scaling * calc_dispatch_per_carrier(network, timesteps)
bus_sizes = bus_scaling * calc_dispatch_per_carrier(
network, timesteps, bus_colors
)
bus_legend = "Dispatch"
bus_unit = "TW"
elif bus_colors == "flexibility_usage":
Expand Down
64 changes: 56 additions & 8 deletions etrago/appl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import os
import os.path


__copyright__ = (
"Flensburg University of Applied Sciences, "
"Europa-Universität Flensburg, Centre for Sustainable Energy Systems, "
Expand All @@ -52,12 +51,12 @@
"db": "egon-data", # database session
"gridversion": None, # None for model_draft or Version number
"method": { # Choose method and settings for optimization
"type": "lopf", # type of optimization, currently only 'lopf'
"n_iter": 4, # abort criterion of iterative optimization, 'n_iter' or 'threshold'
"type": "market_grid", # type of optimization, currently only 'lopf'
"n_iter": 1, # abort criterion of iterative optimization, 'n_iter' or 'threshold'
"pyomo": True, # set if pyomo is used for model building
},
"pf_post_lopf": {
"active": True, # choose if perform a pf after lopf
"active": False, # choose if perform a pf after lopf
"add_foreign_lopf": True, # keep results of lopf for foreign DC-links
"q_allocation": "p_nom", # allocate reactive power via 'p_nom' or 'p'
},
Expand Down Expand Up @@ -102,18 +101,18 @@
"generator_noise": 789456, # apply generator noise, False or seed number
"extra_functionality": {}, # Choose function name or {}
# Spatial Complexity:
"delete_dispensable_ac_buses": True, # bool. Find and delete expendable buses
"delete_dispensable_ac_buses": True, # bool. Find and delete expendable buses
"network_clustering_ehv": {
"active": False, # choose if clustering of HV buses to EHV buses is activated
"busmap": False, # False or path to stored busmap
"busmap": False, # False or path to stored busmap
},
"network_clustering": {
"active": True, # choose if clustering is activated
"method": "kmedoids-dijkstra", # choose clustering method: kmeans or kmedoids-dijkstra
"n_clusters_AC": 30, # total number of resulting AC nodes (DE+foreign)
"cluster_foreign_AC": False, # take foreign AC buses into account, True or False
"method_gas": "kmedoids-dijkstra", # choose clustering method: kmeans or kmedoids-dijkstra
"n_clusters_gas": 17, # total number of resulting CH4 nodes (DE+foreign)
"n_clusters_gas": 14, # total number of resulting CH4 nodes (DE+foreign)
"cluster_foreign_gas": False, # take foreign CH4 buses into account, True or False
"k_elec_busmap": False, # False or path/to/busmap.csv
"k_gas_busmap": False, # False or path/to/ch4_busmap.csv
Expand Down Expand Up @@ -674,11 +673,55 @@ def run_etrago(args, json_path):
# adjust network regarding eTraGo setting
etrago.adjust_network()

if etrago.args["scn_name"] == "status2019":
etrago.network.mremove(
"Link",
etrago.network.links[
~etrago.network.links.bus0.isin(etrago.network.buses.index)
].index,
)
etrago.network.mremove(
"Link",
etrago.network.links[
~etrago.network.links.bus1.isin(etrago.network.buses.index)
].index,
)
etrago.network.lines.loc[etrago.network.lines.r == 0.0, "r"] = 10

# delete following unconnected CH4 buses. why are they there?
etrago.network.buses.drop(
etrago.network.buses[
etrago.network.buses.index.isin(["37865", "37870"])
].index,
inplace=True,
)

etrago.network.links.loc[
etrago.network.links.carrier.isin(
["central_gas_chp", "industrial_gas_CHP"]
),
"p_nom",
] *= 1e-3
etrago.network.generators.loc[
etrago.network.generators.carrier.isin(
[
"central_lignite_CHP",
"industrial_lignite_CHP",
"central_oil_CHP",
"industrial_coal_CHP",
"central_coal_CHP",
"industrial_oil_CHP" "central_others_CHP",
]
),
"p_nom",
] *= 1e-3

# ehv network clustering
etrago.ehv_clustering()

# spatial clustering
etrago.spatial_clustering()

etrago.spatial_clustering_gas()

# snapshot clustering
Expand All @@ -688,7 +731,12 @@ def run_etrago(args, json_path):
etrago.skip_snapshots()

# start linear optimal powerflow calculations
etrago.lopf()

etrago.network.storage_units.cyclic_state_of_charge = True

etrago.network.lines.loc[etrago.network.lines.r == 0.0, "r"] = 10

etrago.optimize()

# conduct lopf with full complex timeseries for dispatch disaggregation
etrago.temporal_disaggregation()
Expand Down
Loading

0 comments on commit ab79776

Please sign in to comment.