Skip to content

Commit

Permalink
various improvements for pypsa and amiris loader (#509)
Browse files Browse the repository at this point in the history
Fix Amiris and PyPSA loaders
This also fixes the deprecation warning in PyPSA
  • Loading branch information
maurerle authored Dec 10, 2024
1 parent 1681b84 commit 30fdd9e
Show file tree
Hide file tree
Showing 18 changed files with 878 additions and 858 deletions.
9 changes: 9 additions & 0 deletions assume/common/forecasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,13 @@ def __init__(
index=self.index, value=price_forecast, name="price_forecast"
)

self.data_dict = {}

for key, value in kwargs.items():
self.data_dict[key] = FastSeries(index=self.index, value=value, name=key)



def __getitem__(self, column: str) -> FastSeries:
"""
Retrieves forecasted values.
Expand Down Expand Up @@ -579,5 +586,7 @@ def __getitem__(self, column: str) -> FastSeries:
return self.demand
elif column == "price_EOM":
return self.price_forecast
elif column in self.data_dict.keys():
return self.data_dict[column]
else:
return FastSeries(value=0.0, index=self.index)
49 changes: 25 additions & 24 deletions assume/common/grid_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def add_generators(
if "marginal_cost" not in gen_c.columns:
gen_c["marginal_cost"] = p_set

network.madd(
network.add(
"Generator",
names=generators.index,
name=generators.index,
bus=generators["node"], # bus to which the generator is connected to
p_nom=generators[
"max_power"
Expand All @@ -49,9 +49,10 @@ def add_generators(
)
else:
# add generators
network.madd(
generators.drop(["p_min_pu", "p_max_pu", "marginal_cost"], axis=1, inplace=True, errors="ignore")
network.add(
"Generator",
names=generators.index,
name=generators.index,
bus=generators["node"], # bus to which the generator is connected to
p_nom=generators[
"max_power"
Expand Down Expand Up @@ -84,18 +85,18 @@ def add_redispatch_generators(
)

# add generators and their sold capacities as load with reversed sign to have fixed feed in
network.madd(
network.add(
"Load",
names=generators.index,
name=generators.index,
bus=generators["node"], # bus to which the generator is connected to
p_set=p_set,
sign=1,
)

# add upward redispatch generators
network.madd(
network.add(
"Generator",
names=generators.index,
name=generators.index,
suffix="_up",
bus=generators["node"], # bus to which the generator is connected to
p_nom=generators["max_power"], # Nominal capacity of the powerplant/generator
Expand All @@ -105,9 +106,9 @@ def add_redispatch_generators(
)

# add downward redispatch generators
network.madd(
network.add(
"Generator",
names=generators.index,
name=generators.index,
suffix="_down",
bus=generators["node"], # bus to which the generator is connected to
p_nom=generators["max_power"], # Nominal capacity of the powerplant/generator
Expand All @@ -118,18 +119,18 @@ def add_redispatch_generators(
)

# add upward and downward backup generators at each node
network.madd(
network.add(
"Generator",
names=network.buses.index,
name=network.buses.index,
suffix="_backup_up",
bus=network.buses.index, # bus to which the generator is connected to
p_nom=10e4,
marginal_cost=backup_marginal_cost,
)

network.madd(
network.add(
"Generator",
names=network.buses.index,
name=network.buses.index,
suffix="_backup_down",
bus=network.buses.index, # bus to which the generator is connected to
p_nom=10e4,
Expand All @@ -151,9 +152,9 @@ def add_backup_generators(
"""

# add backup generators at each node
network.madd(
network.add(
"Generator",
names=network.buses.index,
name=network.buses.index,
suffix="_backup",
bus=network.buses.index, # bus to which the generator is connected to
p_nom=10e4,
Expand All @@ -174,9 +175,9 @@ def add_loads(
"""

# add loads
network.madd(
network.add(
"Load",
names=loads.index,
name=loads.index,
bus=loads["node"], # bus to which the generator is connected to
**loads,
)
Expand All @@ -201,9 +202,9 @@ def add_redispatch_loads(
del loads_c["sign"]

# add loads with opposite sign (default for loads is -1). This is needed to properly model the redispatch
network.madd(
network.add(
"Load",
names=loads.index,
name=loads.index,
bus=loads["node"], # bus to which the generator is connected to
sign=1,
**loads_c,
Expand Down Expand Up @@ -237,9 +238,9 @@ def add_nodal_loads(
del loads_c["sign"]

# add loads as negative generators
network.madd(
network.add(
"Generator",
names=loads.index,
name=loads.index,
bus=loads["node"], # bus to which the generator is connected to
p_nom=loads["max_power"], # Nominal capacity of the powerplant/generator
p_min_pu=p_set,
Expand All @@ -264,10 +265,10 @@ def read_pypsa_grid(
"""

def add_buses(network: pypsa.Network, buses: pd.DataFrame) -> None:
network.import_components_from_dataframe(buses, "Bus")
network.add("Bus", buses.index, **buses)

def add_lines(network: pypsa.Network, lines: pd.DataFrame) -> None:
network.import_components_from_dataframe(lines, "Line")
network.add("Line", lines.index, **lines)

# setup the network
add_buses(network, grid_dict["buses"])
Expand Down
5 changes: 2 additions & 3 deletions assume/common/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,14 @@ def convert_flows(self, data: dict[tuple[datetime, str], float]):
data, orient="index", columns=["flow"]
).reset_index()
# Split the 'index' column into 'timestamp' and 'line'
df[["timestamp", "line"]] = pd.DataFrame(
df[["datetime", "line"]] = pd.DataFrame(
df["index"].tolist(), index=df.index
)
# Rename the columns
df = df.drop(columns=["index"])

# set timestamp to index
df.set_index("timestamp", inplace=True)
df.set_index("datetime", inplace=True)

df["simulation"] = self.simulation_id

Expand Down Expand Up @@ -480,7 +480,6 @@ async def store_dfs(self):
if df is None:
continue

df.reset_index()
if df.empty:
continue

Expand Down
3 changes: 0 additions & 3 deletions assume/markets/clearing_algorithms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@

# try importing pypsa if it is installed
try:
from .nodal_pricing import NodalMarketRole
from .redispatch import RedispatchMarketRole

clearing_mechanisms["redispatch"] = RedispatchMarketRole
clearing_mechanisms["nodal"] = NodalMarketRole

except ImportError:
pass
Loading

0 comments on commit 30fdd9e

Please sign in to comment.