Skip to content

Commit

Permalink
Merge branch 'dev' into hybit
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosEpia committed Nov 14, 2024
2 parents ec51267 + af4b038 commit e0bee93
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 105 deletions.
8 changes: 5 additions & 3 deletions etrago/analyze/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,16 +842,18 @@ def calc_dispatch_per_carrier(network, timesteps, dispatch_type="total"):
]

dist = pd.Series(
index=pd.MultiIndex.from_tuples(index, names=["bus", "carrier"]),
index=pd.MultiIndex.from_tuples(
index, names=["bus", "carrier"]
).unique(),
dtype=float,
)
).sort_index()

for i in dist.index:
gens = network.generators[
(network.generators.bus == i[0])
& (network.generators.carrier == i[1])
].index
dist[i] = (
dist.loc[i] = (
(
network.generators_t.p[gens].transpose()[
network.snapshots[timesteps]
Expand Down
21 changes: 2 additions & 19 deletions etrago/appl.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,21 +680,6 @@ def run_etrago(args, json_path):
# import network from database
etrago.build_network_from_db()

# drop generators without p_nom
etrago.network.mremove(
"Generator",
etrago.network.generators[
etrago.network.generators.p_nom==0].index
)

# Temporary drop DLR as it is currently not working with sclopf
if (etrago.args["method"]["type"] == "sclopf") & (
not etrago.network.lines_t.s_max_pu.empty):
print("Setting s_max_pu timeseries to 1")
etrago.network.lines_t.s_max_pu = pd.DataFrame(
index=etrago.network.snapshots,
)

# adjust network regarding eTraGo setting
etrago.adjust_network()

Expand All @@ -703,16 +688,15 @@ def run_etrago(args, json_path):

# spatial clustering
etrago.spatial_clustering()

etrago.spatial_clustering_gas()
etrago.network.links.loc[etrago.network.links.carrier=="CH4", "p_nom"] *= 100
etrago.network.generators_t.p_max_pu.where(etrago.network.generators_t.p_max_pu>1e-5, other=0., inplace=True)

# snapshot clustering
etrago.snapshot_clustering()

# skip snapshots
etrago.skip_snapshots()

# start linear optimal powerflow calculations
etrago.optimize()

# conduct lopf with full complex timeseries for dispatch disaggregation
Expand All @@ -722,7 +706,6 @@ def run_etrago(args, json_path):
etrago.pf_post_lopf()

# spatial disaggregation
# needs to be adjusted for new sectors
etrago.spatial_disaggregation()

# calculate central etrago results
Expand Down
18 changes: 9 additions & 9 deletions etrago/cluster/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,20 +433,20 @@ def gas_postprocessing(
},
one_port_strategies={
"Generator": {
"marginal_cost": np.mean,
"capital_cost": np.mean,
"p_nom_max": np.sum,
"p_nom_min": np.sum,
"e_nom_max": np.sum,
"marginal_cost": "mean",
"capital_cost": "mean",
"p_nom_max": "sum",
"p_nom_min": "sum",
"e_nom_max": "sum",
},
"Store": {
"marginal_cost": np.mean,
"capital_cost": np.mean,
"e_nom": np.sum,
"marginal_cost": "mean",
"capital_cost": "mean",
"e_nom": "sum",
"e_nom_max": sum_with_inf,
},
"Load": {
"p_set": np.sum,
"p_set": "sum",
},
},
)
Expand Down
80 changes: 40 additions & 40 deletions etrago/cluster/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,38 +127,38 @@ def strategies_lines():
def strategies_one_ports():
return {
"StorageUnit": {
"marginal_cost": np.mean,
"capital_cost": np.mean,
"efficiency_dispatch": np.mean,
"standing_loss": np.mean,
"efficiency_store": np.mean,
"p_min_pu": np.min,
"marginal_cost": "mean",
"capital_cost": "mean",
"efficiency_dispatch": "mean",
"standing_loss": "mean",
"efficiency_store": "mean",
"p_min_pu": "min",
"p_nom_extendable": ext_storage,
"p_nom_max": sum_with_inf,
},
"Store": {
"marginal_cost": np.mean,
"capital_cost": np.mean,
"standing_loss": np.mean,
"e_nom": np.sum,
"e_nom_min": np.sum,
"marginal_cost": "mean",
"capital_cost": "mean",
"standing_loss": "mean",
"e_nom": "sum",
"e_nom_min": "sum",
"e_nom_max": sum_with_inf,
"e_initial": np.sum,
"e_min_pu": np.mean,
"e_max_pu": np.mean,
"e_initial": "sum",
"e_min_pu": "mean",
"e_max_pu": "mean",
},
}


def strategies_generators():
return {
"p_nom_min": np.min,
"p_nom_min": "min",
"p_nom_max": sum_with_inf,
"weight": np.sum,
"p_nom": np.sum,
"p_nom_opt": np.sum,
"marginal_cost": np.mean,
"capital_cost": np.mean,
"weight": "sum",
"p_nom": "sum",
"p_nom_opt": "sum",
"marginal_cost": "mean",
"capital_cost": "mean",
"e_nom_max": sum_with_inf,
}

Expand All @@ -169,30 +169,30 @@ def strategies_links():
"bus0": _make_consense_links,
"bus1": _make_consense_links,
"carrier": _make_consense_links,
"p_nom": np.sum,
"p_nom": "sum",
"p_nom_extendable": _make_consense_links,
"p_nom_max": sum_with_inf,
"capital_cost": np.mean,
"length": np.mean,
"capital_cost": "mean",
"length": "mean",
"geom": nan_links,
"topo": nan_links,
"type": nan_links,
"efficiency": np.mean,
"p_nom_min": np.sum,
"p_set": np.mean,
"p_min_pu": np.min,
"p_max_pu": np.max,
"marginal_cost": np.mean,
"efficiency": "mean",
"p_nom_min": "sum",
"p_set": "mean",
"p_min_pu": "min",
"p_max_pu": "max",
"marginal_cost": "mean",
"terrain_factor": _make_consense_links,
"p_nom_opt": np.mean,
"p_nom_opt": "mean",
"country": nan_links,
"build_year": np.mean,
"lifetime": np.mean,
"min_up_time": np.mean,
"min_down_time": np.mean,
"up_time_before": np.mean,
"down_time_before": np.mean,
"committable": np.all,
"build_year": "mean",
"lifetime": "mean",
"min_up_time": "mean",
"min_down_time": "mean",
"up_time_before": "mean",
"down_time_before": "mean",
"committable": "all",
}


Expand Down Expand Up @@ -261,7 +261,7 @@ def arrange_dc_bus0_bus1(network):
strategies.pop("topo")
strategies.pop("geom")

new_df = links.groupby(grouper, axis=0).agg(strategies)
new_df = links.groupby(grouper).agg(strategies)
new_df.index = flatten_multiindex(new_df.index).rename("name")
new_df = pd.concat(
[new_df, network.links.loc[~links_agg_b]], axis=0, sort=False
Expand All @@ -281,7 +281,7 @@ def arrange_dc_bus0_bus1(network):
df_agg = df_agg.multiply(
weighting.loc[df_agg.columns], axis=1
)
pnl_df = df_agg.groupby(grouper, axis=1).sum()
pnl_df = df_agg.T.groupby(grouper).sum().T
pnl_df.columns = flatten_multiindex(pnl_df.columns).rename(
"name"
)
Expand Down Expand Up @@ -790,7 +790,7 @@ def kmedoids_dijkstra_clustering(
kmeans.fit(points)

busmap = pd.Series(
data=kmeans.predict(buses.loc[buses_i, ["x", "y"]]),
data=kmeans.predict(buses.loc[buses_i, ["x", "y"]].values),
index=buses_i,
dtype=object,
)
Expand Down
7 changes: 2 additions & 5 deletions etrago/execute/market_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ def optimize_with_rolling_horizon(
n.storage_units.state_of_charge_initial = (
n.storage_units_t.state_of_charge.loc[snapshots[start - 1]]
)
print(i)
# Make sure that state of charge of batteries and pumped hydro
# plants are cyclic over the year by using the state_of_charges
# from the pre_market_model
Expand Down Expand Up @@ -302,7 +301,7 @@ def build_market_model(self):

logger.info("Start market zone specifc clustering")

self.clustering, busmap = postprocessing(
clustering, busmap = postprocessing(
self,
busmap,
busmap_foreign,
Expand All @@ -312,9 +311,7 @@ def build_market_model(self):
apply_on="market_model",
)

self.update_busmap(busmap)

net = self.clustering.network
net = clustering.network
# links_col = net.links.columns
ac = net.lines[net.lines.carrier == "AC"]
str1 = "transshipment_"
Expand Down
Loading

0 comments on commit e0bee93

Please sign in to comment.