Skip to content

Commit

Permalink
Merge branch 'features/#663-update-pypsa-version' into features/marke…
Browse files Browse the repository at this point in the history
…t-simulation
  • Loading branch information
ulfmueller committed Dec 1, 2023
2 parents 66765a7 + 9daf55f commit 30f3882
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 66 deletions.
8 changes: 0 additions & 8 deletions etrago/appl.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,14 +670,6 @@ def run_etrago(args, json_path):

# import network from database
etrago.build_network_from_db()
etrago.network.lines.loc[etrago.network.lines.r == 0, "r"] = 0.0001
etrago.network.transformers.loc[
etrago.network.transformers.r == 0, "r"
] = 0.0001

etrago.network.transformers["v_nom"] = etrago.network.buses.loc[
etrago.network.transformers.bus0.values, "v_nom"
].values

# adjust network regarding eTraGo setting
etrago.adjust_network()
Expand Down
70 changes: 16 additions & 54 deletions etrago/cluster/electrical.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,7 @@ def cluster_on_extra_high_voltage(etrago, busmap, with_time=True):
for one_port in network.one_port_components.copy():
if one_port == "Generator":
custom_strategies = strategies_generators()
import pdb

pdb.set_trace()
else:
custom_strategies = strategies_one_ports().get(one_port, {})
new_df, new_pnl = aggregateoneport(
Expand Down Expand Up @@ -452,6 +450,13 @@ def ehv_clustering(self):
self.update_busmap(busmap)
self.buses_by_country()

# Drop nan values in timeseries after clustering
for c in self.network.iterate_components():
for pnl in c.attrs[
(c.attrs.status == "Output") & (c.attrs.varying)
].index:
c.pnl[pnl] = pd.DataFrame(index=self.network.snapshots)

logger.info("Network clustered to EHV-grid")


Expand Down Expand Up @@ -936,41 +941,12 @@ def calc_availability_factor(gen):
cannot be found in the dictionary, it is assumed to be 1.
"""

if gen["carrier"] in time_dependent:
if gen.name in network.generators_t.p_max_pu.columns:
cf = network.generators_t["p_max_pu"].loc[:, gen.name].mean()
else:
try:
cf = fixed_capacity_fac[gen["carrier"]]
except KeyError:
cf = 1
return cf
cf = network.generators.loc[gen.name, "p_max_pu"]

time_dependent = [
"solar_rooftop",
"solar",
"wind_onshore",
"wind_offshore",
]
fixed_capacity_fac = {
# A value of 1 is given to power plants where its availability
# does not depend on the weather
"industrial_gas_CHP": 1,
"industrial_biomass_CHP": 1,
"biomass": 1,
"central_biomass_CHP": 1,
"central_gas_CHP": 1,
"OCGT": 1,
"other_non_renewable": 1,
"run_of_river": 0.50,
"reservoir": 1,
"gas": 1,
"oil": 1,
"others": 1,
"coal": 1,
"lignite": 1,
"nuclear": 1,
}
return cf

gen = network.generators[network.generators.carrier != "load shedding"][
["bus", "carrier", "p_nom"]
Expand Down Expand Up @@ -1082,26 +1058,12 @@ def run_spatial_clustering(self):
self.network.links.min_down_time.fillna(0, inplace=True)
self.network.links.up_time_before.fillna(0, inplace=True)
self.network.links.down_time_before.fillna(0, inplace=True)
self.network.loads_t.p = pd.DataFrame(index=self.network.snapshots)
self.network.loads_t.q = pd.DataFrame(index=self.network.snapshots)
self.network.stores_t.p = pd.DataFrame(index=self.network.snapshots)
self.network.storage_units_t.p = pd.DataFrame(
index=self.network.snapshots
)
self.network.stores_t.e = pd.DataFrame(index=self.network.snapshots)
self.network.stores_t.q = pd.DataFrame(index=self.network.snapshots)
self.network.stores_t.mu_lower = pd.DataFrame(
index=self.network.snapshots
)
self.network.stores_t.mu_upper = pd.DataFrame(
index=self.network.snapshots
)
self.network.stores_t.mu_energy_balance = pd.DataFrame(
index=self.network.snapshots
)
self.network.storage_units_t.q = pd.DataFrame(
index=self.network.snapshots
)
# Drop nan values in timeseries after clustering
for c in self.network.iterate_components():
for pnl in c.attrs[
(c.attrs.status == "Output") & (c.attrs.varying)
].index:
c.pnl[pnl] = pd.DataFrame(index=self.network.snapshots)

logger.info(
"Network clustered to {} buses with ".format(
Expand Down
2 changes: 1 addition & 1 deletion etrago/execute/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def dispatch_disaggregation(self):
transits = self.network.snapshots[0::slice_len]
if len(transits) > 1:
transits = transits[1:]
if transits[-1] != self.network_tsa.snapshots[-1]:
if transits[-1] != self.network.snapshots[-1]:
transits = transits.insert(
(len(transits)), self.network.snapshots[-1]
)
Expand Down
5 changes: 2 additions & 3 deletions etrago/tools/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -1820,8 +1820,7 @@ def inter_storage_soc_rule(m, s, i):
L. Kotzur et al: 'Time series aggregation for energy system design:
Modeling seasonal storage', 2018, equation no. 19
"""

if i == network.model.candidates[-1]:
if i == network.model.candidates.at(-1):
last_hour = network.cluster["last_hour_RepresentativeDay"][i]
expr = po.Constraint.Skip
else:
Expand Down Expand Up @@ -1849,7 +1848,7 @@ def inter_storage_soc_rule(m, s, i):
return expr

def inter_store_soc_rule(m, s, i):
if i == network.model.candidates[-1]:
if i == network.model.candidates.at(-1):
last_hour = network.cluster["last_hour_RepresentativeDay"][i]
expr = po.Constraint.Skip
else:
Expand Down
11 changes: 11 additions & 0 deletions etrago/tools/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2882,3 +2882,14 @@ def manual_fixes_datamodel(etrago):
etrago.network.links.loc[
etrago.network.links.carrier == "H2_to_CH4", "marginal_cost"
] = 25

# Set r value if missing
etrago.network.lines.loc[etrago.network.lines.r == 0, "r"] = 0.0001
etrago.network.transformers.loc[
etrago.network.transformers.r == 0, "r"
] = 0.0001

# Set vnom of transformers
etrago.network.transformers["v_nom"] = etrago.network.buses.loc[
etrago.network.transformers.bus0.values, "v_nom"
].values

0 comments on commit 30f3882

Please sign in to comment.